コード例 #1
0
        private List <string> GetSecondaryPayments(int accountId)
        {
            var allPayments = new List <PaymentViewModel>();
            var allPayment  = new List <LiveTilesPaymentInfo>();

            allPayments.AddRange(crudService.ReadManyNoTracked <PaymentViewModel>()
                                 .Where(x => x.ChargedAccountId == accountId)
                                 .ToList());
            try
            {
                allPayments.AddRange(crudService.ReadManyNoTracked <PaymentViewModel>()
                                     .Where(x => x.TargetAccountId == accountId)
                                     .ToList());
            }
            catch (Exception e)
            {
                logger.Fatal(e);
            }

            foreach (PaymentViewModel item in allPayments)
            {
                if (item.IsRecurring)
                {
                    allPayment.AddRange(GetRecurrence(item));
                }
                else
                {
                    var tileInfo = new LiveTilesPaymentInfo
                    {
                        Chargeaccountname = item.ChargedAccount.Name,
                        Amount            = item.Amount,
                        Date = item.Date.Date,
                        Type = item.Type
                    };
                    allPayment.Add(tileInfo);
                }
            }

            List <LiveTilesPaymentInfo> payments = allPayment.OrderByDescending(x => x.Date.Date)
                                                   .ThenBy(x => x.Date.Date <= DateTime.Today.Date)
                                                   .Take(NUMBER_OF_PAYMENTS)
                                                   .ToList();

            List <string> returnList = payments.Select(x => LiveTileHelper.GetTileText(TileSizeOption.Large, x)).ToList();

            for (int i = returnList.Count; i < NUMBER_OF_PAYMENTS - 1; i++)
            {
                returnList.Add(string.Empty);
            }

            return(returnList);
        }
コード例 #2
0
ファイル: LiveTileManager.cs プロジェクト: SethWyma/MoneyFox
        private DateTime CreateLiveTileInfos(PaymentViewModel payment, List <LiveTilesPaymentInfo> allPayment,
                                             DateTime startDate)
        {
            var liveTilesPaymentInfo = new LiveTilesPaymentInfo {
                Date              = startDate,
                Amount            = payment.RecurringPayment?.Amount ?? payment.Amount,
                Chargeaccountname = payment.RecurringPayment == null
                    ? payment.ChargedAccount.Name
                    : payment.RecurringPayment?.ChargedAccount.Name,
                Type = payment.RecurringPayment?.Type ?? payment.Type
            };

            allPayment.Add(liveTilesPaymentInfo);
            return(LiveTileHelper.AddDateByRecurrence(payment, startDate));
        }
コード例 #3
0
        public async Task UpdatePrimaryLiveTile()
        {
            if (await LiveTileHelper.IsPinned())
            {
                var b       = localsettings.Values["lastrun"];
                var lastRun = (string)b;

                List <string> displayLargeContent;
                List <string> displayContentMedium;
                string        headerText = "";
                if (lastRun == "last")
                {
                    localsettings.Values["lastrun"] = "next";
                    headerText           = Strings.LiveTileUpcommingPayments;
                    displayContentMedium = await GetPaymentsAsync(TileSizeOption.Medium, PaymentInformation.Next)
                    ;

                    displayLargeContent = await GetPaymentsAsync(TileSizeOption.Large, PaymentInformation.Next)
                    ;
                }
                else
                {
                    localsettings.Values["lastrun"] = "last";
                    headerText           = Strings.LiveTilePastPayments;
                    displayContentMedium = await GetPaymentsAsync(TileSizeOption.Medium, PaymentInformation.Previous)
                    ;

                    displayLargeContent = await GetPaymentsAsync(TileSizeOption.Large, PaymentInformation.Previous)
                    ;
                }

                var content = new TileContent
                {
                    Visual = new TileVisual
                    {
                        TileMedium = GetTileBinding(headerText, displayContentMedium),
                        TileWide   = GetTileBinding(headerText, displayLargeContent),
                        TileLarge  = GetTileBinding(headerText, displayLargeContent)
                    }
                };

                var tn = new TileNotification(content.GetXml());
                TileUpdateManager.CreateTileUpdaterForApplication().Update(tn);
            }
        }
コード例 #4
0
ファイル: LiveTileManager.cs プロジェクト: SethWyma/MoneyFox
        public async Task UpdatePrimaryLiveTile()
        {
            if (await LiveTileHelper.IsPinned().ConfigureAwait(false))
            {
                object        b                    = localsettings.Values["lastrun"];
                string        lastrun              = (string)b;
                string        headertext           = "";
                List <string> displaycontentmedium = new List <string>();
                List <string> displaycontentlarge  = new List <string>();

                if (lastrun == "last")
                {
                    localsettings.Values["lastrun"] = "next";
                    headertext           = Strings.LiveTileUpcommingPayments;
                    displaycontentmedium = await GetPaymentsAsync(TileSizeOptions.Medium, PaymentInformation.Next).ConfigureAwait(false);

                    displaycontentlarge = await GetPaymentsAsync(TileSizeOptions.Large, PaymentInformation.Next).ConfigureAwait(false);
                }
                else
                {
                    localsettings.Values["lastrun"] = "last";
                    headertext           = Strings.LiveTilePastPayments;
                    displaycontentmedium = await GetPaymentsAsync(TileSizeOptions.Medium, PaymentInformation.Previous).ConfigureAwait(false);

                    displaycontentlarge = await GetPaymentsAsync(TileSizeOptions.Large, PaymentInformation.Previous).ConfigureAwait(false);
                }

                TileContent content = new TileContent {
                    Visual = new TileVisual {
                        TileMedium = GetTileBinding(headertext, displaycontentmedium),
                        TileWide   = GetTileBinding(headertext, displaycontentlarge),
                        TileLarge  = GetTileBinding(headertext, displaycontentlarge)
                    }
                };

                TileNotification tn = new TileNotification(content.GetXml());
                TileUpdateManager.CreateTileUpdaterForApplication().Update(tn);
            }
        }
コード例 #5
0
        public async Task UpdateSecondaryLiveTiles()
        {
            IReadOnlyList <SecondaryTile> tiles = await SecondaryTile.FindAllForPackageAsync();

            if (tiles == null)
            {
                return;
            }

            foreach (SecondaryTile item in tiles)
            {
                AccountViewModel acct = await crudService.ReadSingleAsync <AccountViewModel>(int.Parse(item.TileId));

                List <string> displayContent = GetSecondaryPayments(int.Parse(item.TileId));
                var           content        = new TileContent
                {
                    Visual = new TileVisual
                    {
                        TileSmall = new TileBinding
                        {
                            Content = new TileBindingContentAdaptive
                            {
                                Children =
                                {
                                    new AdaptiveGroup
                                    {
                                        Children =
                                        {
                                            new AdaptiveSubgroup
                                            {
                                                Children =
                                                {
                                                    new AdaptiveText
                                                    {
                                                        Text      = acct.Name,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = LiveTileHelper.TruncateNumber(acct.CurrentBalance),
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        TileMedium = new TileBinding
                        {
                            Content = new TileBindingContentAdaptive
                            {
                                Children =
                                {
                                    new AdaptiveGroup
                                    {
                                        Children =
                                        {
                                            new AdaptiveSubgroup
                                            {
                                                Children =
                                                {
                                                    new AdaptiveText
                                                    {
                                                        Text      = acct.Name,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileAccountBalance,
                                                                             acct.CurrentBalance.ToString("C2",
                                                                                                          CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = Strings.ExpenseLabel,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileLastMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.AddMonths(-1).Month),
                                                                             LiveTileHelper.TruncateNumber(
                                                                                 GetMonthExpenses(
                                                                                     DateTime.Now.AddMonths(-1).Month, DateTime.Now.Year,
                                                                                     acct))),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileCurrentMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.Month),
                                                                             LiveTileHelper.TruncateNumber(
                                                                                 GetMonthExpenses(
                                                                                     DateTime.Now.Month, DateTime.Now.Year, acct))),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        TileWide = new TileBinding
                        {
                            Content = new TileBindingContentAdaptive
                            {
                                Children =
                                {
                                    new AdaptiveGroup
                                    {
                                        Children =
                                        {
                                            new AdaptiveSubgroup
                                            {
                                                Children =
                                                {
                                                    new AdaptiveText
                                                    {
                                                        Text      = acct.Name,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileAccountBalance,
                                                                             acct.CurrentBalance.ToString("C2",
                                                                                                          CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = Strings.ExpenseLabel,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileLastMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.AddMonths(-1).Month),
                                                                             GetMonthExpenses(
                                                                                 DateTime.Now.AddMonths(-1).Month, DateTime.Now.Year,
                                                                                 acct).ToString("C2", CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileCurrentMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.Month),
                                                                             GetMonthExpenses(
                                                                                 DateTime.Now.Month, DateTime.Now.Year, acct)
                                                                             .ToString("C2", CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        },
                        TileLarge = new TileBinding
                        {
                            Content = new TileBindingContentAdaptive
                            {
                                Children =
                                {
                                    new AdaptiveGroup
                                    {
                                        Children =
                                        {
                                            new AdaptiveSubgroup
                                            {
                                                Children =
                                                {
                                                    new AdaptiveText
                                                    {
                                                        Text      = acct.Name,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileAccountBalance,
                                                                             acct.CurrentBalance.ToString("C2",
                                                                                                          CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = Strings.ExpenseLabel,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileLastMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.AddMonths(-1).Month),
                                                                             GetMonthExpenses(
                                                                                 DateTime.Now.AddMonths(-1).Month, DateTime.Now.Year,
                                                                                 acct).ToString("C2", CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text = string.Format(CultureInfo.InvariantCulture,
                                                                             Strings.LiveTileCurrentMonthsExpenses,
                                                                             DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(
                                                                                 DateTime.Now.Month),
                                                                             GetMonthExpenses(
                                                                                 DateTime.Now.Month, DateTime.Now.Year, acct)
                                                                             .ToString("C2", CultureInfo.InvariantCulture)),
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = Strings.LiveTilePastPayments,
                                                        HintStyle = AdaptiveTextStyle.Caption
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[0],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[1],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[2],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[3],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[4],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    },
                                                    new AdaptiveText
                                                    {
                                                        Text      = displayContent[5],
                                                        HintStyle = AdaptiveTextStyle.CaptionSubtle
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                };

                var tn = new TileNotification(content.GetXml());
                TileUpdateManager.CreateTileUpdaterForSecondaryTile(item.TileId).Update(tn);
            }
        }
コード例 #6
0
        private async Task <List <string> > GetPaymentsAsync(TileSizeOption tileSize,
                                                             PaymentInformation paymentInformation)
        {
            List <AccountViewModel> acct = await crudService.ReadManyNoTracked <AccountViewModel>()
                                           .ToListAsync();

            var allPayments = new List <PaymentViewModel>();
            var allPayment  = new List <LiveTilesPaymentInfo>();

            foreach (AccountViewModel item in acct)
            {
                allPayments.AddRange(crudService.ReadManyNoTracked <PaymentViewModel>()
                                     .Where(x => x.ChargedAccountId == item.Id)
                                     .ToList());

                // We have to catch here, since otherwise an Exception is thrown when no payments are there.
                try
                {
                    allPayments.AddRange(crudService.ReadManyNoTracked <PaymentViewModel>()
                                         .Where(x => x.TargetAccountId == item.Id)
                                         .ToList());
                }
                catch (Exception e)
                {
                    logger.Fatal(e);
                }
            }

            foreach (PaymentViewModel item in allPayments)
            {
                if (item.IsRecurring)
                {
                    allPayment.AddRange(GetRecurrence(item));
                }
                else
                {
                    var tileInfo = new LiveTilesPaymentInfo
                    {
                        Chargeaccountname = item.ChargedAccount.Name,
                        Amount            = item.Amount,
                        Date = item.Date.Date,
                        Type = item.Type
                    };
                    allPayment.Add(tileInfo);
                }
            }

            List <LiveTilesPaymentInfo> payments;

            if (paymentInformation == PaymentInformation.Previous)
            {
                payments = allPayment.OrderByDescending(x => x.Date.Date)
                           .ThenBy(x => x.Date.Date <= DateTime.Today.Date)
                           .Take(NUMBER_OF_PAYMENTS)
                           .ToList();
            }
            else
            {
                payments = allPayment.OrderBy(x => x.Date.Date)
                           .ThenBy(x => x.Date.Date >= DateTime.Today.Date)
                           .Take(NUMBER_OF_PAYMENTS)
                           .ToList();
            }

            List <string> returnList = payments.Select(x => LiveTileHelper.GetTileText(tileSize, x)).ToList();

            for (int i = returnList.Count; i < NUMBER_OF_PAYMENTS - 1; i++)
            {
                returnList.Add(string.Empty);
            }

            allPayments.Clear();
            return(returnList);
        }
コード例 #7
0
ファイル: LiveTileManager.cs プロジェクト: SethWyma/MoneyFox
        private async Task <List <string> > GetPaymentsAsync(TileSizeOptions tileSize,
                                                             PaymentInformation paymentInformation)
        {
            List <AccountViewModel> acct = await crudService.ReadManyNoTracked <AccountViewModel>()
                                           .ToListAsync()
                                           .ConfigureAwait(false);

            List <PaymentViewModel>     allpayments = new List <PaymentViewModel>();
            List <LiveTilesPaymentInfo> allpayment  = new List <LiveTilesPaymentInfo>();

            foreach (AccountViewModel item in acct)
            {
                allpayments.AddRange(crudService.ReadManyNoTracked <PaymentViewModel>()
                                     .Where(x => x.ChargedAccountId == item.Id)
                                     .ToList());

                allpayments.AddRange(crudService.ReadManyNoTracked <PaymentViewModel>()
                                     .Where(x => x.TargetAccountId == item.Id)
                                     .ToList());
            }

            foreach (PaymentViewModel item in allpayments)
            {
                if (item.IsRecurring)
                {
                    allpayment.AddRange(GetRecurrence(item));
                }
                else
                {
                    var tileinfo = new LiveTilesPaymentInfo();
                    tileinfo.Chargeaccountname = item.ChargedAccount.Name;
                    tileinfo.Amount            = item.Amount;
                    tileinfo.Date = item.Date.Date;
                    tileinfo.Type = item.Type;
                    allpayment.Add(tileinfo);
                }
            }

            List <LiveTilesPaymentInfo> payments;

            if (paymentInformation == PaymentInformation.Previous)
            {
                payments = allpayment.OrderByDescending(x => x.Date.Date)
                           .ThenBy(x => x.Date.Date <= DateTime.Today.Date)
                           .Take(NUMBER_OF_PAYMENTS)
                           .ToList();
            }
            else
            {
                payments = allpayment.OrderBy(x => x.Date.Date)
                           .ThenBy(x => x.Date.Date >= DateTime.Today.Date)
                           .Take(NUMBER_OF_PAYMENTS)
                           .ToList();
            }

            List <string> returnList = payments.Select(x => LiveTileHelper.GetTileText(tileSize, x)).ToList();

            for (int i = returnList.Count; i < NUMBER_OF_PAYMENTS - 1; i++)
            {
                returnList.Add(string.Empty);
            }

            allpayments.Clear();
            return(returnList);
        }