Ejemplo n.º 1
0
        public void SyncOldModels(IEnumerable <TNewModel> newModels)
        {
            var busyMessage = "";

            if (_consoleTicker != null)
            {
                busyMessage = Message + "...";
                Console.Write(busyMessage + "\r");
            }

            var oldSet = _oldContext.CreateObjectSet <TOldModel>();
            var count  = 0;

            foreach (var newModel in newModels)
            {
                if (_consoleTicker != null)
                {
                    _consoleTicker.TickConsole(busyMessage);
                }

                SyncOldContextModel(oldSet.First(GetOldModelPredicate(newModel)), newModel);
                count++;
            }
            _oldContext.SaveChanges();

            if (_consoleTicker != null)
            {
                _consoleTicker.ReplaceCurrentLine(string.Format("{0} Done - {1} records.", busyMessage, count));
            }
        }
        protected static void LoadRecords <T>(IBulkInsertContext context, List <T> records, string message, ConsoleTicker consoleTicker)
            where T : class
        {
            if (message != null)
            {
                Console.Write(message + "...\r");
            }

            consoleTicker.ResetTicker();
            var count = context.BulkAddAll(records, message != null ? () => consoleTicker.TickConsole(message + "...") : (Action)null);

            consoleTicker.ReplaceCurrentLine("{0}: {1} records.", message, count);
        }
Ejemplo n.º 3
0
        private static List <TEntity> LoadProducts <TEntity>(IBulkInsertContext newContext, IMother <TEntity> mother, ConsoleTicker consoleTicker, string message, Func <TEntity, Product> productSelector = null) where TEntity : class
        {
            var products = mother.BirthAll(() => consoleTicker.TickConsole(message + "...")).ToList();

            consoleTicker.ReplaceCurrentLine(message);

            if (productSelector != null)
            {
                LoadRecords(newContext, products.Select(productSelector), "\t\tproducts", consoleTicker);
            }
            LoadRecords(newContext, products, "\t" + message.ToLower(), consoleTicker);

            return(products);
        }
        protected static void LoadRecords <T>(IBulkInsertContext context, IEnumerable <T> records, string message, ConsoleTicker consoleTicker, int?takeLimit = null)
            where T : class
        {
            if (message != null)
            {
                Console.Write(message + "...\r");
            }

            var recordsList = takeLimit != null?records.Take(takeLimit.Value).ToList() : records.ToList();

            consoleTicker.ResetTicker();
            var count = context.BulkAddAll(recordsList, message != null ? () => consoleTicker.TickConsole(message + "...") : (Action)null);

            consoleTicker.ReplaceCurrentLine("{0}: {1} records.", message, count);
        }
        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);
            }
        }
Ejemplo n.º 6
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;
                }
            }
        }
        protected static void ProcessedBirth <TEntity>(IProcessedMother <TEntity> mother, string message, ConsoleTicker consoleTicker, Action <TEntity> processResult)
            where TEntity : class
        {
            var tickedMessage = message == null || consoleTicker == null ? null : message + "...";

            mother.ProcessedBirthAll(processResult, tickedMessage == null ? (Action)null : () => consoleTicker.TickConsole(tickedMessage));
        }
        protected static IList <TEntity> Birth <TEntity>(IMother <TEntity> mother, string message, ConsoleTicker consoleTicker, int?takeLimit = null)
            where TEntity : class
        {
            var tickedMessage = message == null || consoleTicker == null ? null : message + "...";
            var entities      = mother.BirthAll(tickedMessage == null ? (Action)null : () => consoleTicker.TickConsole(tickedMessage));

            return(takeLimit != null?entities.Take(takeLimit.Value).ToList() : entities.ToList());
        }