WorkbookPublishSettings.helper_LookUpOwnerId C# (CSharp) Method

helper_LookUpOwnerId() static private method

Looks
static private helper_LookUpOwnerId ( string ownerId, KeyedLookup userLookups ) : string
ownerId string GUID of content owner
userLookups KeyedLookup set we are looking the owner up in
return string
    internal static string helper_LookUpOwnerId(string ownerId, KeyedLookup<SiteUser> userLookups)
    {
        //Sanity test
        AppDiagnostics.Assert(!string.IsNullOrWhiteSpace(ownerId), "blank owner id to look up?");

        string contentOwnerName;
        var contentOwner = userLookups.FindItem(ownerId);
        //This should only ever happen if there is a race condition between getting the list of users, and downloading the content, where a user did not exist when we asked for the list of users
        //Should be very rare
        if (contentOwner == null)
        {
            return UnknownOwnerName;
        }
        return contentOwnerName = contentOwner.Name;
    }

Usage Example

    /// <summary>
    /// Save Datasource metadata in a XML file along-side the workbook file
    /// </summary>
    /// <param name="wb">Information about the workbook we have downloaded</param>
    /// <param name="localDatasourcePath">Local path to the twb/twbx of the workbook</param>
    /// <param name="userLookups">If non-NULL contains the mapping of users/ids so we can look up the owner</param>
    internal static void CreateSettingsFile(SiteDatasource ds, string localDatasourcePath, KeyedLookup <SiteUser> userLookups)
    {
        string contentOwnerName = null; //Start off assuming we have no content owner information

        if (userLookups != null)
        {
            contentOwnerName = WorkbookPublishSettings.helper_LookUpOwnerId(ds.OwnerId, userLookups);
        }

        var xml = System.Xml.XmlWriter.Create(PathForSettingsFile(localDatasourcePath));

        xml.WriteStartDocument();
        xml.WriteStartElement(XmlElement_DatasourceInfo);

        //If we have an owner name, write it out
        if (!string.IsNullOrWhiteSpace(contentOwnerName))
        {
            XmlHelper.WriteValueElement(xml, WorkbookPublishSettings.XmlElement_ContentOwner, contentOwnerName);
        }
        xml.WriteEndElement();     //end: WorkbookInfo
        xml.WriteEndDocument();
        xml.Close();
    }