Example #1
0
        public override void SeedContext(RioValleyChiliDataContext newContext)
        {
            new ProductsDbContextDataSeeder().SeedContext(newContext);

            var consoleTicker = new ConsoleTicker();

            using (var oldContext = ContextsHelper.GetOldContext())
            {
                var proxyCreation            = newContext.Configuration.ProxyCreationEnabled;
                var autoDetectChangesEnabled = newContext.Configuration.AutoDetectChangesEnabled;
                var lazyLoading = newContext.Configuration.LazyLoadingEnabled;

                try
                {
                    newContext.Configuration.ProxyCreationEnabled     = false;
                    newContext.Configuration.AutoDetectChangesEnabled = false;
                    newContext.Configuration.LazyLoadingEnabled       = false;

                    oldContext.CommandTimeout = 1800;

                    LoadLots(newContext, oldContext, consoleTicker);
                    LoadLotAttributeHistory(newContext, oldContext, consoleTicker);
                    LoadInventory(newContext, oldContext, consoleTicker);
                    LoadInventoryAdjustments(newContext, oldContext, consoleTicker);
                }
                finally
                {
                    newContext.Configuration.ProxyCreationEnabled     = proxyCreation;
                    newContext.Configuration.AutoDetectChangesEnabled = autoDetectChangesEnabled;
                    newContext.Configuration.LazyLoadingEnabled       = lazyLoading;
                }
            }
        }
Example #2
0
        public override void SeedContext(RioValleyChiliDataContext newContext)
        {
            new OrderDbContextDataSeeder().SeedContext(newContext);
            var consoleTicker = new ConsoleTicker();

            using (var oldContext = ContextsHelper.GetOldContext())
            {
                var proxyCreation            = newContext.Configuration.ProxyCreationEnabled;
                var autoDetectChangesEnabled = newContext.Configuration.AutoDetectChangesEnabled;
                var lazyLoading = newContext.Configuration.LazyLoadingEnabled;

                try
                {
                    newContext.Configuration.ProxyCreationEnabled     = false;
                    newContext.Configuration.AutoDetectChangesEnabled = true;
                    newContext.Configuration.LazyLoadingEnabled       = false;

                    oldContext.CommandTimeout = 1200;

                    LoadInventoryTransactions(oldContext, newContext, consoleTicker);
                }
                finally
                {
                    newContext.Configuration.ProxyCreationEnabled     = proxyCreation;
                    newContext.Configuration.AutoDetectChangesEnabled = autoDetectChangesEnabled;
                    newContext.Configuration.LazyLoadingEnabled       = lazyLoading;
                }
            }
        }
Example #3
0
        public override void SeedContext(RioValleyChiliDataContext newContext)
        {
            new CompanyDbContactDataSeeder().SeedContext(newContext);

            var consoleTicker = new ConsoleTicker();

            using (var oldContext = ContextsHelper.GetOldContext())
            {
                var proxyCreation    = newContext.Configuration.ProxyCreationEnabled;
                var autoDetecChanges = newContext.Configuration.AutoDetectChangesEnabled;
                var lazyLoading      = newContext.Configuration.LazyLoadingEnabled;

                try
                {
                    newContext.Configuration.ProxyCreationEnabled     = false;
                    newContext.Configuration.AutoDetectChangesEnabled = false;
                    newContext.Configuration.LazyLoadingEnabled       = false;

                    Console.WriteLine("Loading Products");

                    var chileProducts = LoadProducts(newContext, new ChileProductEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.ChileProductLoadLoggerCallback), consoleTicker, "\tChile Products", c => c.Product);
                    LoadRecords(newContext, chileProducts.SelectMany(c => c.ProductAttributeRanges), "\t\tproduct attribute ranges", consoleTicker);
                    LoadRecords(newContext, new ChileProductIngredientsMother(oldContext, newContext, RVCDataLoadLoggerGate.ChileProductIngredientsLoadLoggerCallback), "\t\tingredients", consoleTicker);

                    LoadProducts(newContext, new PackagingProductEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.PackagingProductLoadLoggerCallback), consoleTicker, "\tPackaging Products", p => p.Product);
                    LoadProducts(newContext, new AdditiveProductEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.AdditiveProductLoadLoggerCallback), consoleTicker, "\tAdditive Products", a => a.Product);

                    LoadProducts(newContext, new NonInventoryProductEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.NonInventoryProductLoadLoggerCallback), consoleTicker, "\tNon-Inventory Products");

                    StartWatch();
                    var specs = new List <CustomerProductAttributeRange>();
                    ProcessedBirth(new CustomerProductSpecMother(oldContext, newContext, RVCDataLoadLoggerGate.CustomerSpecsLoadLoggerCallback), "Loading Customer Product Specs", consoleTicker, specs.Add);
                    consoleTicker.ReplaceCurrentLine("Loading Customer Product Specs");
                    LoadRecords(newContext, specs, "\tcustomer product attribute ranges", consoleTicker);
                    consoleTicker.WriteTimeElapsed(StopWatch());

                    StartWatch();
                    var codes = new List <CustomerProductCode>();
                    ProcessedBirth(new CustomerProductCodeMother(oldContext, newContext, RVCDataLoadLoggerGate.CustomerProductCodeLoadLoggerCallback), "Loading Customer Product Codes", consoleTicker, codes.Add);
                    consoleTicker.ReplaceCurrentLine("Loading Customer Product Codes");
                    LoadRecords(newContext, codes, "\tcustomer product codes", consoleTicker);
                    consoleTicker.WriteTimeElapsed(StopWatch());

                    oldContext.ClearContext();
                }
                finally
                {
                    newContext.Configuration.ProxyCreationEnabled     = proxyCreation;
                    newContext.Configuration.AutoDetectChangesEnabled = autoDetecChanges;
                    newContext.Configuration.LazyLoadingEnabled       = lazyLoading;
                }
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            Environment.ExitCode = -1;

            try
            {
                using (var newContext = ContextsHelper.GetNewContext())
                {
                    if (args != null && args.Length > 0 && args[0].Length == 1)
                    {
                        ExecuteSilently(newContext, args);
                    }
                    else
                    {
                        ExecuteNormal(newContext, args);
                    }
                }

                Environment.ExitCode = 0;
            }
            catch (Exception ex)
            {
                if (RVCDataLoadLoggerGate.RVCDataLoadLogger != null)
                {
                    RVCDataLoadLoggerGate.RVCDataLoadLogger.WriteException(ex);
                }

                Console.Write("\n");
                Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                Console.WriteLine("The program encountered an exception. \n\nError message: \n{0}", ex.Message);

                var innermostException = FindInnermostException(ex);
                if (innermostException != null)
                {
                    Console.WriteLine("Innermost exception message:\n{0}", innermostException.Message);
                }

                Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                Console.Write("\n");
                Console.Write("\n");

                new RVCDataLoadResultObtainer().SetDataLoadResult(new RVCDataLoadResultObtainer.LoadResult
                {
                    Success         = DataLoadResult.Success = false,
                    RanToCompletion = false,
                    TimeStamp       = DateTime.Now
                });

                Console.Read();
            }
        }
Example #5
0
        public override void SeedContext(RioValleyChiliDataContext newContext)
        {
            var consoleTicker = new ConsoleTicker();

            using (var oldContext = ContextsHelper.GetOldContext())
            {
                InitializeOldContext();

                var proxyCreation    = newContext.Configuration.ProxyCreationEnabled;
                var autoDetecChanges = newContext.Configuration.AutoDetectChangesEnabled;
                var lazyLoading      = newContext.Configuration.LazyLoadingEnabled;

                try
                {
                    newContext.Configuration.ProxyCreationEnabled     = false;
                    newContext.Configuration.AutoDetectChangesEnabled = false;
                    newContext.Configuration.LazyLoadingEnabled       = false;

                    CreateOldContextRecords(oldContext);

                    LoadRecords(newContext, new EmployeeObjectMother(oldContext, RVCDataLoadLoggerGate.EmployeeLoadLoggerCallback), "Loading Employees", consoleTicker);
                    LoadRecords(newContext, new NotebookMother(RVCDataLoadLoggerGate.LogSummaryEntry("Notebooks")), "Loading Notebooks", consoleTicker);
                    LoadRecords(newContext, new ChileTypeMother(), "Loading Chile Types", consoleTicker);
                    LoadRecords(newContext, new AdditiveTypeMother(), "Loading Additive Types", consoleTicker);
                    LoadRecords(newContext, new WorkTypeMother(), "Loading Work Types", consoleTicker);
                    LoadRecords(newContext, new AttributeNameMother(RVCDataLoadLoggerGate.LogSummaryEntry("Attribute Names")), "Loading Attribute Names", consoleTicker);
                    LoadRecords(newContext, new InventoryTreatmentMother(oldContext, RVCDataLoadLoggerGate.InventoryTreatmentLoadLoggerCallback), "Loading Inventory Treatment Types", consoleTicker);
                    LoadRecords(newContext, new InventoryTreatmentForAttributeMother(), "Loading inventory treatment valdiation rules", consoleTicker);

                    var message    = "Loading Facilities";
                    var facilities = new FacilityEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.WarehouseLoadLoggerCallback).BirthAll(() => consoleTicker.TickConsole(message + "...")).ToList();
                    consoleTicker.ReplaceCurrentLine(message);
                    LoadRecords(newContext, facilities, "\tfacilities", consoleTicker);
                    LoadRecords(newContext, facilities.SelectMany(w => w.Locations), "\tlocations", consoleTicker);

                    oldContext.ClearContext();
                }
                finally
                {
                    newContext.Configuration.ProxyCreationEnabled     = proxyCreation;
                    newContext.Configuration.AutoDetectChangesEnabled = autoDetecChanges;
                    newContext.Configuration.LazyLoadingEnabled       = lazyLoading;
                }
            }
        }
Example #6
0
        private void InitializeOldContext()
        {
            var addColumnsScript = GetAddColumnsScript();

            if (addColumnsScript != null)
            {
                var originalEntityConnection = ContextsHelper.GetOldContextConnection();
                if (originalEntityConnection != null)
                {
                    using (originalEntityConnection)
                        using (var connection = new SqlConnection(originalEntityConnection.StoreConnection.ConnectionString))
                        {
                            connection.Open();
                            AddColumns(connection, addColumnsScript);
                            connection.Close();
                        }
                }
            }
        }
Example #7
0
        private static void ExecuteInitialization(RioValleyChiliDataContext context, IDataContextInitializationAdapter <RioValleyChiliDataContext> initializationAdapter, string[] args)
        {
            ContextsHelper.ConsoleOutputSettings();
            RVCDataLoadLoggerGate.RVCDataLoadLogger = RVCDataLoadLogger.GetDataLoadLogger(ExtractArgs(args, "-LogFolder "));

            if (context.Database.Exists())
            {
                Console.WriteLine("Preserving old data.");
                PreservedData.ObtainData(context);

                Console.WriteLine("Deleting existing database.");
                context.Database.Delete();
            }

            Console.WriteLine("Initializing database.");

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            DataLoadResult.Success = true;
            initializationAdapter.InitializeDataContext(ref context);
            new RVCDataLoadResultObtainer().SetDataLoadResult(new RVCDataLoadResultObtainer.LoadResult
            {
                Success         = DataLoadResult.Success,
                RanToCompletion = true,
                TimeStamp       = DateTime.Now
            });
            stopwatch.Stop();

            Console.WriteLine("\n****************************************");
            Console.WriteLine("DATA LOAD COMPLETE");
            Console.WriteLine("Success: {0}", DataLoadResult.Success);
            Console.WriteLine("Total Run Time: {0:g}", stopwatch.Elapsed);
            Console.WriteLine("****************************************\n");

            if (RVCDataLoadLoggerGate.RVCDataLoadLogger != null)
            {
                RVCDataLoadLoggerGate.RVCDataLoadLogger.WriteLogSummary();
            }
        }
        public override void SeedContext(RioValleyChiliDataContext newContext)
        {
            new ProductionDataSeeder().SeedContext(newContext);

            var consoleTicker = new ConsoleTicker();

            using (var oldContext = ContextsHelper.GetOldContext())
            {
                var proxyCreation            = newContext.Configuration.ProxyCreationEnabled;
                var autoDetectChangesEnabled = newContext.Configuration.AutoDetectChangesEnabled;
                var lazyLoading = newContext.Configuration.LazyLoadingEnabled;

                try
                {
                    newContext.Configuration.ProxyCreationEnabled     = false;
                    newContext.Configuration.AutoDetectChangesEnabled = true;
                    newContext.Configuration.LazyLoadingEnabled       = false;
                    newContext.Configuration.UseDatabaseNullSemantics = true;

                    oldContext.CommandTimeout = 1800;

                    LoadContracts(oldContext, newContext, consoleTicker);
                    LoadSalesOrders(oldContext, newContext, consoleTicker);
                    LoadTreatmentOrders(oldContext, newContext, consoleTicker);
                    LoadInterWarehouseOrders(oldContext, newContext, consoleTicker);
                    LoadIntraWarehouserOrders(oldContext, newContext, consoleTicker);
                    LoadLotAllowances(oldContext, newContext, consoleTicker);
                    LoadSampleOrders(oldContext, newContext, consoleTicker);
                    LoadSalesQuotes(oldContext, newContext, consoleTicker);
                }
                finally
                {
                    newContext.Configuration.ProxyCreationEnabled     = proxyCreation;
                    newContext.Configuration.AutoDetectChangesEnabled = autoDetectChangesEnabled;
                    newContext.Configuration.LazyLoadingEnabled       = lazyLoading;
                }
            }
        }
        public override void SeedContext(RioValleyChiliDataContext newContext)
        {
            new CoreDbContextDataSeeder().SeedContext(newContext);

            var consoleTicker = new ConsoleTicker();

            using (var oldContext = ContextsHelper.GetOldContext())
            {
                var companyResults = new CompanyAndContactsMother(oldContext, newContext, RVCDataLoadLoggerGate.CompanyAndContactsLoadLoggerCallback).BirthAll(() => consoleTicker.TickConsole("Loading Companies...")).ToList();
                consoleTicker.ReplaceCurrentLine("Loading Companies");
                var companies        = new List <Models.Company>();
                var contacts         = new List <Models.Contact>();
                var contactAddresses = new List <ContactAddress>();
                var customers        = new List <Customer>();
                var customerNotes    = new List <CustomerNote>();
                foreach (var result in companyResults)
                {
                    companies.Add(result.Company);
                    contacts.AddRange(result.Company.Contacts);
                    contactAddresses.AddRange(result.Company.Contacts.SelectMany(c => c.Addresses));

                    if (result.Customer != null)
                    {
                        customers.Add(result.Customer);
                        customerNotes.AddRange(result.Customer.Notes);
                    }
                }

                LoadRecords(newContext, companies, "\tcompanies", consoleTicker);
                LoadRecords(newContext, companies.SelectMany(c => c.CompanyTypes), "\tcompany types", consoleTicker);
                LoadRecords(newContext, contacts, "\tcontacts", consoleTicker);
                LoadRecords(newContext, contactAddresses, "\tcontact addresses", consoleTicker);
                LoadRecords(newContext, customers, "\tcustomers", consoleTicker);
                LoadRecords(newContext, customerNotes, "\tcustomer notes", consoleTicker);
            }
        }
Example #10
0
        public override void SeedContext(RioValleyChiliDataContext newContext)
        {
            new InventoryDbContextDataSeeder().SeedContext(newContext);

            var consoleTicker = new ConsoleTicker();

            using (var oldContext = ContextsHelper.GetOldContext())
            {
                var proxyCreation            = newContext.Configuration.ProxyCreationEnabled;
                var autoDetectChangesEnabled = newContext.Configuration.AutoDetectChangesEnabled;
                var lazyLoading = newContext.Configuration.LazyLoadingEnabled;

                try
                {
                    newContext.Configuration.ProxyCreationEnabled     = false;
                    newContext.Configuration.AutoDetectChangesEnabled = true;
                    newContext.Configuration.LazyLoadingEnabled       = false;

                    oldContext.CommandTimeout = 2400;
                    oldContext.ClearContext();

                    LoadPackSchedules(oldContext, newContext, consoleTicker);
                    LoadProductionBatches(oldContext, newContext, consoleTicker);
                    LoadProductionSchedules(oldContext, newContext, consoleTicker);
                    LoadInstructions(oldContext, newContext, consoleTicker);
                    LoadChileMaterialsReceived(oldContext, newContext, consoleTicker);
                    LoadMillAndWetdown(oldContext, newContext, consoleTicker);
                }
                finally
                {
                    newContext.Configuration.ProxyCreationEnabled     = proxyCreation;
                    newContext.Configuration.AutoDetectChangesEnabled = autoDetectChangesEnabled;
                    newContext.Configuration.LazyLoadingEnabled       = lazyLoading;
                }
            }
        }