Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the specified config item.
        /// </summary>
        /// <param name="configItem">The config item.</param>
        /// <exception cref="Forge.Configuration.Shared.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="Forge.Configuration.Shared.InvalidConfigurationException">Invalid certificate.
        /// or
        /// Failed to find certificate.
        /// or
        /// Failed to find certificate.</exception>
        public override void Initialize(CategoryPropertyItem configItem)
        {
            if (configItem == null)
            {
                ThrowHelper.ThrowArgumentNullException("configItem");
            }
            if (!IsInitialized)
            {
                CertificateConfigurationSource certSource = new CertificateConfigurationSource();
                certSource.Initialize(configItem);
                mCertificate = certSource.Certificate;

                CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(configItem.PropertyItems, "Protocol");
                if (pi != null)
                {
                    try
                    {
                        Protocol = (SslProtocols)Enum.Parse(typeof(SslProtocols), pi.EntryValue, true);
                    }
                    catch (Exception)
                    {
                    }
                }

                base.Initialize(configItem);

                IsInitialized = true;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses the int value.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <param name="minValue">The min value.</param>
        /// <param name="maxValue">The max value.</param>
        /// <param name="value">The value.</param>
        /// <returns>True, if the parse method was succeeded, otherwise False.</returns>
        protected static bool ParseIntValue(CategoryPropertyItem root, String entryId, int minValue, int maxValue, ref int value)
        {
            bool result             = false;
            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root.PropertyItems, entryId);

            if (pi != null)
            {
                try
                {
                    value  = int.Parse(pi.EntryValue);
                    result = true;
                }
                catch (FormatException ex)
                {
                    throw new InvalidConfigurationException(String.Format("Invalid value for item: {0}", entryId), ex);
                }
                if (value < minValue)
                {
                    throw new InvalidConfigurationException(String.Format("Minimum value ({0}) is out of range ({1}) for item: {2}", minValue, result, entryId));
                }
                if (value > maxValue)
                {
                    throw new InvalidConfigurationException(String.Format("Maximum value ({0}) is out of range ({1}) for item: {2}", maxValue, result, entryId));
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        private void Initialize()
        {
            string appId       = ApplicationHelper.ApplicationId;
            bool   mutexResult = false;
            string typeName    = String.Format("HibernateStorageProvider_{0}_{1}_{2}", appId, StorageId, typeof(T).AssemblyQualifiedName.GetHashCode().ToString());

            if (typeName.Length > 255)
            {
                // limit the length of the mutex name to avoid exception
                typeName = typeName.Substring(0, 255);
            }
            mAppIdMutex = new Mutex(true, typeName, out mutexResult);
            if (!mutexResult)
            {
                throw new InitializationException("An other application with the specified application identifier is running.");
            }

            this.mDeviceId = HashGeneratorHelper.GetSHA256BasedValue(StorageId);
            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(StorageConfiguration.Settings.CategoryPropertyItems, String.Format("NHibernateProvider/KnownStorageIdsToReset/{0}", StorageId));

            if (pi != null)
            {
                Reset();
            }
            LoadAllocationTable();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initialize message sink from configuration
        /// </summary>
        /// <param name="pi">The pi.</param>
        public virtual void Initialize(CategoryPropertyItem pi)
        {
            if (pi == null)
            {
                ThrowHelper.ThrowArgumentNullException("pi");
            }

            if (!this.mInitialized)
            {
                CategoryPropertyItem piCompressData = ConfigurationAccessHelper.GetCategoryPropertyByPath(pi.PropertyItems, "CompressData");
                if (piCompressData != null)
                {
                    bool.TryParse(piCompressData.EntryValue, out mCompressData);
                    CategoryPropertyItem piCompressDataOverSize = ConfigurationAccessHelper.GetCategoryPropertyByPath(pi.PropertyItems, "CompressDataOverSize");
                    if (piCompressDataOverSize != null)
                    {
                        int result = 0;
                        if (int.TryParse(piCompressDataOverSize.EntryValue, out result))
                        {
                            mCompressDataOverSize = result;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        public override void Initialize(CategoryPropertyItem item)
        {
            base.Initialize(item);

            this.MemberName = null;
            this.Value      = null;
            if (item.PropertyItems != null)
            {
                string memberName = string.Empty;
                if (ConfigurationAccessHelper.ParseStringValue(item.PropertyItems, CONFIG_MEMBERNAME, ref memberName))
                {
                    this.MemberName = memberName;
                }

                string value = string.Empty;
                if (ConfigurationAccessHelper.ParseStringValue(item.PropertyItems, CONFIG_VALUE, ref value))
                {
                    this.Value = value;
                }
            }

            if (string.IsNullOrEmpty(this.MemberName))
            {
                throw new InitializationException("Member name has not been definied.");
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes the specified item.
 /// </summary>
 /// <param name="item">The item.</param>
 public virtual void Initialize(CategoryPropertyItem item)
 {
     this.Filter = null;
     if (item != null)
     {
         this.SinkId = item.Id;
         CategoryPropertyItem rootItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(item.PropertyItems, CONFIG_FILTER);
         if (rootItem != null)
         {
             try
             {
                 Type filterType = TypeHelper.GetTypeFromString(rootItem.EntryValue, TypeLookupModeEnum.AllowAll, true, true, true);
                 this.Filter = (IErrorReportFilter)filterType.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
                 this.Filter.Initialize(rootItem);
             }
             catch (Exception ex)
             {
                 this.Filter = null;
                 string message = string.Format("Failed to create error report filter. Type: '{0}'. Sink type: '{1}'", rootItem.EntryValue, this.GetType().AssemblyQualifiedName);
                 if (LOGGER.IsErrorEnabled)
                 {
                     LOGGER.Error(message, ex);
                 }
                 throw new InitializationException(message, ex);
             }
         }
     }
 }
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
0
        /// <summary>
        /// Fails the safe start storage provider.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="storageId">The storage id.</param>
        /// <param name="dataFormatter">The data formatter.</param>
        /// <param name="compressContent">if set to <c>true</c> [compress content].</param>
        /// <param name="enableReset">if set to <c>true</c> [enable reset].</param>
        /// <param name="hasError">if set to <c>true</c> [has error].</param>
        /// <returns></returns>
        public static HibernateStorageProvider <T> FailSafeStartStorageProvider <T>(string storageId, IDataFormatter <T> dataFormatter, bool compressContent, bool enableReset, out bool hasError)
        {
            HibernateStorageProvider <T> result = null;

            hasError = false;

            try
            {
                result = new HibernateStorageProvider <T>(storageId, dataFormatter, compressContent);
                IEnumeratorSpecialized <T> iterator = result.GetEnumerator();
                while (iterator.MoveNext())
                {
                    // check data consistency
                }
            }
            catch (Exception ex)
            {
                if (LOGGER.IsErrorEnabled)
                {
                    LOGGER.Error(string.Format("NHIBERNATE_STORAGE_PROVIDER, failed to initialize storage provider: '{0}'. Reset allowed: {1}", storageId, enableReset.ToString()), ex);
                }
                hasError = true;
                if (enableReset)
                {
                    // reset the content of the storage provider
                    CategoryPropertyItem root       = ConfigurationAccessHelper.GetCategoryPropertyByPath(StorageConfiguration.Settings.CategoryPropertyItems, "NHibernateProvider");
                    CategoryPropertyItem removeItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(root.PropertyItems, "KnownStorageIdsToReset");
                    if (removeItem == null)
                    {
                        removeItem    = new CategoryPropertyItem();
                        removeItem.Id = "KnownStorageIdsToReset";
                        root.PropertyItems.Add(removeItem);
                    }

                    CategoryPropertyItem storeItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(removeItem.PropertyItems, storageId);
                    if (storeItem == null)
                    {
                        storeItem    = new CategoryPropertyItem();
                        storeItem.Id = storageId;
                        removeItem.PropertyItems.Add(storeItem);
                        try
                        {
                            result = new HibernateStorageProvider <T>(storageId, dataFormatter, compressContent);
                        }
                        finally
                        {
                            removeItem.PropertyItems.Remove(storeItem);
                        }
                    }
                }
                else
                {
                    throw;
                }
            }

            return(result);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Parses the string value.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns>True, if the parse method was succeeded, otherwise False.</returns>
        protected static String ParseStringValue(CategoryPropertyItem root, String entryId, String defaultValue)
        {
            String result           = defaultValue;
            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root.PropertyItems, entryId);

            if (pi != null)
            {
                result = pi.EntryValue;
            }
            return(result);
        }
Ejemplo n.º 12
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.º 13
0
        private void SectionHandler_OnConfigurationChanged(object sender, EventArgs e)
        {
            CategoryPropertyItem   piRoot = ConfigurationAccessHelper.GetCategoryPropertyByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "NetworkPeering/NAT_Gateways");
            List <AddressEndPoint> list   = new List <AddressEndPoint>();

            if (piRoot != null)
            {
                foreach (CategoryPropertyItem pi in piRoot)
                {
                    list.Add(AddressEndPoint.Parse(pi.EntryValue));
                }
            }
            EndPoints = list;
        }
Ejemplo n.º 14
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.º 15
0
        private static void SectionHandler_OnConfigurationChanged(object sender, EventArgs e)
        {
            CategoryPropertyItem rootItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(RemoteDesktopConfiguration.Settings.CategoryPropertyItems, CONFIG_ROOT);

            if (rootItem != null)
            {
                int mouseMoveSendingInterval = Consts.DEFAULT_MOUSE_MOVE_SEND_INTERVAL;
                if (ConfigurationAccessHelper.ParseIntValue(rootItem.PropertyItems, CONFIG_MOUSE_MOVE_SEND_INTERVAL, 0, int.MaxValue, ref mouseMoveSendingInterval))
                {
                    MouseMoveSendInterval = mouseMoveSendingInterval;
                }
            }

            Raiser.CallDelegatorBySync(EventConfigurationChanged, new object[] { null, EventArgs.Empty });
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        public override void Initialize(CategoryPropertyItem item)
        {
            base.Initialize(item);

            this.Operand = ArithmeticFilterOperandEnum.Equal;
            if (item.PropertyItems != null)
            {
                ArithmeticFilterOperandEnum operand = ArithmeticFilterOperandEnum.Equal;
                if (ConfigurationAccessHelper.ParseEnumValue <ArithmeticFilterOperandEnum>(item.PropertyItems, CONFIG_OPERAND, ref operand))
                {
                    this.Operand = operand;
                }
            }

            this.IsInitialized = true;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        public override void Initialize(CategoryPropertyItem item)
        {
            base.Initialize(item);

            this.MatchMode = LikeMatchModeFilterEnum.Exact;
            if (item.PropertyItems != null)
            {
                LikeMatchModeFilterEnum matchMode = LikeMatchModeFilterEnum.Exact;
                if (ConfigurationAccessHelper.ParseEnumValue <LikeMatchModeFilterEnum>(item.PropertyItems, CONFIG_MATCHMODE, ref matchMode))
                {
                    this.MatchMode = matchMode;
                }
            }

            this.IsInitialized = true;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        public virtual void Initialize(CategoryPropertyItem item)
        {
            if (item == null)
            {
                ThrowHelper.ThrowArgumentNullException("item");
            }

            if (item.PropertyItems != null)
            {
                bool negation = false;
                if (ConfigurationAccessHelper.ParseBooleanValue(item.PropertyItems, CONFIG_NEGATION, ref negation))
                {
                    this.Negation = negation;
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Parses the boolean value.
        /// </summary>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry id.</param>
        /// <returns>True, if the parse method was succeeded, otherwise False.</returns>
        protected static bool ParseBooleanValue(CategoryPropertyItem root, String entryId)
        {
            bool result             = false;
            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root.PropertyItems, entryId);

            if (pi != null)
            {
                try
                {
                    result = bool.Parse(pi.EntryValue);
                }
                catch (Exception)
                {
                }
            }
            return(result);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Parses the enum value.
        /// </summary>
        /// <typeparam name="TEnum">The type of the enum.</typeparam>
        /// <param name="root">The root.</param>
        /// <param name="entryId">The entry unique identifier.</param>
        /// <returns></returns>
        protected static TEnum ParseEnumValue <TEnum>(CategoryPropertyItem root, String entryId) where TEnum : struct
        {
            TEnum result            = default(TEnum);
            CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(root.PropertyItems, entryId);

            if (pi != null)
            {
                try
                {
                    result = (TEnum)Enum.Parse(typeof(TEnum), pi.EntryValue, true);
                }
                catch (Exception)
                {
                }
            }
            return(result);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Initializes the <see cref="HibernateStorageProvider&lt;T&gt;"/> class.
        /// </summary>
        static HibernateStorageProvider()
        {
            SYSTEM_ID = HashGeneratorHelper.GetSHA256BasedValue(ApplicationHelper.ApplicationId);

            CategoryPropertyItem configItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(StorageConfiguration.Settings.CategoryPropertyItems, "NHibernateProvider/NHibernateStorages/Default");

            if (configItem != null)
            {
                DEFAULT_SESSION_FACTORY = CreateEntityManagerFactory(configItem);
            }

            configItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(StorageConfiguration.Settings.CategoryPropertyItems, "NHibernateProvider/NHibernateStorages/StorageSpecified");
            if (configItem != null)
            {
                foreach (CategoryPropertyItem pi in configItem)
                {
                    mSessionFactoriesForStorages.Add(configItem.Id, CreateEntityManagerFactory(configItem));
                }
            }
        }
Ejemplo n.º 22
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.º 23
0
        /// <summary>
        /// Initializes the channel.
        /// </summary>
        /// <param name="pi">The pi.</param>
        public virtual void Initialize(CategoryPropertyItem pi)
        {
            DoDisposeCheck();
            if (pi == null)
            {
                ThrowHelper.ThrowArgumentNullException("pi");
            }

            if (!mInitialized)
            {
                {
                    this.mConnectionData = null;
                    CategoryPropertyItem item = ConfigurationAccessHelper.GetCategoryPropertyByPath(pi.PropertyItems, "RemoteAddress");
                    if (item != null)
                    {
                        this.mConnectionData = AddressEndPoint.Parse(item.EntryValue);
                    }
                    if (item != null)
                    {
                        ConfigurationAccessHelper.ParseLongValue(pi.PropertyItems, "DefaultErrorResponseTimeout", Timeout.Infinite, long.MaxValue, ref mDefaultErrorResponseTimeout);
                    }
                }
                {
                    mServerEndpoints.Clear();
                    CategoryPropertyItem baseAddressesItems = ConfigurationAccessHelper.GetCategoryPropertyByPath(pi.PropertyItems, "BaseAddresses");
                    if (baseAddressesItems != null)
                    {
                        IEnumerator <CategoryPropertyItem> iterator = baseAddressesItems.GetEnumerator();
                        while (iterator.MoveNext())
                        {
                            mServerEndpoints.Add(AddressEndPoint.Parse(iterator.Current.EntryValue));
                        }
                    }
                }
                {
                    mSessionReusable = true;
                    ConfigurationAccessHelper.ParseBooleanValue(pi.PropertyItems, "SessionReusable", ref mSessionReusable);
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Initializes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        public override void Initialize(CategoryPropertyItem item)
        {
            base.Initialize(item);

            this.FilterLogic = GroupFilterLoginEnum.And;
            mFilters.Clear();
            if (item.PropertyItems != null)
            {
                GroupFilterLoginEnum logic = GroupFilterLoginEnum.And;
                if (ConfigurationAccessHelper.ParseEnumValue <GroupFilterLoginEnum>(item.PropertyItems, CONFIG_FILTER_LOGIC, ref logic))
                {
                    this.FilterLogic = logic;
                }

                CategoryPropertyItem filterItems = ConfigurationAccessHelper.GetCategoryPropertyByPath(item.PropertyItems, CONFIG_FILTERS);
                if (filterItems != null && filterItems.PropertyItems != null)
                {
                    foreach (CategoryPropertyItem filterItem in filterItems.PropertyItems)
                    {
                        try
                        {
                            Type filterType           = TypeHelper.GetTypeFromString(filterItem.EntryValue, TypeLookupModeEnum.AllowAll, true, true, true);
                            IErrorReportFilter filter = (IErrorReportFilter)filterType.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
                            filter.Initialize(filterItem);
                            mFilters.Add(filter);
                        }
                        catch (Exception ex)
                        {
                            if (LOGGER.IsErrorEnabled)
                            {
                                LOGGER.Error(string.Format("GROUP_FILTER, failed to create error report filter. Type: '{0}'", filterItem.EntryValue), ex);
                            }
                        }
                    }
                }
            }
            this.IsInitialized = true;
        }
Ejemplo n.º 25
0
        public static void Save(ConfigurationSaveMode saveMode)
        {
            CategoryPropertyItem rootItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(RemoteDesktopConfiguration.Settings.CategoryPropertyItems, CONFIG_ROOT);

            if (rootItem == null)
            {
                rootItem    = new CategoryPropertyItem();
                rootItem.Id = CONFIG_ROOT;
                RemoteDesktopConfiguration.Settings.CategoryPropertyItems.Add(rootItem);
            }

            CategoryPropertyItem piMouseMoveSendingInterval = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_MOUSE_MOVE_SEND_INTERVAL);

            if (piMouseMoveSendingInterval == null)
            {
                piMouseMoveSendingInterval    = new CategoryPropertyItem();
                piMouseMoveSendingInterval.Id = CONFIG_MOUSE_MOVE_SEND_INTERVAL;
                rootItem.PropertyItems.Add(piMouseMoveSendingInterval);
            }
            piMouseMoveSendingInterval.EntryValue = MouseMoveSendInterval.ToString();

            RemoteDesktopConfiguration.Save(saveMode);
        }
Ejemplo n.º 26
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.º 27
0
        private void btLoadConfig_Click(object sender, EventArgs e)
        {
            string configId = lvConfigs.SelectedItems[0].Text;
            CategoryPropertyItem configItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(TerraGrafTestConfiguration.Settings.CategoryPropertyItems, configId);
            int i = 0;

            foreach (CategoryPropertyItem item in configItem)
            {
                string domainId   = item.Id;
                string configDir  = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configuration"), configId);
                string configFile = Path.Combine(configDir, item.EntryValue);

                AppDomainSetup domainInfo = new AppDomainSetup();
                domainInfo.ApplicationBase   = AppDomain.CurrentDomain.BaseDirectory;
                domainInfo.ConfigurationFile = configFile;
                domainInfo.ApplicationName   = AppDomain.CurrentDomain.SetupInformation.ApplicationName;

                AppDomain domain = AppDomain.CreateDomain(domainId, AppDomain.CurrentDomain.Evidence, domainInfo);

                TreeView     treeView             = new TreeView();
                Button       btInit               = new Button();
                Button       btDebug              = new Button();
                ListView     lvNetworkConnections = new ListView();
                ColumnHeader chNetworkConnections = new ColumnHeader();
                Button       btDisconnect         = new Button();
                Button       btDisconnectActive   = new Button();
                CheckBox     cbBlackHole          = new CheckBox();
                Panel        pServers             = new System.Windows.Forms.Panel();
                ListView     lvServers            = new System.Windows.Forms.ListView();
                Button       btStartServer        = new System.Windows.Forms.Button();
                Button       btStopServer         = new System.Windows.Forms.Button();
                ColumnHeader chServers            = new System.Windows.Forms.ColumnHeader();
                Label        lContext             = new System.Windows.Forms.Label();
                TextBox      tbContext            = new System.Windows.Forms.TextBox();
                Button       btSendContext        = new System.Windows.Forms.Button();
                Label        lConnect             = new Label();
                Button       btConnect            = new Button();
                TextBox      tbConnect            = new TextBox();
                Button       btBroadcast          = new Button();
                Button       btUDP       = new Button();
                Button       btTcp       = new Button();
                Button       btSockets   = new System.Windows.Forms.Button();
                Button       btRemoting  = new System.Windows.Forms.Button();
                Button       btEverlight = new System.Windows.Forms.Button();
                Button       btUpdateWF  = new Button();

                TabPage page = new TabPage(domainId);
                //page.Controls.Add(btUpdateWF);
                //page.Controls.Add(btEverlight);
                page.Controls.Add(btRemoting);
                page.Controls.Add(btSockets);
                page.Controls.Add(btTcp);
                page.Controls.Add(btUDP);
                page.Controls.Add(btBroadcast);
                page.Controls.Add(btConnect);
                page.Controls.Add(tbConnect);
                page.Controls.Add(lConnect);
                page.Controls.Add(btSendContext);
                page.Controls.Add(tbContext);
                page.Controls.Add(lContext);
                page.Controls.Add(pServers);
                page.Controls.Add(btDisconnectActive);
                page.Controls.Add(btDisconnect);
                page.Controls.Add(cbBlackHole);
                page.Controls.Add(lvNetworkConnections);
                page.Controls.Add(btDebug);
                page.Controls.Add(btInit);
                page.Controls.Add(treeView);
                page.Location = new System.Drawing.Point(4, 22);
                page.Size     = new System.Drawing.Size(571, 343);
                page.TabIndex = i + 1;
                page.Text     = domainId;
                page.UseVisualStyleBackColor = true;
                page.Tag = domain;

                cbBlackHole.AutoSize = true;
                cbBlackHole.Location = new System.Drawing.Point(170, 7);
                cbBlackHole.Size     = new System.Drawing.Size(75, 17);
                cbBlackHole.TabIndex = 2;
                cbBlackHole.Text     = "BlackHole";
                cbBlackHole.UseVisualStyleBackColor = true;
                cbBlackHole.Enabled = false;
                cbBlackHole.Tag     = domain;
                // TODO: blackhole értéket kiolvasni
                cbBlackHole.CheckedChanged += new System.EventHandler(this.cbBlackHole_CheckedChanged);

                btDisconnect.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
                btDisconnect.Location = new System.Drawing.Point(230, 283);
                btDisconnect.Size     = new System.Drawing.Size(75, 23);
                btDisconnect.TabIndex = 1;
                btDisconnect.Text     = "Disconnect";
                btDisconnect.UseVisualStyleBackColor = true;
                btDisconnect.Click += new System.EventHandler(this.btDisconnect_Click);

                btDisconnectActive.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
                btDisconnectActive.Location = new System.Drawing.Point(230, 312);
                btDisconnectActive.Size     = new System.Drawing.Size(75, 23);
                btDisconnectActive.TabIndex = 3;
                btDisconnectActive.Text     = "Dis. Active";
                btDisconnectActive.UseVisualStyleBackColor = true;
                btDisconnectActive.Click += new System.EventHandler(this.btDisconnectActive_Click);

                treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                         | System.Windows.Forms.AnchorStyles.Left)
                                                                        | System.Windows.Forms.AnchorStyles.Right)));
                treeView.Location     = new System.Drawing.Point(8, 37);
                treeView.Size         = new System.Drawing.Size(216, 298);
                treeView.TabIndex     = 1;
                treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.TreeView_AfterSelect);

                btInit.Location = new System.Drawing.Point(8, 3);
                btInit.Size     = new System.Drawing.Size(75, 23);
                btInit.TabIndex = 0;
                btInit.Text     = "Initialize";
                btInit.UseVisualStyleBackColor = true;
                btInit.Click += new System.EventHandler(this.btInitialize_Click);

                btDebug.Location = new System.Drawing.Point(89, 3);
                btDebug.Size     = new System.Drawing.Size(75, 23);
                btDebug.TabIndex = 2;
                btDebug.Text     = "Debug";
                btDebug.UseVisualStyleBackColor = true;
                btDebug.Click  += new EventHandler(btDebug_Click);
                btDebug.Enabled = false;

                chNetworkConnections.Text  = "Id";
                chNetworkConnections.Width = 50;

                lvNetworkConnections.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                                    | System.Windows.Forms.AnchorStyles.Right)));
                lvNetworkConnections.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { chNetworkConnections });
                lvNetworkConnections.FullRowSelect = true;
                lvNetworkConnections.HeaderStyle   = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
                lvNetworkConnections.HideSelection = false;
                lvNetworkConnections.Location      = new System.Drawing.Point(230, 37);
                lvNetworkConnections.MultiSelect   = false;
                lvNetworkConnections.Size          = new System.Drawing.Size(75, 240);
                lvNetworkConnections.TabIndex      = 0;
                lvNetworkConnections.UseCompatibleStateImageBehavior = false;
                lvNetworkConnections.View = System.Windows.Forms.View.Details;

                pServers.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                pServers.Controls.Add(btStopServer);
                pServers.Controls.Add(btStartServer);
                pServers.Controls.Add(lvServers);
                pServers.Location = new System.Drawing.Point(311, 37);
                pServers.Size     = new System.Drawing.Size(252, 139);
                pServers.TabIndex = 4;

                lvServers.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                          | System.Windows.Forms.AnchorStyles.Left)
                                                                         | System.Windows.Forms.AnchorStyles.Right)));
                lvServers.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { chServers });
                lvServers.FullRowSelect = true;
                lvServers.HeaderStyle   = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
                lvServers.HideSelection = false;
                lvServers.Location      = new System.Drawing.Point(3, 3);
                lvServers.MultiSelect   = false;
                lvServers.Size          = new System.Drawing.Size(162, 133);
                lvServers.TabIndex      = 0;
                lvServers.UseCompatibleStateImageBehavior = false;
                lvServers.View = System.Windows.Forms.View.Details;
                lvServers.SelectedIndexChanged += new System.EventHandler(this.lvServers_SelectedIndexChanged);

                btStartServer.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                btStartServer.Location = new System.Drawing.Point(171, 3);
                btStartServer.Size     = new System.Drawing.Size(75, 23);
                btStartServer.TabIndex = 1;
                btStartServer.Text     = "Start";
                btStartServer.UseVisualStyleBackColor = true;
                btStartServer.Click += new System.EventHandler(this.btStartServer_Click);

                btStopServer.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                btStopServer.Enabled  = false;
                btStopServer.Location = new System.Drawing.Point(171, 32);
                btStopServer.Size     = new System.Drawing.Size(75, 23);
                btStopServer.TabIndex = 2;
                btStopServer.Text     = "Stop";
                btStopServer.UseVisualStyleBackColor = true;
                btStopServer.Click += new System.EventHandler(this.btStopServer_Click);

                chServers.Text  = "Endpoints";
                chServers.Width = 128;

                lContext.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                lContext.AutoSize = true;
                lContext.Location = new System.Drawing.Point(314, 183);
                lContext.Size     = new System.Drawing.Size(46, 13);
                lContext.TabIndex = 5;
                lContext.Text     = "Context:";

                tbContext.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                tbContext.Location = new System.Drawing.Point(366, 179);
                tbContext.Size     = new System.Drawing.Size(100, 20);
                tbContext.TabIndex = 6;

                btSendContext.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                btSendContext.Location = new System.Drawing.Point(482, 178);
                btSendContext.Size     = new System.Drawing.Size(75, 23);
                btSendContext.TabIndex = 7;
                btSendContext.Text     = "Send";
                btSendContext.UseVisualStyleBackColor = true;
                btSendContext.Click += new System.EventHandler(this.btSendContext_Click);

                lConnect.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                lConnect.AutoSize = true;
                lConnect.Location = new System.Drawing.Point(311, 209);
                lConnect.Size     = new System.Drawing.Size(47, 13);
                lConnect.TabIndex = 8;
                lConnect.Text     = "Connect";

                tbConnect.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                tbConnect.Location = new System.Drawing.Point(366, 206);
                tbConnect.Size     = new System.Drawing.Size(100, 20);
                tbConnect.TabIndex = 9;

                btConnect.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                btConnect.Location = new System.Drawing.Point(482, 206);
                btConnect.Size     = new System.Drawing.Size(75, 23);
                btConnect.TabIndex = 10;
                btConnect.Text     = "Connect";
                btConnect.UseVisualStyleBackColor = true;
                btConnect.Click += new System.EventHandler(this.btConnect_Click);

                btBroadcast.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                btBroadcast.Location = new System.Drawing.Point(311, 232);
                btBroadcast.Size     = new System.Drawing.Size(75, 23);
                btBroadcast.TabIndex = 11;
                btBroadcast.Text     = "Broadcast";
                btBroadcast.UseVisualStyleBackColor = true;
                btBroadcast.Click += new System.EventHandler(this.btBroadcast_Click);

                btUDP.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                btUDP.Location = new System.Drawing.Point(393, 232);
                btUDP.Size     = new System.Drawing.Size(75, 23);
                btUDP.TabIndex = 12;
                btUDP.Text     = "UDP";
                btUDP.UseVisualStyleBackColor = true;
                btUDP.Click += new System.EventHandler(this.btUDP_Click);

                btTcp.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                btTcp.Location = new System.Drawing.Point(475, 232);
                btTcp.Size     = new System.Drawing.Size(75, 23);
                btTcp.TabIndex = 13;
                btTcp.Text     = "TCP";
                btTcp.UseVisualStyleBackColor = true;
                btTcp.Click += new System.EventHandler(this.btTcp_Click);

                btSockets.Anchor   = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
                btSockets.Location = new System.Drawing.Point(311, 261);
                btSockets.Size     = new System.Drawing.Size(75, 23);
                btSockets.TabIndex = 14;
                btSockets.Text     = "Sockets";
                btSockets.UseVisualStyleBackColor = true;
                btSockets.Click += new System.EventHandler(this.btSockets_Click);

                btRemoting.Location = new System.Drawing.Point(393, 261);
                btRemoting.Size     = new System.Drawing.Size(75, 23);
                btRemoting.TabIndex = 15;
                btRemoting.Text     = "Remoting";
                btRemoting.UseVisualStyleBackColor = true;
                btRemoting.Click += new System.EventHandler(this.btRemoting_Click);

                tcDomains.TabPages.Add(page);
                mTreeViewsById.Add(domainId, treeView);
                mButtonDebugs.Add(domainId, btDebug);
                mListViewNetworkConnections.Add(domainId, lvNetworkConnections);
                mBlackHoleCheckBoxes.Add(domainId, cbBlackHole);
                mListViewServers.Add(domainId, lvServers);
                mButtonStartServers.Add(domainId, btStartServer);
                mButtonStopServers.Add(domainId, btStopServer);
                mContexts.Add(domainId, tbContext);
                mConnections.Add(domainId, tbConnect);

                Wrapper wrapper = (Wrapper)domain.CreateInstanceAndUnwrap(typeof(Wrapper).Assembly.FullName, typeof(Wrapper).FullName);
                mWrapper.Add(domainId, wrapper);
                //wrapper.NetworkPeerDiscovered += new EventHandler<NetworkPeerChangedEventArgs>(wrapper_NetworkPeerDiscovered);
                //wrapper.NetworkPeerDistanceChanged += new EventHandler<NetworkPeerChangedEventArgs>(wrapper_NetworkPeerDistanceChanged);
                //wrapper.NetworkPeerUnaccessible += new EventHandler<NetworkPeerChangedEventArgs>(wrapper_NetworkPeerUnaccessible);
                //wrapper.NetworkPeerContextChanged += new EventHandler<NetworkPeerContextEventArgs>(wrapper_NetworkPeerContextChanged);

                mRootNodes.Add(domainId, new Dictionary <string, TreeNode>());
                mPeerNodes.Add(domainId, new Dictionary <string, TreeNode>());

                lvServers.Tag     = wrapper;
                btStartServer.Tag = wrapper;
                btStopServer.Tag  = wrapper;
                btSendContext.Tag = wrapper;
                btConnect.Tag     = wrapper;
                btBroadcast.Tag   = wrapper;
                btUDP.Tag         = wrapper;
                btTcp.Tag         = wrapper;
                btSockets.Tag     = wrapper;
                btRemoting.Tag    = wrapper;
                btEverlight.Tag   = wrapper;
                btUpdateWF.Tag    = wrapper;

                i++;
            }
            btLoadConfig.Enabled = false;
            lvConfigs.Enabled    = false;
        }
Ejemplo n.º 28
0
        public static void Initialize()
        {
            if (!mInitialized)
            {
                Raiser.CallDelegatorBySync(EventInitialization, new object[] { null, new ServiceInitializationStateEventArgs(ServiceInitializationStateEnum.Before) });
                ChannelServices.Initialize();
                if (LOGGER.IsInfoEnabled)
                {
                    LOGGER.Info("Initializing ServiceBase services.");
                }

                CategoryPropertyItem pi = ConfigurationAccessHelper.GetCategoryPropertyByPath(RemotingConfiguration.Settings.CategoryPropertyItems, "Services");
                if (pi != null)
                {
                    IEnumerator <CategoryPropertyItem> iterator = pi.GetEnumerator();
                    try
                    {
                        while (iterator.MoveNext())
                        {
                            pi = iterator.Current;
                            if (string.IsNullOrEmpty(pi.Id))
                            {
                                throw new InvalidConfigurationException("Contract type not definied. Empty item found in configuration.");
                            }
                            Type contractType = null;
                            Type defaultImplementationType = null;

                            try
                            {
                                contractType = TypeHelper.GetTypeFromString(pi.Id);
                                if (ContractDescriptors.ContainsKey(contractType))
                                {
                                    throw new InvalidConfigurationException(String.Format("Duplicated contract type configuration found in services. Contract: {0}", contractType.FullName));
                                }
                                ContractValidator.ValidateContractIntegrity(contractType);
                            }
                            catch (Exception ex)
                            {
                                throw new InvalidConfigurationValueException(String.Format("Unable to resolve contract type: {0}", pi.Id), ex);
                            }

                            if (!string.IsNullOrEmpty(pi.EntryValue))
                            {
                                try
                                {
                                    defaultImplementationType = TypeHelper.GetTypeFromString(pi.EntryValue);
                                    if (!contractType.IsAssignableFrom(defaultImplementationType))
                                    {
                                        throw new InvalidProxyImplementationException(String.Format("Provided default implementation type '{0}' does not implement contract interface '{1}'.", defaultImplementationType.FullName, contractType.FullName));
                                    }
                                    ImplementationValidator.ValidateImplementationIntegrity(defaultImplementationType);
                                }
                                catch (Exception ex)
                                {
                                    throw new InvalidConfigurationValueException(String.Format("Unable to resolve implementation type: {0}", pi.EntryValue), ex);
                                }
                            }

                            ContractServiceSideDescriptor descriptor = new ContractServiceSideDescriptor(contractType, defaultImplementationType);

                            IEnumerator <CategoryPropertyItem> channelIterator = pi.GetEnumerator();
                            while (channelIterator.MoveNext())
                            {
                                CategoryPropertyItem channelImplementationItem = channelIterator.Current;
                                if (string.IsNullOrEmpty(channelImplementationItem.Id))
                                {
                                    throw new InvalidConfigurationValueException(String.Format("Channel identifier is missing from a configuration item of the contract '{0}'", pi.Id));
                                }
                                if (string.IsNullOrEmpty(channelImplementationItem.EntryValue))
                                {
                                    throw new InvalidConfigurationValueException(String.Format("Implementation type is missing from a configuration item of the contract '{0}'", pi.Id));
                                }
                                if (!ChannelServices.IsChannelRegistered(channelImplementationItem.Id))
                                {
                                    throw new InvalidConfigurationValueException(String.Format("Unregistered channel provided '{0}' in configuration section of the contract: {1}.", channelImplementationItem.Id, pi.Id));
                                }
                                Type type = null;
                                try
                                {
                                    type = TypeHelper.GetTypeFromString(channelImplementationItem.EntryValue);
                                    if (!contractType.IsAssignableFrom(type))
                                    {
                                        throw new InvalidProxyImplementationException(String.Format("Provided implementation type '{0}' does not implement contract interface '{1}'.", type.FullName, contractType.FullName));
                                    }
                                    ImplementationValidator.ValidateImplementationIntegrity(type);
                                }
                                catch (Exception ex)
                                {
                                    throw new InvalidConfigurationValueException(String.Format("Unable to resolve non-default implementation type: {0} for contract: {1} for the channel: {2}", channelImplementationItem.EntryValue, pi.Id, channelImplementationItem.Id), ex);
                                }
                                if (descriptor.ImplementationPerChannel.ContainsKey(channelImplementationItem.Id))
                                {
                                    throw new InvalidConfigurationException(String.Format("Duplicated channel identifier at contract '{0}'.", pi.Id));
                                }
                                descriptor.ImplementationPerChannel.Add(channelImplementationItem.Id, type);
                            }

                            ContractDescriptors.Add(contractType, descriptor);
                        }
                        ChannelServices.StartListeningChannels();
                    }
                    catch (Exception ex)
                    {
                        ContractDescriptors.Clear();
                        throw ex;
                    }
                }

                mInitialized = true;
                if (LOGGER.IsInfoEnabled)
                {
                    LOGGER.Info("ServiceBase services successfully initialized.");
                }
                Raiser.CallDelegatorBySync(EventInitialization, new object[] { null, new ServiceInitializationStateEventArgs(ServiceInitializationStateEnum.After) });
            }
        }
Ejemplo n.º 29
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.º 30
0
        private static void SectionHandler_OnConfigurationChanged(object sender, EventArgs e)
        {
            CategoryPropertyItem rootItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(RemoteDesktopConfiguration.Settings.CategoryPropertyItems, CONFIG_ROOT);

            if (rootItem != null)
            {
                AuthenticationModeEnum authMode = AuthenticationModeEnum.OnlyPassword;
                if (ConfigurationAccessHelper.ParseEnumValue <AuthenticationModeEnum>(rootItem.PropertyItems, CONFIG_AUTHENTICATION_MODE, ref authMode))
                {
                    AuthenticationMode = authMode;
                }

                string moduleStore = string.Empty;
                if (ConfigurationAccessHelper.ParseStringValue(rootItem.PropertyItems, CONFIG_AUTHENTICATION_MODULE_STORE, ref moduleStore))
                {
                    mAuthenticationModuleStore = moduleStore;
                }

                bool propagateOnNetwork = true;
                if (ConfigurationAccessHelper.ParseBooleanValue(rootItem.PropertyItems, CONFIG_PROPAGATE_ON_NETWORK, ref propagateOnNetwork))
                {
                    PropagateServiceOnTheNetwork = propagateOnNetwork;
                }

                DesktopShareModeEnum desktopShareMode = DesktopShareModeEnum.Shared;
                if (ConfigurationAccessHelper.ParseEnumValue <DesktopShareModeEnum>(rootItem.PropertyItems, CONFIG_DESKTOP_SHARE_MODE, ref desktopShareMode))
                {
                    DesktopShareMode = desktopShareMode;
                }

                bool acceptKeyboardAndMouseInputFromClients = true;
                if (ConfigurationAccessHelper.ParseBooleanValue(rootItem.PropertyItems, CONFIG_ACCEPT_INPUTS_FROM_CLIENTS, ref acceptKeyboardAndMouseInputFromClients))
                {
                    AcceptKeyboardAndMouseInputFromClients = acceptKeyboardAndMouseInputFromClients;
                }

                int desktopImageClipWidth = Consts.DEFAULT_DESKTOP_IMAGE_CLIP_SIZE;
                if (ConfigurationAccessHelper.ParseIntValue(rootItem.PropertyItems, CONFIG_DESKTOP_IMAGE_CLIP_WIDTH, Consts.MINIMAL_CLIP_SIZE, int.MaxValue, ref desktopImageClipWidth))
                {
                    DesktopImageClipWidth = desktopImageClipWidth;
                }

                int desktopImageClipHeight = Consts.DEFAULT_DESKTOP_IMAGE_CLIP_SIZE;
                if (ConfigurationAccessHelper.ParseIntValue(rootItem.PropertyItems, CONFIG_DESKTOP_IMAGE_CLIP_WIDTH, Consts.MINIMAL_CLIP_SIZE, int.MaxValue, ref desktopImageClipHeight))
                {
                    DesktopImageClipHeight = desktopImageClipHeight;
                }

                int clientsPerServiceThreads = Consts.DEFAULT_CLIENTS_PER_SERVICE_THREADS;
                if (ConfigurationAccessHelper.ParseIntValue(rootItem.PropertyItems, CONFIG_DESKTOP_IMAGE_CLIP_WIDTH, Consts.MINIMAL_CLIENTS_PER_SERVICE_THREADS, int.MaxValue, ref clientsPerServiceThreads))
                {
                    ClientsPerServiceThreads = clientsPerServiceThreads;
                }

                int maximumFailedLoginAttempt = Consts.DEFAULT_MAXIMUM_FAILED_LOGIN_ATTEMPT;
                if (ConfigurationAccessHelper.ParseIntValue(rootItem.PropertyItems, CONFIG_MAXIMUM_FAILED_LOGIN_ATTEMPT, 0, int.MaxValue, ref maximumFailedLoginAttempt))
                {
                    MaximumFailedLoginAttempt = maximumFailedLoginAttempt;
                }

                int blackListTimeout = Consts.DEFAULT_BLACKLIST_TIMEOUT_IN_MINUTES;
                if (ConfigurationAccessHelper.ParseIntValue(rootItem.PropertyItems, CONFIG_BLACKLIST_TIMEOUT, 0, int.MaxValue, ref blackListTimeout))
                {
                    BlackListTimeout = blackListTimeout;
                }

                int imageClipQuality = Consts.DEFAULT_IMAGE_CLIP_QUALITY;
                if (ConfigurationAccessHelper.ParseIntValue(rootItem.PropertyItems, CONFIG_IMAGE_CLIP_QUALITY, 10, 100, ref imageClipQuality))
                {
                    DefaultImageClipQuality = imageClipQuality;
                }

                int mouseMoveSendingInterval = Consts.DEFAULT_MOUSE_MOVE_SEND_INTERVAL;
                if (ConfigurationAccessHelper.ParseIntValue(rootItem.PropertyItems, CONFIG_MOUSE_MOVE_SEND_INTERVAL, 0, int.MaxValue, ref mouseMoveSendingInterval))
                {
                    MouseMoveSendInterval = mouseMoveSendingInterval;
                }
            }

            Raiser.CallDelegatorBySync(EventConfigurationChanged, new object[] { null, EventArgs.Empty });
        }