Beispiel #1
0
        private bool LoadFile( Stream stream )
        {
            string magic = stream.ReadAscii( 8 );
            uint strategySetCount = stream.ReadUInt32().SwapEndian();
            uint strategyOptionCount = stream.ReadUInt32().SwapEndian();
            uint refStringStart = stream.ReadUInt32().SwapEndian();

            StrategySetList = new List<StrategySet>( (int)strategySetCount );
            for ( uint i = 0; i < strategySetCount; ++i ) {
                StrategySet ss = new StrategySet( stream, refStringStart );
                StrategySetList.Add( ss );
            }
            StrategyOptionList = new List<StrategyOption>( (int)strategyOptionCount );
            for ( uint i = 0; i < strategyOptionCount; ++i ) {
                StrategyOption so = new StrategyOption( stream, refStringStart );
                StrategyOptionList.Add( so );
            }

            StrategyOptionDict = new Dictionary<uint, StrategyOption>( StrategyOptionList.Count );
            foreach ( var option in StrategyOptionList ) {
                StrategyOptionDict.Add( option.InGameID, option );
            }

            return true;
        }
        public override void Configuration(Action <StrategyOption> config)
        {
            var options = new StrategyOption();

            config?.Invoke(options);
            _tradeManager = options.TradeManager ?? throw new ArgumentNullException(nameof(options.TradeManager));
            _volumeBase   = options.Volume ?? 1;
        }
        public List <PersonComponent> ShowStructure(StrategyOption option)
        {
            if (option == StrategyOption.Height)
            {
                choosenStrategy = new Context(new ShowByHeightStrategy(root));
            }
            if (option == StrategyOption.Directsubordination)
            {
                choosenStrategy = new Context(new DirectSubordinationStrategy(root));
            }
            List <PersonComponent> list = choosenStrategy.ExecuteAlgorithm(root);

            return(list);
        }
        public void Builder(StrategyOption strategyOption)
        {
            //at this point all dependencies can be added
            //to the DI system via service collection

            service.AddScoped <IPathRetriever, AppsettingsRetriever>();

            switch (strategyOption)
            {
            case StrategyOption.UnitTestScripts:
                service.AddScoped <IAppLogic, AppLogicForCopyingScripts>();
                break;

            case StrategyOption.WebConfig:
                service.AddScoped <IAppLogic, AppLogic>();
                break;

            default:
                throw new Exception("No strategy chosen");
            }



            //configuration are heavily used in the .net core DI
            //for configuring services, so can be done usage of that
            var configurationBuilder = new ConfigurationBuilder();

            //adding default configuration file
            configurationBuilder.SetBasePath(GetAppsettingpath()).AddJsonFile("appsettings.json");

            // building the configuration
            var configuration = configurationBuilder.Build();

            //Inject the configuration into the DI system
            //service.AddSingleton<IConfiguration>(configuration);
            service.AddSingleton(configuration);

            // builder service provider
            ServiceProvider = service.BuildServiceProvider();
        }
Beispiel #5
0
        public StrategyOption ResolveStrategy <T>(ModelActionOption option, out string implementorType)
        {
            implementorType = String.Empty;
            StrategyOption strategy = StrategyOption.None;
            Model          m        = Models.Find(x => x.modelType.Equals(typeof(T).FullName, StringComparison.OrdinalIgnoreCase));

            if (m != null)
            {
                if (option == ModelActionOption.ExecuteAction)
                {
                    if (String.IsNullOrEmpty(m.actionExecutorType))
                    {
                        // log
                    }
                    else
                    {
                        implementorType = m.actionExecutorType;
                    }
                }
                else
                {
                    ModelAction a = m.ModelActions.Find(x => x.Verb.Equals(option));
                    if (a != null)
                    {
                        strategy = a.Strategy;
                        switch (a.Strategy)
                        {
                        case StrategyOption.Factory:
                            implementorType = m.factoryType;
                            break;

                        case StrategyOption.ActionExecutor:
                            implementorType = m.actionExecutorType;
                            break;

                        case StrategyOption.Custom:
                            implementorType = m.customType;
                            break;

                        case StrategyOption.None:
                        case StrategyOption.Config:
                        default:
                            break;
                        }
                    }
                    else
                    {
                        strategy = DefaultStrategy;
                        if (strategy == StrategyOption.ActionExecutor)
                        {
                            implementorType = m.actionExecutorType;
                        }
                        else if (strategy == StrategyOption.Factory)
                        {
                            implementorType = m.factoryType;
                        }
                        else if (strategy == StrategyOption.Custom)
                        {
                            implementorType = m.customType;
                        }
                    }
                }
            }
            else
            {
                strategy = DefaultStrategy;
            }

            if (option == ModelActionOption.ExecuteAction)
            {
                strategy = StrategyOption.ActionExecutor;
            }
            return(strategy);
        }