예제 #1
0
        private static void WriteData(ApplicationDbContext db, bool removeCycles, Person[] people)
        {
            const string outDir = @"C:\Users\AustinWise\Dropbox\DKP";

            List <Debt> netMoney = null;

            using (Stream fs = removeCycles ? new FileStream(Path.Combine(outDir, "Info.txt"), FileMode.Create, FileAccess.Write) : Stream.Null)
            {
                using (var infoOutput = new StreamWriter(fs))
                {
                    netMoney = DebtGraph.CalculateDebts(db, people, removeCycles, infoOutput ?? Console.Out);
                }
            }
            Console.WriteLine("{0:c}", netMoney.Sum(m => m.Amount) / 100d);

            const string gvPath = @"c:\temp\graph\test.gv";

            using (var fs = new FileStream(gvPath, FileMode.Create, FileAccess.Write))
            {
                using (var sw = new StreamWriter(fs))
                {
                    DebtGraph.WriteGraph(netMoney, sw);
                }
            }

            DebtGraph.RenderGraphAsPng(gvPath, Path.Combine(outDir, removeCycles ? "current.png" : "nocycles.png"));
            if (removeCycles)
            {
                DebtGraph.RenderGraphAsPng(gvPath, Path.Combine(outDir, DateTime.Now.ToString("yyyy-MM-dd") + ".png"));
            }
        }
예제 #2
0
        public async Task Send(int creditorId)
        {
            bool actuallySend = false;

            Console.Write("Type 'true' to actually send emails: ");
            bool.TryParse(Console.ReadLine(), out actuallySend);

            var person = mDb.Person
                         .Where(p => p.Id == creditorId)
                         .Include(p => p.PaymentIdentity).ThenInclude(p => p.PaymentMeth)
                         .Single();

            var transactions = mDb.Transaction
                               .Where(t => t.CreditorId != t.DebtorId &&
                                      (t.CreditorId == person.Id || t.DebtorId == person.Id) &&
                                      (!t.Creditor.IsDeleted && !t.Debtor.IsDeleted));

            foreach (var dontUse in PEOPLE_TO_EXCLUDE)
            {
                var p = dontUse;
                transactions = transactions.Where(t => t.DebtorId != p && t.CreditorId != p);
            }

            var netMoney = DebtGraph.CalculateDebts(mDb, transactions, true, TextWriter.Null);

            var swGraph = new StringWriter();

            DebtGraph.WriteGraph(netMoney, swGraph);
            var bytes = DebtGraph.RenderGraphAsPng(swGraph.ToString());

            var debtors = DebtGraph.GreatestDebtor(netMoney);
            var myDebt  = debtors.Where(d => d.Item1.Id == person.Id).SingleOrDefault();

            if (myDebt != null)
            {
                debtors.Remove(myDebt);
            }

            debtors = debtors.Where(tup => tup.Item2 > 1000 && !string.IsNullOrEmpty(tup.Item1.Email)).ToList();

            int sentSoFar = 0;

            foreach (var tup in debtors)
            {
                var fields = ProcessOnePerson(person, tup.Item1, tup.Item2);

                if (actuallySend)
                {
                    await mEmail.SendHtmlEmailAsync(tup.Item1.FullName, tup.Item1.Email, "DKP Invoice", fields.BODY);
                }
                Console.WriteLine(actuallySend ? "Sent {0,2}/{1,2} ({2} {3})" : "Would send: {2} {3}", ++sentSoFar, debtors.Count, tup.Item1.FirstName, tup.Item1.LastName);
            }

            Console.WriteLine();
            Console.WriteLine("Done! Press enter to exit.");
            Console.ReadLine();
        }