コード例 #1
0
        /// <summary>
        /// Generate the necessary parameters
        /// </summary>
        public List <KeyValuePair <string, string> > GetParams()
        {
            var p = new List <KeyValuePair <string, string> >();

            if (ConfigurationUrl != null)
            {
                p.Add(new KeyValuePair <string, string>("Configuration.Url", ConfigurationUrl));
            }

            if (ConfigurationMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("Configuration.Method", ConfigurationMethod.ToString()));
            }

            if (ConfigurationFilters != null)
            {
                p.AddRange(ConfigurationFilters.Select(prop => new KeyValuePair <string, string>("Configuration.Filters", prop)));
            }

            if (ConfigurationTriggers != null)
            {
                p.AddRange(ConfigurationTriggers.Select(prop => new KeyValuePair <string, string>("Configuration.Triggers", prop)));
            }

            if (ConfigurationFlowSid != null)
            {
                p.Add(new KeyValuePair <string, string>("Configuration.FlowSid", ConfigurationFlowSid.ToString()));
            }

            return(p);
        }
コード例 #2
0
        /// <summary>
        /// Assigns a certificate to a website binding
        /// </summary>
        /// <param name="siteInformation">Information identifying the website and binding to assign the certificate to</param>
        public static void AssignCertificateToSite(SiteInformation siteInformation)
        {
            if (siteInformation == null)
            {
                throw new ArgumentNullException("siteInformation");
            }

            Binding binding = GetBinding(siteInformation);

            if (string.IsNullOrEmpty(siteInformation.CertificateHash))
            {
                throw new CertificateException("Certificate hash is required when adding certificate.");
            }

            ConfigurationMethod configurationMethod = binding.Methods.FirstOrDefault(x =>
                                                                                     string.Equals(x.Name, "AddSslCertificate", StringComparison.InvariantCultureIgnoreCase));

            if (configurationMethod == null)
            {
                throw new CertificateException("Unable to access the AddSslCertificate configuration method.");
            }

            ConfigurationMethodInstance configurationMethodInstance = configurationMethod.CreateInstance();

            configurationMethodInstance.Input.SetAttributeValue("certificateHash", siteInformation.CertificateHash);
            configurationMethodInstance.Input.SetAttributeValue("certificateStoreName", siteInformation.CertificateStore);
            configurationMethodInstance.Execute();
        }
コード例 #3
0
ファイル: SessionElement.cs プロジェクト: pasamsin/SolidCP
 public void Terminate()
 {
     if (this._terminateMethod == null)
     {
         this._terminateMethod = base.Methods["Terminate"];
     }
     this._terminateMethod.CreateInstance().Execute();
 }
コード例 #4
0
 public void Stop()
 {
     if (this._stopMethod == null)
     {
         this._stopMethod = base.Methods["Stop"];
     }
     this._stopMethod.CreateInstance().Execute();
 }
コード例 #5
0
 public void FlushLog()
 {
     if (this._flushLogMethod == null)
     {
         this._flushLogMethod = base.Methods["FlushLog"];
     }
     this._flushLogMethod.CreateInstance().Execute();
 }
コード例 #6
0
 public ConfigurationActionRecord(ConfigurationMethod configurationMethod, Type typeFrom, Type typeTo, string name, object instance, LifetimeManager lifetime)
 {
     this.configurationMethod = configurationMethod;
     this.typeFrom            = typeFrom;
     this.typeTo   = typeTo;
     this.name     = string.IsNullOrEmpty(name) ? null : name;
     this.instance = instance;
     this.lifetime = lifetime;
 }
コード例 #7
0
        /// <summary>
        /// Generate the necessary parameters
        /// </summary>
        public List <KeyValuePair <string, string> > GetParams()
        {
            var p = new List <KeyValuePair <string, string> >();

            if (Target != null)
            {
                p.Add(new KeyValuePair <string, string>("Target", Target.ToString()));
            }

            if (ConfigurationUrl != null)
            {
                p.Add(new KeyValuePair <string, string>("Configuration.Url", ConfigurationUrl));
            }

            if (ConfigurationMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("Configuration.Method", ConfigurationMethod.ToString()));
            }

            if (ConfigurationFilters != null)
            {
                p.AddRange(ConfigurationFilters.Select(prop => new KeyValuePair <string, string>("Configuration.Filters", prop)));
            }

            if (ConfigurationTriggers != null)
            {
                p.AddRange(ConfigurationTriggers.Select(prop => new KeyValuePair <string, string>("Configuration.Triggers", prop)));
            }

            if (ConfigurationFlowSid != null)
            {
                p.Add(new KeyValuePair <string, string>("Configuration.FlowSid", ConfigurationFlowSid.ToString()));
            }

            if (ConfigurationRetryCount != null)
            {
                p.Add(new KeyValuePair <string, string>("Configuration.RetryCount", ConfigurationRetryCount.ToString()));
            }

            if (ConfigurationReplayAfter != null)
            {
                p.Add(new KeyValuePair <string, string>("Configuration.ReplayAfter", ConfigurationReplayAfter.ToString()));
            }

            if (ConfigurationBufferMessages != null)
            {
                p.Add(new KeyValuePair <string, string>("Configuration.BufferMessages", ConfigurationBufferMessages.Value.ToString().ToLower()));
            }

            if (ConfigurationBufferWindow != null)
            {
                p.Add(new KeyValuePair <string, string>("Configuration.BufferWindow", ConfigurationBufferWindow.ToString()));
            }

            return(p);
        }
コード例 #8
0
        /// <summary>
        /// Marks a server as unhealthy
        /// </summary>
        /// <param name="farm">The name of the WebFarm</param>
        /// <param name="address">The address of the server</param>
        public void SetServerUnhealthy(string farm, string address)
        {
            ConfigurationElement arrElement = this.GetServerArr(farm, address);

            if (arrElement != null)
            {
                ConfigurationMethod         method   = arrElement.Methods["SetUnhealthy"];
                ConfigurationMethodInstance instance = method.CreateInstance();

                instance.Execute();

                _Log.Information("Marking the server '{0}' as unhealthy.", address);
            }
        }
コード例 #9
0
        /// <summary>
        /// Marks a server as unavailable
        /// </summary>
        /// <param name="farm">The name of the WebFarm</param>
        /// <param name="address">The address of the server</param>
        public void SetServerUnavailable(string farm, string address)
        {
            ConfigurationElement arrElement = this.GetServerArr(farm, address);

            if (arrElement != null)
            {
                ConfigurationMethod         method   = arrElement.Methods["SetState"];
                ConfigurationMethodInstance instance = method.CreateInstance();

                instance.Input.Attributes[0].Value = 3;
                instance.Execute();

                _Log.Information("Marking the server '{0}' as unavailable.", address);
            }
        }
コード例 #10
0
        /// <summary>
        /// Unassigns a certificate to a website binding
        /// </summary>
        /// <param name="siteInformation">Information identifying the website and binding to assign the certificate to</param>
        public static void UnassignCertificateFromSite(SiteInformation siteInformation)
        {
            if (siteInformation == null)
            {
                throw new ArgumentNullException("siteInformation");
            }

            Binding binding = GetBinding(siteInformation);

            ConfigurationMethod configurationMethod = binding.Methods.FirstOrDefault(x =>
                                                                                     string.Equals(x.Name, "RemoveSslCertificate", StringComparison.InvariantCultureIgnoreCase));

            if (configurationMethod == null)
            {
                throw new CertificateException("Unable to access the RemoveSslCertificate configuration method.");
            }

            ConfigurationMethodInstance configurationMethodInstance = configurationMethod.CreateInstance();

            configurationMethodInstance.Execute();
        }
コード例 #11
0
ファイル: MockUnityContainer.cs プロジェクト: CFMITL/unity
 public ConfigurationActionRecord(ConfigurationMethod configurationMethod, Type typeFrom, Type typeTo, string name, object instance, LifetimeManager lifetime)
 {
     this.configurationMethod = configurationMethod;
     this.typeFrom = typeFrom;
     this.typeTo = typeTo;
     this.name = string.IsNullOrEmpty(name) ? null : name;
     this.instance = instance;
     this.lifetime = lifetime;
 }
コード例 #12
0
        static void Main(string[] args)
        {
            try
            {
                string certHash  = "";
                string certStore = "MY";

                X509Store certificateStore = new X509Store(StoreLocation.LocalMachine);
                certificateStore.Open(OpenFlags.ReadOnly);

                foreach (var certificate in certificateStore.Certificates)
                {
                    bool isServerAuth = false;
                    Console.WriteLine("[Info] " + certificate.GetCertHashString());
                    foreach (X509Extension extension in certificate.Extensions)
                    {
                        Console.WriteLine(extension.Format(true));
                        Console.WriteLine(extension.Oid.Value.ToString());
                        if (extension.Format(true).Contains("Server Authentication"))
                        {
                            isServerAuth = true;
                        }
                        if (certificate.Verify() && isServerAuth)
                        {
                            certHash = certificate.GetCertHashString();
                        }
                        else if (certificate.Verify() && isServerAuth)
                        {
                            certHash = certificate.GetCertHashString();
                        }
                        else if (certificate.Verify())
                        {
                            certHash = certificate.GetCertHashString();
                        }
                    }
                }
                certificateStore.Close();
                ServerManager mgr = null;

                string server   = null; // or remote machine name
                string siteName = "Default Web Site";

                string bindingProtocol = "https";
                string bindingInfo     = "*:7443:";


                if (String.IsNullOrEmpty(server))
                {
                    mgr = new ServerManager();
                }
                else
                {
                    mgr = ServerManager.OpenRemote(server);
                }

                Site site = mgr.Sites[siteName];

                Binding binding = null;
                foreach (Binding b in site.Bindings)
                {
                    Console.WriteLine(bindingInfo);
                    if (b.Protocol.Equals(bindingProtocol) &&
                        b.BindingInformation.Equals(bindingInfo))
                    {
                        binding = b;
                        break;
                    }
                }

                if (binding == null)
                {
                    throw new Exception("Binding not found!");
                }


                if (!String.IsNullOrEmpty(certHash))
                {
                    ConfigurationMethod method = binding.Methods["AddSslCertificate"];
                    if (method == null)
                    {
                        throw new Exception("Unable to access the AddSslCertificate configuration method");
                    }

                    ConfigurationMethodInstance mi = method.CreateInstance();
                    mi.Input.SetAttributeValue("certificateHash", certHash);
                    mi.Input.SetAttributeValue("certificateStoreName", certStore);
                    mi.Execute();

                    Console.WriteLine("Certificate has been added: " + certHash);
                }
                else
                {
                    Console.WriteLine("Certificate can not be found");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                Console.Read();
                Environment.Exit(-1);
            }
            Thread.Sleep(9000);
        }