Ejemplo n.º 1
0
        /// <summary>
        /// Synkroniserer finansstyringsdata til og fra det lokale datalager.
        /// </summary>
        /// <param name="finansstyringRepository">Implementering af finansstyringsrepositoryet, hvorfra data skal synkroniseres til og fra det lokale datalager.</param>
        /// <param name="finansstyringKonfigurationRepository">Implementering af konfiguration til finansstyringsrepositoryet.</param>
        /// <param name="localeDataStorage">Implementering af det lokale datalager.</param>
        /// <param name="syncDataDocument">XML dokument indeholdende de synkroniserede data.</param>
        /// <param name="regnskabModel">Model for regnskabet, hvor data skal synkroniseres til og fra.</param>
        /// <param name="makeFullSync">Angivelse af, om der skal foretages en fuld synkronisering.</param>
        private static async Task SyncData(IFinansstyringRepository finansstyringRepository, IFinansstyringKonfigurationRepository finansstyringKonfigurationRepository, ILocaleDataStorage localeDataStorage, XDocument syncDataDocument, IRegnskabModel regnskabModel, bool makeFullSync)
        {
            if (finansstyringRepository == null)
            {
                throw new ArgumentNullException(nameof(finansstyringRepository));
            }
            if (finansstyringKonfigurationRepository == null)
            {
                throw new ArgumentNullException(nameof(finansstyringKonfigurationRepository));
            }
            if (localeDataStorage == null)
            {
                throw new ArgumentNullException(nameof(localeDataStorage));
            }
            if (syncDataDocument == null)
            {
                throw new ArgumentNullException(nameof(syncDataDocument));
            }
            if (regnskabModel == null)
            {
                throw new ArgumentNullException(nameof(regnskabModel));
            }

            try
            {
                // Synkronisér regnskabsdata fra det online finansstyringsrepository til det lokale datalager.
                DateTime currentDate = DateTime.Now;
                foreach (IKontoModel kontoModel in await finansstyringRepository.KontoplanGetAsync(regnskabModel.Nummer, currentDate))
                {
                    lock (SyncRoot)
                    {
                        kontoModel.StoreInDocument(syncDataDocument);
                    }
                }
                foreach (IBudgetkontoModel budgetkontoModel in await finansstyringRepository.BudgetkontoplanGetAsync(regnskabModel.Nummer, currentDate))
                {
                    lock (SyncRoot)
                    {
                        budgetkontoModel.StoreInDocument(syncDataDocument);
                    }
                }
                if (makeFullSync)
                {
                    DateTime historicStatusDate = currentDate.AddMonths(-2);
                    while (historicStatusDate.Year >= currentDate.AddYears(-1).Year)
                    {
                        historicStatusDate = new DateTime(historicStatusDate.Year, historicStatusDate.Month, DateTime.DaysInMonth(historicStatusDate.Year, historicStatusDate.Month), 23, 59, 59);
                        foreach (IBudgetkontoModel budgetkontoModel in await finansstyringRepository.BudgetkontoplanGetAsync(regnskabModel.Nummer, historicStatusDate))
                        {
                            lock (SyncRoot)
                            {
                                budgetkontoModel.StoreInDocument(syncDataDocument);
                            }
                        }
                        historicStatusDate = historicStatusDate.AddMonths(-2);
                    }
                }
                foreach (IAdressekontoModel adressekontoModel in await finansstyringRepository.AdressekontolisteGetAsync(regnskabModel.Nummer, currentDate))
                {
                    lock (SyncRoot)
                    {
                        adressekontoModel.StoreInDocument(syncDataDocument);
                    }
                }
                foreach (IBogføringslinjeModel bogføringslinjeModel in await finansstyringRepository.BogføringslinjerGetAsync(regnskabModel.Nummer, currentDate, finansstyringKonfigurationRepository.AntalBogføringslinjer))
                {
                    lock (SyncRoot)
                    {
                        bogføringslinjeModel.StoreInDocument(syncDataDocument, true);
                    }
                }
                lock (SyncRoot)
                {
                    localeDataStorage.StoreSyncDocument(syncDataDocument);
                }
            }
            catch (IntranetGuiOfflineRepositoryException)
            {
                // We are currently offline.
                // Don't rethrow the exception.
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Synchronize the locale accounting data for a collection of <see cref="IRegnskabModel"/> to the online accounting repository.
        /// </summary>
        /// <param name="accountingRepository">The <see cref="IFinansstyringRepository"/> for the online accounting repository.</param>
        /// <param name="localeDataStorage">The <see cref="ILocaleDataStorage"/> for storing locale data.</param>>
        /// <param name="syncDataDocument">The <see cref="XDocument"/> containing the locale accounting data.</param>
        /// <param name="accountingCollection">The collection of <see cref="IRegnskabModel"/> on which to synchronize locale accounting data to the online repository.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="accountingRepository"/>, <paramref name="localeDataStorage"/> or <paramref name="accountingCollection"/> is null.</exception>
        private static async Task SyncLocaleData(IFinansstyringRepository accountingRepository, ILocaleDataStorage localeDataStorage, XDocument syncDataDocument, IEnumerable <IRegnskabModel> accountingCollection)
        {
            if (accountingRepository == null)
            {
                throw new ArgumentNullException(nameof(accountingRepository));
            }
            if (localeDataStorage == null)
            {
                throw new ArgumentNullException(nameof(localeDataStorage));
            }
            if (accountingCollection == null)
            {
                throw new ArgumentNullException(nameof(accountingCollection));
            }

            try
            {
                lock (SyncRoot)
                {
                    if (syncDataDocument == null)
                    {
                        return;
                    }
                }

                foreach (IRegnskabModel accountingModel in accountingCollection)
                {
                    await SyncLocaleData(accountingRepository, localeDataStorage, syncDataDocument, accountingModel);

                    if (_cancelRequested)
                    {
                        return;
                    }
                }
            }
            catch (IntranetGuiOfflineRepositoryException)
            {
                // We are currently offline.
                // Don't rethrow the exception.
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Synchronize the locale accounting data for a given <see cref="IRegnskabModel"/> to the online accounting repository.
        /// </summary>
        /// <param name="accountingRepository">The <see cref="IFinansstyringRepository"/> for the online accounting repository.</param>
        /// <param name="localeDataStorage">The <see cref="ILocaleDataStorage"/> for storing locale data.</param>>
        /// <param name="syncDataDocument">The <see cref="XDocument"/> containing the locale accounting data.</param>
        /// <param name="accountingModel">The given <see cref="IRegnskabModel"/> on which to synchronize locale accounting data to the online repository.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="accountingRepository"/>, <paramref name="localeDataStorage"/>, <paramref name="syncDataDocument"/> or <paramref name="accountingModel"/> is null.</exception>
        private static async Task SyncLocaleData(IFinansstyringRepository accountingRepository, ILocaleDataStorage localeDataStorage, XDocument syncDataDocument, IRegnskabModel accountingModel)
        {
            if (accountingRepository == null)
            {
                throw new ArgumentNullException(nameof(accountingRepository));
            }
            if (localeDataStorage == null)
            {
                throw new ArgumentNullException(nameof(localeDataStorage));
            }
            if (syncDataDocument == null)
            {
                throw new ArgumentNullException(nameof(syncDataDocument));
            }
            if (accountingModel == null)
            {
                throw new ArgumentNullException(nameof(accountingModel));
            }

            try
            {
                XElement rootElement       = syncDataDocument.Root;
                XElement accountingElement = rootElement?.Elements(XName.Get("Regnskab", rootElement.Name.NamespaceName)).SingleOrDefault(element => GetAttributeValue(element, "nummer") != null && string.Compare(GetAttributeValue(element, "nummer"), accountingModel.Nummer.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal) == 0);
                if (accountingElement == null)
                {
                    return;
                }

                XElement postingLineToSync;
                lock (SyncRoot)
                {
                    postingLineToSync = GetPostingLineToSync(rootElement, accountingElement);
                    if (postingLineToSync != null && _cancelRequested == false)
                    {
                        postingLineToSync.StorePendingPostingLineInDocument();
                        localeDataStorage.StoreSyncDocument(syncDataDocument);
                    }
                }
                while (postingLineToSync != null && _cancelRequested == false)
                {
                    DateTime postingDate          = DateTime.ParseExact(GetAttributeValue(postingLineToSync, "dato"), "yyyyMMdd", CultureInfo.InvariantCulture);
                    string   voucherNo            = GetAttributeValue(postingLineToSync, "bilag");
                    string   accountNumber        = GetAttributeValue(postingLineToSync, "kontonummer");
                    string   text                 = GetAttributeValue(postingLineToSync, "tekst");
                    string   budgetAccountNumber  = GetAttributeValue(postingLineToSync, "budgetkontonummer");
                    decimal  debit                = GetAttributeValue(postingLineToSync, "debit") == null ? 0M : decimal.Parse(GetAttributeValue(postingLineToSync, "debit"), NumberStyles.Any, CultureInfo.InvariantCulture);
                    decimal  credit               = GetAttributeValue(postingLineToSync, "kredit") == null ? 0M : decimal.Parse(GetAttributeValue(postingLineToSync, "kredit"), NumberStyles.Any, CultureInfo.InvariantCulture);
                    int      addressAccountNumber = GetAttributeValue(postingLineToSync, "adressekonto") == null ? 0 : int.Parse(GetAttributeValue(postingLineToSync, "adressekonto"), NumberStyles.Integer, CultureInfo.InvariantCulture);
                    await accountingRepository.BogførAsync(accountingModel.Nummer, postingDate, voucherNo, accountNumber, text, budgetAccountNumber, debit, credit, addressAccountNumber);

                    lock (SyncRoot)
                    {
                        postingLineToSync.Remove();
                        localeDataStorage.StoreSyncDocument(syncDataDocument);

                        postingLineToSync = GetPostingLineToSync(rootElement, accountingElement);
                        if (postingLineToSync != null && _cancelRequested == false)
                        {
                            postingLineToSync.StorePendingPostingLineInDocument();
                            localeDataStorage.StoreSyncDocument(syncDataDocument);
                        }
                    }
                }
            }
            catch (IntranetGuiOfflineRepositoryException)
            {
                // We are currently offline.
                // Don't rethrow the exception.
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Synkroniserer finansstyringsdata til og fra det lokale datalager.
        /// </summary>
        /// <param name="finansstyringRepository">Implementering af finansstyringsrepositoryet, hvorfra data skal synkroniseres til og fra det lokale datalager.</param>
        /// <param name="finansstyringKonfigurationRepository">Implementering af konfiguration til finansstyringsrepositoryet.</param>
        /// <param name="localeDataStorage">Implementering af det lokale datalager.</param>
        private static async Task SyncData(IFinansstyringRepository finansstyringRepository, IFinansstyringKonfigurationRepository finansstyringKonfigurationRepository, ILocaleDataStorage localeDataStorage)
        {
            if (finansstyringRepository == null)
            {
                throw new ArgumentNullException(nameof(finansstyringRepository));
            }
            if (finansstyringKonfigurationRepository == null)
            {
                throw new ArgumentNullException(nameof(finansstyringKonfigurationRepository));
            }
            if (localeDataStorage == null)
            {
                throw new ArgumentNullException(nameof(localeDataStorage));
            }

            try
            {
                XDocument syncDataDocument = null;

                IEnumerable <IKontogruppeModel> kontogruppeliste = await finansstyringRepository.KontogruppelisteGetAsync();

                foreach (IKontogruppeModel kontogruppe in kontogruppeliste)
                {
                    lock (SyncRoot)
                    {
                        if (syncDataDocument == null)
                        {
                            localeDataStorage.StoreSyncData(kontogruppe);
                            syncDataDocument = localeDataStorage.GetLocaleData();
                        }
                        else
                        {
                            kontogruppe.StoreInDocument(syncDataDocument);
                        }
                    }
                }

                IEnumerable <IBudgetkontogruppeModel> budgetkontogruppeliste = await finansstyringRepository.BudgetkontogruppelisteGetAsync();

                foreach (IBudgetkontogruppeModel budgetkontogruppe in budgetkontogruppeliste)
                {
                    lock (SyncRoot)
                    {
                        if (syncDataDocument == null)
                        {
                            localeDataStorage.StoreSyncData(budgetkontogruppe);
                            syncDataDocument = localeDataStorage.GetLocaleData();
                        }
                        else
                        {
                            budgetkontogruppe.StoreInDocument(syncDataDocument);
                        }
                    }
                }

                bool makeFullSync = true;
                lock (SyncRoot)
                {
                    if (syncDataDocument != null)
                    {
                        DateTime?lastFullSync = syncDataDocument.GetSidsteFuldeSynkronisering();
                        makeFullSync = lastFullSync.HasValue == false || lastFullSync.Value.Date < DateTime.Now.AddDays(-30).Date;
                    }
                }

                IRegnskabModel[] regnskabsliste = (await finansstyringRepository.RegnskabslisteGetAsync()).ToArray();
                await SyncLocaleData(finansstyringRepository, localeDataStorage, syncDataDocument, regnskabsliste);

                if (_cancelRequested)
                {
                    return;
                }

                IList <Task> regnskabSyncTasks = new List <Task>();
                foreach (IRegnskabModel regnskab in regnskabsliste)
                {
                    lock (SyncRoot)
                    {
                        if (syncDataDocument == null)
                        {
                            localeDataStorage.StoreSyncData(regnskab);
                            syncDataDocument = localeDataStorage.GetLocaleData();
                        }
                        else
                        {
                            regnskab.StoreInDocument(syncDataDocument);
                        }
                    }
                    regnskabSyncTasks.Add(SyncData(finansstyringRepository, finansstyringKonfigurationRepository, localeDataStorage, syncDataDocument, regnskab, makeFullSync));
                }
                Task.WaitAll(regnskabSyncTasks.ToArray());

                lock (SyncRoot)
                {
                    if (syncDataDocument == null)
                    {
                        return;
                    }
                    if (makeFullSync)
                    {
                        syncDataDocument.StoreSidsteFuldeSynkroniseringInDocument(DateTime.Now);
                    }
                    localeDataStorage.StoreSyncDocument(syncDataDocument);
                }
            }
            catch (IntranetGuiOfflineRepositoryException)
            {
                // We are currently offline.
                // Don't rethrow the exception.
            }
        }