Example #1
0
        public void CreateTest()
        {
            _objectsCreated = 0;

            var config = A.Fake <IConfiguration>();

            A.CallTo(() => config.GetItems <object>())
            .Returns(CreateNewObjects())
            .NumberOfTimes(1)
            .Then
            .Returns(CreateNewObjects());

            var factory = new SettingsFactory <object>(config);


            var items0 = factory.Create().ToArray();
            var items1 = factory.Create().ToArray();

            Assert.Equal(2, _objectsCreated);
            Assert.Single((IEnumerable)items0);
            Assert.Single(items1);
            Assert.Contains("c", items0);
            Assert.Contains("cc", items1);
            Assert.NotSame(items0, items1);
        }
Example #2
0
        public static void BeginProgram()
        {
            var timer = new Timer("Starting DaySim Controller...");

            Console.WriteLine("Run initial DaySim steps locally");

            var settingsFactory = new SettingsFactory(Global.Configuration);

            Global.Settings = settingsFactory.Create();

            ParallelUtility.Init(Global.Configuration);

            Engine.InitializeDaySim();
            Engine.BeginInitialize();
            Engine.BeginRunRawConversion();
            Engine.BeginImportData();
            Engine.BeginBuildIndexes();

            BeginRunRemoteProcesses();
            BeginMerge();
            BeginLoadData();

            Engine.BeginUpdateShadowPricing();
            if (Global.Configuration.RemoteCopySPFilesToRemoteMachines)
            {
                BeginCopyFilesToRemoteMachines();
            }

            timer.Stop("Total running time");
        }
Example #3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log, ExecutionContext context)
        {
            var formContents = await FormContentsFactory.Create(req);

            var comment  = CommentFactory.Create(formContents);
            var settings = SettingsFactory.Create(formContents.Options.Origin, log);

            var reCaptcha         = new ReCaptchaService(settings.ReCaptchaSecretKey, log);
            var reCaptchaResponse = await reCaptcha.Validate(formContents.Options.Recaptcha.Token);

            var akismetService  = new AkismetService(settings, log);
            var akismetResponse = await akismetService.IsSpam(req, comment, formContents);

            var gitHubService = new GitHubService(settings.GitHubOwner, settings.GitHubRepository, settings.GitHubBranch,
                                                  settings.GitHubCommentPath, settings.GitHubToken);
            var knownCommenterResponse = await gitHubService.IsKnownCommenter(comment.Name, comment.Email);

            var analyzer       = new ModerationAnalyzer(settings, log);
            var analysisReport = analyzer.NeedsModeration(comment, reCaptchaResponse, akismetResponse, knownCommenterResponse);

            await gitHubService.AddComment(comment, analysisReport, knownCommenterResponse);

            return(new OkResult());
        }
        private IServiceConfiguration LoadConfiguration(ICDSExecutionContext executionContext, bool disableCache)
        {
            var settings = SettingsFactory.Create(executionContext);

            if (!disableCache && executionContext.Cache.Exists(CACHE_KEY))
            {
                return(executionContext.Cache.Get <IServiceConfiguration>(CACHE_KEY));
            }

            IServiceConfiguration config = new ServiceConfiguration();

            //get all XML data configuration files located in the virtual configuration path.
            var qry = new QueryExpression
            {
                EntityName = "webresource",
                ColumnSet  = new ColumnSet("name"),
                Criteria   = new FilterExpression
                {
                    Conditions =
                    {
                        new ConditionExpression
                        {
                            AttributeName = "name",
                            Operator      = ConditionOperator.BeginsWith,
                            Values        = { settings.ConfigurationDataPath }
                        }
                    }
                }
            };

            var xmlDataResources = executionContext.OrganizationService.RetrieveMultiple(qry).Entities;

            executionContext.Trace(string.Format("Retrieved {0} XML Data resource records.", xmlDataResources.Count));

            // Process each named XML configuration resource to build out the field level configuration service configuration.
            foreach (var resource in xmlDataResources)
            {
                var name = resource.GetAttributeValue <string>("name");
                try
                {
                    var xmlConfigData = executionContext.XmlConfigurationResources.Get(name, false);
                    config.AddConfiguration(xmlConfigData);
                }
                catch (Exception ex)
                {
                    executionContext.Trace(Core.eSeverityLevel.Error, "Error processing entity file {0} - {1}", name, ex.Message);
                }
            }

            if (!disableCache && executionContext.Cache != null && settings.CacheTimeout != null)
            {
                executionContext.Cache.Add <IServiceConfiguration>(CACHE_KEY, config, settings.CacheTimeout.Value);
            }

            return(config);
        }
Example #5
0
 protected void MakeDefaults()
 {
     this.Add(new Setting <bool>(DYSLEXIC_MODE, new List <bool> {
         false, true
     }));
     this.Add(new Setting <bool>(HAPPINESS_WORLD, new List <bool> {
         true, false
     }));
     this.Add(new Setting <bool>(HAPPINESS_UI, new List <bool> {
         true, false
     }));
     this.Add(new Setting <bool>(HAPPINESS_CURSOR, new List <bool> {
         true, false
     }));
     this.Add(SettingsFactory.Create(RUMOUR_CHANCE, Enumerable.Range(1, 5).Select(x => x * 5).ToArray()));
 }
Example #6
0
        public IEnumerable <ISetting> Load()
        {
            List <ISetting> settings = new List <ISetting>();

            string[] files = Directory.GetFiles(
                this.SettingsDirectory,
                "*.json");

            foreach (string file in files)
            {
                JSONParseResult result = JSON.Parse(File.ReadAllText(file));

                if (result.Error != Error.Ok)
                {
                    GD.PushWarning("Could not parse settings file " + file);
                    continue;
                }

                if (!(result.Result is Dictionary dictionary))
                {
                    GD.PushWarning("Could not parse JSON to Dictionary from " + file);
                    continue;
                }

                ICollection <Dictionary> settingsArray =
                    this.ValueExtractor
                    .GetArrayValuesCollectionFromDictionary <Dictionary>(
                        dictionary,
                        "Settings");

                foreach (Dictionary settingsDict in settingsArray)
                {
                    string      name   = this.ValueExtractor.GetValueFromDictionary <string>(settingsDict, "Name");
                    ICollection values = this.ValueExtractor
                                         .GetArrayValuesCollectionFromDictionary <object>(settingsDict, "ValuesRange")
                                         .ToArray();
                    int      index   = this.ValueExtractor.GetValueFromDictionary <int>(settingsDict, "Index");
                    ISetting setting = SettingsFactory.Create(name, values);
                    setting.Index = index;
                    settings.Add(setting);
                }
            }

            return(settings);
        }
Example #7
0
        private static void Main(string[] args)
        {
            try {
                var options = new OptionSet {
                    { "c|configuration=", "Path to configuration file", v => _configurationPath = v },
                    { "p|printfile=", "Path to print file", v => _printFilePath = v },
                    { "s|start=", "Start index of household range", v => _start = int.Parse(v) },
                    { "e|end=", "End index of household range", v => _end = int.Parse(v) },
                    { "i|index=", "Cluser index", v => _index = int.Parse(v) },
                    { "h|?|help", "Show help and syntax summary", v => _showHelp = v != null }
                };

                options.Parse(args);

                if (_showHelp)
                {
                    options.WriteOptionDescriptions(Console.Out);

                    Console.WriteLine();
                    Console.WriteLine("If you do not provide a configuration then the default is to use {0}, in the same directory as the executable.", ConfigurationManager.DEFAULT_CONFIGURATION_NAME);

                    Console.WriteLine();
                    Console.WriteLine("If you do not provide a printfile then the default is to create {0}, in the same directory as the executable.", PrintFile.DEFAULT_PRINT_FILE_NAME);

                    Console.WriteLine("Please press any key to exit");
                    Console.ReadKey();

                    Environment.Exit(0);
                }

                var configurationManager = new ConfigurationManager(_configurationPath);
                var configuration        = configurationManager.Open();
                var settingsFactory      = new SettingsFactory(configuration);
                var settings             = settingsFactory.Create();
                var printFile            = new PrintFile(_printFilePath, configuration);

                configurationManager.Write(configuration, printFile);

                ParallelUtility.Init(configuration);

                Global.Configuration = configuration;
                Global.Settings      = settings;
                Global.PrintFile     = printFile;
                Global.Kernel        = new StandardKernel(new DaysimModule());

                var moduleFactory = new ModuleFactory(configuration);
                var modelModule   = moduleFactory.Create();

                Global.Kernel.Load(modelModule);

                Engine.BeginProgram(_start, _end, _index);
                //Engine.BeginTestMode();
            }
            catch (Exception e) {
                Console.WriteLine();
                Console.WriteLine(e.GetBaseException().Message);

                Console.WriteLine();
                Console.WriteLine(e.StackTrace);

                Console.WriteLine();
                Console.WriteLine("Please press any key to exit");

                if (Global.PrintFile != null)
                {
                    Global.PrintFile.WriteLine(e.GetBaseException().Message);
                    Global.PrintFile.WriteLine();
                    Global.PrintFile.WriteLine(e.StackTrace);
                }

                Console.ReadKey();

                Environment.Exit(2);
            }
            finally {
                if (Global.PrintFile != null)
                {
                    Global.PrintFile.Dispose();
                }
            }
            Environment.Exit(0);
        }