public AppController(IOptionsSnapshot <App> options, SourceSetting sourceSetting)
        {
            _options       = options;
            _sourceSetting = sourceSetting;
            //_dicSettings = dicSettings;

            //_dicSettings.OnChange((option, value) => Console.WriteLine("changed"));
        }
示例#2
0
        /// <summary>
        /// setButton_Click() - Set the Image Processing parameters for a Display System and a specified source.
        ///
        /// Author: ameja
        /// Date: 1/25/2018
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void setButton_Click(object sender, EventArgs e)
        {
            try
            {
                SourceSetting source = new SourceSetting(availableSourcesComboBox.Text);

                //ImageProcessingParametersPerSource imageProcessingParametersPerSource = new ImageProcessingParametersPerSource("hdmi");
                source.ImageProcessingParameters.Add(new ImageProcessingParameter("brightness", brightnessNumericUpDown.Value.ToString(),
                                                                                  double.Parse(brightnessNumericUpDown.Minimum.ToString()),
                                                                                  double.Parse(brightnessNumericUpDown.Maximum.ToString())));
                source.ImageProcessingParameters.Add(new ImageProcessingParameter("sharpness", sharpnessNumericUpDown.Value.ToString(),
                                                                                  Int32.Parse(sharpnessNumericUpDown.Minimum.ToString()),
                                                                                  Int32.Parse(sharpnessNumericUpDown.Maximum.ToString())));
                source.ImageProcessingParameters.Add(new ImageProcessingParameter("hue", hueNumericUpDown.Value.ToString(),
                                                                                  Int32.Parse(hueNumericUpDown.Minimum.ToString()),
                                                                                  Int32.Parse(hueNumericUpDown.Maximum.ToString())));
                source.ImageProcessingParameters.Add(new ImageProcessingParameter("steepness", steepnessNumericUpDown.Value.ToString(),
                                                                                  Int32.Parse(steepnessNumericUpDown.Minimum.ToString()),
                                                                                  Int32.Parse(steepnessNumericUpDown.Maximum.ToString())));
                source.ImageProcessingParameters.Add(new ImageProcessingParameter("cliptosubblack", clipToSubblackNumericUpDown.Value.ToString(),
                                                                                  Int32.Parse(clipToSubblackNumericUpDown.Minimum.ToString()),
                                                                                  Int32.Parse(clipToSubblackNumericUpDown.Maximum.ToString())));

                //   string imageprocessingparameters = JsonConvert.SerializeObject(displaySystem);
                string sourcestring = JsonConvert.SerializeObject(source);

                //Call JSON rpc post request with source value
                byte[] data = Encoding.ASCII.GetBytes(Common.CreateJsonRequest("setsource", "{\"source\":" + sourcestring + "}"));

                try
                {
                    SendRequest(data);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 internal void UpdateSetting(SourceSetting sourceSetting)
 {
     _sourceSetting = sourceSetting;
 }
示例#4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            /*
             * IServiceCollection用来配置依赖容器中的服务。然后被Buld成IServiceProvider,IServiceProvider可看作时容器。
             *
             * IApplicationBuilder.ApplicationServices返回的是IServiceProvider
             *
             * HttpContext.RequestServices返回的是IServiceProvider
             *
             * 如何获取服务呢?
             *
             * var service  = (IFooService)serviceProvider.GetService(typeof(IFooService));
             *
             * 如果引用Microsoft.Extensions.DependencyInjection,可以这样获取服务:
             *
             * var service  = serviceProvider.GetService<IFooService>();
             *
             *
             */


            services.AddControllersWithViews()
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
                options.JsonSerializerOptions.IgnoreNullValues     = true;
            });

            #region 加密

            services.AddCertificateManager();
            services.AddTransient <SymmetricEncryptDecrypt>();
            services.AddTransient <AsymmetricEncryptDecrypt>();
            services.AddTransient <DigitalSignatures>();
            #endregion

            #region 配置
            services.Configure <App>(Configuration.GetSection(nameof(App)));//把appsettings.json中的配置读取到App


            //services.ConfigureDictionary<SourceSetting>(Configuration.GetSection(nameof(SourceSetting)));//配置字典集,通常写法


            var sourceSetting = new SourceSetting();
            Configuration.GetSection("SourceSetting").Bind(sourceSetting);
            services.AddSingleton(sourceSetting);
            Action onChange = () =>
            {
                Configuration.GetSection("SourceSetting").Bind(sourceSetting);
                Console.WriteLine("onChange fired!");
            };

            ChangeToken.OnChange(() => Configuration.GetReloadToken(), onChange);


            ////通过Bind把类和配置文件绑定起来
            //var leaningOptions = new LearningOptions();
            //Configuration.GetSection("Learning").Bind(leaningOptions);

            ////获取配置文件对应的类实例
            //leaningOptions = Configuration.GetSection("Learning").Get<LearningOptions>();

            ////通过Configure把类和配置文件绑定起来
            //services.Configure<LearningOptions>(Configuration.GetSection("Learning"));

            ////通过PostConfigure把类和配置文件绑定起来,并且可以附加动作
            //services.PostConfigure<LearningOptions>(options => options.Years += 1);

            ////通过委托设置
            //services.Configure<AppInfoOptions>(options =>
            //{
            //    options.AppName = "ASP.NET Core";
            //    options.AppVersion = "1.2.1";
            //});

            //services.Configure<ThemeOptions>("DarkTheme", Configuration.GetSection("Themes:Dark"));
            //services.Configure<ThemeOptions>("WhiteTheme", Configuration.GetSection("Themes:White"));
            #endregion

            #region 线程和调试和日志
            ThreadMananger.RegisterThreads();
            var ddSetting = new DDSetting();
            Configuration.GetSection("DDSetting").Bind(ddSetting);
            Config.DDSetting = ddSetting;
            Config.WebPath   = Env.ContentRootPath;
            #endregion

            #region AutoWrapper

            services.Configure <ApiBehaviorOptions>(options =>
            {
                //取消APIController中OnActionExecuting事件对模型的验证返回400 Bad Request
                options.SuppressModelStateInvalidFilter = true;
            });
            #endregion

            #region API Key 验证授权

            /*
             * 验证的配置放在了:AuthenticationSchemeOptions
             * 验证的验证逻辑放在了:AuthenticationHandler
             * AuthenticaitonBuilder是建造者
             *
             * 验证的逻辑是:List<Cliam> → List<ClaimsIdentity> → ClaimsPrincipal → AuthenticationTicket
             */

            //services.AddAuthentication(options =>
            //{
            //    options.DefaultAuthenticateScheme = ApiKeyAuthenticationOptions.DefaultScheme;
            //    options.DefaultChallengeScheme = ApiKeyAuthenticationOptions.DefaultScheme;
            //}).AddApiKeySupport(options => { });

            /*
             * 授权
             * IAuthorizationRequirement
             * AuthorizationHandler<IAuthorizationRequirement>
             */

            //services.AddAuthorization(options =>
            //{
            //    options.AddPolicy(Policies.OnlyEmployees, policy => policy.Requirements.Add(new OnlyEmployeesRequirement()));
            //    options.AddPolicy(Policies.OnlyManagers, policy => policy.Requirements.Add(new OnlyManagersRequirement()));
            //    options.AddPolicy(Policies.OnlyThirdParties, policy => policy.Requirements.Add(new OnlyThirdPartiesRequirement()));
            //});

            //services.AddSingleton<IAuthorizationHandler, OnlyEmployeesAuthorizationHandler>();
            //services.AddSingleton<IAuthorizationHandler, OnlyManagersAuthorizationHandler>();
            //services.AddSingleton<IAuthorizationHandler, OnlyThirdPartiesAuthorizationHandler>();

            //services.AddSingleton<IGetApiKeyQuery, InMemoryGetApiKeyQuery>();

            //services.AddRouting(x => x.LowercaseUrls = true);
            #endregion

            //缓存
            services.AddMemoryCache();

            #region 手机号和验证码登录注册
            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = NormalAuthAuthenticationOptions.DefaultScheme;
                x.DefaultChallengeScheme    = NormalAuthAuthenticationOptions.DefaultScheme;
            })
            .AddNormalAuthSupport(options => { })
            .AddJwtBearer(x =>
            {
                x.TokenValidationParameters = new TokenValidationParameters();
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy(NormalAuthPolicies.OnlyAdmin, policy => policy.Requirements.Add(new OnlyAdminRequirement()));
            });

            services.AddSingleton <IAuthorizationHandler, OnlyAdminAuthorizationHandler>();
            services.AddSingleton <TokenHelper>();
            services.AddSingleton <IGetNormalUser, InMemoryGetNormalUser>();
            #endregion

            #region multi-tenant
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // To access HttpContext
            services.AddDbContext <GlobalDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddDbContext <TenantDbContext>();
            services.AddScoped <DbSeeder>();
            #endregion

            services.AddDbContext <ApplicationContext>(options =>
                                                       options.UseSqlServer(
                                                           Configuration.GetConnectionString("DefaultConnection"),
                                                           b => b.MigrationsAssembly(typeof(ApplicationContext).Assembly.FullName)));

            #region Swagger
            //services.AddSwaggerGen(c =>
            //{
            //    c.IncludeXmlComments(string.Format(@"{0}\CQRS.WebApi.xml", System.AppDomain.CurrentDomain.BaseDirectory));
            //    c.SwaggerDoc("v1", new OpenApiInfo
            //    {
            //        Version = "v1",
            //        Title = "CQRS.WebApi",
            //    });

            //});
            #endregion
            #region MediatR
            services.AddScoped <IApplicationContext>(provider => provider.GetService <ApplicationContext>());

            services.AddMediatR(Assembly.GetExecutingAssembly());
            services.AddValidatorsFromAssembly(typeof(Startup).Assembly);
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(ValidationBehaviour <,>));
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(LoggingBehaviour <,>));
            #endregion
        }
示例#5
0
        /// <summary>
        /// getButton_Click() - Get a set of Image Processing parameters from a Display System and a specified source.
        ///
        /// Author: ameja
        /// Date: 1/25/2018
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void getButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(displaySystemIdsComboBox.Text))
            {
                MessageBox.Show("Please enter a display system ID");
                return;
            }
            string displaySystemId = displaySystemIdsComboBox.Text;

            //Call JSON rpc post request with source value
            JObject result;

            try
            {
                result = SendGetRequest(Common.CreateJsonRequest("getsource", "{\"displaySystemId\": \"" + displaySystemId + "\", \"sourceType\":\"" + availableSourcesComboBox.Text + "\"}"));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }

            SourceSetting source = JsonConvert.DeserializeObject <SourceSetting>(result["result"].ToString());

            if (source.ImageProcessingParameters != null && source.ImageProcessingParameters.Count() > 0)
            {
                try
                {
                    if (source.ImageProcessingParameters.Exists(x => x.Type.Equals("brightness")))
                    {
                        brightnessNumericUpDown.Minimum = (decimal)source.ImageProcessingParameters.Where(x => x.Type.Equals("brightness")).First().Min;
                        brightnessNumericUpDown.Maximum = (decimal)source.ImageProcessingParameters.Where(x => x.Type.Equals("brightness")).First().Max;
                        brightnessNumericUpDown.Value   = decimal.Parse(source.ImageProcessingParameters.Where(x => x.Type.Equals("brightness")).First().Value);
                    }

                    if (source.ImageProcessingParameters.Exists(x => x.Type.Equals("hue")))
                    {
                        hueNumericUpDown.Minimum = (decimal)source.ImageProcessingParameters.Where(x => x.Type.Equals("hue")).First().Min;
                        hueNumericUpDown.Maximum = (decimal)source.ImageProcessingParameters.Where(x => x.Type.Equals("hue")).First().Max;
                        hueNumericUpDown.Value   = Int32.Parse(source.ImageProcessingParameters.Where(x => x.Type.Equals("hue")).First().Value);
                    }

                    if (source.ImageProcessingParameters.Exists(x => x.Type.Equals("sharpness")))
                    {
                        sharpnessNumericUpDown.Minimum = (decimal)source.ImageProcessingParameters.Where(x => x.Type.Equals("sharpness")).First().Min;
                        sharpnessNumericUpDown.Maximum = (decimal)source.ImageProcessingParameters.Where(x => x.Type.Equals("sharpness")).First().Max;
                        sharpnessNumericUpDown.Value   = Int32.Parse(source.ImageProcessingParameters.Where(x => x.Type.Equals("sharpness")).First().Value);
                    }

                    if (source.ImageProcessingParameters.Exists(x => x.Type.Equals("cliptosubblack")))
                    {
                        clipToSubblackNumericUpDown.Minimum = (decimal)source.ImageProcessingParameters.Where(x => x.Type.Equals("cliptosubblack")).First().Min;
                        clipToSubblackNumericUpDown.Maximum = (decimal)source.ImageProcessingParameters.Where(x => x.Type.Equals("cliptosubblack")).First().Max;
                        clipToSubblackNumericUpDown.Value   = Int32.Parse(source.ImageProcessingParameters.Where(x => x.Type.Equals("cliptosubblack")).First().Value);
                    }

                    if (source.ImageProcessingParameters.Exists(x => x.Type.Equals("steepness")))
                    {
                        steepnessNumericUpDown.Minimum = (decimal)source.ImageProcessingParameters.Where(x => x.Type.Equals("steepness")).First().Min;
                        steepnessNumericUpDown.Maximum = (decimal)source.ImageProcessingParameters.Where(x => x.Type.Equals("steepness")).First().Max;
                        steepnessNumericUpDown.Value   = Int32.Parse(source.ImageProcessingParameters.Where(x => x.Type.Equals("steepness")).First().Value);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show("There are no image processing parameters for this source.");
            }
        }