Exemplo n.º 1
0
        private IEnumerable <ProductRegistry> GetRegistryKeys(string cn)
        {
            var comparer = SmoContext.GetComparer();
            var list     = new List <ProductRegistry>();

            using (var regKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, cn))
            {
                using (RegistryKey baseKey = regKey.OpenSubKey(BASE_KEY))
                {
                    foreach (string key in baseKey.GetSubKeyNames())
                    {
                        for (int i = 0; i < this.InstanceName.Length; i++)
                        {
                            string inst = this.InstanceName[i];
                            if (key.Contains(inst))
                            {
                                ProductRegistry prodReg = GetSetupKeys(inst, key, baseKey);
                                if (prodReg != null)
                                {
                                    list.Add(prodReg);
                                }
                            }
                        }
                    }
                }
            }
            return(list);
        }
Exemplo n.º 2
0
        protected override void BeginProcessing()
        {
            base.BeginProcessing();


            if (this.MyInvocation.BoundParameters.ContainsKey(JOBNAME))
            {
                if (this.SqlServer == null && SmoContext.GetNullOrEmpty(SmoContext.Jobs))
                {
                    SmoContext.SetJobs(SmoContext.Connection.JobServer.Jobs);
                }

                else if (this.SqlServer != null)
                {
                    SmoContext.SetJobs(this.SqlServer.JobServer.Jobs);
                }

                _input = this.GetJobFromName(this.JobName);
            }


            else if (this.MyInvocation.BoundParameters.ContainsKey(JOBID))
            {
                _input = this.GetJobFromId(this.JobId, _server);
            }
        }
Exemplo n.º 3
0
        public object GetDynamicParameters()
        {
            if (SmoContext.IsSet && SmoContext.IsConnected && _dynLib == null)
            {
                if (SmoContext.GetNullOrEmpty(SmoContext.Jobs))
                {
                    SmoContext.SetJobs(SmoContext.Connection.JobServer.Jobs);
                }

                _dynLib = new DynamicLibrary();
                var dp = new DynamicParameter <Microsoft.SqlServer.Management.Smo.Agent.Job>("JobName", SmoContext.Jobs, x => x.Name, "Name", true)
                {
                    Position         = 0,
                    Mandatory        = false,
                    ParameterSetName = "ByJobName"
                };
                _dynLib.Add(dp);
            }
            else if (_dynLib == null)
            {
                _dynLib = new DynamicLibrary();
                _dynLib.Add("JobName", new RuntimeDefinedParameter("JobName", typeof(string[]), new Collection <Attribute>
                {
                    new ParameterAttribute
                    {
                        Mandatory        = false,
                        Position         = 0,
                        ParameterSetName = "ByJobName"
                    }
                }));
            }
            return(_dynLib);
        }
Exemplo n.º 4
0
        public virtual object GetDynamicParameters()
        {
            if (_dynLib == null && SmoContext.IsSet && SmoContext.IsConnected)
            {
                if (SmoContext.GetNullOrEmpty(SmoContext.Databases))
                {
                    SmoContext.SetDatabases(SmoContext.Connection.Databases);
                }

                _dynLib = this.NewDynamicLibrary(SmoContext.Databases);
            }
            else if (_dynLib == null)
            {
                _dynLib = this.NewDynamicLibrary();
            }


            return(_dynLib);
        }
Exemplo n.º 5
0
        private static ProductRegistry GetSetupKeys(string instance, string key, RegistryKey baseKey)
        {
            IEqualityComparer <string> comparer = SmoContext.GetComparer();

            using (RegistryKey test = baseKey.OpenSubKey(key))
            {
                if (test.GetSubKeyNames().Contains(SETUP))
                {
                    using (RegistryKey setup = test.OpenSubKey(SETUP))
                    {
                        return(setup.GetValueNames().Contains(DIGITALID)
                            ? new ProductRegistry(instance, setup)
                            : null);
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 6
0
        public object GetDynamicParameters()
        {
            if (_dynLib == null && SmoContext.IsSet && SmoContext.IsConnected)
            {
                if (SmoContext.GetNullOrEmpty(SmoContext.Databases))
                {
                    SmoContext.SetDatabases(SmoContext.Connection.Databases);
                }

                _dynLib = new DynamicLibrary();
                IDynParam param = new DynamicParameter <Database>(DBNAME, SmoContext.Databases, x => x.Name, "Name", true)
                {
                    Mandatory = false,
                    Position  = 0,
                };
                param.Aliases.Add("n");
                _dynLib.Add(param);
            }
            else if (_dynLib == null)
            {
                _dynLib = new DynamicLibrary
                {
                    {
                        DBNAME,
                        new RuntimeDefinedParameter(DBNAME, typeof(string[]), new Collection <Attribute>
                        {
                            new ParameterAttribute
                            {
                                Mandatory = false,
                                Position  = 0
                            }
                        })
                    }
                };
            }
            return(_dynLib);
        }
Exemplo n.º 7
0
        protected override void ProcessRecord()
        {
            if (InstanceName == "MSSQLSERVER")
            {
                InstanceName = null;
            }

            var smo = new Server(
                this.CreateConnection(
                    ServerName, InstanceName, SQLCredential, EncryptConnection.ToBool(), TrustServerCertificate
                    )
                );

            this.TestSMO(smo);
            if (!this.AsObject.ToBool())
            {
                SmoContext.AddConnection(smo, Force.ToBool());
            }

            else
            {
                base.WriteObject(smo);
            }
        }
Exemplo n.º 8
0
 protected override void ProcessRecord() => SmoContext.Disconnect();
Exemplo n.º 9
0
        private bool HasSetValues(Dictionary <string, object> parameters)
        {
            IEqualityComparer <string> comparer = SmoContext.GetComparer();

            return(parameters.Any(x => !SkipThese.Contains(x.Key, comparer)));
        }