예제 #1
0
        public async Task CheckLicenceFeaturepack()
        {
#if DEBUG
            _isFeaturepackLicensed = true;
            return;
#endif
            try {
                var listing = await CurrentApp.LoadListingInformationAsync();

                var featurepackLicence =
                    listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == FeaturepackProductKey);

                if (CurrentApp.LicenseInformation.ProductLicenses != null)
                {
                    _isFeaturepackLicensed =
                        CurrentApp.LicenseInformation.ProductLicenses[featurepackLicence.Key].IsActive;
                }
            }
            catch (Exception ex) {
                if (!ex.Message.Contains("0x805A0194"))
                {
                    InsightHelper.Report(ex);
                }
            }
        }
        private async Task GetBackupId()
        {
            await GetBackupFolder();

            try {
                var operationResultFolder = await _liveClient.GetAsync(_folderId + "/files");

                dynamic files = operationResultFolder.Result.Values;

                foreach (var data in files)
                {
                    foreach (var file in data)
                    {
                        if (file.name == BACKUP_NAME)
                        {
                            _backupId = file.id;
                            break;
                        }
                    }
                }
            }
            catch (LiveConnectException ex) {
                InsightHelper.Report(ex);
            }
        }
        /// <summary>
        ///     Uploads a copy of the current database to onedrive
        /// </summary>
        /// <returns>State if the task succeed successfully</returns>
        public async Task <TaskCompletionType> Upload()
        {
            if (_liveClient == null)
            {
                await Login();
            }

            await GetBackupFolder();

            if (string.IsNullOrEmpty(_folderId))
            {
                return(TaskCompletionType.Unsuccessful);
            }

            try {
                var localFolder = ApplicationData.Current.LocalFolder;
                var storageFile = await localFolder.GetFileAsync(DB_NAME);

                var uploadOperation = await _liveClient.CreateBackgroundUploadAsync(
                    _folderId, BACKUP_NAME, storageFile, OverwriteOption.Overwrite);

                var uploadResult = await uploadOperation.StartAsync();

                return(TaskCompletionType.Successful);
            }
            catch (TaskCanceledException ex) {
                InsightHelper.Report(ex);
                return(TaskCompletionType.Aborted);
            }
            catch (Exception ex) {
                InsightHelper.Report(ex);
                return(TaskCompletionType.Unsuccessful);
            }
        }
예제 #4
0
        private static void SaveTransaction(RecurringTransaction recurringTransaction)
        {
            try {
                DateTime date = DateTime.Now;

                if (recurringTransaction.Recurrence == (int)TransactionRecurrence.Monthly)
                {
                    date = DateTime.Now.AddDays(recurringTransaction.StartDate.Day - DateTime.Today.Day);
                }

                var newTransaction = new FinancialTransaction {
                    ChargedAccount         = recurringTransaction.ChargedAccount,
                    TargetAccount          = recurringTransaction.TargetAccount,
                    Date                   = date,
                    IsRecurring            = true,
                    Amount                 = recurringTransaction.Amount,
                    AmountWithoutExchange  = recurringTransaction.AmountWithoutExchange,
                    Currency               = recurringTransaction.Currency,
                    CategoryId             = recurringTransaction.CategoryId,
                    Type                   = recurringTransaction.Type,
                    ReccuringTransactionId = recurringTransaction.Id,
                    Note                   = recurringTransaction.Note
                };

                transactionRepository.Save(newTransaction);
            } catch (Exception ex) {
                InsightHelper.Report(ex);
            }
        }
        /// <summary>
        ///     Returns the Creationtime of an existing backup.
        /// </summary>
        /// <returns>Creationtime as DateTime</returns>
        public async Task <DateTime> GetLastCreationDate()
        {
            if (_liveClient == null)
            {
                await Login();
            }

            await GetBackupId();

            if (string.IsNullOrEmpty(_backupId))
            {
                return(DateTime.MinValue);
            }

            try {
                var operationResult =
                    await _liveClient.GetAsync(_backupId);

                dynamic  result    = operationResult.Result;
                DateTime createdAt = Convert.ToDateTime(result.created_time);
                return(createdAt);
            }
            catch (Exception ex) {
                InsightHelper.Report(ex);
                return(DateTime.MinValue);
            }
        }
        private async Task GetBackupFolder()
        {
            try {
                var operationResultFolder = await _liveClient.GetAsync("me/skydrive/");

                dynamic toplevelfolder = operationResultFolder.Result;

                operationResultFolder = await _liveClient.GetAsync(toplevelfolder.id + "/files");

                dynamic folders = operationResultFolder.Result.Values;

                foreach (var data in folders)
                {
                    foreach (var folder in data)
                    {
                        if (folder.name == BACKUP_FOLDER_NAME)
                        {
                            _folderId = folder.id;
                            break;
                        }
                    }
                }
            }
            catch (LiveConnectException ex) {
                InsightHelper.Report(ex);
            }
        }
예제 #7
0
 /// <summary>
 ///     Restore the database backup
 /// </summary>
 /// <returns></returns>
 public async Task RestoreBackup()
 {
     try {
         await _backupService.Restore();
     }
     catch (Exception ex) {
         InsightHelper.Report(ex);
         throw new BackupException(Translation.GetTranslation("RestoreFailedMessage"), ex);
     }
 }
예제 #8
0
 /// <summary>
 ///     Prompts a login screen to the user.
 /// </summary>
 /// <exception cref="ConnectionException">Is thrown if the user couldn't be logged in.</exception>
 public async void Login()
 {
     try {
         await _backupService.Login();
     }
     catch (Exception ex) {
         InsightHelper.Report(ex);
         throw new ConnectionException(Translation.GetTranslation("LoginFailedMessage"), ex);
     }
 }
예제 #9
0
 public async void Run(IBackgroundTaskInstance taskInstance)
 {
     try {
         new BackgroundTaskViewModelLocator();
         RecurringTransactionLogic.CheckRecurringTransactions();
         await TransactionLogic.ClearTransactions();
     }
     catch (Exception ex) {
         InsightHelper.Report(ex);
     }
 }
예제 #10
0
        public static async Task ClearTransactions()
        {
            IEnumerable <FinancialTransaction> transactions = TransactionRepository.GetUnclearedTransactions();

            foreach (FinancialTransaction transaction in transactions)
            {
                try {
                    await AccountLogic.AddTransactionAmount(transaction);
                }
                catch (Exception ex) {
                    InsightHelper.Report(ex);
                }
            }
        }
예제 #11
0
        private static async Task <double> GetAmount(double baseAmount, FinancialTransaction transaction, Account account)
        {
            try {
                if (transaction.Currency != account.Currency)
                {
                    double ratio = await CurrencyManager.GetCurrencyRatio(transaction.Currency, account.Currency);

                    return(baseAmount * ratio);
                }
            }
            catch (Exception ex) {
                InsightHelper.Report(ex);
            }
            return(baseAmount);
        }
예제 #12
0
        /// <summary>
        /// Return a JSON string from the instanced service
        /// </summary>
        /// <param name="url"></param>
        /// <returns>Recived JSON string.</returns>
        public async Task <string> GetJsonFromService(string url)
        {
            try {
                PrepareHttpClient();
                var req = new HttpRequestMessage(HttpMethod.Get, url);
                HttpResponseMessage response = await _httpClient.SendAsync(req);

                response.EnsureSuccessStatusCode();

                return(await response.Content.ReadAsStringAsync());
            } catch (Exception ex) {
                InsightHelper.Report(ex);
            }
            return(String.Empty);
        }
예제 #13
0
        public static void RemoveRecurringForTransactions(RecurringTransaction recTrans)
        {
            try {
                IEnumerable <FinancialTransaction> relatedTrans =
                    transactionRepository.Data.Where(x => x.IsRecurring && x.ReccuringTransactionId == recTrans.Id);

                foreach (FinancialTransaction transaction in relatedTrans)
                {
                    transaction.IsRecurring            = false;
                    transaction.ReccuringTransactionId = null;
                    transactionRepository.Save(transaction);
                }
            }
            catch (Exception ex) {
                InsightHelper.Report(ex);
            }
        }
예제 #14
0
        private double ParseToExchangeRate(string jsonString)
        {
            try {
                var typeExample =
                    new {
                    Conversion = new {
                        val = ""
                    }
                };

                var currency = JsonConvert.DeserializeAnonymousType(jsonString, typeExample);
                //use US culture info for parsing, since service uses us format
                return(Double.Parse(currency.Conversion.val, new CultureInfo("en-us")));
            }
            catch (Exception ex) {
                InsightHelper.Report(ex);
            }
            return(1);
        }
예제 #15
0
        public static async void RegisterBackgroundTask()
        {
            try {
                if (IsTaskExisting() || !await RequestAccess())
                {
                    return;
                }

                var builder = new BackgroundTaskBuilder();
                //Task soll alle 12 Stunden laufen
                var trigger = new TimeTrigger(720, false);

                builder.Name           = name;
                builder.TaskEntryPoint = typeof(TransactionTask).FullName;
                builder.SetTrigger(trigger);
                builder.Register();
            }
            catch (Exception ex) {
                InsightHelper.Report(ex);
            }
        }
        private async void ButtonBuyNow_Clicked(object sender, RoutedEventArgs e)
        {
            try {
                var btn = sender as Button;

                string key = btn.Tag.ToString();

                if (!CurrentApp.LicenseInformation.ProductLicenses[key].IsActive)
                {
                    ListingInformation products = await CurrentApp.LoadListingInformationAsync();

                    ProductListing productListing;
                    if (!products.ProductListings.TryGetValue(ServiceLocator.Current.GetInstance <LicenseManager>().FeaturepackProductKey, out productListing))
                    {
                        await ShowProductNotFoundDialog();

                        return;
                    }

                    await CurrentApp.RequestProductPurchaseAsync(productListing.ProductId);

                    RenderStoreItems();
                }
            }
            catch (Exception ex) {
                if (ex.Message.Contains("0x80004005"))
                {
                    var dialog = new MessageDialog(Translation.GetTranslation("PurchasedFailedMessage"),
                                                   Translation.GetTranslation("PurchasedFailedTitle"));
                    dialog.Commands.Add(new UICommand(Translation.GetTranslation("OkLabel")));
                    dialog.ShowAsync();
                }
                else
                {
                    InsightHelper.Report(ex);
                }
            }
        }
예제 #17
0
        private static void SetDefaultAccount()
        {
            try {
                if (AccountRepository.Data.Any())
                {
                    SelectedTransaction.ChargedAccount = AccountRepository.Data.First();
                }

                if (AccountRepository.Data.Any() && Settings.DefaultAccount != -1)
                {
                    SelectedTransaction.ChargedAccount =
                        AccountRepository.Data.First(x => x.Id == Settings.DefaultAccount);
                }

                if (AccountRepository.Selected != null)
                {
                    SelectedTransaction.ChargedAccount = AccountRepository.Selected;
                }
            }
            catch (Exception ex) {
                InsightHelper.Report(ex);
            }
        }
        /// <summary>
        ///     Restore a database backup from OneDrive
        /// </summary>
        /// <returns>TaskCompletionType wether the task was successful or not.</returns>
        public async Task <TaskCompletionType> Restore()
        {
            if (_liveClient == null)
            {
                await Login();
            }

            try {
                await GetBackupId();

                var localFolder = ApplicationData.Current.LocalFolder;
                var storageFile =
                    await localFolder.CreateFileAsync(DB_NAME, CreationCollisionOption.ReplaceExisting);

                await _liveClient.BackgroundDownloadAsync(_backupId + "/content", storageFile);

                return(TaskCompletionType.Successful);
            }
            catch (Exception ex) {
                InsightHelper.Report(ex);
                return(TaskCompletionType.Unsuccessful);
            }
        }
        private async void RenderStoreItems()
        {
            picItems.Clear();

            try {
                ListingInformation li = await CurrentApp.LoadListingInformationAsync();

                foreach (string key in li.ProductListings.Keys)
                {
                    ProductListing pListing = li.ProductListings[key];
                    string         status   = CurrentApp.LicenseInformation.ProductLicenses[key].IsActive
                        ? Translation.GetTranslation("PurchasedLabel")
                        : pListing.FormattedPrice;

                    picItems.Add(
                        new ProductItem {
                        ImgLink             = key.Equals("10001") ? "/Images/{0}/unlock.png" : "/Assets/Logo.scale-240.png",
                        Name                = pListing.Name,
                        Status              = status,
                        Key                 = key,
                        Description         = pListing.Description,
                        BuyNowButtonVisible =
                            CurrentApp.LicenseInformation.ProductLicenses[key].IsActive
                                    ? Visibility.Collapsed
                                    : Visibility.Visible
                    }
                        );
                }

                Plugin.ItemsSource = picItems;
            }
            catch (Exception ex) {
                ShowProductNotFoundDialog();
                InsightHelper.Report(ex);
            }
        }