Exemplo n.º 1
0
        public override bool SavePageConfig()
        {
            IsConfigValid = ValidatePageConfiguration();
            if (!IsConfigValid)
            {
                return(false);
            }
            ConnectionAndQueryConfig config = new ConnectionAndQueryConfig();

            config.TemplateIdString = templateIdString;
            config.Instance         = txtInstanceName.Text;
            config.Database         = Database;
            config.Query            = txtQuery.Text;
            config.UniqueID         = UniqueID;
            config.MetricType       = txtMetricType.Text;
            config.PrincipalName    = principalName;
            if (cmbRunAsAccount.SelectedIndex >= 0)
            {
                config.RunAsAccount = runAsAccountList[cmbRunAsAccount.SelectedIndex].AccountStorageIdString;
            }
            else
            {
                config.RunAsAccount = "01020202020202020202020202020202020202020200000000000000000000000000000000000000";
            }
            config.ConnectionString = txtConnectionString.Text; //providers[cmbProvider.SelectedItem as string];

            OutputConfigurationXml = XmlHelper.Serialize(config, true);
            SetSharedUserData();
            return(true);
        }
Exemplo n.º 2
0
        public override void LoadPageConfig()
        {
            if (IsCreationMode)
            {
                // in create mode init new id
                templateIdString = Guid.NewGuid().ToString("N");
                UniqueID         = Guid.NewGuid().ToString("N");

                cmbDatabase.Enabled = false;
                txtQuery.Enabled    = false;
                btnTest.Enabled     = false;
                rbSQLAuth.Enabled   = false;
                rbWinAuth.Enabled   = false;
            }
            else
            {
                if (string.IsNullOrEmpty(InputConfigurationXml))
                {
                    return;
                }
                try
                {
                    ConnectionAndQueryConfig config        = XmlHelper.Deserialize(InputConfigurationXml, typeof(ConnectionAndQueryConfig), true) as ConnectionAndQueryConfig;
                    Predicate <RunAsAccount> match         = null;
                    Predicate <string>       providerMatch = null;

                    PopulateProvidersComboBox();
                    PopulateRunAsComboBox();

                    templateIdString     = config.TemplateIdString;
                    UniqueID             = config.UniqueID;
                    txtInstanceName.Text = config.Instance;
                    txtQuery.Text        = config.Query;
                    Database             = config.Database;
                    cmbDatabase.Text     = Database;
                    txtMetricType.Text   = config.MetricType;
                    principalName        = config.PrincipalName;

                    //cmbDatabase.Enabled = false;
                    //txtQuery.Enabled = false;
                    //btnTest.Enabled = false;
                    //rbSQLAuth.Enabled = false;
                    //rbWinAuth.Enabled = false;
                    if (string.IsNullOrEmpty(config.RunAsAccount) || config.RunAsAccount == "01020202020202020202020202020202020202020200000000000000000000000000000000000000")
                    {
                        cmbRunAsAccount.SelectedIndex = -1;
                    }
                    else
                    {
                        if (match == null)
                        {
                            match = delegate(RunAsAccount simpleAccount)
                            {
                                return(simpleAccount.AccountStorageIdString.Equals(config.RunAsAccount));
                            };
                        }
                        cmbRunAsAccount.SelectedIndex = runAsAccountList.FindIndex(match);
                        rbSQLAuth.Checked             = true;
                    }

                    if (string.IsNullOrEmpty(config.ConnectionString))
                    {
                        cmbProvider.SelectedIndex = -1;
                    }
                    else
                    {
                        if (providerMatch == null)
                        {
                            providerMatch = delegate(string provider)
                            {
                                return(provider.Equals(config.ConnectionString.Split('=')[1].Split(';')[0]));
                            };
                        }
                        cmbProvider.SelectedIndex = providers.Keys.ToList <string>().FindIndex(providerMatch);
                        txtConnectionString.Text  = config.ConnectionString;
                    }

                    SetSharedUserData();
                }
                catch (ArgumentNullException exception)
                {
                    return;
                }
                catch (InvalidOperationException exception2)
                {
                    return;
                }
            }
            base.IsConfigValid = ValidatePageConfiguration();
            base.LoadPageConfig();
        }