Пример #1
0
        /// <summary>
        /// 注册WebApi
        /// </summary>
        public static AppStartup RegWebApi(this AppStartup startup, Assembly assembly)
        {
            if (EasyAutofac.Container != null)
            {
                throw new Exception("注册WebApi必须在初始化IOC容器【InitIoC】之前完成!");
            }

            var builder = EasyAutofac.ContainerBuilder;

            builder.RegisterApiControllers(assembly);

            builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);

            //配置默认返回json
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

            GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(
                new QueryStringMapping("datatype", "json", "application/json"));

            //返回格式选择 datatype 可以替换为任何参数
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.MediaTypeMappings.Add(
                new QueryStringMapping("datatype", "xml", "application/xml"));

            //MessageHandlers:被调用的顺序与添加到MessageHandlers集合的顺序相同
            GlobalConfiguration.Configuration.MessageHandlers.Add(new IPHandler());

            //异常拦截
            GlobalConfiguration.Configuration.Services.Replace(typeof(IExceptionHandler), new GlobalErrorHandler());
            GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger), new GlobalErrorLogger());

            //Filter 先添加的先执行
            GlobalConfiguration.Configuration.Filters.Add(new ModelValidatorAttribute());

            return(startup);
        }
Пример #2
0
        private void CheckAutoBind()
        {
            List <BindingIP> bindingIps = _bindings.GetBindings(true);

            AppStartup.RegisterInStartup(bindingIps.Count > 0);
            //AppStartup.RegisterInStartup(false);
        }
Пример #3
0
        /// <summary>
        /// 注册MVC
        /// </summary>
        public static AppStartup RegMvc(this AppStartup startup, Assembly assembly)
        {
            if (EasyAutofac.Container != null)
            {
                throw new Exception("注册MVC必须在初始化IOC容器【InitIoC】之前完成!");
            }

            var builder = EasyAutofac.ContainerBuilder;

            builder.RegisterControllers(assembly);

            builder.RegisterModelBinders(assembly);

            builder.RegisterModelBinderProvider();

            builder.RegisterModule <AutofacWebTypesModule>();

            builder.RegisterSource(new ViewRegistrationSource());

            builder.RegisterFilterProvider();

            //Filter 先添加的先执行
            GlobalFilters.Filters.Add(new CompressAttribute());
            GlobalFilters.Filters.Add(new GlobalExceptionFilter());
            GlobalFilters.Filters.Add(new ModelValidatorAttribute());

            //设置需要客户端验证和启用非介入式JavaScript
            HtmlHelper.ClientValidationEnabled      = true;
            HtmlHelper.UnobtrusiveJavaScriptEnabled = true;

            return(startup);
        }
Пример #4
0
        /// <summary>
        /// 获取需要防御流量攻击的【RouteName】
        /// </summary>
        public static AppStartup InitMvcLimitAttack(this AppStartup startup, Assembly assembly)
        {
            var limitAttackModelList = DefendAttackService.GetLimitAttackModel(assembly);

            DefendAttackContainer.InitDefendAttackList(limitAttackModelList, assembly.GetName().Name);

            return(startup);
        }
Пример #5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            AppStartup startup = new AppStartup();

            startup.Initialize();
            startup.Boot();
        }
Пример #6
0
        public MainWindow()
        {
            AppStartup.Initialize();
            InitializeComponent();

            var vmc = DI.Provider.GetService <ViewModelsController>();

            DataContext = vmc.GetViewModel <WindowViewModel>();
        }
Пример #7
0
 static void Main()
 {
     try
     {
         var container = AppStartup.StartContainer();
         RunApplication(container);
     }
     catch (Exception ex)
     {
     }
 }
Пример #8
0
 private void RegisterStartup()
 {
     if (AppStartup.IsRegistered)
     {
         AppStartup.Unregister();
     }
     else
     {
         AppStartup.Register();
     }
     RegStartupButtonContent = AppStartup.IsRegistered ? Resources.UnregFromStartup : Resources.RegToStartup;
 }
Пример #9
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            // For iOS, wrap inside a navigation page, otherwise the header looks wrong
            var formsApp = new AppStartup();

            formsApp.MainPage = new NavigationPage(formsApp.MainPage);

            LoadApplication(formsApp);

            return(base.FinishedLaunching(app, options));
        }
Пример #10
0
        public static AppStartup StartMvc(this AppStartup startup)
        {
            startup.Start();

            if (EasyAutofac.Container == null)
            {
                throw new Exception("请先加载IoC容器");
            }

            DependencyResolver.SetResolver(new AutofacDependencyResolver(EasyAutofac.Container));

            return(startup);
        }
Пример #11
0
        public static AppStartup StartWebApi(this AppStartup startup)
        {
            startup.Start();

            if (EasyAutofac.Container == null)
            {
                throw new Exception("请先加载IoC容器");
            }

            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(EasyAutofac.Container);

            return(startup);
        }
Пример #12
0
        public static Logger CreateGlobalLogger()
        {
            AppStartup.LoadConfiguration();

            return(new LoggerConfiguration()
                   .WriteTo.Console()
                   .WriteTo.Seq(
                       AppStartup.Configuration["Seq:IngestionEndpoint"],
                       apiKey: AppStartup.Configuration["Seq:ApiKey"])
                   .Enrich.WithMachineName()
                   .Enrich.FromLogContext()
                   .Enrich.WithDemystifiedStackTraces()
                   .Enrich.With(LoggingEnrichers.AppEnricher)
                   .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                   .CreateLogger());

            ;
        }
Пример #13
0
        public static AppStartup RegisterConsul(this AppStartup startup, ConsulOption consulOption)
        {
            try
            {
                ConsulClient consulClient = RegisterConsul(consulOption);

                //当应用程序结束时,应注销服务注册
                OnApplicationStopping(consulClient, consulOption.GlobalRegId);

                if (_checkServiceIsExistTask == null)
                {
                    _checkServiceIsExistTask = Task.Factory.StartNew(() => CheckServiceIsExistTask(consulClient, consulOption), TaskCreationOptions.LongRunning);
                }

                return(startup);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "注册Consul异常");
                throw;
            }
        }
Пример #14
0
        public ConfigurationContentViewModel(IConfigurationService configurationService)
        {
            var configuration = configurationService.Configuration;

            _product     = Product.Find(configurationService.Configuration.ModelNumber, configurationService.Configuration.Windows);
            Interval     = ReactiveProperty.FromObject(configuration, w => w.Interval, w => (int)w, IntervalExt.ToInterval);
            IsRegistered = new ReactiveProperty <bool>(AppStartup.IsRegistered);
            IsRegistered.Subscribe(w =>
            {
                if (AppStartup.IsRegistered == IsRegistered.Value)
                {
                    return;
                }
                if (AppStartup.IsRegistered)
                {
                    AppStartup.Unregister();
                }
                else
                {
                    AppStartup.Register();
                }
            }).AddTo(this);
        }
Пример #15
0
 public AppStartupManager(AppStartup appStartup, ILogger logger, AppSettings appSettings)
 {
     this._appStartup  = appStartup;
     this._logger      = logger;
     this._appSettings = appSettings;
 }
Пример #16
0
        /// <summary>
        /// Change to the next layout
        /// </summary>
        private void ChangeToNextLayout(string layoutPath)
        {
            if (ApplicationSettings.Default.PreventSleep)
            {
                try
                {
                    SetThreadExecutionState(EXECUTION_STATE.ES_DISPLAY_REQUIRED | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_CONTINUOUS);
                }
                catch
                {
                    Trace.WriteLine(new LogMessage("MainForm - ChangeToNextLayout", "Unable to set Thread Execution state"), LogType.Info.ToString());
                }
            }

            try
            {
                // Destroy the Current Layout
                try
                {
                    DestroyLayout();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(new LogMessage("MainForm - ChangeToNextLayout", "Destroy Layout Failed. Exception raised was: " + e.Message), LogType.Info.ToString());
                    throw e;
                }

                // Prepare the next layout
                try
                {
                    PrepareLayout(_layoutId.ToString());

                    _clientInfoForm.CurrentLayoutId = layoutPath;
                    //_schedule.CurrentLayoutId = _layoutId;
                }
                catch (DefaultLayoutException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    DestroyLayout();
                    Trace.WriteLine(new LogMessage("MainForm - ChangeToNextLayout", "Prepare Layout Failed. Exception raised was: " + e.Message), LogType.Info.ToString());
                    throw;
                }

                // _clientInfoForm.ControlCount = Controls.Count;

                // Do we need to notify?
                try
                {
                    AppStartup.Notify(_layoutId.ToString());
                }
                catch (Exception e)
                {
                    Trace.WriteLine(new LogMessage("MainForm - ChangeToNextLayout", "Notify Status Failed. Exception raised was: " + e.Message), LogType.Info.ToString());
                    throw;
                }
            }
            catch (Exception ex)
            {
                if (!(ex is DefaultLayoutException))
                {
                    Trace.WriteLine(new LogMessage("MainForm - ChangeToNextLayout", "Layout Change to " + layoutPath + " failed. Exception raised was: " + ex.Message), LogType.Error.ToString());
                }
                Trace.WriteLine(new LogMessage("MainForm - ChangeToNextLayout", "Layout Change to " + layoutPath + " failed. Exception raised was: " + ex.Message), LogType.Error.ToString());
                //if (!_showingSplash)
                //    ShowSplashScreen();

                // In 10 seconds fire the next layout
                System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                timer.Interval = 10000;
                timer.Tick    += new EventHandler(splashScreenTimer_Tick);

                // Start the timer
                timer.Start();
            }

            // We have finished changing the layout
            _changingLayout = false;
        }
 public AppStartupManager(AppStartup appStartup, IPersistedSettings settings)
 {
     this._appStartup = appStartup;
     this._settings   = settings;
 }
Пример #18
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
 {
     AppStartup.Configure(app, env);
 }
Пример #19
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     AppStartup.ConfigureServices(Configuration, services);
     AppStartup.ConfigureMapping(services, typeof(AppStartup), typeof(Startup));
 }
Пример #20
0
        /// <summary>
        /// 注册验证模型提供者
        /// </summary>
        public static AppStartup RegFluentValid(this AppStartup startup)
        {
            FluentValidationModelValidatorProvider.Configure(GlobalConfiguration.Configuration);

            return(startup);
        }