Exemplo n.º 1
0
 /// <summary>
 /// Instantiates an new instance with the data from the <paramref name="configuration"/>.
 /// </summary>
 /// <param name="configuration">The configuration to use to populate the new instance.</param>
 public TransportController(Configuration.IConfigurationGroup configuration)
     : this()
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     if (configuration.Key != "TransportController")
     {
         throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"TransportController\". Configuration Key={configuration.Key}", nameof(configuration));
     }
     // _TransportConfiguration
     if (configuration.ContainsKey("TransportConfiguration"))
     {
         TransportConfiguration = (ITransportConfiguration)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(typeof(TransportConfiguration), configuration["TransportConfiguration"]);
     }
     // _RegistrationController
     if (!configuration.ContainsKey("RegistrationController"))
     {
         throw new ArgumentException($"Configuration missing subgroup. Configuration must have subgroup: \"RegistrationController\".", nameof(configuration));
     }
     if ((!configuration["RegistrationController"].ContainsKey("TransportConfiguration")) &&
         (configuration.ContainsKey("TransportConfiguration")))
     {
         configuration["RegistrationController"].Add(configuration["TransportConfiguration"]);
     }
     RegistrationController = (IRegistrationController)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(null, configuration["RegistrationController"]);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Instantiates an new instance with the data from the <paramref name="configuration"/>.
 /// </summary>
 /// <param name="configuration">The configuration to use to populate the new instance.</param>
 public NullRegistrationController(Configuration.IConfigurationGroup configuration)
     : this()
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     if (configuration.Key != "RegistrationController")
     {
         throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"RegistrationController\". Configuration Key={configuration.Key}", nameof(configuration));
     }
     // _TransportConfiguration
     if (configuration.ContainsKey("TransportConfiguration"))
     {
         TransportConfiguration = (ITransportConfiguration)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(typeof(TransportConfiguration), configuration["TransportConfiguration"]);
     }
     // _ChallengeController
     if (configuration.ContainsKey("ChallengeController"))
     {
         ChallengeController = (IChallengeController)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(null, configuration["ChallengeController"]);
     }
     else if (configuration.Items.ContainsKey("Evidence"))
     {
         if (!configuration.Items["Evidence"].ValueType.StartsWith(typeof(byte[]).FullName))
         {
             throw new Exception($"Configuration item invalid format. Configuration item \"Evidence\" must be a <{typeof(byte[])}>.");
         }
         _ChallengeEvidence = (byte[])configuration.Items["Evidence"].Value;
     }
     else
     {
         throw new ArgumentException($"Configuration missing information. Configuration must have either an \"Evidence\" item or a \"ChallengeController\" subgroup.", nameof(configuration));
     }
 }
 /// <summary>
 /// Instantiates an new instance with the data from the <paramref name="configuration"/>.
 /// </summary>
 /// <param name="configuration">The configuration to use to populate the new instance.</param>
 public StackableEncryptor(Configuration.IConfigurationGroup configuration)
     : this()
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     if (configuration.Key != "Encryptor")
     {
         throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"Encryptor\". Configuration Key={configuration.Key}", nameof(configuration));
     }
     // EncryptorConfigurations
     if (!configuration.ContainsKey("EncryptorConfigurations"))
     {
         throw new ArgumentException($"Configuration missing subgroup. Configuration must have subgroup: \"EncryptorConfigurations\".", nameof(configuration));
     }
     _EncryptorConfigurations = new List <IEncryptorConfiguration>();
     foreach (var item in configuration["EncryptorConfigurations"])
     {
         // TODO: change this configuration item name to HashAlgorithmType to be consistent
         // HashAlgorithm
         var hashAlgorithmType = Type.GetType((string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "HashAlgorithm", typeof(Type)).Value);
         // Salt
         var    saltValue = (string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "Salt", typeof(string)).Value;
         byte[] salt      = Convert.FromBase64String(saltValue);
         // PasswordSaltHash
         var    passwordSaltHashValue = (string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "PasswordSaltHash", typeof(string)).Value;
         byte[] passwordSaltHash      = Convert.FromBase64String(passwordSaltHashValue);
         // SymmetricAlgorithmType
         Type            symmetricAlgorithmType = Type.GetType((string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "SymmetricAlgorithmType", typeof(Type)).Value);
         ISaltedPassword saltedPassword         = new SaltedPassword(hashAlgorithmType, passwordSaltHash, salt);
         var             dude = new EncryptorConfiguration(saltedPassword, symmetricAlgorithmType);
         _EncryptorConfigurations.Add(dude);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Instantiates an new instance with the data from the <paramref name="configuration"/>.
 /// </summary>
 /// <param name="configuration">The configuration to use to populate the new instance.</param>
 public CachedLog(Configuration.IConfigurationGroup configuration)
     : this()
 {
     // check
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     if (configuration.Key != "Log")
     {
         throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"Log\". Configuration Key={configuration.Key}", nameof(configuration));
     }
     // Log
     if (!configuration.ContainsKey("Log"))
     {
         throw new ArgumentException($"Configuration missing subgroup. Configuration must have subgroup: \"Log\".", nameof(configuration));
     }
     InnerLog = (ILog)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(null, configuration["Log"]);
     InnerLog.Open();
     // AutoFlushLogs
     AutoFlushEnabled = (bool)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "AutoFlushLogs", typeof(bool)).Value;
     // FlushMaximumLogs
     FlushMaximumLogs = (int)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "FlushMaximumLogs", typeof(int)).Value;
     // FlushTimeLimit
     FlushTimeLimit = (TimeSpan)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "FlushTimeLimit", typeof(TimeSpan)).Value;
 }
        /// <summary>
        /// Instantiates an new instance with the data from the <paramref name="configuration"/>.
        /// </summary>
        /// <param name="configuration">The configuration to use to populate the new instance.</param>
        public TransportConfiguration(Configuration.IConfigurationGroup configuration)
            : this()
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (configuration.Key != "TransportConfiguration")
            {
                throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"TransportConfiguration\". Configuration Key={configuration.Key}", nameof(configuration));
            }
            // Compressor
            CompressorType = Type.GetType((string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "Compressor", typeof(Type)).Value);
            // UseChunking
            UseChunking = (bool)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "UseChunking", typeof(bool)).Value;
            // ChunkSize
            var chunkSize = (int)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "ChunkSize", typeof(int)).Value;

            if (chunkSize < NetworkingHelper.MinimumTransportEnvelopeChunkSize)
            {
                throw new ArgumentOutOfRangeException(string.Format("ChunkSize too small. Minimum Chunk Size= {0}", NetworkingHelper.MinimumTransportEnvelopeChunkSize));
            }
            ChunkSize = chunkSize;
            // EnvelopeCacheTimeLimit
            var envelopeCacheTimeLimit = (TimeSpan)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "EnvelopeCacheTimeLimit", typeof(TimeSpan)).Value;

            if (envelopeCacheTimeLimit < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("EnvelopeCacheTimeLimit cannot be less than TimeSpan.Zero.");
            }
            EnvelopeCacheTimeLimit = envelopeCacheTimeLimit;
            // SeenMessageCacheTimeLimit
            var seenMessageCacheTimeLimit = (TimeSpan)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "SeenMessageCacheTimeLimit", typeof(TimeSpan)).Value;

            if (seenMessageCacheTimeLimit < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("SeenMessageCacheTimeLimit cannot be less than TimeSpan.Zero.");
            }
            SeenMessageCacheTimeLimit = seenMessageCacheTimeLimit;
            // EncryptorConfigurations
            if (configuration.ContainsKey("EncryptorConfigurations"))
            {
                var configs = new List <Cryptography.IEncryptorConfiguration>();
                foreach (var group in configuration["EncryptorConfigurations"])
                {
                    ((dodSON.Core.Configuration.IConfigurationGroupAdvanced)group).SetKey("EncryptorConfiguration");
                    var dude = (Cryptography.IEncryptorConfiguration)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(typeof(Cryptography.EncryptorConfiguration), group);
                    configs.Add(dude);
                }
                EncryptorConfigurations = configs;
            }
        }
        /// <summary>
        /// Instantiates an new instance with the data from the <paramref name="configuration"/>.
        /// </summary>
        /// <param name="configuration">The configuration to use to populate the new instance.</param>
        public PackageConfiguration(Configuration.IConfigurationGroup configuration)
            : this()
        {
            // check
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (configuration.Key != "PackageConfiguration")
            {
                throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"PackageConfiguration\". Configuration Key={configuration.Key}", nameof(configuration));
            }
            // Name
            var temp1 = (string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "Name", typeof(string)).Value; //

            if (string.IsNullOrWhiteSpace(temp1))
            {
                throw new Exception($"Configuration invalid information. Configuration item: \"Name\" cannot be empty.");
            }
            Name = temp1;
            // Version
            Version = (Version)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "Version", typeof(Version)).Value;
            // IsEnabled
            IsEnabled = (bool)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "IsEnabled", typeof(bool)).Value;
            // Priority
            Priority = (double)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "Priority", typeof(double)).Value;
            // IsDependencyPackage
            IsDependencyPackage = (bool)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "IsDependencyPackage", typeof(bool)).Value;
            // group: DependencyPackages
            if (configuration.ContainsKey("DependencyPackages"))
            {
                foreach (var item in configuration["DependencyPackages"])
                {
                    ((Configuration.IConfigurationGroupAdvanced)item).SetKey("DependencyPackage");
                    DependencyPackages.Add(new DependencyPackage(item));
                }
            }
        }
 /// <summary>
 /// Instantiates an new instance with the data from the <paramref name="configuration"/>.
 /// </summary>
 /// <param name="configuration">The configuration to use to populate the new instance.</param>
 public EncryptorConfiguration(Configuration.IConfigurationGroup configuration)
     : this()
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     if (configuration.Key != "EncryptorConfiguration")
     {
         throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"EncryptorConfiguration\". Configuration Key={configuration.Key}", nameof(configuration));
     }
     // SymmetricAlgorithm
     try
     {
         SymmetricAlgorithmType = Type.GetType((string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "SymmetricAlgorithmType", typeof(Type)).Value);
     }
     catch { }
     // SaltedPassword
     if (!configuration.ContainsKey("SaltedPassword"))
     {
         throw new Exception($"Configuration missing information. Configuration must have item: \"SaltedPassword\".");
     }
     SaltedPassword = (Cryptography.ISaltedPassword)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(typeof(Cryptography.SaltedPassword), configuration["SaltedPassword"]);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Instantiates an new instance with the data from the <paramref name="configuration"/>.
 /// </summary>
 /// <param name="configuration">The configuration to use to populate the new instance.</param>
 public LogCombiner(Configuration.IConfigurationGroup configuration)
     : this()
 {
     // check
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     if (configuration.Key != "LogCombiner")
     {
         throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"LogCombiner\". Configuration Key={configuration.Key}", nameof(configuration));
     }
     // group: Logs
     if (configuration.ContainsKey("Logs"))
     {
         var logs = new List <ILog>();
         foreach (var item in configuration["Logs"])
         {
             ((Configuration.IConfigurationGroupAdvanced)item).SetKey("Log");
             logs.Add((ILog)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(item));
         }
         Logs = logs;
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Instantiates an new instance with the data from the <paramref name="configuration"/>.
        /// </summary>
        /// <param name="configuration">The configuration to use to populate the new instance.</param>
        public CommunicationController(Configuration.IConfigurationGroup configuration)
            : this()
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (configuration.Key != "CommunicationController")
            {
                throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"CommunicationController\". Configuration Key={configuration.Key}", nameof(configuration));
            }
            // log source id
            LogSourceId = (string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "LogSourceId", typeof(string)).Value;
            // _ServerType
            ServerType = (Type)Type.GetType((string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "Server", typeof(Type)).Value);
            // _ClientType
            ClientType = (Type)Type.GetType((string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "Client", typeof(Type)).Value);
            // _SharedServerChannelAddress
            if (!configuration.ContainsKey("ServerChannel"))
            {
                throw new ArgumentException($"Configuration missing subgroup. Configuration must have subgroup: \"ServerChannel\".", nameof(configuration));
            }
            // ---- ip address
            if (!configuration["ServerChannel"].Items.ContainsKey("IPAddress"))
            {
                configuration["ServerChannel"].Items.Add("IPAddress", "localhost", typeof(string));
            }
            else
            {
                if (configuration["ServerChannel"].Items["IPAddress"].Value.ToString() == "")
                {
                    configuration["ServerChannel"].Items.Add("IPAddress", "localhost", typeof(string));
                }
            }
            if (!configuration["ServerChannel"].Items["IPAddress"].ValueType.StartsWith(typeof(string).FullName))
            {
                throw new Exception($"Configuration item invalid format. Configuration item \"ServerChannel:IPAddress\" must be a <{typeof(string)}>.");
            }
            string ipAddress = (string)configuration["ServerChannel"].Items["IPAddress"].Value;

            // ---- port
            if (!configuration["ServerChannel"].Items.ContainsKey("Port"))
            {
                throw new ArgumentException($"Configuration missing information. Configuration must have item: \"ServerChannel:Port\".", nameof(configuration));
            }
            if (!configuration["ServerChannel"].Items["Port"].ValueType.StartsWith(typeof(int).FullName))
            {
                throw new Exception($"Configuration item invalid format. Configuration item \"ServerChannel:Port\" must be a <{typeof(int)}>.");
            }
            int port = (int)configuration["ServerChannel"].Items["Port"].Value;

            // ---- name
            if (!configuration["ServerChannel"].Items.ContainsKey("Name"))
            {
                throw new ArgumentException($"Configuration missing information. Configuration must have item: \"ServerChannel:Name\".", nameof(configuration));
            }
            if (!configuration["ServerChannel"].Items["Name"].ValueType.StartsWith(typeof(string).FullName))
            {
                throw new Exception($"Configuration item invalid format. Configuration item \"ServerChannel:Name\" must be a <{typeof(string)}>.");
            }
            if (string.IsNullOrWhiteSpace((string)configuration["ServerChannel"].Items["Name"].Value))
            {
                throw new Exception($"Configuration invalid information. Configuration item: \"ServerChannel:Name\" cannot be empty.");
            }
            string name = (string)configuration["ServerChannel"].Items["Name"].Value;

            SharedChannelAddress = new Networking.ChannelAddress(ipAddress, port, name);
            // _SharedServerConfiguration
            if (!configuration.Items.ContainsKey("ServerId"))
            {
                throw new ArgumentException($"Configuration missing information. Configuration must have item: \"ServerId\".", nameof(configuration));
            }
            if (!configuration.Items["ServerId"].ValueType.StartsWith(typeof(string).FullName))
            {
                throw new Exception($"Configuration item invalid format. Configuration item \"ServerId\" must be a <{typeof(string)}>.");
            }
            string id = (string)configuration.Items["ServerId"].Value;

            if (!configuration.ContainsKey("ServerOverrideTypesFilter"))
            {
                throw new ArgumentException($"Configuration missing subgroup. Configuration must have subgroup: \"ServerOverrideTypesFilter\".", nameof(configuration));
            }
            List <Networking.IPayloadTypeInfo> overrideTypesFilter = new List <Networking.IPayloadTypeInfo>();

            foreach (var item in configuration["ServerOverrideTypesFilter"].Items)
            {
                string typeName = (string)item.Value;
                overrideTypesFilter.Add(new Networking.PayloadTypeInfo(typeName));
            }
            SharedServerConfiguration = new Networking.ServerConfiguration(id, overrideTypesFilter);
            // _TransportController
            if (!configuration.ContainsKey("TransportController"))
            {
                throw new ArgumentException($"Configuration missing subgroup. Configuration must have subgroup: \"TransportController\".", nameof(configuration));
            }
            TransportController = (Networking.ITransportController)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(typeof(Networking.TransportController), configuration["TransportController"]);
        }