/// <summary> /// Eventhandler, der rejses, når eventet til håndtering af exceptions publiceres. /// </summary> /// <param name="eventArgs">Argumenter fra eventet, der publiceres.</param> public void OnEvent(IHandleExceptionEventArgs eventArgs) { if (eventArgs == null) { throw new ArgumentNullException("eventArgs"); } var validationException = eventArgs.Error as IntranetGuiValidationException; if (validationException != null) { eventArgs.IsHandled = false; return; } var businessException = eventArgs.Error as IntranetGuiBusinessException; if (businessException != null) { eventArgs.IsHandled = false; return; } var offlineRepositoryException = eventArgs.Error as IntranetGuiOfflineRepositoryException; if (offlineRepositoryException != null) { var finansstyringKonfigurationRepository = FinansstyringKonfigurationRepository.Instance; var localeDataStorage = new LocaleDataStorage(finansstyringKonfigurationRepository.LokalDataFil, finansstyringKonfigurationRepository.SynkroniseringDataFil, FinansstyringRepositoryLocale.XmlSchema); localeDataStorage.OnHasLocaleData += LocaleDataStorageHelper.HasLocaleDataEventHandler; localeDataStorage.OnCreateReaderStream += LocaleDataStorageHelper.CreateReaderStreamEventHandler; localeDataStorage.OnCreateWriterStream += LocaleDataStorageHelper.CreateWriterStreamEventHandler; eventArgs.IsHandled = true; MainViewModel.SwitchToLocaleDataStorage(new FinansstyringRepositoryLocale(finansstyringKonfigurationRepository, localeDataStorage)); var contentPage = FinansstyringFrame.Content as Page; if (contentPage != null) { while (contentPage.Frame.CanGoBack) { contentPage.Frame.GoBack(); } return; } FinansstyringFrame.Navigate(typeof(RegnskabslistePage), null); } var repositoryException = eventArgs.Error as IntranetGuiRepositoryException; if (repositoryException != null) { Debug.WriteLine("{0}: {1}", repositoryException.GetType().Name, repositoryException.Message); eventArgs.IsHandled = true; return; } var systemException = eventArgs.Error as IntranetGuiSystemException; if (systemException != null) { Debug.WriteLine("{0}: {1}", systemException.GetType().Name, systemException.Message); eventArgs.IsHandled = true; return; } try { var exception = eventArgs.Error; if (exception == null) { return; } Debug.WriteLine("{0}: {1}", exception.GetType().Name, exception.Message); } finally { eventArgs.IsHandled = true; } }
/// <summary> /// Starter baggrundstask, der kan loaded nyheder til finansstyring. /// </summary> /// <param name="taskInstance">Instans af baggrundstasken.</param> public async void Run(IBackgroundTaskInstance taskInstance) { lock (SyncRoot) { if (_isLoading) { return; } _isLoading = true; } BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); try { WindowsRuntimeResourceManager.PatchResourceManagers(); ConfigurationProvider configurationProvider = new ConfigurationProvider(); IDictionary <string, object> finansstyringConfiguration = configurationProvider.Settings .Where(m => FinansstyringKonfigurationRepository.Keys.Contains(m.Key)) .ToDictionary(m => m.Key, m => m.Value); IFinansstyringKonfigurationRepository finansstyringKonfigurationRepository = new FinansstyringKonfigurationRepository(); finansstyringKonfigurationRepository.KonfigurationerAdd(finansstyringConfiguration); IEnumerable <INyhedModel> finansstyringsnyheder; try { IFinansstyringRepository finansstyringRepository = new FinansstyringRepository(finansstyringKonfigurationRepository); finansstyringsnyheder = await FinansstyringsnyhederGetAsync(finansstyringRepository); } catch (IntranetGuiOfflineRepositoryException) { ILocaleDataStorage localeDataStorage = new LocaleDataStorage(finansstyringKonfigurationRepository.LokalDataFil, finansstyringKonfigurationRepository.SynkroniseringDataFil, FinansstyringRepositoryLocale.XmlSchema); localeDataStorage.OnHasLocaleData += LocaleDataStorageHelper.HasLocaleDataEventHandler; localeDataStorage.OnCreateReaderStream += LocaleDataStorageHelper.CreateReaderStreamEventHandler; localeDataStorage.OnCreateWriterStream += LocaleDataStorageHelper.CreateWriterStreamEventHandler; IFinansstyringRepository finansstyringRepository = new FinansstyringRepositoryLocale(finansstyringKonfigurationRepository, localeDataStorage); Task <IEnumerable <INyhedModel> > finansstyringsnyhederGetTask = FinansstyringsnyhederGetAsync(finansstyringRepository); finansstyringsnyhederGetTask.Wait(); finansstyringsnyheder = finansstyringsnyhederGetTask.Result; } UpdateTile(finansstyringsnyheder); } catch (AggregateException aggregateException) { aggregateException.Handle(ex => { Logger.LogError(ex); return(true); }); } catch (Exception ex) { Logger.LogError(ex); } finally { lock (SyncRoot) { _isLoading = false; } deferral.Complete(); } }
/// <summary> /// Sarter baggrundstask, der kan synkronisere finansstyringsdata til og fra det lokale datalager. /// </summary> /// <param name="taskInstance">Instans af baggrundstasken.</param> public async void Run(IBackgroundTaskInstance taskInstance) { lock (SyncRoot) { if (_isSynchronizing) { return; } _isSynchronizing = true; _cancelRequested = false; } taskInstance.Canceled += CanceledEventHandler; BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); try { WindowsRuntimeResourceManager.PatchResourceManagers(); ConfigurationProvider configurationProvider = new ConfigurationProvider(); IDictionary <string, object> finansstyringConfiguration = configurationProvider.Settings .Where(m => FinansstyringKonfigurationRepository.Keys.Contains(m.Key)) .ToDictionary(m => m.Key, m => m.Value); IFinansstyringKonfigurationRepository finansstyringKonfigurationRepository = new FinansstyringKonfigurationRepository(); finansstyringKonfigurationRepository.KonfigurationerAdd(finansstyringConfiguration); IFinansstyringRepository finansstyringRepository = new FinansstyringRepository(finansstyringKonfigurationRepository); ILocaleDataStorage localeDataStorage = new LocaleDataStorage(finansstyringKonfigurationRepository.LokalDataFil, finansstyringKonfigurationRepository.SynkroniseringDataFil, FinansstyringRepositoryLocale.XmlSchema); localeDataStorage.OnHasLocaleData += LocaleDataStorageHelper.HasLocaleDataEventHandler; localeDataStorage.OnCreateReaderStream += LocaleDataStorageHelper.CreateReaderStreamEventHandler; localeDataStorage.OnCreateWriterStream += LocaleDataStorageHelper.CreateWriterStreamEventHandler; localeDataStorage.PrepareLocaleData += PrepareLocaleDataEventHandler; await SyncData(finansstyringRepository, finansstyringKonfigurationRepository, localeDataStorage); } catch (AggregateException aggregateException) { aggregateException.Handle(ex => { if (ex is IntranetGuiOfflineRepositoryException) { return(true); } Logger.LogError(ex); return(true); }); } catch (Exception ex) { Logger.LogError(ex); } finally { lock (SyncRoot) { _isSynchronizing = false; } deferral.Complete(); } }