Beispiel #1
0
        public void With_EmptyJson_Return_Null()
        {
            Mock <IDataProvider> dataProvider = new Mock <IDataProvider>();

            dataProvider.Setup(d => d.Provide()).Returns("");
            IOperationEngine engine = new OperationEngine(dataProvider.Object);

            Assert.IsNull(engine.Run());
        }
        /// <summary>
        /// Command line runner entry point
        /// </summary>
        private static void Main(string[] args)
        {
            try
            {
                Log.Info("================== Data Migration CommandLine Runner ==================");
                var operationEngine = new OperationEngine();

                Log.Info("******** Verifying Connectivity ********");
                var connectivityTests = new ConnectivityTests(Log);
                if (!connectivityTests.TestConnections())
                {
                    Log.Fatal("Fatal exception while trying to establish connectivity to systems under migration.");
                    Console.Read();
                    return;
                }

                Log.Info("******** Migrating catalog, culture, currency definitions ********");
                var migrateCatalogs = new MigrateCatalogs {
                    Log = Log
                };
                operationEngine.Execute(migrateCatalogs.BuildOperation());

                Log.Info("******** Migrating taxonomy ********");
                var migrateTaxonomy = new MigrateTaxonomy()
                {
                    Log = Log
                };
                operationEngine.Execute(migrateTaxonomy.BuildOperation());

                Log.Info("******** Migrating product types ********");
                var migrateProductTypes = new MigrateProductTypes {
                    Log = Log
                };
                operationEngine.Execute(migrateProductTypes.BuildOperation());

                Log.Info("******** Migrating core product data ********");
                var productCount      = DataHelper.GetProductCount();
                var currentBatchCount = 0;
                do
                {
                    var migrateProductData = new MigrateProductData {
                        Log = Log, Skip = currentBatchCount, Take = ProductBatchSize
                    };
                    operationEngine.Execute(migrateProductData.BuildOperation());
                    currentBatchCount += ProductBatchSize;
                } while (currentBatchCount < productCount);

                Log.Info("======================= Data Migration Complete =======================");
                Console.Read();
            }
            catch (Exception ex)
            {
                Log.Fatal("There was an unrecoverable error while executing the migration.  Details: ", ex);
                Console.Read();
            }
        }
Beispiel #3
0
        public void With_InvalidOperator_Throws_Exception()
        {
            Mock <IDataProvider> dataProvider = new Mock <IDataProvider>();
            string json = "{\r\n  \"parm1\": 8,\r\n  \"parm2\": 8,\r\n  \"op\": \"abc\"\r\n}";

            dataProvider.Setup(d => d.Provide()).Returns(json);
            IOperationEngine engine = new OperationEngine(dataProvider.Object);

            Assert.IsNull(engine.Run());
        }
Beispiel #4
0
        public void With_ValidData_Return_Complete_Dto()
        {
            Mock <IDataProvider> dataProvider = new Mock <IDataProvider>();
            string json = "{\r\n  \"parm1\": 8,\r\n  \"parm2\": 8,\r\n  \"op\": \"-\"\r\n}";

            dataProvider.Setup(d => d.Provide()).Returns(json);
            IOperationEngine engine = new OperationEngine(dataProvider.Object);
            var dto = engine.Run();

            Assert.IsNotNull(dto);
            Assert.AreEqual(dto.Operator, "-");
            Assert.AreEqual(dto.Parameter1, "8");
            Assert.AreEqual(dto.Parameter2, "8");
            Assert.AreEqual(dto.Result, "0");
        }
Beispiel #5
0
        public void SummonEngine(OperationType operation, Package package, Project project)
        {
            // Ensure operation is valid.
            if (this.operation == OperationType.Unknown)
            {
                throw new InvalidOperationException("Unexpected operation to be unknown.");
            }

            // Create the engine context.
            EngineContext context = new EngineContext
            {
                Options = this.options,
                Project = project,
                Package = package
            };

            // Create the engine buffer.
            OperationEngine engine = null;

            // Create a new build engine instance.
            if (this.operation == OperationType.Build)
            {
                engine = new BuildEngine(context);
            }
            // Create a new execution engine instance.
            else if (this.operation == OperationType.Run)
            {
                engine = new Engines.ExecutionEngine(context);
            }
            // At this point, the provided operation is invalid.
            else
            {
                throw new ArgumentException($"Unknown requested operation: {operation}");
            }

            // Ensure the engine buffer is not null.
            if (engine == null)
            {
                throw new Exception("Unexpected engine to be null.");
            }

            // Invoke the engine buffer.
            engine.Invoke();
        }
Beispiel #6
0
        public ActionResult Download(int?id, string typeName, DownloadAs?type)
        {
            var typeInfo = new TypeInfo
            {
                Id       = id.GetValueOrDefault(0),
                TypeName = typeName ?? "",
                Type     = type.GetValueOrDefault(DownloadAs.Excel),
            };

            WorkFile   output = null;
            IOperation operation;

            if (typeInfo.Type == DownloadAs.Excel)
            {
                var builder = FluentOperationBuilder
                              .Receive <InvokeMethodReceiver <TypeInfo> >().WithOption(x => x.Method = () => typeInfo)
                              .Transform <TypeInfoToProductListCog>()
                              .Transform <ProductListToDataTable>()
                              .Transform <FromDataTableToExcelStream>()
                              .Transform <NamingCog>().WithOption(a => a.Extension = ".xlsx")
                              .Send <InvokeMethodSender <WorkFile> >().WithOption(x => x.Method = (value) => output = value);
                operation = builder.ToOperation();
            }
            else
            {
                var builder = FluentOperationBuilder
                              .Receive <InvokeMethodReceiver <TypeInfo> >().WithOption(x => x.Method = () => typeInfo)
                              .Transform <TypeInfoToProductListCog>()
                              .Transform <ProductListToDataTable>()
                              .Transform <FromDataTableToCsvStream>()
                              .Transform <NamingCog>().WithOption(a => a.Extension = ".csv")
                              .Send <InvokeMethodSender <WorkFile> >().WithOption(x => x.Method = (value) => output = value);
                operation = builder.ToOperation();
            }

            var runner = new OperationEngine();

            runner.Execute(operation);
            output.Stream.Flush();
            output.Stream.Position = 0;
            return(File(output.Stream, MediaTypeNames.Application.Octet, output.Name));
        }
Beispiel #7
0
 public OperationRequestHandler(OperationEngine operationEngine)
 {
     _operationEngine = operationEngine;
 }