Example #1
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            node.NonEmpty(nameof(GdidProviderModule) + ".conf");
            base.DoConfigure(node);

            var isLocal = node.Of(CONFIG_LOCAL_ATTR).ValueAsBool(false);

            var naccessor = node[CONFIG_ACCESSOR_SECT];

            if (!isLocal && naccessor.Exists)
            {
                var accessor = FactoryUtils.MakeAndConfigureDirectedComponent <IGdidAuthorityAccessor>(this, naccessor);
                m_Generator = new GdidGenerator(this, nameof(GdidProviderModule), ScopePrefix, SequencePrefix, accessor);
            }
            else
            {
                if (isLocal)
                {
                    m_Generator = new LocalGdidGenerator(this);
                }
                else
                {
                    m_Generator = new GdidGenerator(this, nameof(GdidProviderModule));
                }
            }

            var ngen = node[CONFIG_GENERATOR_SECT];

            if (ngen.Exists && m_Generator is IConfigurable configurable)
            {
                configurable.Configure(ngen);
            }
        }
Example #2
0
        internal Area(Heap director, IConfigSectionNode cfg) : base(director)
        {
            cfg.NonEmpty(nameof(cfg));

            //1. Build Schema
            m_Schema = new TypeSchema(this, cfg[TypeSchema.CONFIG_SCHEMA_SECTION]);

            //2. Build Selector
            var cfgSelector = cfg[CONFIG_NODE_SELECTOR_SECTION];

            m_NodeSelector = FactoryUtils.MakeDirectedComponent <INodeSelector>(this, cfgSelector, typeof(DefaultNodeSelector), new object[] { cfgSelector });

            //3. Build Service Client
            var cfgClient = cfg[CONFIG_SERVICE_CLIENT_SECTION];

            m_ServiceClient = FactoryUtils.MakeDirectedComponent <IHttpService>(this, cfgClient, typeof(HttpService), new object[] { cfgClient });

            //4. Build Spaces
            m_Spaces = new Dictionary <Type, ISpace>();
            foreach (var tObject in m_Schema.ObjectTypes)
            {
                var tSpace = typeof(Space <>).MakeGenericType(tObject);
                var space  = Activator.CreateInstance(tSpace).CastTo <ISpace>("space .ctor");
                m_Spaces.Add(tSpace, space);
            }
        }
Example #3
0
        protected WorkHandler(WorkDispatcher dispatcher, IConfigSectionNode confNode) : base(dispatcher)
        {
            confNode.NonEmpty(nameof(confNode));

            ConfigAttribute.Apply(this, confNode);

            m_Dispatcher = dispatcher;
            m_Server     = dispatcher.ComponentDirector;
            m_Name       = confNode.AttrByName(Configuration.CONFIG_NAME_ATTR).Value;
            m_Order      = confNode.AttrByName(Configuration.CONFIG_ORDER_ATTR).ValueAsInt(0);
            if (m_Name.IsNullOrWhiteSpace())
            {
                m_Name = "{0}({1})".Args(GetType().FullName, Guid.NewGuid());
            }


            foreach (var cn in confNode.Children.Where(cn => cn.IsSameName(WorkFilter.CONFIG_FILTER_SECTION)))
            {
                if (!m_Filters.Register(FactoryUtils.Make <WorkFilter>(cn, typeof(WorkFilter), args: new object[] { this, cn })))
                {
                    throw new WaveException(StringConsts.CONFIG_HANDLER_DUPLICATE_FILTER_NAME_ERROR.Args(cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value));
                }
            }

            foreach (var cn in confNode.Children.Where(cn => cn.IsSameName(WorkMatch.CONFIG_MATCH_SECTION)))
            {
                if (!m_Matches.Register(FactoryUtils.Make <WorkMatch>(cn, typeof(WorkMatch), args: new object[] { cn })))
                {
                    throw new WaveException(StringConsts.CONFIG_HANDLER_DUPLICATE_MATCH_NAME_ERROR.Args(cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value));
                }
            }
        }
        protected byte[][] BuildKeysFromConfig(IConfigSectionNode config, string sectionName, int len)
        {
            var result = config.NonEmpty(nameof(config))
                         .Children
                         .Where(c => c.IsSameName(sectionName) && c.ValOf(CONFIG_KEY_ATTR).IsNotNullOrWhiteSpace())
                         .Select(c => BuildKeyFromConfig(c, len))
                         .ToArray();

            if (result.Length == 0)
            {
                throw new SecurityException("{0} config section `{1}` must contain at least one key entry".Args(GetType().Name, sectionName));
            }

            foreach (var a in result)
            {
                if (a.Length != len)
                {
                    throw new SecurityException("{0} config section `{1}` all keys must be of {2} bytes in length".Args(GetType().Name, sectionName, len));
                }
                if (result.Any(a2 => a2 != a && a.MemBufferEquals(a2)))
                {
                    throw new SecurityException("{0} config section `{1}` contains duplicate keys".Args(GetType().Name, sectionName));
                }
            }

            return(result);
        }
Example #5
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            base.DoConfigure(node);
            var ndata = node.NonEmpty(nameof(node))[CONFIG_DATA_SECTION]
                        .NonEmpty($"section `{CONFIG_DATA_SECTION}`");

            m_Data = FactoryUtils.MakeAndConfigureDirectedComponent <IForestDataSource>(this, ndata, typeof(ForestDataSource));
        }
Example #6
0
 protected LoginProvider(IIdpHandlerLogic handler, IConfigSectionNode cfg) : base(handler)
 {
     cfg.NonEmpty(nameof(cfg));
     m_Name = cfg.Of(Configuration.CONFIG_NAME_ATTR).ValueAsAtom(Atom.ZERO).Value;
     m_Name.NonBlank("attribute ${0}".Args(Configuration.CONFIG_NAME_ATTR));
     m_DefaultLoginType = cfg.Of(CONFIG_DEFAULT_LOGIN_TYPE_ATTR).ValueAsAtom(Atom.ZERO);
     SupportedLoginTypes.Any(t => t == m_DefaultLoginType)
     .IsTrue("Known login type");
 }
Example #7
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            var nlog = node.NonEmpty(nameof(node))[CommonApplicationLogic.CONFIG_LOG_SECTION]
                       .NonEmpty($"`{CommonApplicationLogic.CONFIG_LOG_SECTION}` config section");

            DisposeAndNull(ref m_Log);

            m_Log = FactoryUtils.MakeAndConfigureDirectedComponent <ILogImplementation>(this, nlog, typeof(LogDaemon));

            base.DoConfigure(node);
        }
Example #8
0
File: Shard.cs Project: azist/azos
        protected internal Shard(ShardSet set, IConfigSectionNode conf)
        {
            m_Set = set.NonNull(nameof(set));
            ConfigAttribute.Apply(this, conf.NonEmpty(nameof(conf)));
            m_Name     = conf.ValOf(Configuration.CONFIG_NAME_ATTR).NonBlank("$name");
            m_NameHash = ShardKey.ForString(m_Name);

            m_Weight = conf.Of(CONFIG_WEIGHT_ATTR).ValueAsDouble(1.0d);

            m_ConnectString = conf.Of(CONFIG_CONNECT_ATTR, CONFIG_CONNECT_STRING_ATTR).Value.NonBlank($"${CONFIG_CONNECT_ATTR}");
            m_DatabaseName  = conf.Of(CONFIG_DB_ATTR).Value.NonBlank($"${CONFIG_DB_ATTR}");
        }
Example #9
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            node.NonEmpty(nameof(GdidAuthorityModule) + ".conf");

            base.DoConfigure(node);

            var nauth = node[CONFIG_AUTHORITY_SECT];

            nauth.NonEmpty("cfg section `{0}`".Args(CONFIG_AUTHORITY_SECT));

            DisposeAndNull(ref m_Svc);
            m_Svc = FactoryUtils.MakeAndConfigureDirectedComponent <GdidAuthorityService>(this, nauth, typeof(GdidAuthorityService));
        }
Example #10
0
 internal ServerLocation(IAMClient owner, IConfigSectionNode cfg)
 {
     Owner = owner;
     ConfigAttribute.Apply(this, cfg.NonEmpty(nameof(cfg)));
     if (Uri == null)
     {
         throw new IAMException(StringConsts.ARGUMENT_ERROR + "ServerLocation.ctor(uri==null)");
     }
     if (Name.IsNullOrWhiteSpace())
     {
         Name = Uri.AbsolutePath;
     }
 }
Example #11
0
        internal TypeSchema(IArea area, IConfigSectionNode cfg)
        {
            m_Area = area.NonNull(nameof(area));

            if (!cfg.NonEmpty(nameof(cfg)).IsSameName(CONFIG_SCHEMA_SECTION))
            {
                cfg = cfg[CONFIG_SCHEMA_SECTION];
            }

            cfg.NonEmpty(nameof(CONFIG_SCHEMA_SECTION));

            m_Assemblies  = new Dictionary <string, BuildInformation>(StringComparer.OrdinalIgnoreCase);
            m_ObjectTypes = new Dictionary <string, Type>(StringComparer.OrdinalIgnoreCase);
            m_QueryTypes  = new Dictionary <string, List <Type> >(StringComparer.OrdinalIgnoreCase);

            try
            {
                foreach (var node in cfg.ChildrenNamed(CONFIG_ASSEMBLY_SECTION))
                {
                    var fn    = node.ValOf(CONFIG_FILE_ATTR).NonBlank("{0}/${1}".Args(node.RootPath, CONFIG_FILE_ATTR));
                    var asm   = Assembly.LoadFrom(fn);
                    var nsPat = node.ValOf(CONFIG_NS_PATTERN_ATTR).Default("*");
                    load(asm, nsPat);
                }

                //Computer version digest on SORTED assembly Build infos
                //the operation is deferred after all assemblies finished loading
                m_Version = 0;
                foreach (var entry in m_Assemblies.OrderBy(e => e.Key))   //(deterministic order) based on Assembly FQN
                {
                    m_Version ^= ShardKey.ForString(entry.Value.Content); //compute version digest hash based on the BuildInfo
                }
            }
            catch (Exception error)
            {
                throw new ConfigException("Bad config of {0}: {1}".Args(nameof(TypeSchema), error.ToMessageWithType()), error);
            }
        }
        protected byte[] BuildKeyFromConfig(IConfigSectionNode keyNode, int len)
        {
            var result = keyNode.NonEmpty(nameof(keyNode))
                         .AttrByName(CONFIG_KEY_ATTR)
                         .ValueAsByteArray(null)
                         ??
                         throw new SecurityException("{0} config section `{1}` does not contain a valid key byte array".Args(GetType().Name, keyNode.RootPath));

            if (result.Length != len)
            {
                throw new SecurityException("{0} config section `{1}` keys must be of {2} bytes in length".Args(GetType().Name, keyNode.RootPath, len));
            }

            return(result);
        }
Example #13
0
        private void ctor(WorkDispatcher dispatcher, IConfigSectionNode confNode)
        {
            confNode.NonEmpty(nameof(confNode));

            ConfigAttribute.Apply(this, confNode);

            m_Dispatcher = dispatcher;
            m_Server     = dispatcher.ComponentDirector;
            m_Name       = confNode.AttrByName(Configuration.CONFIG_NAME_ATTR).Value;
            m_Order      = confNode.AttrByName(Configuration.CONFIG_ORDER_ATTR).ValueAsInt(0);

            if (m_Name.IsNullOrWhiteSpace())
            {
                throw new WaveException(StringConsts.ARGUMENT_ERROR + GetType().FullName + ".ctor(confNode$name==null|empty)");
            }
        }
Example #14
0
        public ShardSet(IShardedCrudDataStoreImplementation director, IConfigSectionNode conf) : base(director)
        {
            ConfigAttribute.Apply(this, conf.NonEmpty(nameof(conf)));
            m_Name.NonBlank("$name");

            m_Shards = new List <IShard>();
            //read shards
            foreach (var nsh in conf.ChildrenNamed(CONFIG_SHARD_SECTION))
            {
                var shard = director.MakeShard(this, nsh);
                if (m_Shards.Any(s => s.Name.EqualsIgnoreCase(shard.Name)))
                {
                    throw new DataAccessException(StringConsts.DATA_SHARDING_DUPLICATE_SECTION_CONFIG_ERROR.Args(CONFIG_SHARD_SECTION, shard.Name));
                }
                m_Shards.Add(shard);
            }

            m_Shards.IsTrue(s => s.Count > 0, StringConsts.DATA_SHARDING_AT_LEAST_ONE_CLAUSE);
        }
Example #15
0
 protected Cmdlet(AppRemoteTerminal terminal, IConfigSectionNode args)
 {
     m_Terminal = terminal.NonNull(nameof(terminal));
     m_Args     = args.NonEmpty(nameof(args));
 }
 protected CryptoMessageAlgorithm(ICryptoManagerImplementation director, IConfigSectionNode config) : base(director)
 {
     ConfigAttribute.Apply(this, config.NonEmpty("{0}.ctor(config=null|!Exists)".Args(GetType().Name)));
 }
Example #17
0
 /// <summary>
 /// Typically you would not call this .ctor directly unless you are temporarily mocking assumptions.
 /// Call <see cref="AssumptionsForCaller(string)"/> or <see cref="AssumptionsForCallerStory(string, string)"/> instead
 /// </summary>
 public Assumptions(AssumptionsType tp, IConfigSectionNode data)
 {
     Type = tp;
     Data = data.NonEmpty(nameof(data));
 }
Example #18
0
 /// <summary>
 /// Warning: storing plain credentials in config file is not secure. Use this method for the most simplistic cases
 /// like unit testing
 /// </summary>
 public IDPasswordCredentials(IConfigSectionNode cfg)
 {
     cfg.NonEmpty(nameof(cfg));
     ConfigAttribute.Apply(this, cfg);
 }
Example #19
0
 protected EndpointBase(TService service, IConfigSectionNode conf) : base(service)
 {
     ConfigAttribute.Apply(this, conf.NonEmpty(nameof(conf)));
 }