/// <summary>
 /// Factory (create instance).
 /// The factory is here for backward compatibility, newer component should use IoC (Dependency Injection)
 /// </summary>
 /// <param name="activationFactory">The activation factory.</param>
 /// <param name="simpleConfig">The simple configuration.</param>
 /// <param name="tagContext">The tag context.</param>
 /// <returns></returns>
 private static IMetricsReporterBuilder Create(
     ITelemetryActivationFactory activationFactory,
     ISimpleConfig simpleConfig,
     ITelemetryTagContext tagContext)
 {
     return(new MetricsReporterBuilder(activationFactory, simpleConfig, tagContext));
 }
Beispiel #2
0
        public object LoadFromFile(ISimpleConfig config, string path)
        {
            var fileSystem = new FileSystem { CurrentDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase };
            log.InfoFormat(CultureInfo.InvariantCulture, "Executing '{0}'", fileSystem.GetFullPath(path));
            log.DebugFormat(CultureInfo.InvariantCulture, "The current directory is {0}", fileSystem.CurrentDirectory);

            var scriptCsLog = LogManager.GetLogger("ScriptCs");
            var lineProcessors = new ILineProcessor[]
            {
                new LoadLineProcessor(fileSystem),
                new ReferenceLineProcessor(fileSystem),
                new UsingLineProcessor(),
            };

            var filePreProcessor = new FilePreProcessor(fileSystem, scriptCsLog, lineProcessors);
            var engine = new RoslynScriptInMemoryEngine(new ConfigRScriptHostFactory(config), scriptCsLog);
            var executor = new ConfigRScriptExecutor(fileSystem, filePreProcessor, engine, scriptCsLog);
            executor.AddReferenceAndImportNamespaces(new[] { typeof(Config), typeof(IScriptHost) });

            ScriptResult result;
            executor.Initialize(new string[0], new IScriptPack[0]);
            try
            {
                result = executor.Execute(path);
            }
            finally
            {
                executor.Terminate();
            }

            RethrowExceptionIfAny(result, path);
            return result.ReturnValue;
        }
    private async void SetUp(ISimpleConfig sims)
    {
        string firstPart = await sims.GetStringAsync(Key);

        Uri secondPart = new(firstPart);

        BaseAddress = new(secondPart, ServicePath);
    }
        public static void RetrievingAnObject(ISimpleConfig configurator, string result)
        {
            "Given a configurator containing a string of 'bar' keyed by 'foo'"
                .Given(() => (configurator = new BasicConfig()).Add("foo", "bar"));

            "When I load the configurator"
                .When(() => Config.Global.Load(configurator));

            "And I get the Foo"
                .And(() => result = Config.Global.Get<string>("foo"));

            "Then the result should be 'bar'"
                .Then(() => result.Should().Be("bar"));
        }
Beispiel #5
0
        public static void RetrievingAnObject(ISimpleConfig configurator, string result)
        {
            "Given a configurator containing a string of 'bar' keyed by 'foo'"
            .f(() => (configurator = new BasicConfig()).Add("foo", "bar"));

            "When I load the configurator"
            .f(() => Config.Global.Load(configurator));

            "And I get the Foo"
            .f(() => result = Config.Global.Get <string>("foo"));

            "Then the result should be 'bar'"
            .f(() => result.Should().Be("bar"));
        }
Beispiel #6
0
        public object LoadFromFile(ISimpleConfig config, string path)
        {
            // HACK (adamralph): workaround for https://github.com/scriptcs/scriptcs/issues/1022
            var originalCurrentDirectory = Environment.CurrentDirectory;

            try
            {
                var fileSystem = new FileSystem {
                    CurrentDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase
                };
                log.InfoFormat("Executing '{0}'", fileSystem.GetFullPath(path));
                log.DebugFormat("The current directory is {0}", fileSystem.CurrentDirectory);

                var scriptCsLog    = new LogProviderAdapter();
                var lineProcessors = new ILineProcessor[]
                {
                    new LoadLineProcessor(fileSystem),
                    new ReferenceLineProcessor(fileSystem),
                    new UsingLineProcessor(),
                };

                var filePreProcessor = new FilePreProcessor(fileSystem, scriptCsLog, lineProcessors);
                var engine           = new CSharpScriptInMemoryEngine(new ConfigRScriptHostFactory(config), scriptCsLog);
                var executor         = new ScriptExecutor(fileSystem, filePreProcessor, engine, scriptCsLog);
                executor.AddReferenceAndImportNamespaces(new[] { typeof(Config), typeof(IScriptHost) });
                executor.AddReferences(this.references);

                ScriptResult result;
                executor.Initialize(new string[0], new IScriptPack[0]);

                // HACK (adamralph): BaseDirectory is set to bin subfolder in Initialize()!
                executor.ScriptEngine.BaseDirectory = executor.FileSystem.CurrentDirectory;
                try
                {
                    result = executor.Execute(path);
                }
                finally
                {
                    executor.Terminate();
                }

                RethrowExceptionIfAny(result, path);
                return(result.ReturnValue);
            }
            finally
            {
                Environment.CurrentDirectory = originalCurrentDirectory;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MetricsReporterBuilder"/> class.
        /// </summary>
        /// <param name="activationFactory">The activation factory.</param>
        /// <param name="simpleConfig">The simple configuration.</param>
        /// <param name="tagContext">The tag context.</param>
        public MetricsReporterBuilder(
            ITelemetryActivationFactory activationFactory,
            ISimpleConfig simpleConfig,
            ITelemetryTagContext tagContext)
        {
            // TODO: move it into Influx provider (InfluxMetricFactory)
            string url     = simpleConfig["influx-url"];
            string db      = simpleConfig["influx-database"];
            string version = simpleConfig["influx-report-version"];

            _activation          = activationFactory.Create();
            _influxConfiguration = new CollectorConfiguration()
                                   .Tag.With("version", version)
                                   .Tag.With("host", Environment.MachineName)
                                   .Tag.With("user", Environment.UserName)
                                   .Batch.AtInterval(TimeSpan.FromSeconds(5))
                                   .WriteTo.InfluxDB(url, database: db);
            _tagContext = tagContext;
        }
Beispiel #8
0
        public IConfig Load(ISimpleConfig config)
        {
            this.loadInvoked = true;

            Guard.AgainstNullArgument("config", config);

            var index = this.dictionaries.Count;

            this.dictionaries.Add(config);
            try
            {
                config.Load();
            }
            catch
            {
                this.dictionaries.RemoveRange(index, this.dictionaries.Count - index);
                throw;
            }

            return(this);
        }
Beispiel #9
0
        public object LoadFromFile(ISimpleConfig config, string path)
        {
            var fileSystem = new FileSystem {
                CurrentDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase
            };

            log.InfoFormat(CultureInfo.InvariantCulture, "Executing '{0}'", fileSystem.GetFullPath(path));
            log.DebugFormat(CultureInfo.InvariantCulture, "The current directory is {0}", fileSystem.CurrentDirectory);

            var scriptCsLog    = LogManager.GetLogger("ScriptCs");
            var lineProcessors = new ILineProcessor[]
            {
                new LoadLineProcessor(fileSystem),
                new ReferenceLineProcessor(fileSystem),
                new UsingLineProcessor(),
            };

            var filePreProcessor = new FilePreProcessor(fileSystem, scriptCsLog, lineProcessors);
            var engine           = new RoslynScriptInMemoryEngine(new ConfigRScriptHostFactory(config), scriptCsLog);
            var executor         = new ConfigRScriptExecutor(fileSystem, filePreProcessor, engine, scriptCsLog);

            executor.AddReferenceAndImportNamespaces(new[] { typeof(Config), typeof(IScriptHost) });
            executor.AddReferences(this.references);

            ScriptResult result;

            executor.Initialize(new string[0], new IScriptPack[0]);
            try
            {
                result = executor.Execute(path);
            }
            finally
            {
                executor.Terminate();
            }

            RethrowExceptionIfAny(result, path);
            return(result.ReturnValue);
        }
        public object LoadFromFile(ISimpleConfig config, string path)
        {
            var fileSystem = new FileSystem { CurrentDirectory = AppDomain.CurrentDomain.SetupInformation.ApplicationBase };
            log.InfoFormat("Executing '{0}'", fileSystem.GetFullPath(path));
            log.DebugFormat("The current directory is {0}", fileSystem.CurrentDirectory);

            var scriptCsLog = new LogProviderAdapter();
            var lineProcessors = new ILineProcessor[]
            {
                new LoadLineProcessor(fileSystem),
                new ReferenceLineProcessor(fileSystem),
                new UsingLineProcessor(),
            };

            var filePreProcessor = new FilePreProcessor(fileSystem, scriptCsLog, lineProcessors);
            var engine = new RoslynScriptInMemoryEngine(new ConfigRScriptHostFactory(config), scriptCsLog);
            var executor = new ScriptExecutor(fileSystem, filePreProcessor, engine, scriptCsLog);
            executor.AddReferenceAndImportNamespaces(new[] { typeof(Config), typeof(IScriptHost) });
            executor.AddReferences(this.references);

            ScriptResult result;
            executor.Initialize(new string[0], new IScriptPack[0]);

            // HACK (adamralph): BaseDirectory is set to bin subfolder in Initialize()!
            executor.ScriptEngine.BaseDirectory = executor.FileSystem.CurrentDirectory;
            try
            {
                result = executor.Execute(path);
            }
            finally
            {
                executor.Terminate();
            }

            RethrowExceptionIfAny(result, path);
            return result.ReturnValue;
        }
 public ConfigRScriptHostFactory(ISimpleConfig config)
 {
     this.config = config;
 }
Beispiel #12
0
 public static ISimpleConfig Get()
 {
     lock (SimpleConfigSingletonLocker) return(SingletonContext ?? (SingletonContext = new SimpleConfig()));
 }
Beispiel #13
0
 public IConfigRScriptHost Load(ISimpleConfig config)
 {
     ConfigR.Config.Global.Load(config);
     return(this);
 }
Beispiel #14
0
 public static void AddOrUpdateModel <T>(this ISimpleConfig simpleConfig, T value)
 {
     simpleConfig.AddOrUpdate(typeof(T).FullName, value);
 }
Beispiel #15
0
 public static T TryGetModel <T>(this ISimpleConfig simpleConfig, T defaultValue)
 {
     return(simpleConfig.TryGet(typeof(T).FullName, defaultValue));
 }
 public CustomWebAPIClient(ISimpleConfig sims, HttpClient client)
 {
     Client = client;
     SetUp(sims);
 }
Beispiel #17
0
 public static IConfig Load(ISimpleConfig config)
 {
     LogObsolete();
     return(Config.DisableGlobalAutoLoading().Load(config));
 }
 public ConfigRScriptHostFactory(ISimpleConfig config)
 {
     this.config = config;
 }
 protected CustomMinimumAPIClient(ISimpleConfig sims, HttpClient client) : base(sims, client)
 {
 }
Beispiel #20
0
 public static ISimpleConfig Get()
 {
     lock (SimpleConfigSingletonLocker) return SingletonContext ?? (SingletonContext = new SimpleConfig());
 }