/// <summary>
        /// Find is getting data from remote (redis) storage. After this
        /// it writes updated version of data into locaL (litedb) storage
        /// </summary>
        /// <param name="key"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        private T Find <T>(string key)
        {
            var liteDbService = new LiteDbService();
            var dynamicConfig = new DynamicConfig
            {
                ApplicationName = ApplicationName,
                Name            = key,
                IsActive        = 1
            };

            var configurationReaderFactory = new ConfigurationServiceFactory();
            var reader = configurationReaderFactory.ProduceReader("Redis", ConnectionString);

            var redisResult = reader.Read <DynamicConfig>(dynamicConfig);

            // If redis result fits with requested data type
            if (redisResult?.Value is T)
            {
                liteDbService.RemoveConfig(key);
                liteDbService.AddConfig(redisResult);
                return((T)Convert.ChangeType(redisResult.Value, typeof(T)));
            }

            return(default(T));
        }
    public static void CreateGameObjecrPool()
    {
        DynamicConfig test = (DynamicConfig)FindObjectOfType(typeof(DynamicConfig));

        if (test == null)
        {
            GameObject dynamicConfig = new GameObject("DynamicConfig");
            dynamicConfig.AddComponent <DynamicConfig>();
        }
    }
        public void ConfigFile_Read_NestedObjects()
        {
            var config = DynamicConfig.Load(GetTextResource("Config.2.js"));
            var pa     = config.PageAppearance;

            Assert.AreEqual("TimesNewRoman", pa.Font.Name);
            Assert.AreEqual(18.0, pa.Font.Size);
            Assert.AreEqual("000000", pa.Color.Background);
            Assert.AreEqual("FFFFFF", pa.Color.Foreground);
            Assert.AreEqual(123.0, pa.getSomething());
        }
示例#4
0
//		private void miSquareRoot_Click(object sender, System.EventArgs e)
//		{
//			ChartControl.Chart[1].AxisY.Scale = ScaleType.SquareRoot;
//			ChartControl.NeedRedraw();
//		}
//
//		private void miLineColor_Click(object sender, System.EventArgs e)
//		{
//			if (cdFormulaColor.ShowDialog()==DialogResult.OK)
//			{
//				ChartControl.Chart[1][1].FormulaUpColor = cdFormulaColor.Color;
//				ChartControl.NeedRedraw();
//			};
//		}
//
//		private void miCrossCursor_Click(object sender, System.EventArgs e)
//		{
//			ChartControl.ShowCrossCursor = !ChartControl.ShowCrossCursor;
//		}
//
//		private void miFormulaValue_Click(object sender, System.EventArgs e)
//		{
//			FormulaData fd = ChartControl.Chart[1][0];
//			MessageBox.Show(ChartControl.Chart[1].Formulas[0].Name+" = "+fd[fd.Length-1].ToString("f2"));
//		}

        private void DemoForm_Closed(object sender, System.EventArgs e)
        {
            DynamicConfig.Save(ChartControl);
            if (dcbStream != null)
            {
                dcbStream.StopStreaming();
            }
            if (dcbForex != null)
            {
                dcbForex.StopStreaming();
            }
        }
        public void ConfigFile_Read_CallFunction()
        {
            var config = DynamicConfig.Load(GetTextResource("Config.3.js"));

            Assert.AreEqual(true, config.getDebug());
            Assert.AreEqual(123.0, config.getCount());
            Assert.AreEqual("http://www.google.com", config.getUri());
            Assert.AreEqual(1.0, config.getValues(0));
            Assert.AreEqual(2.0, config.getValues(1));
            Assert.AreEqual(3.0, config.getValues(2));
            Assert.AreEqual(true, config.getValues(3));
            Assert.AreEqual("abc", config.getValues(4));
        }
        public void ConfigFile_Read_GlobalVariableBoolNumberStringAndArray()
        {
            var config = DynamicConfig.Load(GetTextResource("Config.1.js"));

            Assert.AreEqual(true, config.Debug);
            Assert.AreEqual(true, config.T);
            Assert.AreEqual(false, config.F);
            Assert.AreEqual(123.0, config.Count);
            Assert.AreEqual("http://www.google.com", config.Uri);
            Assert.AreEqual(1.0, config.Values[0]);
            Assert.AreEqual(2.0, config.Values[1]);
            Assert.AreEqual(3.0, config.Values[2]);
            Assert.AreEqual(true, config.Values[3]);
            Assert.AreEqual("abc", config.Values[4]);
        }
示例#7
0
        public override bool AddConfig(DynamicConfig config)
        {
            try
            {
                using (var client = _manager.GetClient())
                {
                    return(client.Add(config.ApplicationName + "." + config.Name, config));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(false);
        }
示例#8
0
        protected override T GetConfig <T>(DynamicConfig config)
        {
            try
            {
                using (var client = _manager.GetClient())
                {
                    return(client.Get <T>(config.ApplicationName + "." + config.Name));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(default(T));
        }
示例#9
0
        private void RedisInitializer()
        {
            if (!ConnectionStatus())
            {
                return;
            }
            using (var client = _manager.GetClient())
            {
                var firstKey = new DynamicConfig
                {
                    Name            = "SERVICE-A.SiteName",
                    Value           = "Boyner.com.tr",
                    IsActive        = 1,
                    ApplicationName = "SERVICE-A"
                };

                var secondKey = new DynamicConfig
                {
                    Name            = "SERVICE-A.IsBasketEnabled",
                    Value           = "1",
                    IsActive        = 1,
                    ApplicationName = "SERVICE-B"
                };

                var thirdKey = new DynamicConfig
                {
                    Name            = "SERVICE-A.MaxItemCount",
                    Value           = "50",
                    IsActive        = 0,
                    ApplicationName = "SERVICE-A"
                };

                var serviceB = new DynamicConfig
                {
                    Name            = "SERVICE-B.SiteName",
                    Value           = "boyner.com",
                    IsActive        = 0,
                    ApplicationName = "SERVICE-B"
                };

                client.Set(firstKey.Name, firstKey);
                client.Set(secondKey.Name, secondKey);
                client.Set(thirdKey.Name, thirdKey);

                _isRedisInitialized = true;
            }
        }
示例#10
0
 public override bool AddConfig(DynamicConfig dynamicConfiguration)
 {
     lock (_asyncBlock)
     {
         try
         {
             var configs = Db.GetCollection <DynamicConfig>("configs");
             dynamicConfiguration.Id = Guid.NewGuid();
             configs.Insert(dynamicConfiguration);
             return(true);
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
             return(false);
         }
     }
 }
示例#11
0
        public async Task SetDynamicConfig()
        {
            var dbConfig = await _configData.GetConfiguration();

            if (dbConfig != null)
            {
                dbConfig.ToDynamicConfig(DynamicConfig);
            }
            else
            {
                dbConfig = new Model.Config();
                dbConfig.FromDynamicConfig(DynamicConfig.GetDefault());
                dbConfig.ToDynamicConfig(DynamicConfig);
                await _configData.SaveConfiguration(dbConfig);
            }

            DynamicConfig.TrackChanges = true;
        }
示例#12
0
        /// <summary>
        /// Renders the tree using ELK.js.
        /// </summary>
        private async Task <string> RenderTree(INodeJSService js, TreeLayoutVM tree, DynamicConfig cfg)
        {
            var thoroughness = Interpolator.MapValue(
                cfg.TreeRenderThoroughness,
                new IntervalMap(1, 10, 1, 10),
                new IntervalMap(11, 50, 11, 600),
                new IntervalMap(51, 100, 301, 15000)
                );

            var json   = JsonConvert.SerializeObject(tree);
            var result = await js.InvokeFromFileAsync <string>("./External/tree/tree-layout.js", args : new object[] { json, thoroughness });

            if (string.IsNullOrEmpty(result))
            {
                throw new Exception("Failed to render tree: output is empty.");
            }

            return(result);
        }
示例#13
0
 public override bool UpdateConfig(DynamicConfig config)
 {
     if (!ConnectionStatus())
     {
         return(false);
     }
     try
     {
         using (var client = _manager.GetClient())
         {
             client.Delete(config.ApplicationName + "." + config.Name);
             client.Set(config.ApplicationName + "." + config.Name, config);
             return(true);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(false);
     }
 }
        /// <summary>
        /// ConfigJob is the definition of scheduled job of worker.
        /// It's comparing local (litedb) data with remote (redis) storage data. Also it's
        /// making neccessary updates on local.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="refreshTimerIntervalInMs"></param>
        /// <returns></returns>
        private async Task <bool> ConfigJob(string key, TimeSpan refreshTimerIntervalInMs)
        {
            var isCancelled = _cancellationToken.IsCancellationRequested;

            // if task not cancelled
            if (!isCancelled)
            {
                await Task.Delay(refreshTimerIntervalInMs, _cancellationToken);

                var liteDbService = new LiteDbService();
                var dynamicConfig = new DynamicConfig
                {
                    ApplicationName = ApplicationName,
                    Name            = key,
                    IsActive        = 1
                };

                var configurationReaderFactory = new ConfigurationServiceFactory();
                var reader = configurationReaderFactory.ProduceReader("Redis", ConnectionString);

                var redisResult  = reader.Read <DynamicConfig>(dynamicConfig);
                var liteDbResult = liteDbService.GetConfig(key);

                if (redisResult != null && liteDbResult != null)
                {
                    // Comparing data changes
                    if (redisResult.Value != liteDbResult.Value)
                    {
                        liteDbService.RemoveConfig(key);
                        liteDbService.AddConfig(redisResult);
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#15
0
 public abstract bool UpdateConfig(DynamicConfig config);
示例#16
0
 public abstract bool AddConfig(DynamicConfig config);
示例#17
0
 protected abstract T GetConfig <T>(DynamicConfig config);
示例#18
0
        /// <summary>
        /// Run Console Command
        /// </summary>
        /// <param name="cmd">Command wanna be run</param>
        /// <remarks>Command should be valid</remarks>
        /// <exception cref="NotImplementedException">Command is not recognized nor implemented</exception>
        public void RunCommand(string cmd)
        {
            string vimpath      = @"C:\Program Files (x86)\Vim\vim72\gvim.exe";
            string explorerpath = @"C:\Windows\explorer.exe";
            string daemonpath   = @"C:\Program Files (x86)\DAEMON Tools Lite\DTLite.exe";

            if (cmd == "edit this")
            {
                FileInfo     file = new FileInfo(vimpath);
                IBrowserItem item = Browser.Cursor;
                Win32.SHExecute(file, "\"" + item.FullPath + "\"", false);
                return;
            }
            if (cmd == "sudo edit this")
            {
                FileInfo     file = new FileInfo(vimpath);
                IBrowserItem item = Browser.Cursor;
                Win32.SHExecute(file, "\"" + item.FullPath + "\"", true);
                return;
            }
            if (cmd == "explore here")
            {
                FileInfo      file = new FileInfo(explorerpath);
                DirectoryInfo dir  = Browser.CurrentDir;

                Win32.SHExecute(file, dir.FullName, false);
                return;
            }
            if (cmd == "save 1 here")
            {
                object[] args = new object[3];
                args[0] = "save";
                args[1] = 1;
                args[2] = Browser.CurrentDir;
                DynamicConfig.execute(args);
                return;
            }
            if (cmd == "load 1")
            {
                object[] args = new object[2];
                args[0] = "load";
                args[1] = 1;
                DynamicConfig.execute(args);
                return;
            }
            if (cmd == "select this")
            {
                Browser.MarkItem(Browser.Cursor);
                return;
            }
            if (cmd == "select all")
            {
                List <IBrowserItem> items = Browser.Items;
                Selection           sel   = Browser.Selection;
                foreach (IBrowserItem item in items)
                {
                    sel.addItem(item);
                }
                return;
            }
            if (cmd.StartsWith("open ", true, null))
            {
                Browser.CurrentDir = new DirectoryInfo(cmd.Substring(5));
                return;
            }
            if (cmd == "refresh")
            {
                Browser.Refresh();
                return;
            }
            if (cmd == "delete")
            {
                DeleteFiles();
                return;
            }
            if (cmd == "mount this")
            {
                FileInfo     file = new FileInfo(daemonpath);
                IBrowserItem item = Browser.Cursor;
                Win32.SHExecute(file, "-mount 0," + item.FullPath, false);
                return;
            }
            if (cmd == "!cmd" || cmd == "!")
            {
                Win32.SHExecute("cmd", "", false);
                return;
            }
            if (cmd == "paste")
            {
                Paste();
                return;
            }
            if (cmd == "cut selected")
            {
                SetDropFileList(true);
                return;
            }
            if (cmd == "copy selected")
            {
                SetDropFileList(false);
                return;
            }
            if (cmd == "goroot")
            {
                Browser.CurrentDir = Browser.CurrentDir.Root;
                return;
            }
            throw new NotImplementedException();
        }
 void OnEnable()
 {
     _myTarget               = (DynamicConfig)target;
     _defaultColor           = GUI.color;
     _defaultBackgroundColor = GUI.backgroundColor;
 }
示例#20
0
 public ActionResult EditDynamicConfigSubmit(DynamicConfig config)
 {
     DynamicConfig.SaveConfig(config);
     return(RedirectToAction("EditDynamicConfig"));
 }
 public abstract bool AddConfig(DynamicConfig dynamicConfiguration);
示例#22
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <JwtAuthentication>(Configuration.GetSection("JwtAuthentication"));
            services.AddControllersWithViews()
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
            .AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.Formatting       = Formatting.Indented;
                options.SerializerSettings.TypeNameHandling = TypeNameHandling.None;
                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                options.SerializerSettings.Converters.Add(new StringEnumConverter());
                options.SerializerSettings.TypeNameHandling = TypeNameHandling.None;
            });

            services.AddAntiforgery(options =>
            {
                options.HeaderName          = "X-XSRF-Token";
                options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
            });

            services.AddSingleton <IPostConfigureOptions <JwtBearerOptions>, ConfigureJwtBearerOptions>();
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer();

            services.AddAuthorization(options =>
            {
                options.AddPolicy("Admins", policy => policy.RequireRole(RoleType.Admin.ToString()));
                options.AddPolicy("Contributers", policy => policy.RequireRole(RoleType.Contributer.ToString(), RoleType.Admin.ToString()));
                options.AddPolicy("Readers", policy => policy.RequireRole(RoleType.Reader.ToString(), RoleType.Contributer.ToString(), RoleType.Admin.ToString()));
            });

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });

            services.AddCors(options =>
            {
                options.AddPolicy("AllowAllOrigins",
                                  builder =>
                {
                    builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
                });
            });

            services.AddSignalR();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "HomePhotos API", Version = "v1"
                });
                c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "SCS.HomePhotos.Web.xml"));
                c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "SCS.HomePhotos.Model.xml"));
                c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "SCS.HomePhotos.Service.xml"));
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    In          = ParameterLocation.Header,
                    Description = "Please insert JWT with Bearer into field; for example: Bearer [token here]",
                    Name        = "Authorization",
                    Type        = SecuritySchemeType.ApiKey
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            }
                        },
                        new string[] { }
                    }
                });
            });

            // config
            var staticConfig  = StaticConfig.Build(Configuration);
            var configData    = new ConfigData(staticConfig);
            var dynamicConfig = new DynamicConfig();

            services.AddSingleton <IStaticConfig>(staticConfig);
            services.AddSingleton <IConfigData>(configData);
            services.AddSingleton <IDynamicConfig>(dynamicConfig);
            var configService = new ConfigService(configData, dynamicConfig, staticConfig);

            SetDynamicConfig(configService).Wait();
            services.AddSingleton <IConfigService>(configService);

            // background tasks
            services.AddHostedService <QueuedHostedService>();
            services.AddHostedService <TimedIndexHostedService>();
            services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();

            // data objects
            services.AddScoped <IPhotoData, PhotoData>();
            services.AddScoped <ITagData, TagData>();
            services.AddScoped <IUserData, UserData>();
            services.AddScoped <IUserTokenData, UserTokenData>();
            services.AddScoped <ILogData, LogData>();

            // services
            services.AddScoped <IFileSystemService, FileSystemService>();
            services.AddScoped <IImageTransformer, ImageTransformer>();
            services.AddScoped <IImageService, ImageService>();
            services.AddScoped <IPhotoService, PhotoService>();
            services.AddScoped <IFileUploadService, FileUploadService>();
            services.AddScoped <IAccountService, AccountService>();
            services.AddScoped <ISecurityService, SecurityService>();
            services.AddSingleton <IAdminLogService>(new AdminLogService(new LogData(staticConfig), staticConfig));
            services.AddSingleton <IIndexEvents, IndexEvents>();
            services.AddSingleton <IQueueEvents, QueueEvents>();
            services.AddSingleton <IClientMessageSender, ClientMessageSender>();
            services.AddSingleton <IUploadTracker, UploadTracker>();
            services.AddSingleton <IImageMetadataService, ImageMetadataService>();
        }
示例#23
0
        public void Update(DynamicConfig config)
        {
            var redisService = new RedisConfigurationService("127.0.0.1:6379");

            redisService.UpdateConfig(config);
        }
示例#24
0
        public void Post(DynamicConfig config)
        {
            var redisService = new RedisConfigurationService("127.0.0.1:6379");

            redisService.AddConfig(config);
        }
示例#25
0
 public T Read <T>(DynamicConfig config)
 {
     return(GetConfig <T>(config));
 }