Exemple #1
0
 public static ServiceFunction GetSourceFunction(this ServiceFunction value, int serviceFunctionId)
 {
     using (var sourceDb = new SLMDataContext("Name=SLMSourceDataContext"))
     {
         // For expediency grab everything and store in memory
         return(sourceDb.ServiceFunctions.AsNoTracking()
                .Include(c => c.ServiceDomain)
                .Include(c => c.FunctionType)
                .Include(c => c.ServiceComponents)
                .Include(c => c.ServiceComponents.Select(cc => cc.ChildServiceComponents))
                .Include(c => c.ServiceComponents.Select(r => r.Resolver))
                .Include(c => c.ServiceComponents.Select(r => r.Resolver.OperationalProcessTypes.Select(op => op.OperationalProcessTypeRefData)))
                .Include(c => c.ServiceComponents.Select(r => r.Resolver.ServiceDeliveryOrganisationType))
                .Include(c => c.ServiceComponents.Select(r => r.Resolver.ServiceDeliveryUnitType))
                .Include(c => c.ServiceComponents.Select(r => r.Resolver.ResolverGroupType))
                .Include(c => c.ServiceComponents.Select(r => r.Resolver.ServiceComponent))
                .Include(c => c.ServiceComponents.Select(r => r.Resolver.ServiceDesk))
                .Include(c => c.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver)))
                .Include(c => c.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.OperationalProcessTypes.Select(op => op.OperationalProcessTypeRefData))))
                .Include(c => c.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.ServiceDeliveryOrganisationType)))
                .Include(c => c.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.ServiceDeliveryUnitType)))
                .Include(c => c.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.ResolverGroupType)))
                .Include(c => c.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.ServiceComponent)))
                .Include(c => c.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.ServiceDesk)))
                .FirstOrDefault(x => x.Id == serviceFunctionId));
     }
 }
Exemple #2
0
 public static Customer GetSourceCustomer(this Customer value, int sourceCustomerId)
 {
     using (var sourceDb = new SLMDataContext("Name=SLMSourceDataContext"))
     {
         // For expediency grab everything and store in memory
         return(sourceDb.Customers.AsNoTracking()
                .Include(c => c.Contributors)
                .Include(c => c.ServiceDesks.Select(s => s.DeskInputTypes.Select(i => i.InputTypeRefData)))
                .Include(c => c.ServiceDesks.Select(s => s.Resolvers.Select(r => r.OperationalProcessTypes)))
                .Include(c => c.ServiceDesks.Select(s => s.Resolvers.Select(r => r.ServiceDeliveryOrganisationType)))
                .Include(c => c.ServiceDesks.Select(s => s.Resolvers.Select(r => r.ServiceDeliveryUnitType)))
                .Include(c => c.ServiceDesks.Select(s => s.Resolvers.Select(r => r.ResolverGroupType)))
                .Include(c => c.ServiceDesks.Select(s => s.Resolvers.Select(sc => sc.ServiceComponent)))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.DomainType)))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions)))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(ft => ft.FunctionType))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(cc => cc.ChildServiceComponents)))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(r => r.Resolver)))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(r => r.Resolver.OperationalProcessTypes.Select(op => op.OperationalProcessTypeRefData))))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(r => r.Resolver.ServiceDeliveryOrganisationType)))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(r => r.Resolver.ServiceDeliveryUnitType)))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(r => r.Resolver.ResolverGroupType)))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(r => r.Resolver.ServiceComponent)))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(r => r.Resolver.ServiceDesk)))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver))))))
                .Include(
                    c =>
                    c.ServiceDesks.Select(
                        s =>
                        s.ServiceDomains.Select(
                            d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.OperationalProcessTypes.Select(op => op.OperationalProcessTypeRefData)))))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.ServiceDeliveryOrganisationType))))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.ServiceDeliveryUnitType))))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.ResolverGroupType))))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.ServiceComponent))))))
                .Include(c => c.ServiceDesks.Select(s => s.ServiceDomains.Select(d => d.ServiceFunctions.Select(sc => sc.ServiceComponents.Select(cc => cc.ChildServiceComponents.Select(ccr => ccr.Resolver.ServiceDesk))))))
                .FirstOrDefault(x => x.Id == sourceCustomerId));
     }
 }
Exemple #3
0
        public void Execute()
        {
            // HMRC
            // =====
            // 45 = HMRC (Live Services) ( * - Copied )
            // 69 = HMRC ( * - Copied )
            // 84 = HMRC Service Management ( * - Copied )
            // 118 = HMRC FAST-DA ( * - Copied )
            // 180 = HMRC FAST-DA_COPY ( * - Copied )


            // MATT TEST
            // ==========
            // 184 = Matt Test

            // VANDA
            // ======
            // 185 = TestingMagic

            var customer = new Customer().GetSourceCustomer(84);

            if (customer != null)
            {
                using (var targetDbContext = new SLMDataContext("Name=SLMTargetDataContext"))
                {
                    var unitOfWork = new UnitOfWork(targetDbContext);
                    IRepositoryTransaction repositoryTransaction = null;

                    using (var dbConnection = unitOfWork.CreateConnection())
                    {
                        try
                        {
                            // Open the connection and begin a transaction
                            dbConnection.Open();
                            repositoryTransaction = unitOfWork.BeginTransaction();

                            if (!targetDbContext.Customers.Any(x => x.CustomerName == customer.CustomerName))
                            {
                                var targetCustomer = new Customer
                                {
                                    Active            = customer.Active,
                                    CustomerName      = customer.CustomerName,
                                    CustomerNotes     = customer.CustomerNotes,
                                    AssignedArchitect = customer.AssignedArchitect,
                                    Contributors      = new List <Contributor>(),
                                    ServiceDesks      = new List <ServiceDesk>(),
                                    InsertedBy        = customer.InsertedBy,
                                    InsertedDate      = customer.InsertedDate,
                                    UpdatedBy         = customer.UpdatedBy,
                                    UpdatedDate       = customer.UpdatedDate
                                };

                                targetDbContext.Customers.Add(targetCustomer);
                                unitOfWork.Save();

                                if (customer.Contributors.Any())
                                {
                                    var contributorProcessor = new ContributorProcessor(targetCustomer, customer.Contributors.ToList(), unitOfWork);
                                    contributorProcessor.Execute();
                                }

                                if (customer.ServiceDesks.Any())
                                {
                                    foreach (var serviceDesk in customer.ServiceDesks.ToList())
                                    {
                                        var serviceDeskProcessor = new ServiceDeskProcessor(targetCustomer, serviceDesk, unitOfWork);
                                        serviceDeskProcessor.Execute();

                                        var targetServiceDesk      = targetDbContext.ServiceDesks.Single(x => x.DeskName == serviceDesk.DeskName && x.CustomerId == targetCustomer.Id);
                                        var deskInputTypeProcessor = new DeskInputTypeProcessor(targetServiceDesk, serviceDesk.DeskInputTypes.ToList(), targetDbContext, unitOfWork);
                                        deskInputTypeProcessor.Execute();

                                        var serviceDeskResolverProcessor = new ServiceDeskResolverProcessor(targetServiceDesk, serviceDesk.Resolvers, targetDbContext, unitOfWork);
                                        serviceDeskResolverProcessor.Execute();

                                        var serviceDomainProcessor = new ServiceDomainProcessor(targetServiceDesk, serviceDesk.ServiceDomains.ToList(), targetDbContext, unitOfWork);
                                        serviceDomainProcessor.Execute();
                                    }
                                }
                                repositoryTransaction?.Save();
                                System.Console.WriteLine($@"Successfully Migrated Customer > {customer.CustomerName}");
                            }
                        }
                        catch (Exception ex)
                        {
                            // If we have a transaction then roll it back
                            repositoryTransaction?.Rollback();

                            System.Console.WriteLine($@"Exception => {ex.Message}");
                        }
                    }
                }
            }
        }
Exemple #4
0
        public void Execute()
        {
            // HMRC
            // =====
            // xxx = HMRC FAST-DA ( * - Copied )

            // Domains
            // ========
            // xxx = Network Services (Source)
            // xxx = Security Services (Target)

            var sourceFunctionId = 978;
            var targetDomainId   = 280;

            var serviceFunction = new ServiceFunction().GetSourceFunction(sourceFunctionId);

            if (serviceFunction != null)
            {
                using (var targetDbContext = new SLMDataContext("Name=SLMTargetDataContext"))
                {
                    var unitOfWork = new UnitOfWork(targetDbContext);
                    IRepositoryTransaction repositoryTransaction = null;

                    using (var dbConnection = unitOfWork.CreateConnection())
                    {
                        try
                        {
                            // Open the connection and begin a transaction
                            dbConnection.Open();
                            repositoryTransaction = unitOfWork.BeginTransaction();

                            var targetDomain = targetDbContext.ServiceDomains.Single(x => x.Id == targetDomainId);

                            var serviceFunctions = new List <ServiceFunction> {
                                serviceFunction
                            };

                            var serviceFunctionProcessor = new ServiceFunctionProcessor(targetDomain, serviceFunctions, targetDbContext, unitOfWork);
                            serviceFunctionProcessor.Execute();

                            var targetServiceFunction = targetDomain.ServiceFunctions.Single(x => x.FunctionType.FunctionName == serviceFunction.FunctionType.FunctionName);
                            // Add underlying Service Function hierarchy
                            foreach (var serviceComponent in serviceFunction.ServiceComponents.Where(x => x.ComponentLevel == 1))
                            {
                                var serviceComponentProcessor = new ServiceComponentProcessor(targetDomain.ServiceDesk, targetServiceFunction, serviceComponent, targetDbContext, unitOfWork);
                                serviceComponentProcessor.Execute();
                            }

                            repositoryTransaction?.Save();
                            System.Console.WriteLine($@"Successfully Copied Service Function [{serviceFunction.FunctionType.FunctionName}] To Service Domain [{targetDomain.DomainType.DomainName}]");
                        }
                        catch (Exception ex)
                        {
                            // If we have a transaction then roll it back
                            repositoryTransaction?.Rollback();

                            System.Console.WriteLine($@"Exception => {ex.Message}");
                        }
                    }
                }
            }
        }
Exemple #5
0
        public void Execute()
        {
            foreach (var resolver in _resolvers)
            {
                int sqlResult;
                using (var sourceDbContext = new SLMDataContext("Name=SLMSourceDataContext"))
                {
                    sqlResult = sourceDbContext.Database.SqlQuery <int>($"SELECT Count(*) FROM RESOLVER WHERE Id = {resolver.Id} AND ServiceComponent_Id IS NULL").FirstOrDefault();
                }

                if (sqlResult > 0)
                {
                    if (resolver.ServiceDeliveryUnitType != null)
                    {
                        if (!_dataContext.ServiceDeliveryUnitTypeRefData.Any(x => x.ServiceDeliveryUnitTypeName == resolver.ServiceDeliveryUnitType.ServiceDeliveryUnitTypeName))
                        {
                            var serviceDeliveryUnitType = new ServiceDeliveryUnitTypeRefData
                            {
                                ServiceDeliveryUnitTypeName = resolver.ServiceDeliveryUnitType.ServiceDeliveryUnitTypeName,
                                SortOrder = resolver.ServiceDeliveryUnitType.SortOrder,
                                Visible   = resolver.ServiceDeliveryUnitType.Visible
                            };

                            _dataContext.ServiceDeliveryUnitTypeRefData.Add(serviceDeliveryUnitType);
                            _unitOfWork.Save();
                        }
                    }

                    if (resolver.ResolverGroupType != null)
                    {
                        if (!_dataContext.ResolverGroupTypeRefData.Any(x => x.ResolverGroupTypeName == resolver.ResolverGroupType.ResolverGroupTypeName))
                        {
                            var resolverGroupType = new ResolverGroupTypeRefData
                            {
                                ResolverGroupTypeName = resolver.ResolverGroupType.ResolverGroupTypeName,
                                SortOrder             = resolver.ResolverGroupType.SortOrder,
                                Visible = resolver.ResolverGroupType.Visible
                            };

                            _dataContext.ResolverGroupTypeRefData.Add(resolverGroupType);
                            _unitOfWork.Save();
                        }
                    }

                    var newResolver = new Resolver
                    {
                        ServiceDesk   = _serviceDesk,
                        ServiceDeskId = _serviceDesk.Id,
                        ServiceDeliveryOrganisationType  = _dataContext.ServiceDeliveryOrganisationTypeRefData.Single(x => x.ServiceDeliveryOrganisationTypeName == resolver.ServiceDeliveryOrganisationType.ServiceDeliveryOrganisationTypeName),
                        ServiceDeliveryOrganisationNotes = resolver.ServiceDeliveryOrganisationNotes,
                        ServiceDeliveryUnitNotes         = resolver.ServiceDeliveryUnitNotes,
                        ServiceDeliveryUnitType          = resolver.ServiceDeliveryUnitType != null?_dataContext.ServiceDeliveryUnitTypeRefData.Single(x => x.ServiceDeliveryUnitTypeName == resolver.ServiceDeliveryUnitType.ServiceDeliveryUnitTypeName) : null,
                                                               ResolverGroupType = resolver.ResolverGroupType != null?_dataContext.ResolverGroupTypeRefData.Single(x => x.ResolverGroupTypeName == resolver.ResolverGroupType.ResolverGroupTypeName) : null,
                                                                                       InsertedBy   = resolver.InsertedBy,
                                                                                       InsertedDate = resolver.InsertedDate,
                                                                                       UpdatedBy    = resolver.UpdatedBy,
                                                                                       UpdatedDate  = resolver.UpdatedDate
                    };

                    _serviceDesk.Resolvers.Add(newResolver);
                    _unitOfWork.Save();
                }
            }
        }
Exemple #6
0
 public UnitOfWork(SLMDataContext dbContext)
 {
     _dbContext = dbContext;
 }
Exemple #7
0
 public Repository(SLMDataContext context)
 {
     _context            = context;
     _dbSet              = context.Set <TEntity>();
     _objectStateManager = ((IObjectContextAdapter)_context).ObjectContext.ObjectStateManager;
 }