WorkbookPublishSettings.CreateSettingsFile C# (CSharp) 메소드

CreateSettingsFile() 정적인 개인적인 메소드

Save Workbook metadata in a XML file along-side the workbook file
static private CreateSettingsFile ( SiteWorkbook, wb, string localWorkbookPath, KeyedLookup userLookups ) : void
wb SiteWorkbook, Information about the workbook we have downloaded
localWorkbookPath string Local path to the twb/twbx of the workbook
userLookups KeyedLookup If non-NULL contains the mapping of users/ids so we can look up the owner
리턴 void
    internal static void CreateSettingsFile(SiteWorkbook wb, string localWorkbookPath, KeyedLookup<SiteUser> userLookups)
    {
        string contentOwnerName = null; //Start off assuming we have no content owner information
        if(userLookups != null)
        {
            contentOwnerName = helper_LookUpOwnerId(wb.OwnerId, userLookups);
        }

        var xml = System.Xml.XmlWriter.Create(PathForSettingsFile(localWorkbookPath));
        xml.WriteStartDocument();
            xml.WriteStartElement(XmlElement_WorkbookInfo);
            XmlHelper.WriteValueElement(xml, XmlElement_ShowTabsInWorkbook, wb.ShowTabs);

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

Usage Example

예제 #1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="serverName"></param>
    public ICollection <SiteWorkbook> ExecuteRequest()
    {
        var statusLog         = _onlineSession.StatusLog;
        var downloadedContent = new List <SiteWorkbook>();

        var workbooks = _workbooks;

        if (workbooks == null)
        {
            statusLog.AddError("NULL workbooks. Aborting download.");
            return(null);
        }

        //Depending on the HTTP download file type we want different file extensions
        var typeMapper = new DownloadPayloadTypeHelper("twbx", "twb");

        foreach (var contentInfo in workbooks)
        {
            //Local path save the workbook
            string urlDownload = _onlineUrls.Url_WorkbookDownload(_onlineSession, contentInfo);
            statusLog.AddStatus("Starting Workbook download " + contentInfo.Name + " " + contentInfo.ToString());
            try
            {
                //Generate the directory name we want to download into
                var pathToSaveTo = FileIOHelper.EnsureProjectBasedPath(
                    _localSavePath,
                    _downloadToProjectDirectories,
                    contentInfo,
                    this.StatusLog);

                var fileDownloaded       = this.DownloadFile(urlDownload, pathToSaveTo, contentInfo.Name, typeMapper);
                var fileDownloadedNoPath = System.IO.Path.GetFileName(fileDownloaded);
                statusLog.AddStatus("Finished Workbook download " + fileDownloadedNoPath);

                //Add to the list of our downloaded workbooks, and save metadata
                if (!string.IsNullOrWhiteSpace(fileDownloaded))
                {
                    downloadedContent.Add(contentInfo);

                    //Generate the metadata file that has additional server provided information about the workbook
                    if (_generateInfoFile)
                    {
                        WorkbookPublishSettings.CreateSettingsFile(contentInfo, fileDownloaded, _siteUserLookup);
                    }
                }
                else
                {
                    //We should never hit this code; just being defensive
                    statusLog.AddError("Download error, no local file path for downloaded content");
                }
            }
            catch (Exception ex)
            {
                statusLog.AddError("Error during Workbook download " + contentInfo.Name + "\r\n  " + urlDownload + "\r\n  " + ex.ToString());
            }
        } //foreach

        return(downloadedContent);
    }