Exemple #1
0
        /// <summary>
        /// Initialises this class with settings for an import or export operation.
        /// </summary>
        /// <param name="DeploymentXml">XML containing settings - this should be initially generated by using the 'Save settings' functionality in the UI.</param>
        /// <param name="DeploymentType">The type of operation to perform.</param>
        public WizardDeployment(XmlTextReader DeploymentXml, DeploymentType DeploymentType)
        {
            trace = new TraceHelper(this);
            Type  = DeploymentType;

            if (DeploymentType == DeploymentType.Export)
            {
                WizardExportSettings weSettings = CollectExportSettings(DeploymentXml);
                ExportSettings = (SPExportSettings)weSettings.Settings;
            }
            if (DeploymentType == DeploymentType.Import)
            {
                WizardImportSettings wiSettings = CollectImportSettings(DeploymentXml);
                ImportSettings = (SPImportSettings)wiSettings.Settings;
            }
        }
Exemple #2
0
        internal static WizardExportSettings CollectExportSettings(XmlTextReader exportSettingsXml)
        {
            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("CollectExportSettings: Entered CollectExportSettings().");
            }

            // create SPExportSettings object..
            SPExportSettings    exportSettings      = new SPExportSettings();
            List <SPObjectData> exportObjectDetails = new List <SPObjectData>();

            if (exportSettingsXml.Name != "ExportSettings")
            {
                exportSettingsXml.Read();
            }

            if (exportSettingsXml.Name == "ExportSettings")
            {
                if (exportSettingsXml.MoveToAttribute("SiteUrl"))
                {
                    exportSettings.SiteUrl = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("ExcludeDependencies"))
                {
                    exportSettings.ExcludeDependencies = bool.Parse(exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("ExportMethod"))
                {
                    exportSettings.ExportMethod =
                        (SPExportMethodType)Enum.Parse(typeof(SPExportMethodType), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("IncludeVersions"))
                {
                    exportSettings.IncludeVersions =
                        (SPIncludeVersions)Enum.Parse(typeof(SPIncludeVersions), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("IncludeSecurity"))
                {
                    exportSettings.IncludeSecurity =
                        (SPIncludeSecurity)Enum.Parse(typeof(SPIncludeSecurity), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("FileCompression"))
                {
                    exportSettings.FileCompression = bool.Parse(exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("FileLocation"))
                {
                    exportSettings.FileLocation = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("BaseFileName"))
                {
                    exportSettings.BaseFileName = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("IncludeSecurity"))
                {
                    exportSettings.IncludeSecurity =
                        (SPIncludeSecurity)Enum.Parse(typeof(SPIncludeSecurity), exportSettingsXml.Value);
                }

                exportSettingsXml.MoveToElement();
            }

            while (exportSettingsXml.Read())
            {
                if (exportSettingsXml.Name == "DeploymentObject")
                {
                    SPExportObject exportObject     = new SPExportObject();
                    SPObjectData   exportObjectData = new SPObjectData();

                    if (exportSettingsXml.MoveToAttribute("Id"))
                    {
                        Guid gID = new Guid(exportSettingsXml.Value);
                        exportObject.Id     = gID;
                        exportObjectData.ID = gID;
                    }
                    if (exportSettingsXml.MoveToAttribute("Type"))
                    {
                        SPDeploymentObjectType type = (SPDeploymentObjectType)
                                                      Enum.Parse(typeof(SPDeploymentObjectType), exportSettingsXml.Value);
                        exportObject.Type           = type;
                        exportObjectData.ObjectType = type;
                    }
                    if (exportSettingsXml.MoveToAttribute("ExcludeChildren"))
                    {
                        bool bExcludeChildren = bool.Parse(exportSettingsXml.Value);
                        exportObject.ExcludeChildren     = bExcludeChildren;
                        exportObjectData.ExcludeChildren = bExcludeChildren;
                    }
                    if (exportSettingsXml.MoveToAttribute("IncludeDescendants"))
                    {
                        SPIncludeDescendants includeDescs = (SPIncludeDescendants)
                                                            Enum.Parse(typeof(SPIncludeDescendants),
                                                                       exportSettingsXml.Value);
                        exportObject.IncludeDescendants     = includeDescs;
                        exportObjectData.IncludeDescendents = includeDescs;
                    }
                    if (exportSettingsXml.MoveToAttribute("Url"))
                    {
                        exportObject.Url     = exportSettingsXml.Value;
                        exportObjectData.Url = exportSettingsXml.Value;
                    }
                    if (exportSettingsXml.MoveToAttribute("Title"))
                    {
                        exportObjectData.Title = exportSettingsXml.Value;
                    }

                    exportSettings.ExportObjects.Add(exportObject);
                    exportObjectDetails.Add(exportObjectData);
                }
            }

            exportSettingsXml.Close();

            // set other properties which aren't tied to values in XML..
            exportSettings.TestRun = false;
            exportSettings.OverwriteExistingDataFile = true;
            exportSettings.LogFilePath = string.Format("{0}\\{1}.Export.log",
                                                       exportSettings.FileLocation, exportSettings.BaseFileName);

            if (traceSwitchStatic.TraceInfo)
            {
                traceStatic.TraceInfo("CollectExportSettings: Using site URL '{0}'.", exportSettings.SiteUrl);
                traceStatic.TraceInfo("CollectExportSettings: Exclude dependencies IDs = '{0}'.", exportSettings.ExcludeDependencies);
                traceStatic.TraceInfo("CollectExportSettings: Export method = '{0}'.", exportSettings.ExportMethod);
                traceStatic.TraceInfo("CollectExportSettings: File location = '{0}'.", exportSettings.FileLocation);
                traceStatic.TraceInfo("CollectExportSettings: Base filename = '{0}'.", exportSettings.BaseFileName);
                traceStatic.TraceInfo("CollectExportSettings: Include versions = '{0}'.", exportSettings.IncludeVersions);
                traceStatic.TraceInfo("CollectExportSettings: Log file path = '{0}'.", exportSettings.LogFilePath);
                traceStatic.TraceInfo("CollectExportSettings: Include security = '{0}'.", exportSettings.IncludeSecurity);
            }

            WizardExportSettings weSettings = new WizardExportSettings(exportSettings, exportObjectDetails);

            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("CollectExportSettings: Leaving CollectExportSettings().");
            }

            return(weSettings);
        }
        private void loadSettings(WizardExportSettings weSettings)
        {
            if (f_traceSwitch.TraceVerbose)
            {
                f_traceHelper.TraceVerbose("loadSettings[SPExportSettings]: Entered.");
            }

            SPExportSettings exportSettings = (SPExportSettings)weSettings.Settings;

            rdoExport.Checked = true;
            txtSiteUrl.Text = exportSettings.SiteUrl;
            chkExcludeDependencies.Checked = exportSettings.ExcludeDependencies;

            cboExportMethod.SelectedIndex = cboExportMethod.FindStringExact(exportSettings.ExportMethod.ToString());
            cboIncludeVersions.SelectedIndex = cboIncludeVersions.FindStringExact(exportSettings.IncludeVersions.ToString());
            cboIncludeSecurity.SelectedIndex = cboIncludeSecurity.FindStringExact(exportSettings.IncludeSecurity.ToString());
            lblExportFolderValue.Text = exportSettings.FileLocation;
            txtExportBaseFilename.Text = exportSettings.BaseFileName;

            if (f_traceSwitch.TraceVerbose)
            {
                f_traceHelper.TraceVerbose("loadSettings[SPExportSettings]: Leaving.");
            }
        }
Exemple #4
0
        internal static WizardExportSettings CollectExportSettings(XmlTextReader exportSettingsXml)
        {
            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("CollectExportSettings: Entered CollectExportSettings().");
            }

            // create SPExportSettings object..
            SPExportSettings exportSettings = new SPExportSettings();
            List<SPObjectData> exportObjectDetails = new List<SPObjectData>();

            if (exportSettingsXml.Name != "ExportSettings")
            {
                exportSettingsXml.Read();
            }

            if (exportSettingsXml.Name == "ExportSettings")
            {
                if (exportSettingsXml.MoveToAttribute("SiteUrl"))
                {
                    exportSettings.SiteUrl = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("ExcludeDependencies"))
                {
                    exportSettings.ExcludeDependencies = bool.Parse(exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("ExportMethod"))
                {
                    exportSettings.ExportMethod =
                        (SPExportMethodType)Enum.Parse(typeof(SPExportMethodType), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("IncludeVersions"))
                {
                    exportSettings.IncludeVersions =
                        (SPIncludeVersions)Enum.Parse(typeof(SPIncludeVersions), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("IncludeSecurity"))
                {
                    exportSettings.IncludeSecurity =
                        (SPIncludeSecurity)Enum.Parse(typeof(SPIncludeSecurity), exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("FileCompression"))
                {
                    exportSettings.FileCompression = bool.Parse(exportSettingsXml.Value);
                }
                if (exportSettingsXml.MoveToAttribute("FileLocation"))
                {
                    exportSettings.FileLocation = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("BaseFileName"))
                {
                    exportSettings.BaseFileName = exportSettingsXml.Value;
                }
                if (exportSettingsXml.MoveToAttribute("IncludeSecurity"))
                {
                    exportSettings.IncludeSecurity =
                        (SPIncludeSecurity)Enum.Parse(typeof(SPIncludeSecurity), exportSettingsXml.Value);
                }

                exportSettingsXml.MoveToElement();
            }

            while (exportSettingsXml.Read())
            {
                if (exportSettingsXml.Name == "DeploymentObject")
                {
                    SPExportObject exportObject = new SPExportObject();
                    SPObjectData exportObjectData = new SPObjectData();

                    if (exportSettingsXml.MoveToAttribute("Id"))
                    {
                        Guid gID = new Guid(exportSettingsXml.Value);
                        exportObject.Id = gID;
                        exportObjectData.ID = gID;
                    }
                    if (exportSettingsXml.MoveToAttribute("Type"))
                    {
                        SPDeploymentObjectType type = (SPDeploymentObjectType)
                            Enum.Parse(typeof(SPDeploymentObjectType), exportSettingsXml.Value);
                        exportObject.Type = type;
                        exportObjectData.ObjectType = type;
                    }
                    if (exportSettingsXml.MoveToAttribute("ExcludeChildren"))
                    {
                        bool bExcludeChildren = bool.Parse(exportSettingsXml.Value);
                        exportObject.ExcludeChildren = bExcludeChildren;
                        exportObjectData.ExcludeChildren = bExcludeChildren;
                    }
                    if (exportSettingsXml.MoveToAttribute("IncludeDescendants"))
                    {
                        SPIncludeDescendants includeDescs = (SPIncludeDescendants)
                                                            Enum.Parse(typeof(SPIncludeDescendants),
                                                                       exportSettingsXml.Value);
                        exportObject.IncludeDescendants = includeDescs;
                        exportObjectData.IncludeDescendents = includeDescs;
                    }
                    if (exportSettingsXml.MoveToAttribute("Url"))
                    {
                        exportObject.Url = exportSettingsXml.Value;
                        exportObjectData.Url = exportSettingsXml.Value;
                    }
                    if (exportSettingsXml.MoveToAttribute("Title"))
                    {
                        exportObjectData.Title = exportSettingsXml.Value;
                    }

                    exportSettings.ExportObjects.Add(exportObject);
                    exportObjectDetails.Add(exportObjectData);
                }
            }
            
            exportSettingsXml.Close();

            // set other properties which aren't tied to values in XML..
            exportSettings.TestRun = false;
            exportSettings.OverwriteExistingDataFile = true;
            exportSettings.LogFilePath = string.Format("{0}\\{1}.Export.log",
                exportSettings.FileLocation, exportSettings.BaseFileName);
            
            if (traceSwitchStatic.TraceInfo)
            {
                traceStatic.TraceInfo("CollectExportSettings: Using site URL '{0}'.", exportSettings.SiteUrl);
                traceStatic.TraceInfo("CollectExportSettings: Exclude dependencies IDs = '{0}'.", exportSettings.ExcludeDependencies);
                traceStatic.TraceInfo("CollectExportSettings: Export method = '{0}'.", exportSettings.ExportMethod);
                traceStatic.TraceInfo("CollectExportSettings: File location = '{0}'.", exportSettings.FileLocation);
                traceStatic.TraceInfo("CollectExportSettings: Base filename = '{0}'.", exportSettings.BaseFileName);
                traceStatic.TraceInfo("CollectExportSettings: Include versions = '{0}'.", exportSettings.IncludeVersions);
                traceStatic.TraceInfo("CollectExportSettings: Log file path = '{0}'.", exportSettings.LogFilePath);
                traceStatic.TraceInfo("CollectExportSettings: Include security = '{0}'.", exportSettings.IncludeSecurity);
            }

            WizardExportSettings weSettings = new WizardExportSettings(exportSettings, exportObjectDetails);

            if (traceSwitchStatic.TraceVerbose)
            {
                traceStatic.TraceVerbose("CollectExportSettings: Leaving CollectExportSettings().");
            }

            return weSettings;
        }
        private void btnLoadSettings_Click(object sender, EventArgs e)
        {

            if (f_traceSwitch.TraceVerbose)
            {
                f_traceHelper.TraceVerbose("btnLoadSettings_Click: Entered.");
            }

            string sPath = string.Empty;

            if (f_dlgLoadSettingsFile.ShowDialog() == DialogResult.OK)
            {
                sPath = f_dlgLoadSettingsFile.FileName;
                if (f_traceSwitch.TraceInfo)
                {
                    f_traceHelper.TraceInfo("btnLoadLoadingSettings_Click: Loading saved settings from '{0}'.", sPath);
                }

                // determine whether we are loading import or export settings, then get SPImportSettings/SPExportSettings, then set controls..

                Byte[] fileBytes = null;
                XmlTextReader xReader = null;
                using (xReader = new XmlTextReader(sPath))
                {
                    xReader.WhitespaceHandling = WhitespaceHandling.None;
                    xReader.MoveToContent();
                    string sXml = xReader.ReadOuterXml();
                    UTF8Encoding encoding = new UTF8Encoding();
                    fileBytes = encoding.GetBytes(sXml);
                }

                WizardOperationSettings settings = null;
                using (MemoryStream settingsMemStream = new MemoryStream(fileBytes))
                {
                    settingsMemStream.Position = 0;

                    using (xReader = new XmlTextReader(settingsMemStream))
                    {
                        settings = WizardDeployment.CollectSettings(xReader);
                    }
                }

                if (settings != null)
                {
                    if (settings is WizardExportSettings)
                    {
                        WizardExportSettings weSettings = (WizardExportSettings)settings;
                        loadSettings(weSettings);
                        f_exportSettings = (SPExportSettings)settings.Settings;
                        f_supplementaryExportSettings = weSettings;
                    }
                    if (settings is WizardImportSettings)
                    {
                        WizardImportSettings wiSettings = (WizardImportSettings)settings;
                        loadSettings(wiSettings);
                    }
                }
                else
                {
                    MessageBox.Show(
                        "Unable to load settings from this file! XML root node was not of type 'ImportSettings' or 'ExportSettings.",
                        "Error loading settings", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                if (f_traceSwitch.TraceInfo)
                {
                    f_traceHelper.TraceInfo("btnLoadSettings_Click: Not loading file, user cancelled out of dialog.");
                }
            }

            if (f_traceSwitch.TraceVerbose)
            {
                f_traceHelper.TraceVerbose("btnLoadSettings_Click: Leaving.");
            }
        }