Exemplo n.º 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 (IConfigurableFeature 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();
                }
            }
        }
Exemplo n.º 2
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;

                    EventHandler <ProgressChangedEventArgs> progHandler = (o, e) =>
                    {
                        progress.ActionStatus     = e.ProgressPercentage;
                        progress.ActionStatusText = e.UserState.ToString();
                    };

                    foreach (IConfigurableFeature itm in apply.chkActions.CheckedItems)
                    {
                        if (itm is IReportProgressChanged)
                        {
                            (itm as IReportProgressChanged).ProgressChanged += progHandler;
                        }

                        progress.OverallStatus     = (int)((++i / (float)apply.chkActions.CheckedItems.Count) * 100);
                        progress.OverallStatusText = String.Format("Removing Configuration for {0}...", itm.ToString());
                        Application.DoEvents();

                        itm.UnConfigure(configDocument);

                        if (itm is IReportProgressChanged)
                        {
                            (itm as IReportProgressChanged).ProgressChanged -= progHandler;
                        }
                    }
                    configDocument.Save(ConfigurationApplicationContext.s_configFile);
                    progress.OverallStatusText = "Executing post configuration tasks...";
                    Application.DoEvents();
                    ConfigurationApplicationContext.OnConfigurationApplied();
                }
                finally
                {
                    progress.Close();
                }
            }
        }
Exemplo n.º 3
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 => deploymentList.Contains(o.Name)))
                {
                    if (pnl.IsConfigured(configurationDom))
                    {
                        pnl.UnConfigure(configurationDom);
                    }
                    progress.StatusText = String.Format("Configuring {0}...", pnl.ToString());
                    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.AlwaysConfigure))
                {
                    pnl.Configure(configurationDom);
                }

                configurationDom.Save(ConfigurationApplicationContext.s_configFile);
                progress.StatusText = "Executing post configuration tasks...";
                ConfigurationApplicationContext.OnConfigurationApplied();
            }
            finally
            {
                progress.Close();
            }
        }
Exemplo n.º 4
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);

                    EventHandler <ProgressChangedEventArgs> progHandler = (o, e) =>
                    {
                        progress.ActionStatus     = e.ProgressPercentage;
                        progress.ActionStatusText = e.UserState.ToString();
                    };

                    foreach (IConfigurableFeature itm in apply.chkActions.CheckedItems)
                    {
                        if (itm is IReportProgressChanged)
                        {
                            (itm as IReportProgressChanged).ProgressChanged += progHandler;
                        }

                        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.OverallStatus     = (int)((++i / (float)apply.chkActions.CheckedItems.Count) * 100);
                        progress.OverallStatusText = String.Format("Configuring {0}...", itm.ToString());
                        Application.DoEvents();
                        itm.Configure(configDocument);

                        if (itm is IReportProgressChanged)
                        {
                            (itm as IReportProgressChanged).ProgressChanged -= progHandler;
                        }
                    }

                    // Always applied stuff changes
                    foreach (var itm in ConfigurationApplicationContext.s_configurationPanels.FindAll(o => o.AlwaysConfigure))
                    {
                        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.OverallStatusText = "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 (IConfigurableFeature itm in apply.chkActions.CheckedItems)
                    {
                        progress.OverallStatus     = (int)((i-- / (float)ConfigurationApplicationContext.s_configurationPanels.Count) * 100);
                        progress.OverallStatusText = String.Format("Removing Configuration for {0}...", itm.ToString());
                        Application.DoEvents();

                        itm.UnConfigure(configDocument);
                    }

                    return;
                }
                finally
                {
                    progress.Close();
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Start the configuration process...
        /// </summary>
        private void btnContinue_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            btnContinue.Enabled = false;
            try
            {
                // Start by creating the configuration file
                XmlDocument configFile = new XmlDocument();
                configFile.LoadXml(Resources.Empty);
                IDatabaseProvider conf = cbxProviderType.SelectedItem as IDatabaseProvider;

                // Do an easy config ... first with the connection strings
                foreach (IConfigurableFeature pnl in ConfigurationApplicationContext.s_configurationPanels)
                {
                    if (pnl is IDataboundFeature)
                    {
                        (pnl as IDataboundFeature).ConnectionString = conf.CreateConnectionStringElement(configFile, txtDatabaseAddress.Text, txtUserName.Text, txtPassword.Text, cbxDatabase.SelectedItem.ToString());
                        (pnl as IDataboundFeature).DataProvider     = conf;
                    }
                }

                // Easy or complex?
                if (rdoEasy.Checked)
                {
                    // Save the configuration
                    var progress = new frmProgress();
                    int i        = 0;
                    try
                    {
                        progress.Show();

                        foreach (IConfigurableFeature pnl in ConfigurationApplicationContext.s_configurationPanels)
                        {
                            progress.Status     = (int)((++i / (float)ConfigurationApplicationContext.s_configurationPanels.Count) * 100);
                            progress.StatusText = String.Format("Applying Configuration for {0}...", pnl.ToString());
                            //pnl.EnableConfiguration = true;
                            pnl.EasyConfigure(configFile);
                        }
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        MessageBox.Show(ex.ToString(), "Error Configuring Service");
#else
                        MessageBox.Show(ex.Message, "Error Configuring Service");
#endif
                        foreach (IConfigurableFeature pnl in ConfigurationApplicationContext.s_configurationPanels)
                        {
                            progress.Status     = (int)((i-- / (float)ConfigurationApplicationContext.s_configurationPanels.Count) * 100);
                            progress.StatusText = String.Format("Removing Configuration for {0}...", pnl.ToString());
                            pnl.UnConfigure(configFile);
                        }

                        return;
                    }
                    finally
                    {
                        progress.Close();
                    }
                    configFile.Save(ConfigurationApplicationContext.s_configFile);
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    configFile.Save(ConfigurationApplicationContext.s_configFile);
                    this.DialogResult = DialogResult.OK;
                }

                this.Close();
            }
            finally
            {
                Cursor = Cursors.Default;
                btnContinue.Enabled = true;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Start the configuration process...
        /// </summary>
        private void btnContinue_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            btnContinue.Enabled = false;
            try
            {
                // Start by creating the configuration file
                XmlDocument configFile = new XmlDocument();
                configFile.LoadXml(Resources.Empty);


                // Easy or complex?
                if (rdoEasy.Checked)
                {
                    var connectionString = dbSelector.ConnectionString;
                    connectionString.Name = configFile.CreateConnectionString(connectionString);

                    // Save the configuration
                    var progress = new frmProgress();
                    int i        = 0;

                    EventHandler <ProgressChangedEventArgs> progHandler = (o, ev) =>
                    {
                        progress.ActionStatus     = ev.ProgressPercentage;
                        progress.ActionStatusText = ev.UserState.ToString();
                        Application.DoEvents();
                    };

                    try
                    {
                        progress.Show();

                        connectionString.Provider.ProgressChanged += progHandler;

                        foreach (IConfigurableFeature pnl in ConfigurationApplicationContext.s_configurationPanels)
                        {
                            if (pnl is IReportProgressChanged)
                            {
                                (pnl as IReportProgressChanged).ProgressChanged += progHandler;
                            }

                            progress.OverallStatus     = (int)((++i / (float)ConfigurationApplicationContext.s_configurationPanels.Count) * 100);
                            progress.OverallStatusText = String.Format("Applying Configuration for {0}...", pnl.ToString());
                            //pnl.EnableConfiguration = true;

                            if (pnl is IDataboundFeature)
                            {
                                (pnl as IDataboundFeature).ConnectionString = connectionString;
                                pnl.EasyConfigure(configFile);
                                if (pnl.EnableConfiguration)
                                {
                                    connectionString.Provider.Deploy(pnl as IDataboundFeature, connectionString.Name, configFile);
                                    (pnl as IDataboundFeature).AfterDeploy();
                                }
                            }
                            else
                            {
                                pnl.EasyConfigure(configFile);
                            }


                            if (pnl is IReportProgressChanged)
                            {
                                (pnl as IReportProgressChanged).ProgressChanged -= progHandler;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        MessageBox.Show(ex.ToString(), "Error Configuring Service");
#else
                        MessageBox.Show(ex.Message, "Error Configuring Service");
#endif

                        foreach (IConfigurableFeature pnl in ConfigurationApplicationContext.s_configurationPanels)
                        {
                            if (pnl is IReportProgressChanged)
                            {
                                (pnl as IReportProgressChanged).ProgressChanged += progHandler;
                            }

                            progress.OverallStatus     = (int)((i-- / (float)ConfigurationApplicationContext.s_configurationPanels.Count) * 100);
                            progress.OverallStatusText = String.Format("Removing Configuration for {0}...", pnl.ToString());
                            pnl.UnConfigure(configFile);

                            if (pnl is IDataboundFeature && MessageBox.Show($"Attempt to remove database for {pnl.Name}?", "Confirm Un-Deploy", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                (pnl as IDataboundFeature).ConnectionString = connectionString;
                                if (pnl.EnableConfiguration)
                                {
                                    connectionString.Provider.UnDeploy(pnl as IDataboundFeature, connectionString.Name, configFile);
                                    (pnl as IDataboundFeature).AfterUnDeploy();
                                }
                            }

                            if (pnl is IReportProgressChanged)
                            {
                                (pnl as IReportProgressChanged).ProgressChanged -= progHandler;
                            }
                        }

                        return;
                    }
                    finally
                    {
                        connectionString.Provider.ProgressChanged -= progHandler;
                        progress.Close();
                    }
                    configFile.Save(ConfigurationApplicationContext.s_configFile);
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    configFile.Save(ConfigurationApplicationContext.s_configFile);
                    this.DialogResult = DialogResult.OK;
                }


                new frmUpdate().ShowDialog();

                this.Close();
            }
            finally
            {
                Cursor = Cursors.Default;
                btnContinue.Enabled = true;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Deploy the updates
        /// </summary>
        private void btnOk_Click(object sender, EventArgs e)
        {
            var progress = new frmProgress();
            EventHandler <ProgressChangedEventArgs> progHandler = (o, ev) =>
            {
                if (ev.UserState == null)
                {
                    progress.OverallStatus = ev.ProgressPercentage;
                }
                else
                {
                    progress.ActionStatus     = ev.ProgressPercentage;
                    progress.ActionStatusText = ev.UserState.ToString();
                }
                Application.DoEvents();
            };

            progress.Show();

            int i = 0;

            foreach (IDataboundFeature feature in DatabaseConfiguratorRegistrar.Features)
            {
                try
                {
                    feature.ConnectionString.Provider.ProgressChanged += progHandler;

                    progress.OverallStatus     = (int)((++i / (float)DatabaseConfiguratorRegistrar.Features.Count) * 100);
                    progress.OverallStatusText = String.Format("Applying updates for {0}...", feature.ToString());
                    //pnl.EnableConfiguration = true;

                    // Apply the updates
                    if (feature is IReportProgressChanged)
                    {
                        (feature as IReportProgressChanged).ProgressChanged += progHandler;
                    }

                    try
                    {
                        feature.ConnectionString.Provider.DeployUpdate(lvUpdates.CheckedItems.OfType <ListViewItem>().Select(o => o.Tag as IDataUpdate), feature.ConnectionString);
                        feature.AfterUpdate();
                    }
                    finally
                    {
                        if (feature is IReportProgressChanged)
                        {
                            (feature as IReportProgressChanged).ProgressChanged -= progHandler;
                        }
                    }
                }
                catch (TargetInvocationException ex)
                {
#if DEBUG
                    MessageBox.Show(ex.InnerException?.ToString() ?? ex.ToString(), "Error Configuring Service");
#else
                    MessageBox.Show(ex.InnerException?.Message ?? ex.Message, "Error Configuring Service");
#endif
                }
                catch (Exception ex)
                {
#if DEBUG
                    MessageBox.Show(ex.ToString(), "Error Configuring Service");
#else
                    MessageBox.Show(ex.Message, "Error Configuring Service");
#endif
                }
                finally
                {
                    feature.ConnectionString.Provider.ProgressChanged -= progHandler;
                    progress.Close();
                }
            }

            this.Close();
        }