Ejemplo n.º 1
0
        public void Run(string budgetId, string userId, string file)
        {
            var excel = new ExcelQueryFactory(file);
            var anni = new[] { 2011, 2012, 2013, 2014 };
            var movements = new List<Movimento>();

            DateTime ld;
            int count = 0;
            //"B3","F22",
            //foreach (var asd in excel.WorksheetRange<Movimento>("B3", "F300", 2020 + ""))
            //foreach (var asd in excel.Worksheet<Movimento>(2020 + ""))
            //{
            //    count++;
            //    if (asd.Data != DateTime.MinValue)
            //        ld = asd.Data;
            //}

            foreach (var anno in anni)
            {
                //movements.AddRange(excel.WorksheetRange<Movimento>("B3", "E300", anno + "").Where(r => r.Data != DateTime.MinValue));
                movements.AddRange(excel.Worksheet<Movimento>(anno + "").Where(r => r.Data != DateTime.MinValue));
            }
            movements = movements.OrderBy(d => d.Data).ToList();

            var stats = movements.GroupBy(g => g.Data.Year).ToList();
            var zero = movements.Where(m => m.Spesa == decimal.Zero).ToList();

            Console.WriteLine("Read {0} movements from {1}", movements.Count, file);

            var importer = new ImportManager(_cm, _pm);
            var categorie = movements.Select(s => s.Categoria).Where(r => r != "Arancio").ToArray();

            importer.ImportCategoriesByName(categorie, budgetId, userId);

            var categories = _pm.GetCategories().GetBudgetsCategories(budgetId);

            var createLine = _cm.Create<CreateLine>();
            DateTime last = DateTime.MinValue;
            foreach (var m in movements)
            {
                last = DateTime.Now;
                createLine(m.ToCreateLine(last, new BudgetId(budgetId), userId, categories));
            }
            var bp = _pm.GetBudgetLinesProjection(budgetId);
            var galt = bp.GetAllLines(last);
            galt.Wait();
            var lines = galt.Result;

            Console.WriteLine("Loaded {0} movements into {1}", lines.Count(), budgetId);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("it-IT");
            var endpoint = new IPEndPoint(IPAddress.Loopback, 1113);
            var esCon = EventStoreConnection.Create(endpoint);
            esCon.Connect();

            var credentials = new EventStore.ClientAPI.SystemData.UserCredentials("admin", "changeit");

            var cm = new CommandManager(esCon);
            var pm = new MyBudget.Projections.ProjectionManager(endpoint, credentials, new MyBudget.Infrastructure.EventStoreAdapter(endpoint, credentials));
            pm.Run();

            var tu = pm.GetUsersList().AllUsers();
            tu.Wait();
            userId = tu.Result.Select(s => s.Id).FirstOrDefault();
            budgetId = pm.GetBudgetsList().GetBudgetsUserCanView(new MyBudget.Domain.Users.UserId(userId)).Select(s => s.Id).FirstOrDefault();

            using (var con = new System.Data.SqlClient.SqlConnection(_cs))
            {
                con.Open();
                var movements = LoadMovements(con);

                foreach (var anno in movements.GroupBy(g=> g.DateTime.Year))
                {
                    
                    var str = ServiceStack.Text.CsvSerializer.SerializeToCsv(anno.OrderBy(d=> d.DateTime));
                    System.IO.File.WriteAllText(@"c:\temp\Year_"+anno.Key + ".csv", str);
                }
                var importer = new ImportManager(cm, pm);
                importer.ImportCategoriesByName(movements.Select(s => s.Category), budgetId, userId);

                var categories = pm.GetCategories().GetBudgetsCategories(budgetId);

                var handler = cm.Create<CreateLine>();
                foreach (var m in movements)
                    handler(m.ToCreateLine(new BudgetId(budgetId), userId, categories));
            }
        }
Ejemplo n.º 3
0
        public void Run(string budgetId, string userId, string file)
        {
            var excel = new ExcelQueryFactory(file);
            var anni = new[] { 2013, 2014 };
            var movements = new List<Movimento>();
            foreach (var anno in anni)
            {
                //movements.AddRange(excel.Worksheet<Movement>(anno + "")
                //    .Where(r => r.Data != DateTime.MinValue));

                var laura = excel.WorksheetRange<Movimento>("B6", "E10000", anno + "")
                     .Where(r => r.Data != DateTime.MinValue)
                     .ToList();
                laura.ForEach(m => m.DistributionKey = "Laura");

                var valerio = excel.WorksheetRange<Movimento>("G6", "J10000", anno + "")
                     .Where(r => r.Data != DateTime.MinValue)
                     .ToList();
                valerio.ForEach(m => m.DistributionKey = "Valerio");

                var comune = excel.WorksheetRange<Movimento>("L6", "O10000", anno + "")
                     .Where(r => r.Data != DateTime.MinValue)
                     .ToList();


                movements.AddRange(laura);
                movements.AddRange(valerio);
                movements.AddRange(comune);
            }

            //var tasse = movements.GroupBy(g => g.Categoria).ToList();

            Console.WriteLine("Read {0} movements from {1}", movements.Count, file);
            movements = movements.Where(r => r.Categoria != "Arancio").OrderBy(d => d.Data).ToList();

            
            var importer = new ImportManager(_cm, _pm);
            var categorie = movements.Select(s => s.Categoria).ToArray();
            importer.ImportCategoriesByName(categorie, budgetId, userId);

            var categories = _pm.GetCategories().GetBudgetsCategories(budgetId);

            var createLine = _cm.Create<CreateLine>();
            //foreach (var m in movements.Where(r=> r.Categoria != "Arancio"))
            //    createLine(m.ToCreateLine(new BudgetId(budgetId), userId, categories));

            DateTime last = DateTime.MinValue;
            foreach (var m in movements)
            {
                last = DateTime.Now;
                createLine(m.ToCreateLine(last, new BudgetId(budgetId), userId, categories));
            }


            var bp = _pm.GetBudgetLinesProjection(budgetId);
            var galt = bp.GetAllLines(last);
            galt.Wait();
            var lines = galt.Result;

            Console.WriteLine("Loaded {0} movements into {1}", lines.Count(), budgetId);
        }