Umbraco: Set ContinouslyUpdateXmlDiskCache value programatically

I’m working on a site that requires the synchronisation of around 1000 content nodes to MYOB product data daily. In my quest to speed up the process I saw a post by Richard Soetman, developer of the excellent CMSImport package, where he advises to turn off the “ContinouslyUpdateXmlDiskCache” setting in umbracoSettings.config when performing bulk import operations.

I couldn’t find any code on how to do this, and being the .NET newbie that I am, it took me a little while to figure out. Here’s how I did it:

public static void SwitchContinuousUpdateOfXmlCacheState(bool newValue)
{
    if (UmbracoSettings.continouslyUpdateXmlDiskCache == newValue) return;

    var configFilePath = HttpContext.Current.Server.MapPath("~/config/umbracoSettings.config");

    if (File.Exists(configFilePath))
    {
        var umbracoConfig = new XmlDocument();
        umbracoConfig.Load(configFilePath);

        var key = umbracoConfig.SelectSingleNode("//ContinouslyUpdateXmlDiskCache");

        key.InnerText = newValue.ToString();

        umbracoConfig.Save(configFilePath);
    }
}

This way, I can toggle this setting off before performing the import, and then back on again after calling umbraco.library.RefreshContent();

I’m hoping this is the right approach. Feel free to let me know if it isn’t.

Updated: VBScript – Check if current user is a member of a certain group

I found some code to do this out on the net the other day. I’ve modified it a little, and added the part that checks environment variables.

Note: 11th October 2010 – Since this post is so popular, I’ve cleaned up the code a bit and re-posted it below.

Note 2: 21st February 2013 – I’ve updated the script so that it will work with Option Explicit. People who used this would see every check returning “true”. Thanks to “Zounder1” for making me aware of this.

Option Explicit
Dim objShell,grouplistD,ADSPath,userPath,listGroup
On Error Resume Next

set objShell = WScript.CreateObject( "WScript.Shell" )
 
'Calls the isMember function with the specified group to see if the current user
' is a member of that group.
If isMember("GroupNameToCheckGoesHere") Then
       'MsgBox("Is member") ' Do something here if they are a member of the group
    Else
       'MsgBox("Is not member") ' Do something here if they are not a member of the group
End If
 
' *****************************************************
'This function checks to see if the passed group name contains the current
' user as a member. Returns True or False
Function IsMember(groupName)
    If IsEmpty(groupListD) then
        Set groupListD = CreateObject("Scripting.Dictionary")
        groupListD.CompareMode = 1
        ADSPath = EnvString("userdomain") & "/" & EnvString("username")
        Set userPath = GetObject("WinNT://" & ADSPath & ",user")
        For Each listGroup in userPath.Groups
            groupListD.Add listGroup.Name, "-"
        Next
    End if
    IsMember = CBool(groupListD.Exists(groupName))
End Function
' *****************************************************
 
' *****************************************************
'This function returns a particular environment variable's value.
' for example, if you use EnvString("username"), it would return
' the value of %username%.
Function EnvString(variable)
    variable = "%" & variable & "%"
    EnvString = objShell.ExpandEnvironmentStrings(variable)
End Function
' *****************************************************
 
' Clean up
Set objShell = Nothing

Umbraco Google Maps datatype, display with jQuery + GMaps API v3.0

Recently implemented the great Google Maps Datatype by Darren Ferguson in an Umbraco site. I first got the front-end map display working with v2 of the GMaps API and a third party jQuery addon, but I wasn’t happy with the dependency on API keys as this made it annoying to move/copy files around between production, staging, and local dev PCs.

The setup below will show the map if JS in enabled, or a placeholder image if JS is disabled. If it can’t parse the Google Maps Datatype property name, it will show the map centered on its default coordinates.

To display the map in the front-end, I did the following:

  1. Set up the following in its own JS file:
    $.fn.googleMap = function(location,options) {
        var defaults = {
            lat: -33.302959,
            long: 151.419733,
            zoom: 15,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            mapTypeControl: false,
            controls: ['GSmallZoomControl3D']
        };
    
        options = $.extend(defaults, options || {});
      
        if (location) {
            value = $.trim(location);
            var point = location.split(',');
            options.lat = parseFloat(point[0]);
            options.long = parseFloat(point[1]);
            options.zoom = parseFloat(point[2]);
        };
          
        var center = new google.maps.LatLng(options.lat, options.long);
    
        var map = new google.maps.Map(this.get(0), $.extend(options, { center: center }));
    
        var storeMarker = new google.maps.Marker({
            position: center,
            map: map
        });
    };
  2. Included this on the page where I showed the map:
    1. JS:
      <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
      <script type='text/javascript'>
          $(document).ready(function () {
              $('#map_container img').hide();
              $('#map_container').googleMap("<umbraco:Item field="storeLocationMap" runat="server"></umbraco:Item>");
          });
      </script>
    2. HTML:
      <div class="product_image">
         <div id="map_container" class="map_placeholder">
          <img src="../images/NoGoogleMap.png" alt="Could not load store map" style="margin-top:-20px;"/>
        </div>
      </div>