/// <summary>
        /// Run BLOBPointer converter before mapping
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="sourceDatabase"></param>
        /// <param name="destinationDatabase"></param>
        /// <param name="obj"></param>
        public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj)
        {
            //
            // Cast type
            DatabaseConversion.CleanerTool.EclipseDataAccess.general_insurance_workbooks record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.general_insurance_workbooks;

            //
            // Run blob pointer converter if needed
            if (record.geninswb_document_object_eclipse != null && !IgnoreBlobs)
            {
                string blobPointer = BlobConverter.ConvertToFile(BlobStoreCategories.POLICY_TRANSACTION, BlobStoreCategories.POLICY_TRANSACTION, record.geninswb_document_object_eclipse);
                this._documentFilePath.Add(record.geninswb_id, blobPointer);
            }
            if (record.geninswb_portfolio_object_eclipse != null && !IgnoreBlobs)
            {
                string blobPointer = BlobConverter.ConvertToFile(BlobStoreCategories.POLICY_TRANSACTION, BlobStoreCategories.POLICY_TRANSACTION, record.geninswb_portfolio_object_eclipse);
                this._portfolioFilePath.Add(record.geninswb_id, blobPointer);
            }
            if (record.geninswb_coc_eclipse != null && !IgnoreBlobs)
            {
                string blobPointer = BlobConverter.ConvertToFile(BlobStoreCategories.POLICY_TRANSACTION, BlobStoreCategories.POLICY_TRANSACTION, record.geninswb_coc_eclipse);
                this._cocFilePath.Add(record.geninswb_id, blobPointer);
            }
            if (record.geninswb_object_eclipse != null && !IgnoreBlobs)
            {
                string blobPointer = BlobConverter.ConvertToFile(BlobStoreCategories.POLICY_TRANSACTION, BlobStoreCategories.POLICY_TRANSACTION, record.geninswb_object_eclipse);
                this._objectFilePath.Add(record.geninswb_id, blobPointer);
            }
        }
        /// <summary>
        /// Saves Blob to file -> returns Blob pointer -> generates script insert for blobs as PK|BlobPointer to keep track
        /// After migrating data for a table (which contains Blob), will need this data to set Blob pointer
        /// </summary>
        /// <param name="blobMappings">The BLOB mappings.</param>
        /// <returns></returns>
        private bool HandleBlobFields(List <FieldMappingDefinition> blobMappings, out string blobScript)
        {
            Console.WriteLine("Handling Blob for " + _definition.SourceTable.Name);

            blobScript = "";
            string        insertScript        = string.Format(SqlScriptTemplates.INSERT, "[TempDatabase].dbo.[BlobPointers]", "([PKValue], [BlobFieldName], [BlobPointer])");
            StringBuilder valuesScriptBuilder = new StringBuilder();

            blobMappings.ForEach(m =>
            {
                var blobs = _sourceDatabase.GetBlobs(_definition.SourceTable.Name, m.SourceField.Name);
                blobs.ForEach(b =>
                {
                    byte[] data        = b.Value;
                    string blobPointer = BlobConverter.ConvertToFile(m.BlobCategory, m.BlobCategory, data);

                    valuesScriptBuilder.Append(Environment.NewLine + string.Format("('{0}','{1}','{2}')", b.Key, m.SourceField.Name, blobPointer) + ",");
                });
            });

            if (valuesScriptBuilder.Length == 0)
            {
                return(false);
            }

            string valuesScript = valuesScriptBuilder.ToString().Trim(',');

            blobScript = insertScript + Environment.NewLine + string.Format(SqlScriptTemplates.INSERT_VALUES, valuesScript);
            return(true);
        }
        /// <summary>
        /// Run BLOBPointer converter before mapping
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="sourceDatabase"></param>
        /// <param name="destinationDatabase"></param>
        /// <param name="obj"></param>
        public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj)
        {
            //
            // Cast type
            DatabaseConversion.CleanerTool.EclipseDataAccess.confirmation_of_cover record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.confirmation_of_cover;

            //
            // Run blob pointer converter if needed
            if (record.coc_document_object_eclipse != null && !IgnoreBlobs)
            {
                string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.CONFIRMATION_OF_COVER, BlobStoreCategories.CONFIRMATION_OF_COVER, record.coc_document_object_eclipse);
                this._temporyFilePath.Add(record.coc_id, fullPath);
            }
        }
示例#4
0
        /// <summary>
        /// Run BLOBPointer converter before mapping
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="sourceDatabase"></param>
        /// <param name="destinationDatabase"></param>
        /// <param name="obj"></param>
        public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj)
        {
            //
            // Cast type
            DatabaseConversion.CleanerTool.EclipseDataAccess.gen_ins_documents record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.gen_ins_documents;

            //
            // Run blob pointer converter if needed
            if (record.geninsdo_object_eclipse != null && !IgnoreBlobs)
            {
                string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.POLICY_TASK_TEMPLATE, BlobStoreCategories.POLICY_TASK_TEMPLATE, record.geninsdo_object_eclipse);
                this._temporyFilePath.Add(record.geninsdo_id, fullPath);
            }
        }
        /// <summary>
        /// Run BLOBPointer converter before mapping
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="sourceDatabase"></param>
        /// <param name="destinationDatabase"></param>
        /// <param name="obj"></param>
        public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj)
        {
            //
            // Cast type
            DatabaseConversion.CleanerTool.EclipseDataAccess.client_insurance_portfolio record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.client_insurance_portfolio;

            //
            // Run blob pointer converter if needed
            if (record.cip_document_object_eclipse != null && !IgnoreBlobs)
            {
                string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.CLIENT_INSURANCE_PORTFOLIO, BlobStoreCategories.CLIENT_INSURANCE_PORTFOLIO, record.cip_document_object_eclipse);
                this._temporyFilePath.Add(record.cip_id, fullPath);
            }
        }
        /// <summary>
        /// Run BLOBPointer converter before mapping
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="sourceDatabase"></param>
        /// <param name="destinationDatabase"></param>
        /// <param name="obj"></param>
        public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj)
        {
            //
            // Cast type
            DatabaseConversion.CleanerTool.EclipseDataAccess.tasks_sub_tasks record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.tasks_sub_tasks;

            //
            // Run blob pointer converter if needed
            if (record.tassubta_image != null && !IgnoreBlobs)
            {
                string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.CLIENT_TASK_DOCUMENT, BlobStoreCategories.CLIENT_TASK_DOCUMENT, record.tassubta_image);
                this._temporyFilePath.Add(record.tassubta_id, fullPath);
            }
        }
        /// <summary>
        /// Run BLOBPointer converter before mapping
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="sourceDatabase"></param>
        /// <param name="destinationDatabase"></param>
        /// <param name="obj"></param>
        public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj)
        {
            //
            // Cast type
            DatabaseConversion.CleanerTool.EclipseDataAccess.notes record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.notes;

            //
            // Run blob pointer converter if needed
            if (record.not_object != null && !IgnoreBlobs)
            {
                string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.NOTE, BlobStoreCategories.NOTE, record.not_object);
                this._temporyFilePath.Add(record.not_id, fullPath);
            }
        }
        /// <summary>
        /// Run BLOBPointer converter before mapping
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="sourceDatabase"></param>
        /// <param name="destinationDatabase"></param>
        /// <param name="obj"></param>
        public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj)
        {
            //
            // Cast type
            DatabaseConversion.CleanerTool.EclipseDataAccess.DocumentRepository record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.DocumentRepository;

            //
            // Run blob pointer converter if needed
            if (record.dr_document != null && !IgnoreBlobs)
            {
                string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.DOCUMENT_REPOSITORY, BlobStoreCategories.DOCUMENT_REPOSITORY, record.dr_document);
                this._temporyFilePath.Add(record.dr_id, fullPath);
            }
        }
示例#9
0
        public string GenerateBlobFieldUpdateScript()
        {
            string result = "";

            List <FieldMappingDefinition> blobMappings = GetBlobMappings();

            if (blobMappings.Any())
            {
                // Create temp table to store blob pointer
                string createTempTableScript   = @"CREATE TABLE #Temp (Id int, Value varchar(MAX))";
                string insertScript            = string.Format(SqlTemplates.INSERT, "#Temp", "[Id], [Value]");
                string dropTempTableScript     = @"DROP TABLE #Temp";
                string truncateTempTableScript = @"TRUNCATE TABLE #Temp";

                int    emptyBlobsCount = 0;
                string script          = "";
                Field  destPK          = _definition.DestinationTable.GetPrimaryKey();
                blobMappings.ForEach(m =>
                {
                    // Insert blob value into temp table
                    List <KeyValuePair <int, byte[]> > blobs;
                    if (!string.IsNullOrEmpty(m.GetBlobScriptPath)) // if explicit sql is provided to get blobs, use it
                    {
                        string sql = File.ReadAllText(m.GetBlobScriptPath);
                        blobs      = _definition.SourceTable.GetBlobs(m.SourceField.Name, sql);
                    }
                    else
                    {
                        blobs = _definition.SourceTable.GetBlobs(m.SourceField.Name);
                    }

                    if (blobs.Any())
                    {
                        StringBuilder valuesScriptBuilder = new StringBuilder();
                        if (m.Type == FieldMappingType.BlobToBlobPointer)
                        {
                            blobs.ForEach(b =>
                            {
                                byte[] data = b.Value;
                                if (data != null)
                                {
                                    string blobPointer = BlobConverter.ConvertToFile(m.BlobCategory, m.BlobCategory, data);
                                    valuesScriptBuilder.Append(Environment.NewLine + string.Format("('{0}','{1}')", b.Key, blobPointer) + ",");
                                }
                            });
                        }
                        else if (m.Type == FieldMappingType.BlobToHtml)
                        {
                            blobs.ForEach(b =>
                            {
                                byte[] data = b.Value;
                                if (data != null)
                                {
                                    string blobHtml = WordGenerator.ConvertRtfToHtml(WordGenerator.ConvertDocxToRTF(data));
                                    valuesScriptBuilder.Append(Environment.NewLine + string.Format("('{0}','{1}')", b.Key, blobHtml) + ",");
                                }
                            });
                        }

                        string valuesScript            = valuesScriptBuilder.ToString().Trim(',');
                        string insertBlobPointerScript = insertScript + NewLines(1) + string.Format(SqlTemplates.INSERT_VALUES, valuesScript);

                        // Merge blob pointer into destination table
                        string mergeBlobPointerScript = SqlTemplates.MERGE_UPDATE.Inject(new
                        {
                            TargetTable = _definition.DestinationTable.FullName,
                            SourceTable = "#Temp",
                            TargetPK    = destPK.Name,
                            SourcePK    = "Id",
                            TargetField = m.DestinationField.Name,
                            SourceField = "Value"
                        });

                        script += insertBlobPointerScript + NewLines(2) + mergeBlobPointerScript + NewLines(2) + truncateTempTableScript + NewLines(2);
                    }
                    else
                    {
                        emptyBlobsCount++;
                    }
                });

                // Prevent there is no blobs to update
                if (emptyBlobsCount < blobMappings.Count)
                {
                    result = createTempTableScript + NewLines(2) + script + dropTempTableScript;
                }
            }

            return(result);
        }