Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the specified config item.
        /// </summary>
        /// <param name="configItem">The config item.</param>
        /// <exception cref="Forge.Configuration.Shared.InvalidConfigurationValueException">ServerNameOnCertificate value is invalid.</exception>
        public override void Initialize(CategoryPropertyItem configItem)
        {
            if (configItem == null)
            {
                ThrowHelper.ThrowArgumentNullException("configItem");
            }
            if (!IsInitialized)
            {
                mServerNameOnCertificate = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "ServerNameOnCertificate");
                if (string.IsNullOrEmpty(mServerNameOnCertificate))
                {
                    throw new InvalidConfigurationValueException("ServerNameOnCertificate value is invalid.");
                }

                string skipSslPolicy = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "SkipSslPolicyErrors");
                if (!string.IsNullOrEmpty(skipSslPolicy))
                {
                    bool value = false;
                    if (bool.TryParse(skipSslPolicy, out value))
                    {
                        mSkipSslPolicyErrors = value;
                    }
                }

                base.Initialize(configItem);

                IsInitialized = true;
            }
        }
Ejemplo n.º 2
0
        private void SectionHandler_OnConfigurationChanged(object sender, EventArgs e)
        {
            string value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "NetworkContext");

            if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(value.Trim()))
            {
                throw new InitializationException("Network context name not configured.");
            }
            this.mName = value.Trim();

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "NetworkContext/Separation");
            bool boolValue = false;

            if (!string.IsNullOrEmpty(value))
            {
                bool.TryParse(value, out boolValue);
            }
            Separation = boolValue;

            CategoryPropertyItem piRoot = ConfigurationAccessHelper.GetCategoryPropertyByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "NetworkContext/Separation/WhiteList");
            List <ContextRule>   list   = new List <ContextRule>();

            if (piRoot != null)
            {
                foreach (CategoryPropertyItem pi in piRoot)
                {
                    if (string.IsNullOrEmpty(pi.EntryName) || string.IsNullOrEmpty(pi.EntryName.Trim()))
                    {
                        throw new InitializationException("Invalid context rule.");
                    }
                    if (string.IsNullOrEmpty(pi.EntryValue) || string.IsNullOrEmpty(pi.EntryValue.Trim()))
                    {
                        throw new InitializationException("Invalid context rule.");
                    }
                    list.Add(new ContextRule(pi.EntryName, pi.EntryValue));
                }
            }
            WhiteList = list;

            piRoot = ConfigurationAccessHelper.GetCategoryPropertyByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "NetworkContext/Separation/BlackList");
            list   = new List <ContextRule>();
            if (piRoot != null)
            {
                foreach (CategoryPropertyItem pi in piRoot)
                {
                    if (string.IsNullOrEmpty(pi.EntryName) || string.IsNullOrEmpty(pi.EntryName.Trim()))
                    {
                        throw new InitializationException("Invalid context rule.");
                    }
                    if (string.IsNullOrEmpty(pi.EntryValue) || string.IsNullOrEmpty(pi.EntryValue.Trim()))
                    {
                        throw new InitializationException("Invalid context rule.");
                    }
                    list.Add(new ContextRule(pi.EntryName, pi.EntryValue));
                }
            }
            BlackList = list;
        }
Ejemplo n.º 3
0
        public override ManagerStateEnum Start()
        {
            if (this.ManagerState != ManagerStateEnum.Started)
            {
                if (LOGGER.IsInfoEnabled)
                {
                    LOGGER.Info(string.Format("{0}, initializing locator...", LOG_PREFIX));
                }

                OnStart(ManagerEventStateEnum.Before);

                try
                {
                    Forge.Net.TerraGraf.NetworkManager.Instance.Start();
                    Forge.Net.Remoting.Channels.ChannelServices.Initialize();
                    Forge.Net.Remoting.Proxy.ProxyServices.Initialize();

                    // check channel
                    this.ChannelId = ConfigurationAccessHelper.GetValueByPath(NetworkServiceConfiguration.Settings.CategoryPropertyItems, string.Format("Locators/{0}", Id));
                    if (string.IsNullOrEmpty(this.ChannelId))
                    {
                        this.ChannelId = Id;
                    }

                    Channel channel = LookUpChannel();

                    if (!ProxyServices.IsContractRegistered(typeof(TIProxyType)))
                    {
                        ProxyServices.RegisterContract(typeof(TIProxyType), channel.ChannelId, typeof(TProxyImplementationType));
                    }

                    // init TerraGraf and find the service
                    Forge.Net.TerraGraf.NetworkManager.Instance.NetworkPeerContextChanged += new EventHandler <NetworkPeerContextEventArgs>(NetworkPeerContextChangedEventHandler);
                    Forge.Net.TerraGraf.NetworkManager.Instance.NetworkPeerDiscovered     += new EventHandler <NetworkPeerChangedEventArgs>(NetworkPeerDiscoveredEventHandler);
                    Forge.Net.TerraGraf.NetworkManager.Instance.NetworkPeerUnaccessible   += new EventHandler <NetworkPeerChangedEventArgs>(NetworkPeerUnaccessibleEventHandler);
                    Forge.Net.TerraGraf.NetworkManager.Instance.NetworkPeerContextChanged += new EventHandler <NetworkPeerContextEventArgs>(NetworkPeerContextChangedEventHandler);

                    FindService();

                    this.ManagerState = ManagerStateEnum.Started;

                    if (LOGGER.IsInfoEnabled)
                    {
                        LOGGER.Info(string.Format("{0}, locator successfully initialized.", LOG_PREFIX));
                    }
                }
                catch (Exception)
                {
                    this.ManagerState = ManagerStateEnum.Fault;
                    throw;
                }
                finally
                {
                    OnStart(ManagerEventStateEnum.After);
                }
            }
            return(this.ManagerState);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes the <see cref="ChannelServices"/> class.
        /// </summary>
        static ChannelServices()
        {
            bool   autoLoad      = true;
            string autoLoadValue = ConfigurationAccessHelper.GetValueByPath(RemotingConfiguration.Settings.CategoryPropertyItems, "Settings/AutomaticallyLoadChannels");

            if (string.IsNullOrEmpty(autoLoadValue))
            {
                ThrowHelper.ThrowArgumentNullException("autoLoadValue");
            }
            if (autoLoad)
            {
                Initialize();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes the specified config item.
        /// </summary>
        /// <param name="configItem">The config item.</param>
        /// <exception cref="InitializationException">Administration connection string was not set.</exception>
        /// <exception cref="Forge.InitializationException">Administration connection string was not set.</exception>
        public void Initialize(CategoryPropertyItem configItem)
        {
            if (configItem == null)
            {
                ThrowHelper.ThrowArgumentNullException("configItem");
            }

            mConnectionStringForAdmin = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, CONNECTION_STRING_CONFIG_ID);
            if (string.IsNullOrEmpty(mConnectionStringForAdmin))
            {
                throw new InitializationException("Administration connection string was not set.");
            }

            this.IsInitialized = true;
        }
Ejemplo n.º 6
0
        private void SectionHandler_OnConfigurationChanged(object sender, EventArgs e)
        {
            CategoryPropertyItem   piRoot = ConfigurationAccessHelper.GetCategoryPropertyByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "NetworkPeering/TCP_Connections");
            List <ConnectionEntry> list   = new List <ConnectionEntry>();

            if (piRoot != null)
            {
                foreach (CategoryPropertyItem pi in piRoot)
                {
                    AddressEndPoint address    = AddressEndPoint.Parse(pi.EntryValue);
                    bool            reConnect  = true;
                    int             delayValue = 1000;
                    int             conTimeout = Timeout.Infinite;
                    string          item       = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, string.Format("NetworkPeering/TCP_Connections/{0}/ReconnectOnFailure", pi.Id));
                    if (!string.IsNullOrEmpty(item))
                    {
                        bool.TryParse(item, out reConnect);
                    }
                    item = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, string.Format("NetworkPeering/TCP_Connections/{0}/DelayBetweenAttempsInMS", pi.Id));
                    if (!string.IsNullOrEmpty(item))
                    {
                        int.TryParse(item, out delayValue);
                        if (delayValue < 0)
                        {
                            delayValue = 1000;
                        }
                    }
                    item = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, string.Format("NetworkPeering/TCP_Connections/{0}/ConnectionTimeout", pi.Id));
                    if (!string.IsNullOrEmpty(item))
                    {
                        int.TryParse(item, out conTimeout);
                        if (conTimeout < Timeout.Infinite)
                        {
                            conTimeout = Timeout.Infinite;
                        }
                    }
                    list.Add(new ConnectionEntry(address, reConnect, delayValue, conTimeout));
                }
            }
            EndPoints = list;
        }
Ejemplo n.º 7
0
        private void SectionHandler_OnConfigurationChanged(object sender, EventArgs e)
        {
            CategoryPropertyItem   piRoot = ConfigurationAccessHelper.GetCategoryPropertyByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "NetworkPeering/TCPServers/Auto");
            List <AddressEndPoint> list   = new List <AddressEndPoint>();

            if (piRoot != null)
            {
                foreach (CategoryPropertyItem pi in piRoot)
                {
                    list.Add(AddressEndPoint.Parse(pi.EntryValue));
                }
            }
            EndPoints = list;

            string value     = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "NetworkPeering/TCPServers/Auto");
            bool   boolValue = false;

            if (!string.IsNullOrEmpty(value))
            {
                bool.TryParse(value, out boolValue);
            }
            mAuto = boolValue;
        }
Ejemplo n.º 8
0
        public virtual ManagerStateEnum Start(long priority, IServiceDescriptor serviceDescriptor)
        {
            if (this.ManagerState != ManagerStateEnum.Started)
            {
                if (priority < 0)
                {
                    ThrowHelper.ThrowArgumentOutOfRangeException("priority");
                }

                if (LOGGER.IsInfoEnabled)
                {
                    LOGGER.Info(string.Format("{0}, initializing service...", LOG_PREFIX));
                }

                OnStart(ManagerEventStateEnum.Before);

                try
                {
                    ChannelServices.Initialize();

                    this.ChannelId = ConfigurationAccessHelper.GetValueByPath(NetworkServiceConfiguration.Settings.CategoryPropertyItems, string.Format("Services/{0}", Id));
                    if (string.IsNullOrEmpty(this.ChannelId))
                    {
                        this.ChannelId = Id;
                    }

                    Channel channel = LookUpChannel();

                    if (channel.ServerEndpoints.Count == 0)
                    {
                        throw new InvalidConfigurationException(string.Format("Channel '{0}' has not got listening server endpoint(s).", channel.ChannelId));
                    }

                    ServiceBaseServices.Initialize();
                    if (!ServiceBaseServices.IsContractRegistered(typeof(TIServiceProxyType)))
                    {
                        ServiceBaseServices.RegisterContract(typeof(TIServiceProxyType), typeof(TServiceProxyImplementationType));
                    }

                    this.mPriority          = priority;
                    this.mServiceDescriptor = serviceDescriptor;

                    RegisterToPeerContext(channel, priority, serviceDescriptor);

                    this.ManagerState = ManagerStateEnum.Started;

                    if (LOGGER.IsInfoEnabled)
                    {
                        LOGGER.Info(string.Format("{0}, service successfully initialized.", LOG_PREFIX));
                    }
                }
                catch (Exception)
                {
                    this.ManagerState = ManagerStateEnum.Fault;
                    throw;
                }

                OnStart(ManagerEventStateEnum.After);
            }
            return(this.ManagerState);
        }
Ejemplo n.º 9
0
        private void SectionHandler_OnConfigurationChanged(object sender, EventArgs e)
        {
            string value     = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/BlackHole");
            bool   boolValue = false;

            if (!string.IsNullOrEmpty(value))
            {
                bool.TryParse(value, out boolValue);
            }
            BlackHole = boolValue;

            value     = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/EnableIPV6");
            boolValue = false;
            if (!string.IsNullOrEmpty(value))
            {
                bool.TryParse(value, out boolValue);
            }
            EnableIPV6 = boolValue;

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultConnectionTimeoutInMS");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue >= 0)
                    {
                        DefaultConnectionTimeoutInMS = intValue;
                    }
                }
            }

            value     = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/EnableMultipleConnectionWithNetworkPeers");
            boolValue = false;
            if (!string.IsNullOrEmpty(value))
            {
                if (bool.TryParse(value, out boolValue))
                {
                    EnableMultipleConnectionWithNetworkPeers = boolValue;
                }
            }

            value     = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultLowLevelNoDelay");
            boolValue = false;
            if (!string.IsNullOrEmpty(value))
            {
                if (bool.TryParse(value, out boolValue))
                {
                    DefaultLowLevelNoDelay = boolValue;
                }
            }

            value     = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/EnableAgressiveConnectionEstablishment");
            boolValue = false;
            if (!string.IsNullOrEmpty(value))
            {
                if (bool.TryParse(value, out boolValue))
                {
                    EnableAgressiveConnectionEstablishment = boolValue;
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/MaxConnectionsWithNetworkPeers");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue > 0)
                    {
                        MaxConnectionsWithNetworkPeers = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/MaxMessagePassageNumber");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (mMaxMessagePassageNumber > 0)
                    {
                        MaxMessagePassageNumber = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultSocketAcceptTimeWaitInMS");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue > 0)
                    {
                        mDefaultSocketAcceptTimeWaitInMS = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultSocketBacklogSize");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue > 0)
                    {
                        mDefaultSocketBacklogSize = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultLowLevelSocketReceiveBufferSize");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue > 0)
                    {
                        DefaultLowLevelSocketReceiveBufferSize = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultLowLevelSocketSendBufferSize");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue > 0)
                    {
                        DefaultLowLevelSocketSendBufferSize = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultReceiveBufferSize");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue > 0)
                    {
                        DefaultReceiveBufferSize = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultSendBufferSize");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue > 0)
                    {
                        DefaultSendBufferSize = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultLowLevelSocketKeepAliveTime");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue >= 1000)
                    {
                        DefaultLowLevelSocketKeepAliveTime = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultLowLevelSocketKeepAliveTimeInterval");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue >= 1000)
                    {
                        DefaultLowLevelSocketKeepAliveTimeInterval = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultConcurrentSocketConnectionAttempts");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue > 0)
                    {
                        mDefaultConcurrentSocketConnectionAttempts = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultReceiveTimeoutInMS");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue > 0)
                    {
                        DefaultReceiveTimeoutInMS = intValue;
                    }
                }
            }

            value = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/DefaultSendTimeoutInMS");
            if (!string.IsNullOrEmpty(value))
            {
                int intValue = 0;
                if (int.TryParse(value, out intValue))
                {
                    if (intValue > 0)
                    {
                        DefaultSendTimeoutInMS = intValue;
                    }
                }
            }

            value     = ConfigurationAccessHelper.GetValueByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "Settings/AddWindowsFirewallException");
            boolValue = DEFAULT_ADD_WINDOWS_FIREWALL_EXCEPTION;
            if (!string.IsNullOrEmpty(value))
            {
                if (bool.TryParse(value, out boolValue))
                {
                    AddWindowsFirewallException = boolValue;
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes the specified config item.
        /// </summary>
        /// <param name="configItem">The config item.</param>
        /// <exception cref="InvalidConfigurationValueException">
        /// CertificateSource value is invalid.
        /// or
        /// CertificateSource value is invalid.
        /// or
        /// CertificateFile value is invalid.
        /// or
        /// Password value is invalid.
        /// or
        /// Subject value is invalid.
        /// or
        /// CertificateSource value is invalid.
        /// </exception>
        /// <exception cref="InvalidConfigurationException">
        /// Invalid certificate.
        /// or
        /// Failed to find certificate.
        /// or
        /// Failed to find certificate.
        /// </exception>
        public virtual void Initialize(CategoryPropertyItem configItem)
        {
            if (configItem == null)
            {
                ThrowHelper.ThrowArgumentNullException("configItem");
            }
            if (!mInitialized)
            {
                string certSource = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "CertificateSource");
                if (string.IsNullOrEmpty(certSource))
                {
                    throw new InvalidConfigurationValueException("CertificateSource value is invalid.");
                }
                certSource = certSource.Trim().ToLower();
                if (string.IsNullOrEmpty(certSource))
                {
                    throw new InvalidConfigurationValueException("CertificateSource value is invalid.");
                }
                if ("file".Equals(certSource))
                {
                    string certFile = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "CertificateFile");
                    if (string.IsNullOrEmpty(certFile))
                    {
                        throw new InvalidConfigurationValueException("CertificateFile value is invalid.");
                    }
                    FileInfo fi = new FileInfo(certFile);
                    if (!fi.Exists)
                    {
                        throw new InvalidConfigurationException(string.Format("Certificate file not found: {0}", fi.FullName));
                    }

                    string passwordString = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "Password");
                    if (string.IsNullOrEmpty(passwordString))
                    {
                        throw new InvalidConfigurationValueException("Password value is invalid.");
                    }

                    try
                    {
                        mCertificate = new X509Certificate2(fi.FullName, passwordString);
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidConfigurationException("Invalid certificate.", ex);
                    }
                }
                else if ("store".Equals(certSource))
                {
                    StoreName     storeName     = StoreName.My;
                    StoreLocation storeLocation = StoreLocation.CurrentUser;

                    string storeNameStr = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "StoreName");
                    if (!string.IsNullOrEmpty(storeNameStr))
                    {
                        storeName = (StoreName)Enum.Parse(typeof(StoreName), storeNameStr);
                    }

                    string storeLocationStr = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "StoreLocation");
                    if (!string.IsNullOrEmpty(storeLocationStr))
                    {
                        storeLocation = (StoreLocation)Enum.Parse(typeof(StoreLocation), storeLocationStr);
                    }

                    string subject = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "Subject");
                    if (string.IsNullOrEmpty(subject))
                    {
                        throw new InvalidConfigurationValueException("Subject value is invalid.");
                    }

                    X509Store store = new X509Store(storeName, storeLocation);
                    store.Open(OpenFlags.ReadOnly);
                    try
                    {
                        foreach (X509Certificate2 c in store.Certificates)
                        {
                            if (c.Subject.Equals(subject))
                            {
                                mCertificate = c;
                                break;
                            }
                        }
                        if (mCertificate == null)
                        {
                            throw new InvalidConfigurationException("Failed to find certificate.");
                        }
                    }
                    catch (InvalidConfigurationException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidConfigurationException("Failed to find certificate.", ex);
                    }
                    finally
                    {
                        store.Close();
                    }
                }
                else if ("frombase64".Equals(certSource))
                {
                    string certBase64 = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "CertificateBase64");
                    if (string.IsNullOrEmpty(certBase64))
                    {
                        throw new InvalidConfigurationValueException("CertificateBase64 value is invalid.");
                    }

                    byte[] data = Convert.FromBase64String(certBase64);

                    string passwordString = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "Password");
                    if (string.IsNullOrEmpty(passwordString))
                    {
                        throw new InvalidConfigurationValueException("Password value is invalid.");
                    }

                    try
                    {
                        mCertificate = new X509Certificate2(data, passwordString);
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidConfigurationException("Invalid certificate.", ex);
                    }
                }
                else if ("generatenew".Equals(certSource))
                {
                    string subject = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "Subject");
                    if (string.IsNullOrEmpty(subject))
                    {
                        throw new InvalidConfigurationValueException("Subject value is invalid.");
                    }

                    string passwordString = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "Password");
                    if (string.IsNullOrEmpty(passwordString))
                    {
                        passwordString = Guid.NewGuid().ToString();
                    }

                    DateTime dtCertStart   = DateTime.UtcNow.AddDays(-1);
                    string   certStartDate = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "CertValidStartDate");
                    if (!string.IsNullOrEmpty(certStartDate))
                    {
                        DateTime.TryParse(certStartDate, out dtCertStart);
                    }

                    DateTime dtCertExpired = DateTime.MaxValue;
                    string   certExpiry    = ConfigurationAccessHelper.GetValueByPath(configItem.PropertyItems, "CertExpiryDate");
                    if (!string.IsNullOrEmpty(certExpiry))
                    {
                        DateTime.TryParse(certExpiry, out dtCertExpired);
                    }

                    try
                    {
                        byte[] data = CertificateFactory.CreateSelfSignCertificatePfx(subject, dtCertStart, dtCertExpired, passwordString);
                        mCertificate = new X509Certificate2(data, passwordString);
#if NETCOREAPP3_1
#else
                        mCertificate.FriendlyName = "Generated Certificate";
#endif
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidConfigurationException("Invalid certificate.", ex);
                    }
                }
                else
                {
                    throw new InvalidConfigurationValueException("CertificateSource value is invalid.");
                }

                this.mInitialized = true;
            }
        }