Пример #1
0
        public bool LoadConfigurationXml(IPageContext pageContext)
        {
            if (pageContext == null)
            {
                throw new ArgumentNullException("pageContext");
            }
            ITemplateContext    templateContext = (ITemplateContext)pageContext;
            TemplateInputConfig templateConfig  = new TemplateInputConfig
            {
                Name        = templateContext.OutputFolder.DisplayName,
                Description = templateContext.OutputFolder.Description,
            };

            GetDiscoveryConfig(templateContext, ref templateConfig);
            GetRunAsAccounts(templateContext, ref templateConfig);
            GetConnectionString(templateContext, ref templateConfig);
            pageContext.ConfigurationXml = XmlHelper.Serialize(templateConfig, false);
            return(true);
        }
Пример #2
0
        private void GetRunAsAccounts(ITemplateContext templateContext, ref TemplateInputConfig templateConfig)
        {
            if (templateContext == null)
            {
                throw new ArgumentNullException("templateContext");
            }

            ManagementPackElementCollection <ManagementPackSecureReferenceOverride> folderItems = SDKHelper.GetFolderItems <ManagementPackSecureReferenceOverride>(this, templateContext.OutputFolder);

            templateConfig.RunAsAccount = string.Empty;

            foreach (ManagementPackSecureReferenceOverride @override in folderItems)
            {
                if (@override.Name.StartsWith(AccountOverrideNamePrefix, StringComparison.OrdinalIgnoreCase))
                {
                    templateConfig.RunAsAccount = @override.Value;
                    break;
                }
            }
        }
Пример #3
0
        private void GetConnectionString(ITemplateContext templateContext, ref TemplateInputConfig templateConfig)
        {
            if (templateContext == null)
            {
                throw new ArgumentNullException("templateContext");
            }
            MatchCollection matchs = null;
            ManagementPackElementCollection <ManagementPackUnitMonitor> folderItems = SDKHelper.GetFolderItems <ManagementPackUnitMonitor>(this, templateContext.OutputFolder);

            foreach (ManagementPackUnitMonitor monitor in folderItems)
            {
                if (monitor.Name.StartsWith(MonitorUnitNamePrefix, StringComparison.OrdinalIgnoreCase))
                {
                    matchs =
                        new Regex(ConnectionStringRegex, RegexOptions.CultureInvariant | RegexOptions.Compiled).Matches(monitor.Configuration);

                    templateConfig.ConnectionString = matchs[0].Groups[1].Value;

                    break;
                }
            }
        }
Пример #4
0
        private void GetDiscoveryConfig(ITemplateContext templateContext, ref TemplateInputConfig templateConfig)
        {
            if (templateContext == null)
            {
                throw new ArgumentNullException("templateContext");
            }
            foreach (ManagementPackDiscovery discovery in SDKHelper.GetFolderItems <ManagementPackDiscovery>(this, templateContext.OutputFolder))
            {
                if (discovery.Name.StartsWith(DiscoveryNamePrefix, StringComparison.OrdinalIgnoreCase))
                {
                    MatchCollection matchs =
                        new Regex(ValueNodeRegex, RegexOptions.CultureInvariant | RegexOptions.Compiled).Matches(discovery.DataSource.Configuration);

                    templateConfig.TemplateIdString = GetTemplateIdString(templateContext);// matchs[0].Groups[1].Value;
                    templateConfig.UniqueID         = matchs[0].Groups[1].Value;
                    templateConfig.Instance         = matchs[1].Groups[1].Value;
                    templateConfig.Database         = matchs[2].Groups[1].Value;
                    templateConfig.QueryName        = matchs[3].Groups[1].Value;
                    templateConfig.StartDay         = matchs[4].Groups[1].Value;
                    templateConfig.EndDay           = matchs[5].Groups[1].Value;
                    templateConfig.SyncTime         = matchs[6].Groups[1].Value;
                    templateConfig.IntervalSeconds  = int.Parse(matchs[7].Groups[1].Value);
                    templateConfig.Query            = matchs[8].Groups[1].Value;
                    templateConfig.DaysOfWeekMask   = int.Parse(matchs[9].Groups[1].Value);
                    templateConfig.GroupName        = matchs[10].Groups[1].Value;
                    templateConfig.Direction        = matchs[11].Groups[1].Value;
                    templateConfig.ErrorMessage     = matchs[12].Groups[1].Value;
                    templateConfig.MetricType       = matchs[13].Groups[1].Value;
                    templateConfig.Samples          = int.Parse(matchs[14].Groups[1].Value);
                    templateConfig.Threshold        = double.Parse(matchs[15].Groups[1].Value);
                    templateConfig.PrincipalName    = matchs[16].Groups[1].Value;


                    return;
                }
            }
            throw new ObjectNotFoundException("my message");
        }