コード例 #1
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);
        }
コード例 #2
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            base.DoConfigure(node);
            if (node == null || !node.Exists)
            {
                return;
            }

            cleanup();
            m_Providers = new Registry <LoginProvider>();

            foreach (var np in node.ChildrenNamed(LoginProvider.CONFIG_PROVIDER_SECTION))
            {
                var provider = FactoryUtils.MakeDirectedComponent <LoginProvider>(this, np, extraArgs: new object[] { np });
                if (!m_Providers.Register(provider))
                {
                    throw new AuthKitException("Duplicate provider `{0}` name in config".Args(provider.Name));
                }
            }
        }
コード例 #3
0
ファイル: TypeSchema.cs プロジェクト: azist/azos
        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);
            }
        }
コード例 #4
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            base.DoConfigure(node);
            if (node == null)
            {
                return;
            }

            cleanup();

            //build forests
            foreach (var nforest in node.ChildrenNamed(CONFIG_FOREST_SECTION))
            {
                var idForest = nforest.Of(Configuration.CONFIG_NAME_ATTR, "id").ValueAsAtom(Atom.ZERO);
                if (idForest.IsZero || !idForest.IsValid)
                {
                    throw new ConfigException($"{nameof(ForestDataSource)} config `forest` section is missing a valid atom `$id`");
                }

                var trees  = new Registry <IDataStoreImplementation>();
                var forest = new _forest(idForest, trees);

                if (!m_Forests.Register(forest))
                {
                    throw new ConfigException($"{nameof(ForestDataSource)} config duplicate section: ./forest[name='{forest.Name}']");
                }

                //build trees
                foreach (var ntree in nforest.ChildrenNamed(CONFIG_TREE_SECTION))
                {
                    var idTree = ntree.Of(Configuration.CONFIG_NAME_ATTR).ValueAsAtom(Atom.ZERO);
                    if (idTree.IsZero || !idTree.IsValid)
                    {
                        throw new ConfigException($"{nameof(ForestDataSource)} config `tree` section is missing a valid atom `$id`");
                    }

                    var tree = FactoryUtils.MakeAndConfigureDirectedComponent <IDataStoreImplementation>(this, ntree);

                    if (!trees.Register(tree))
                    {
                        throw new ConfigException($"{nameof(ForestDataSource)} config duplicate section: ./forest[name='{forest.Name}']/tree['{tree.Name}']");
                    }
                }
            }

            //Build CACHE
            var ncache = node[CONFIG_CACHE_SECTION];

            m_Cache = FactoryUtils.MakeAndConfigureDirectedComponent <ICacheImplementation>(this,
                                                                                            ncache,
                                                                                            typeof(LocalCache),
                                                                                            new[] { "Cache::{0}::{1}".Args(nameof(ForestDataSource), Name) });
            if (m_Cache is LocalCache lcache)
            {
                var npile = node[CONFIG_PILE_SECTION];
                m_Pile = FactoryUtils.MakeAndConfigureDirectedComponent <IPileImplementation>(this,
                                                                                              npile,
                                                                                              typeof(DefaultPile),
                                                                                              new[] { "Pile::{0}::{1}".Args(nameof(ForestDataSource), Name) });
                lcache.Pile = m_Pile;
            }
        }