Exemplo n.º 1
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}");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
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}");
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public void Rollback()
 {
     _repositoryTransaction?.Rollback();
 }