Esempio n. 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Контроллеры
            services.AddControllers();

            // Документация
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title       = "Менеджер метрик",
                    Description = "Позволяет отслеживать и анализировать параметры системы",
                    Contact     = new OpenApiContact
                    {
                        Name = "Заярная Анастасия"
                    },
                    Version = "v1"
                });
            });

            // БД
            services.AddSingleton <IDataConnector, SQLLite>();
            // миграции
            var dbConnector = new SQLLite();

            services.AddFluentMigratorCore()
            .ConfigureRunner(
                rb => rb.AddSQLite()
                .WithGlobalConnectionString(dbConnector.GetStringConnection())
                .ScanIn(typeof(Startup).Assembly).For.Migrations()
                ).AddLogging(logger => logger.AddFluentMigratorConsole());

            // Мапперы
            var mapperConfiguration = new MapperConfiguration(mp => mp.AddProfile(new MapperProfile()));
            var mapper = mapperConfiguration.CreateMapper();

            services.AddSingleton(mapper);

            // Репозитории
            services.AddSingleton <ICPUMetricsRepository, CPUMetricsRepository>();
            services.AddSingleton <IDotNetMetricsRepository, DotNetMetricsRepository>();
            services.AddSingleton <IHddMetricsRepository, HddMetricsRepository>();
            services.AddSingleton <INetworkMetricsRepository, NetworkMetricsRepository>();
            services.AddSingleton <IRamMetricsRepository, RamMetricsRepository>();

            // Сервисы по рассписанию
            services.AddSingleton <IJobFactory, SingletonJobFactory>();
            services.AddSingleton <ISchedulerFactory, StdSchedulerFactory>();
            services.AddSingleton <CpuMetricJob>();
            services.AddSingleton <DotNetMetricJob>();
            services.AddSingleton <HddMetricJob>();
            services.AddSingleton <NetworkMetricJob>();
            services.AddSingleton <RamMetricJob>();
            services.AddSingleton(new JobSchedule(jobType: typeof(CpuMetricJob), cronExpression: "0/5 * * * * ?"));
            services.AddSingleton(new JobSchedule(jobType: typeof(DotNetMetricJob), cronExpression: "0/5 * * * * ?"));
            services.AddSingleton(new JobSchedule(jobType: typeof(HddMetricJob), cronExpression: "0/5 * * * * ?"));
            services.AddSingleton(new JobSchedule(jobType: typeof(NetworkMetricJob), cronExpression: "0/5 * * * * ?"));
            services.AddSingleton(new JobSchedule(jobType: typeof(RamMetricJob), cronExpression: "0/5 * * * * ?"));
            services.AddHostedService <QuartzHostedService>();
        }
Esempio n. 2
0
        public static void RegisterFunctions()
        {
            ParserFunction.RegisterFunction("GetLocation", new GetLocationFunction());
            ParserFunction.RegisterFunction("AddWidget", new AddWidgetFunction());
            ParserFunction.RegisterFunction("AddView", new AddWidgetFunction("View"));
            ParserFunction.RegisterFunction("AddButton", new AddWidgetFunction("Button"));
            ParserFunction.RegisterFunction("AddLabel", new AddWidgetFunction("Label"));
            ParserFunction.RegisterFunction("AddTextEdit", new AddWidgetFunction("TextEdit"));
            ParserFunction.RegisterFunction("AddTextView", new AddWidgetFunction("TextView"));
            ParserFunction.RegisterFunction("AddTextEditView", new AddWidgetFunction("TextEditView"));
            ParserFunction.RegisterFunction("AddImageView", new AddWidgetFunction("ImageView"));
            ParserFunction.RegisterFunction("AddPickerView", new AddWidgetFunction("Picker"));
            ParserFunction.RegisterFunction("AddTypePickerView", new AddWidgetFunction("TypePicker"));
            ParserFunction.RegisterFunction("AddSwitch", new AddWidgetFunction("Switch"));
            ParserFunction.RegisterFunction("AddSlider", new AddWidgetFunction("Slider"));
            ParserFunction.RegisterFunction("AddStepper", new AddWidgetFunction("Stepper"));
            ParserFunction.RegisterFunction("AddStepperLeft", new AddWidgetFunction("Stepper", "left"));
            ParserFunction.RegisterFunction("AddStepperRight", new AddWidgetFunction("Stepper", "right"));
            ParserFunction.RegisterFunction("AddListView", new AddWidgetFunction("ListView"));
            ParserFunction.RegisterFunction("AddCombobox", new AddWidgetFunction("Combobox"));
            ParserFunction.RegisterFunction("AddIndicator", new AddWidgetFunction("Indicator"));
            ParserFunction.RegisterFunction("AddSegmentedControl", new AddWidgetFunction("SegmentedControl"));

            ParserFunction.RegisterFunction("AddWidgetData", new AddWidgetDataFunction());
            ParserFunction.RegisterFunction("AddWidgetImages", new AddWidgetImagesFunction());
            ParserFunction.RegisterFunction("AddTab", new AddTabFunction(true));
            ParserFunction.RegisterFunction("AddOrSelectTab", new AddTabFunction(false));
            ParserFunction.RegisterFunction("GetSelectedTab", new GetSelectedTabFunction());
            ParserFunction.RegisterFunction("SelectTab", new SelectTabFunction());
            ParserFunction.RegisterFunction("OnTabSelected", new OnTabSelectedFunction());
            ParserFunction.RegisterFunction("AddBorder", new AddBorderFunction());
            ParserFunction.RegisterFunction("AutoScale", new AutoScaleFunction());
            ParserFunction.RegisterFunction("SetBaseWidth", new SetBaseWidthFunction());
            ParserFunction.RegisterFunction("SetBaseHeight", new SetBaseHeightFunction());
            ParserFunction.RegisterFunction("AddLongClick", new AddLongClickFunction());
            ParserFunction.RegisterFunction("AddSwipe", new AddSwipeFunction());
            ParserFunction.RegisterFunction("AddDragAndDrop", new AddDragAndDropFunction());
            ParserFunction.RegisterFunction("ShowView", new ShowHideFunction(true));
            ParserFunction.RegisterFunction("HideView", new ShowHideFunction(false));
            ParserFunction.RegisterFunction("SetVisible", new ShowHideFunction(true));
            ParserFunction.RegisterFunction("RemoveView", new RemoveViewFunction());
            ParserFunction.RegisterFunction("RemoveViewIfExists", new RemoveViewIfExistsFunction());
            ParserFunction.RegisterFunction("RemoveAllViews", new RemoveAllViewsFunction());
            ParserFunction.RegisterFunction("RemoveTabViews", new RemoveAllViewsFunction());
            ParserFunction.RegisterFunction("GetX", new GetCoordinateFunction(true));
            ParserFunction.RegisterFunction("GetY", new GetCoordinateFunction(false));
            ParserFunction.RegisterFunction("MoveView", new MoveViewFunction(false));
            ParserFunction.RegisterFunction("MoveViewTo", new MoveViewFunction(true));
            ParserFunction.RegisterFunction("SetBackgroundColor", new SetBackgroundColorFunction());
            ParserFunction.RegisterFunction("SetBackground", new SetBackgroundImageFunction());
            ParserFunction.RegisterFunction("AddText", new AddTextFunction());
            ParserFunction.RegisterFunction("SetText", new SetTextFunction());
            ParserFunction.RegisterFunction("GetText", new GetTextFunction());
            ParserFunction.RegisterFunction("SetValue", new SetValueFunction());
            ParserFunction.RegisterFunction("GetValue", new GetValueFunction());
            ParserFunction.RegisterFunction("SetImage", new SetImageFunction());
            ParserFunction.RegisterFunction("SetFontColor", new SetFontColorFunction());
            ParserFunction.RegisterFunction("SetFontSize", new SetFontSizeFunction());
            ParserFunction.RegisterFunction("SetFont", new SetFontFunction());
            ParserFunction.RegisterFunction("SetBold", new SetFontTypeFunction(SetFontTypeFunction.FontType.BOLD));
            ParserFunction.RegisterFunction("SetItalic", new SetFontTypeFunction(SetFontTypeFunction.FontType.ITALIC));
            ParserFunction.RegisterFunction("SetNormalFont", new SetFontTypeFunction(SetFontTypeFunction.FontType.NORMAL));
            ParserFunction.RegisterFunction("AlignText", new AlignTitleFunction());
            ParserFunction.RegisterFunction("SetSize", new SetSizeFunction());
            ParserFunction.RegisterFunction("Relative", new RelativeSizeFunction());
            ParserFunction.RegisterFunction("ShowHideKeyboard", new ShowHideKeyboardFunction());
            ParserFunction.RegisterFunction("IsKeyboard", new IsKeyboardFunction());
            ParserFunction.RegisterFunction("NumKeyboard", new NumKeyboardFunction());
            ParserFunction.RegisterFunction("ClearWidget", new ClearWidgetDataFunction());

            ParserFunction.RegisterFunction("AddAction", new AddActionFunction());
            ParserFunction.RegisterFunction("AllowedOrientation", new AllowedOrientationFunction());
            ParserFunction.RegisterFunction("OnOrientationChange", new OrientationChangeFunction());
            ParserFunction.RegisterFunction("RegisterOrientationChange", new RegisterOrientationChangeFunction());
            ParserFunction.RegisterFunction("OnEnterBackground", new OnEnterBackgroundFunction());
            ParserFunction.RegisterFunction("KillMe", new KillMeFunction());
            ParserFunction.RegisterFunction("ShowToast", new ShowToastFunction());
            ParserFunction.RegisterFunction("AlertDialog", new AlertDialogFunction());
            ParserFunction.RegisterFunction("ColorPicker", new PickColorDialogFunction());
            ParserFunction.RegisterFunction("ConvertColor", new ConvertColorFunction());

            ParserFunction.RegisterFunction("Speak", new SpeakFunction());
            ParserFunction.RegisterFunction("SetupSpeech", new SpeechOptionsFunction());
            ParserFunction.RegisterFunction("VoiceRecognition", new VoiceFunction());
            ParserFunction.RegisterFunction("StopVoiceRecognition", new StopVoiceFunction());
            ParserFunction.RegisterFunction("Localize", new LocalizedFunction());
            ParserFunction.RegisterFunction("TranslateTabBar", new TranslateTabBar());
            ParserFunction.RegisterFunction("InitIAP", new InitIAPFunction());
            ParserFunction.RegisterFunction("InitTTS", new InitTTSFunction());
            ParserFunction.RegisterFunction("Purchase", new PurchaseFunction());
            ParserFunction.RegisterFunction("Restore", new RestoreFunction());
            ParserFunction.RegisterFunction("ProductIdDescription", new ProductIdDescriptionFunction());
            ParserFunction.RegisterFunction("ReadFile", new ReadFileFunction());
            ParserFunction.RegisterFunction("ReadFileAsString", new ReadFileFunction(true));
            ParserFunction.RegisterFunction("Schedule", new PauseFunction(true));
            ParserFunction.RegisterFunction("CancelSchedule", new PauseFunction(false));
            ParserFunction.RegisterFunction("GetDeviceLocale", new GetDeviceLocale());
            ParserFunction.RegisterFunction("SetAppLocale", new SetAppLocale());
            ParserFunction.RegisterFunction("GetSetting", new GetSettingFunction());
            ParserFunction.RegisterFunction("SetSetting", new SetSettingFunction());
            ParserFunction.RegisterFunction("SetStyle", new SetStyleFunction());
            ParserFunction.RegisterFunction("DisplayWidth", new GadgetSizeFunction(true));
            ParserFunction.RegisterFunction("DisplayHeight", new GadgetSizeFunction(false));
            ParserFunction.RegisterFunction("Orientation", new OrientationFunction());
            ParserFunction.RegisterFunction("GetTrie", new CreateTrieFunction());
            ParserFunction.RegisterFunction("SearchTrie", new SearchTrieFunction());
            ParserFunction.RegisterFunction("ImportFile", new ImportFileFunction());
            ParserFunction.RegisterFunction("OpenUrl", new OpenURLFunction());
            ParserFunction.RegisterFunction("WebRequest", new WebRequestFunction());

            ParserFunction.RegisterFunction("EnableWidget", new EnableFunction());
            ParserFunction.RegisterFunction("SetSecure", new MakeSecureFunction());
            ParserFunction.RegisterFunction("SaveToPhotos", new SaveToPhotosFunction());

            ParserFunction.RegisterFunction("_ANDROID_", new CheckOSFunction(CheckOSFunction.OS.ANDROID));
            ParserFunction.RegisterFunction("_IOS_", new CheckOSFunction(CheckOSFunction.OS.IOS));
            ParserFunction.RegisterFunction("_DEVICE_INFO_", new GetDeviceInfoFunction());
            ParserFunction.RegisterFunction("_VERSION_INFO_", new GetVersionInfoFunction());
            ParserFunction.RegisterFunction("_VERSION_NUMBER_", new GetVersionNumberFunction());
            ParserFunction.RegisterFunction("_DEBUG_", new IsDebugFunction());
            ParserFunction.RegisterFunction("CompareVersions", new CompareVersionsFunction());

            ParserFunction.RegisterFunction("Run", new RunScriptFunction());
            ParserFunction.RegisterFunction("SetOptions", new SetOptionsFunction());

            ParserFunction.RegisterFunction("GetLocalIp", new GetLocalIpFunction(true));
            ParserFunction.RegisterFunction("isiPhoneX", new IsiPhoneXFunction());
            ParserFunction.RegisterFunction("isAndroid", new IsAndroidFunction());

            ParserFunction.RegisterFunction("RunOnMain", new RunOnMainFunction());
            ParserFunction.RegisterFunction("PrintConsole", new PrintConsoleFunction());

            ParserFunction.RegisterFunction("time:year", new MyDateTimeFunction("yyyy"));
            ParserFunction.RegisterFunction("time:month", new MyDateTimeFunction("MM"));
            ParserFunction.RegisterFunction("time:day", new MyDateTimeFunction("dd"));
            ParserFunction.RegisterFunction("time:hour", new MyDateTimeFunction("HH"));
            ParserFunction.RegisterFunction("time:minute", new MyDateTimeFunction("mm"));
            ParserFunction.RegisterFunction("time:second", new MyDateTimeFunction("ss"));
            ParserFunction.RegisterFunction("time:millis", new MyDateTimeFunction("fff"));

            SQLLite.Init();
        }
Esempio n. 3
0
        public void ConfigureServices(IServiceCollection services)
        {
            // Контроллеры
            services.AddControllers();

            // Документация
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title       = "Менеджер агентов метрик",
                    Description = "Позволяет управлять агентами",
                    Contact     = new OpenApiContact
                    {
                        Name = "Заярная Анастасия"
                    },
                    Version = "v1"
                });
            });

            // БД
            services.AddSingleton <IDataConnector, SQLLite>();
            // миграции
            var dbConnector = new SQLLite();

            services.AddFluentMigratorCore()
            .ConfigureRunner(
                rb => rb.AddSQLite()
                .WithGlobalConnectionString(dbConnector.GetStringConnection())
                .ScanIn(typeof(Startup).Assembly).For.Migrations()
                ).AddLogging(logger => logger.AddFluentMigratorConsole());

            // Мапперы
            var mapperConfiguration = new MapperConfiguration(mp => mp.AddProfile(new MapperProfile()));
            var mapper = mapperConfiguration.CreateMapper();

            services.AddSingleton(mapper);

            // Репозитории
            services.AddSingleton <ICPUMetricsRepository, CPUMetricsRepository>();
            services.AddSingleton <IDotNetMetricsRepository, DotNetMetricsRepository>();
            services.AddSingleton <IHddMetricsRepository, HddMetricsRepository>();
            services.AddSingleton <INetworkMetricsRepository, NetworkMetricsRepository>();
            services.AddSingleton <IRamMetricsRepository, RamMetricsRepository>();
            services.AddSingleton <IAgentsRepository, AgentsRepository>();

            // Http
            services.AddHttpClient <IMetricsClient, MetricsClient>()
            // Повторная попытка запроса, в случае не удачи
            .AddTransientHttpErrorPolicy(p => p.WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(1000)));

            // Сервисы по расписанию
            services.AddSingleton <IJobFactory, SingletonJobFactory>();
            services.AddSingleton <ISchedulerFactory, StdSchedulerFactory>();
            services.AddSingleton <CpuMetricJob>();
            services.AddSingleton <DotNetMetricJob>();
            services.AddSingleton <HddMetricJob>();
            services.AddSingleton <NetworkMetricJob>();
            services.AddSingleton <RamMetricJob>();
            services.AddSingleton(new JobSchedule(jobType: typeof(CpuMetricJob), cronExpression: "0/5 * * * * ?"));
            services.AddSingleton(new JobSchedule(jobType: typeof(DotNetMetricJob), cronExpression: "0/5 * * * * ?"));
            services.AddSingleton(new JobSchedule(jobType: typeof(HddMetricJob), cronExpression: "0/5 * * * * ?"));
            services.AddSingleton(new JobSchedule(jobType: typeof(NetworkMetricJob), cronExpression: "0/5 * * * * ?"));
            services.AddSingleton(new JobSchedule(jobType: typeof(RamMetricJob), cronExpression: "0/5 * * * * ?"));
            services.AddHostedService <QuartzHostedService>();
        }