Пример #1
0
        /// <summary>
        /// UnConfigure Features
        /// </summary>
        public static void UnConfigureFeatures()
        {
            frmApply apply = new frmApply(false);

            apply.Text = "UnConfigure Features";
            apply.lblDescription.Text = "Select the features that you would like to remove configuration for";

            if (apply.ShowDialog() == DialogResult.OK)
            {
                var progress = new frmProgress();
                try
                {
                    progress.Show();
                    XmlDocument configDocument = new XmlDocument();
                    configDocument.Load(ConfigurationApplicationContext.s_configFile);
                    int i = 0;
                    foreach (IConfigurationPanel itm in apply.chkActions.CheckedItems)
                    {
                        progress.Status     = (int)((++i / (float)apply.chkActions.CheckedItems.Count) * 100);
                        progress.StatusText = String.Format("Removing Configuration for {0}...", itm.ToString());
                        Application.DoEvents();

                        itm.UnConfigure(configDocument);
                    }
                    configDocument.Save(ConfigurationApplicationContext.s_configFile);
                    progress.StatusText = "Executing post configuration tasks...";
                    Application.DoEvents();
                    ConfigurationApplicationContext.OnConfigurationApplied();
                }
                finally
                {
                    progress.Close();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Deploy
        /// </summary>
        public static void Deploy(StringCollection deploymentList, Dictionary <String, StringCollection> options)
        {
            frmProgress progress = new frmProgress();

            try
            {
                var configurationDom = new XmlDocument();

                if (File.Exists(ConfigurationApplicationContext.s_configFile))
                {
                    configurationDom.Load(ConfigurationApplicationContext.s_configFile);
                }
                else
                {
                    configurationDom.LoadXml(Resources.empty);
                }
                // Configure
                progress.Show();
                int i = 0;
                foreach (var pnl in ConfigurationApplicationContext.s_configurationPanels.FindAll(o => o is IAutoDeployConfigurationPanel && deploymentList.Contains(o.Name)))
                {
                    if (pnl.IsConfigured(configurationDom))
                    {
                        pnl.UnConfigure(configurationDom);
                    }
                    progress.StatusText = String.Format("Configuring {0}...", pnl.ToString());
                    (pnl as IAutoDeployConfigurationPanel).PrepareConfigure(configurationDom, options);
                    progress.Status = (int)((++i / (float)deploymentList.Count) * 100);
                    Application.DoEvents();
                    pnl.Configure(configurationDom);
                }

                // Always applied stuff changes
                foreach (var pnl in ConfigurationApplicationContext.s_configurationPanels.FindAll(o => o is IAlwaysDeployedConfigurationPanel))
                {
                    pnl.Configure(configurationDom);
                }

                configurationDom.Save(ConfigurationApplicationContext.s_configFile);
                progress.StatusText = "Executing post configuration tasks...";
                ConfigurationApplicationContext.OnConfigurationApplied();
            }
            finally
            {
                progress.Close();
            }
        }
Пример #3
0
        /// <summary>
        /// Configure features
        /// </summary>
        public static void ConfigureFeatures()
        {
            frmApply apply = new frmApply(true);

            apply.Text = "Configure Features";
            apply.lblDescription.Text = "Select the features that you would like to apply configuration for";
            if (apply.ShowDialog() == DialogResult.OK)
            {
                var progress = new frmProgress();
                int i        = 0;

                XmlDocument configDocument = new XmlDocument();
                try
                {
                    // Try to make a backup
                    try
                    {
                        File.Copy(ConfigurationApplicationContext.s_configFile, ConfigurationApplicationContext.s_configFile + ".bak." + DateTime.Now.ToString("yyyy-MMM-dd"));
                    }
                    catch (Exception e)
                    {
                        if (MessageBox.Show("The configuration file could not be backed up, would you like to proceed making modifications without a backup?", "Backup failed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            return;
                        }
                    }

                    progress.Show();
                    configDocument.Load(ConfigurationApplicationContext.s_configFile);
                    foreach (IConfigurationPanel itm in apply.chkActions.CheckedItems)
                    {
                        try
                        {
                            if (!itm.Validate(configDocument))
                            {
                                MessageBox.Show(String.Format("Configuration of item '{0}' failed, validation failed", itm), "Validation Failure");
                                continue;
                            }
                        }
                        catch (ConfigurationException e)
                        {
                            MessageBox.Show(String.Format("Configuration of item '{0}' failed, validation failed with reason {1}", itm, e.Message), "Validation Failure");
                            continue;
                        }
                        progress.Status     = (int)((++i / (float)apply.chkActions.CheckedItems.Count) * 100);
                        progress.StatusText = String.Format("Configuring {0}...", itm.ToString());
                        Application.DoEvents();
                        itm.Configure(configDocument);
                    }

                    // Always applied stuff changes
                    foreach (var itm in ConfigurationApplicationContext.s_configurationPanels.FindAll(o => o is IAlwaysDeployedConfigurationPanel))
                    {
                        if (!itm.Validate(configDocument))
                        {
                            MessageBox.Show(String.Format("Configuration of item '{0}' failed, validation failed", itm), "Validation Failure");
                            continue;
                        }
                        itm.Configure(configDocument);
                    }
                    configDocument.Save(ConfigurationApplicationContext.s_configFile);
                    progress.StatusText = "Executing post configuration tasks...";
                    ConfigurationApplicationContext.OnConfigurationApplied();
                }
                catch (Exception ex)
                {
#if DEBUG
                    MessageBox.Show(ex.ToString(), "Error Configuring Service");
#else
                    MessageBox.Show(ex.Message, "Error Configuring Service");
#endif
                    foreach (IConfigurationPanel itm in apply.chkActions.CheckedItems)
                    {
                        progress.Status     = (int)((i-- / (float)ConfigurationApplicationContext.s_configurationPanels.Count) * 100);
                        progress.StatusText = String.Format("Removing Configuration for {0}...", itm.ToString());
                        Application.DoEvents();

                        itm.UnConfigure(configDocument);
                    }

                    return;
                }
                finally
                {
                    progress.Close();
                }
            }
        }