예제 #1
0
        private async Task <Mock <RequestContext <DacFxResult> > > SendAndValidateImportRequest()
        {
            // first export a bacpac
            var result = GetLiveAutoCompleteTestObjects();
            var exportRequestContext = new Mock <RequestContext <DacFxResult> >();

            exportRequestContext.Setup(x => x.SendResult(It.IsAny <DacFxResult>())).Returns(Task.FromResult(new object()));

            SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxImportTest");

            string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest");

            Directory.CreateDirectory(folderPath);

            var exportParams = new ExportParams
            {
                DatabaseName    = sourceDb.DatabaseName,
                PackageFilePath = Path.Combine(folderPath, string.Format("{0}.bacpac", sourceDb.DatabaseName))
            };

            DacFxService    service         = new DacFxService();
            ExportOperation exportOperation = new ExportOperation(exportParams, result.ConnectionInfo);

            service.PerformOperation(exportOperation);

            // import the created bacpac
            var importRequestContext = new Mock <RequestContext <DacFxResult> >();

            importRequestContext.Setup(x => x.SendResult(It.IsAny <DacFxResult>())).Returns(Task.FromResult(new object()));

            var importParams = new ImportParams
            {
                PackageFilePath = exportParams.PackageFilePath,
                DatabaseName    = string.Concat(sourceDb.DatabaseName, "-imported")
            };

            ImportOperation importOperation = new ImportOperation(importParams, result.ConnectionInfo);

            service.PerformOperation(importOperation);
            SqlTestDb targetDb = SqlTestDb.CreateFromExisting(importParams.DatabaseName);

            // cleanup
            VerifyAndCleanup(exportParams.PackageFilePath);
            sourceDb.Cleanup();
            targetDb.Cleanup();

            return(importRequestContext);
        }
예제 #2
0
        private static void BackgroundThreadProc(object userData)
        {
            ImportOperation operation = (ImportOperation)userData;

            try {
                using (TextReader reader = new StreamReader(new MemoryStream(operation.format.root.contents), Encoding.UTF8)) {
                    operation.importState = ImportGltf.BeginImport(
                        operation.format.formatType == PolyFormatType.GLTF ? GltfSchemaVersion.GLTF1 : GltfSchemaVersion.GLTF2,
                        reader, operation.loader, operation.options);
                }
            } catch (Exception ex) {
                Debug.LogException(ex);
                operation.status = PolyStatus.Error("Error importing asset.", ex);
            }
            // Done with background thread part, let's queue it so we can finish up on the main thread.
            operation.instance.EnqueueFinishedOperation(operation);
        }
        public async void ImportBacpac()
        {
            // first export a bacpac
            var       result   = GetLiveAutoCompleteTestObjects();
            SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxImportTest");

            SqlTestDb targetDb   = null;
            string    folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest");

            Directory.CreateDirectory(folderPath);

            try
            {
                var exportParams = new ExportParams
                {
                    DatabaseName    = sourceDb.DatabaseName,
                    PackageFilePath = Path.Combine(folderPath, string.Format("{0}.bacpac", sourceDb.DatabaseName))
                };

                DacFxService    service         = new DacFxService();
                ExportOperation exportOperation = new ExportOperation(exportParams, result.ConnectionInfo);
                service.PerformOperation(exportOperation, TaskExecutionMode.Execute);

                // import the created bacpac
                var importParams = new ImportParams
                {
                    PackageFilePath = exportParams.PackageFilePath,
                    DatabaseName    = string.Concat(sourceDb.DatabaseName, "-imported")
                };

                ImportOperation importOperation = new ImportOperation(importParams, result.ConnectionInfo);
                service.PerformOperation(importOperation, TaskExecutionMode.Execute);
                targetDb = SqlTestDb.CreateFromExisting(importParams.DatabaseName);

                VerifyAndCleanup(exportParams.PackageFilePath);
            }
            finally
            {
                sourceDb.Cleanup();
                if (targetDb != null)
                {
                    targetDb.Cleanup();
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Imports the given format of the given asset, asynchronously in a background thread.
        /// Calls the supplied callback when done.
        /// </summary>
        public void ImportAsync(PolyAsset asset, PolyFormat format, PolyImportOptions options,
                                AsyncImportCallback callback = null)
        {
            ImportOperation operation = new ImportOperation();

            operation.instance = this;
            operation.asset    = asset;
            operation.format   = format;
            operation.options  = options;
            operation.callback = callback;
            operation.status   = PolyStatus.Success();
            operation.loader   = new FormatLoader(format);
            if (Application.isPlaying)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(BackgroundThreadProc), operation);
            }
            else
            {
                // If we are in the editor, don't do this in a background thread. Do it directly
                // here on the main thread.
                BackgroundThreadProc(operation);
                Update();
            }
        }
예제 #5
0
        void LoadNtx(string ntxFile)
        {
            Debug.Assert(CadastralMapModel.Current.WorkingSession != null);

            // If the model is currently empty, we'll want to draw an overview upon
            // completion of the import (otherwise we'll refresh using the currently
            // displayed extent).
            bool wasEmpty = CadastralMapModel.Current.IsEmpty;

            ImportOperation   i = null;
            EditingController c = EditingController.Current;

            try
            {
                i = new ImportOperation();
                NtxImport ni = new NtxImport(ntxFile, this);
                i.Execute(ni);
                Trace.Write("Map model updates completed");
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message);
            }

            if (wasEmpty)
            {
                c.ActiveDisplay.DrawOverview();
            }
            else
            {
                c.RefreshAllDisplays();
            }

            SaveTranslations();
        }
예제 #6
0
 private void EnqueueFinishedOperation(ImportOperation operation)
 {
     lock (finishedOperationsLock) {
         finishedOperations.Enqueue(operation);
     }
 }
예제 #7
0
 protected AudioImporter()
 {
     operation = new ImportOperation(this);
 }
예제 #8
0
        public void Insert(ImportOperation importOperation, Config config)
        {
            IList <MappingTable> mappingTables = new Mapping.Setup().Load(config);

            DataTable dataTable = new ReaderService(config.ExcelImportConnectionString).Load(config.ExcelImportSheetName, config.ProductDataStartsFrom);

            List <ProcessedImportRow> exceptionsRows = new List <ProcessedImportRow>();
            DataTable spplierExceptionRows           = new DataTable();

            if (config.ImportType == "Fourth_2.0")
            {
                spplierExceptionRows = FindProductNotInReceivedFile(config, dataTable);
            }
            if (spplierExceptionRows.Rows.Count > 0)
            {
                DataTable exceptionReport = new ExceptionReport()
                                            .Generate(spplierExceptionRows, config.DisplayFileName, config.ImportType);
                if (exceptionReport != null && exceptionReport.Rows.Count > 0)
                {
                    new ExceptionReportService().Export(exceptionReport,
                                                        ConfigurationManager.AppSettings["ExceptionReportFilePath"] + config.ExceptionReportFileName);
                }
                config.FailedRows    = dataTable.Rows.Count;
                config.ProcessedRows = 0;
            }
            else
            {
                int?ingredientOrdinal   = mappingTables.ColumnOrdinalOf("product", "product_name");
                int?ingredientOrdinalPk = mappingTables.ColumnOrdinalOf("ingredient", "product_id");
                int?supplierId          = mappingTables.ColumnOrdinalOf("ingredient", "supplier_code");
                int rowNum        = config.ProductDataStartsFrom;
                int processedRows = 0;
                int failedRows    = 0;

                //Update starts from this column
                int startingCell = mappingTables.GetMinColumnOrdinal();
                CollectProductIds.Clear();

                foreach (DataRow row in dataTable.Rows)
                {
                    if (IsEmpty(row, startingCell))
                    {
                        rowNum++;
                        continue;
                    }
                    ProcessedImportRow processedImportRow = new ProcessedImportRow
                    {
                        Row     = row,
                        IsValid = true,
                        ImportDataExceptions = new List <ImportDataException>(),
                        RowIndex             = rowNum,
                        IngredientName       =
                            ingredientOrdinal == null ? string.Empty : row[(int)ingredientOrdinal].ToString(),
                        IngredientId =
                            (ingredientOrdinalPk == null || ingredientOrdinalPk < 0) ? string.Empty : row[(int)ingredientOrdinalPk].ToString(),
                        DistributorCode =
                            (supplierId == null || supplierId <= 0) ? string.Empty : row[(int)supplierId].ToString(),
                    };

                    GeneratorDelegates generatorDelegates = new GeneratorDelegates();

                    if (importOperation == ImportOperation.Insert)
                    {
                        generatorDelegates = ProductInsertDelegates(config);
                    }
                    else if (importOperation == ImportOperation.FuturePrice)
                    {
                        generatorDelegates = FuturePriceDelegates(config);
                    }
                    else if (importOperation == ImportOperation.InternalFuturePrice)
                    {
                        generatorDelegates = InternalFuturePriceDelegates(config);
                    }
                    else if (importOperation == ImportOperation.FuturePriceWithInvoiceCostPrice)
                    {
                        generatorDelegates = FuturePriceDelegates(config);
                    }
                    else if (importOperation == ImportOperation.IntolUpdate)
                    {
                        generatorDelegates = IntoleranceUpdateDelegates(config);
                    }
                    else if (importOperation == ImportOperation.NutritionUpdate)
                    {
                        generatorDelegates = NutrientUpdateDelegates(config);
                    }
                    else if (importOperation == ImportOperation.PriceOverride)
                    {
                        generatorDelegates = PriceOverrideDelegates(config);
                    }
                    else if (importOperation == ImportOperation.SupIntolUpdate)
                    {
                        generatorDelegates = SupIntoleranceUpdateDelegates(config);
                    }

                    bool result = new Sql.Generate().Query(mappingTables, processedImportRow, generatorDelegates);

                    if (processedImportRow.IsValid)
                    {
                        using (var ips = new ImportProductService(config.TargetConnectionString))
                        {
                            ips.ExecuteSql(processedImportRow.SqlQuery);

                            // add product to the queue for sending to MSMQ
                            if (!string.IsNullOrEmpty(processedImportRow.IngredientId) || !string.IsNullOrEmpty(processedImportRow.DistributorCode))
                            {
                                //New validation for stock count
                                int productId = 0;
                                if (int.TryParse(processedImportRow.IngredientId, out productId))
                                {
                                    ips.ValidateStockInventory(productId);
                                }

                                var item = !string.IsNullOrEmpty(processedImportRow.IngredientId)
                                    ? new Tuple <int?, string>(Convert.ToInt32(processedImportRow.IngredientId), null)
                                    : new Tuple <int?, string>(null, processedImportRow.DistributorCode);
                                CollectProductIds.Add(item);
                            }

                            processedRows++;
                        }
                    }
                    else
                    {
                        exceptionsRows.Add(processedImportRow);
                        failedRows++;
                    }
                    rowNum++;
                }

                List <MappingColumn> mappingColumns = MappingExtensions.GetTemplateColumns(mappingTables);
                using (var exService = new ExceptionMessageService(config.TargetConnectionString))
                {
                    List <ExceptionMessage> exceptionMessages = exService.GetExceptionMessages();

                    IList <int> dataRows;
                    DataTable   exceptionReport = new ExceptionReport()
                                                  .Generate(mappingColumns, config.DisplayFileName, exceptionsRows, exceptionMessages,
                                                            config.ImportType, out dataRows);
                    if (exceptionReport != null && exceptionReport.Rows.Count > 0)
                    {
                        new ExceptionReportService().Export(exceptionReport,
                                                            ConfigurationManager.AppSettings["ExceptionReportFilePath"] + config.ExceptionReportFileName,
                                                            dataRows);
                    }
                    config.FailedRows    = failedRows;
                    config.ProcessedRows = processedRows;
                }
            }
        }