Exemplo n.º 1
0
        public async Task LogoutAsync()
        {
            bool logout = await _dialogService.ShowConfirmationDialogAsync(
                "Confirmation",
                "Are you sure you want to log out?",
                "Yes",
                "No");

            if (logout)
            {
                //TODO: DELETE ALL !!
                //delete all from the db
                //delete user settings
                //delete all view models
                OpenPane(false);
                ShowLoading(true, "Logging out... Please wait..");
                BackgroundTasksManager.UnregisterBackgroundTask();
                _appSettings.ResetAppSettings();

                await _dataService
                .UserService
                .ChangeCurrentUserStatus(false);

                string currentLoggedUsername = _userCredentialService.GetCurrentLoggedUsername();
                if (string.IsNullOrEmpty(currentLoggedUsername))
                {
                    currentLoggedUsername = _userCredentialService.DefaultUsername;
                }

                _userCredentialService.DeleteUserCredential(ResourceType.ALL, currentLoggedUsername);
                _navigationService.GoBack();
                ShowLoading(false);
            }
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            if (!_isInitialized)
            {
                InitializationCallback?.Invoke(_engine, _engine.Environment);
                _engine.Initialize();

                var taskManager = new BackgroundTasksManager(EngineInstance);
                _engine.Environment.InjectGlobalProperty(taskManager, "ФоновыеЗадания", true);
                _engine.Environment.InjectGlobalProperty(taskManager, "BackgroundTasks", true);


                _isInitialized = true;
            }

            // System language
            var SystemLanguageCfg = GetWorkingConfig()["SystemLanguage"];

            if (SystemLanguageCfg != null)
            {
                Locale.SystemLanguageISOName = SystemLanguageCfg;
            }
            else
            {
                Locale.SystemLanguageISOName = System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
            }
        }
Exemplo n.º 3
0
        public static void PrepareBgJobsEnvironment(IServiceProvider services, RuntimeEnvironment environment)
        {
            var hfOptions = services.GetService <IOptions <OscriptBackgroundJobsOptions> >().Value;

            if (hfOptions != null)
            {
                var jobsManager = new ScheduledJobsManagerContext(environment, services.GetService <DbContextProvider>());

                environment.InjectGlobalProperty(jobsManager, "РегламентныеЗадания", true);
                environment.InjectGlobalProperty(jobsManager, "ScheduledJobs", true);

                var runtime = services.GetService <IApplicationRuntime>();

                var bgJobsManager = new BackgroundTasksManager(runtime.Engine);
                environment.InjectGlobalProperty(bgJobsManager, "ФоновыеЗадания", true);
                environment.InjectGlobalProperty(bgJobsManager, "BackgroundJobs", true);
            }
        }
Exemplo n.º 4
0
        public void RegisterBackgroundTasks(BackgroundTaskType backgroundTask, bool restart = true)
        {
            int bgTaskInterval = 0;

            switch (backgroundTask)
            {
            case BackgroundTaskType.ANY:
                throw new ArgumentException("Is not allowed to register all bg tasks at the same time");

            case BackgroundTaskType.SYNC:
                bgTaskInterval = (int)_appSettings.SyncBackgroundTaskInterval;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(backgroundTask), backgroundTask, "The bg task cant be registered because it doesnt exits");
            }

            BackgroundTasksManager.RegisterBackgroundTask(backgroundTask, bgTaskInterval, restart);
        }
Exemplo n.º 5
0
        static void Main(String[] args)
        {
            BackgroundTasksManager _manager = null;

            try
            {
                var defaultCulture = ConfigurationManager.AppSettings["defaultCulture"];
                if (defaultCulture != null)
                {
                    var cultureInfo = new CultureInfo(defaultCulture);
                    CultureInfo.DefaultThreadCurrentCulture   = cultureInfo;
                    CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
                }

                StartServices();
                var              loc       = ServiceLocator.Current;
                ILogger          logger    = loc.GetService <ILogger>();
                IDbContext       dbContext = loc.GetService <IDbContext>();
                IApplicationHost host      = loc.GetService <IApplicationHost>();
                IMessaging       messaging = loc.GetService <IMessaging>();
                Console.WriteLine("Service started");
                _manager = new BackgroundTasksManager(host, dbContext, logger, messaging);
                logger.LogBackground($"CurrentCulutre: {Thread.CurrentThread.CurrentCulture}");
                host.StartApplication(false);
                _manager.Start();
                _manager.StartTasksFromConfig();
                Console.WriteLine("Press any key to stop service...");
                Console.Read();
                _manager.Stop();
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                Console.WriteLine(ex.Message);
                _manager?.Stop();
            }
        }
Exemplo n.º 6
0
 public void UnregisterBackgroundTasks(BackgroundTaskType backgroundTask = BackgroundTaskType.ANY)
 {
     BackgroundTasksManager.UnregisterBackgroundTask(backgroundTask);
 }
Exemplo n.º 7
0
        private void OnLaunchedOrActivated(IActivatedEventArgs e)
        {
            // Initialize things like registering background tasks before the app is loaded
            BackgroundTasksManager.RegisterBackgroundTask(BackgroundTaskType.MARK_AS_COMPLETED, restart: false);
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            // Handle toast activation
            if (e is ToastNotificationActivatedEventArgs toastActivationArgs)
            {
                if (toastActivationArgs.Argument.Length != 0)
                {
                    // If we're loading the app for the first time, place the main page on the back stack
                    // so that user can go back after they've been navigated to the specific page
                    //if (rootFrame.BackStack.Count == 0)
                    //rootFrame.BackStack.Add(new PageStackEntry(typeof(LoginPage), null, null));

                    var queryParams = toastActivationArgs.Argument
                                      .Split('&')
                                      .ToDictionary(c => c.Split('=')[0], c => Uri.UnescapeDataString(c.Split('=')[1]));

                    var actionType = (NotificationActionType)Enum.Parse(typeof(NotificationActionType), queryParams["action"]);

                    switch (actionType)
                    {
                    case NotificationActionType.OPEN_TASK:
                        BaseViewModel.InitDetails = new Tuple <int, int>(int.Parse(queryParams["taskListID"]), int.Parse(queryParams["taskID"]));
                        break;

                    case NotificationActionType.MARK_AS_COMPLETED:
                    default:
                        throw new ArgumentOutOfRangeException(nameof(actionType), actionType, "The provided toast action type is not valid");
                    }
                }
                if (rootFrame.Content == null)
                {
                    rootFrame.Navigate(typeof(LoginPage));
                }

                //kinda hack but works..
                if (ViewModelLocator.IsAppRunning)
                {
                    var vml = new ViewModelLocator();
                    vml.Home.PageLoadedCommand.Execute(null);
                }
            }
            // Handle launch activation
            else if (e is LaunchActivatedEventArgs launchActivationArgs)
            {
                // If launched with arguments (not a normal primary tile/applist launch)
                if (launchActivationArgs.Arguments.Length > 0)
                {
                    // TODO: Handle arguments for cases like launching from secondary Tile, so we navigate to the correct page
                    throw new NotImplementedException("Launched with arguments type of of activation is not currently implemented");
                }
                // Otherwise if launched normally
                else
                {
                    // If we're currently not on a page, navigate to the login page
                    if (rootFrame.Content == null)
                    {
                        rootFrame.Navigate(typeof(LoginPage));
                    }
                }
            }
            else
            {
                // TODO: Handle other types of activation
                throw new NotImplementedException("This type of of activation is not currently implemented");
            }
            //If the app is already initialized just return. Not sure if this is needed
            if (_initialized)
            {
                return;
            }

            ViewModelLocator.IsAppRunning = true;

            // Ensure the current window is active
            Window.Current.Activate();
            GalaSoft.MvvmLight.Threading.DispatcherHelper.Initialize();
            _initialized = true;
        }