/// <summary>
        ///     Create a delegate to convert data after reading from the database.
        /// </summary>
        /// <param name="dataTable">The data table.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private Func <Guid, Guid, object, object> GetDataConverter(string dataTable, IProcessingContext context)
        {
            Func <Guid, Guid, object, object> converter;

            switch (dataTable)
            {
            case "Xml":

                /////
                // Use Xml processor to remap EntityRefs located in XML
                /////
                var xmlProcessor = new XmlFieldProcessor
                {
                    ConversionMode    = XmlConversionMode.LocalIdToUpgradeGuid,
                    TenantId          = TenantId,
                    DatabaseContext   = DatabaseContext,
                    ProcessingContext = context
                };

                converter = (entityUpgradeId, fieldUpgradeId, value) => xmlProcessor.RemapXmlEntities(entityUpgradeId, fieldUpgradeId, ( string )value);
                break;

            default:
                converter = (entityUpgradeId, fieldUpgradeId, value) => value;
                break;
            }

            return(converter);
        }
Beispiel #2
0
        /// <summary>
        ///     Writes the field data for the XML table.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="context">The context.</param>
        private void WriteFieldData_Xml(IEnumerable <DataEntry> data, IProcessingContext context)
        {
            /////
            // Use Xml processor to remap EntityRefs located in XML
            /////
            var xmlProcessor = new XmlFieldProcessor(null, null, _upgradeToIdMap)
            {
                ConversionMode    = XmlConversionMode.UpgradeGuidToLocalId,
                TenantId          = TenantId,
                DatabaseContext   = DatabaseContext,
                ProcessingContext = context
            };

            Func <DataColumn[]> getColumnsAction = () => new[]
            {
                new DataColumn("EntityId", typeof(long))
                {
                    AllowDBNull = false
                },
                new DataColumn("FieldId", typeof(long))
                {
                    AllowDBNull = false
                },
                new DataColumn("Data", Helpers.FieldDataTableTypes["Xml"])
                {
                    AllowDBNull = true
                }
            };

            Func <DataEntry, DataRow, PopulateRowResult> populateRowAction = (entry, row) =>
            {
                long val;

                if (!_upgradeToIdMap.TryGetValue(entry.EntityId, out val))
                {
                    return(PopulateRowResult.MissingEntityDependency);
                }

                row[0] = val;

                if (!_upgradeToIdMap.TryGetValue(entry.FieldId, out val))
                {
                    return(PopulateRowResult.MissingFieldDependency);
                }

                row[1] = val;
                row[2] = entry.Data == null ? DBNull.Value : ( object )xmlProcessor.RemapXmlEntities(entry.EntityId, entry.FieldId, ( string )entry.Data);

                return(PopulateRowResult.Success);
            };

            var executionArguments = new ExecutionArguments <DataEntry>
            {
                Entries            = data,
                GetColumnsAction   = getColumnsAction,
                TableName          = "Xml",
                Context            = context,
                PopulateRowAction  = populateRowAction,
                CommandText        = string.Format(CommandText.TenantMergeTargetWriteFieldCommandText, "Xml", string.Empty, string.Empty, string.Empty, string.Empty),
                ExecuteAction      = ExecuteAction.Writing,
                SetupCommandAction = c => c.AddParameterWithValue("@tenant", TenantId)
            };

            Execute(executionArguments);
        }