Exemple #1
0
        public static void SerializeInDmSet(DmSet set, ServiceConfiguration configuration)
        {
            if (set == null)
            {
                return;
            }

            DmTable dmTableConfiguration    = null;
            DmTable dmTableFilterParameters = null;
            DmTable dmTableTables           = null;

            if (!set.Tables.Contains("DotmimSync__ServiceConfiguration"))
            {
                dmTableConfiguration = new DmTable("DotmimSync__ServiceConfiguration");
                set.Tables.Add(dmTableConfiguration);
            }

            dmTableConfiguration = set.Tables["DotmimSync__ServiceConfiguration"];

            dmTableConfiguration.Clear();
            dmTableConfiguration.Columns.Clear();

            dmTableConfiguration.Columns.Add <String>("BatchDirectory");
            dmTableConfiguration.Columns.Add <Int32>("ConflictResolutionPolicy");
            dmTableConfiguration.Columns.Add <Int32>("DownloadBatchSizeInKB");
            dmTableConfiguration.Columns.Add <Boolean>("EnableDiagnosticPage");
            dmTableConfiguration.Columns.Add <Boolean>("UseBulkOperations");
            dmTableConfiguration.Columns.Add <Boolean>("UseVerboseErrors");
            dmTableConfiguration.Columns.Add <Boolean>("OverwriteConfiguration");
            dmTableConfiguration.Columns.Add <Int32>("SerializationConverter");

            var dmRowConfiguration = dmTableConfiguration.NewRow();

            dmRowConfiguration["BatchDirectory"]           = configuration.BatchDirectory;
            dmRowConfiguration["ConflictResolutionPolicy"] = configuration.ConflictResolutionPolicy;
            dmRowConfiguration["DownloadBatchSizeInKB"]    = configuration.DownloadBatchSizeInKB;
            dmRowConfiguration["EnableDiagnosticPage"]     = configuration.EnableDiagnosticPage;
            dmRowConfiguration["UseBulkOperations"]        = configuration.UseBulkOperations;
            dmRowConfiguration["UseVerboseErrors"]         = configuration.UseVerboseErrors;
            dmRowConfiguration["OverwriteConfiguration"]   = configuration.OverwriteConfiguration;
            dmRowConfiguration["SerializationConverter"]   = configuration.SerializationConverter;
            dmTableConfiguration.Rows.Add(dmRowConfiguration);

            if (configuration.ScopeSet != null && configuration.ScopeSet.Tables.Count > 0)
            {
                foreach (var dmTable in configuration.ScopeSet.Tables)
                {
                    var dmTableConf = dmTable.Clone();
                    set.Tables.Add(dmTableConf);
                }
            }

            if (configuration.FilterParameters != null && configuration.FilterParameters.Count > 0)
            {
                if (!set.Tables.Contains("DotmimSync__FilterParameter"))
                {
                    dmTableFilterParameters = new DmTable("DotmimSync__FilterParameter");
                    set.Tables.Add(dmTableFilterParameters);
                }

                dmTableFilterParameters = set.Tables["DotmimSync__FilterParameter"];
                dmTableFilterParameters.Columns.Add <String>("Name");
                dmTableFilterParameters.Columns.Add <String>("Value");
                dmTableFilterParameters.Columns.Add <String>("ValueType");

                DmSerializer serializer = new DmSerializer();

                foreach (var p in configuration.FilterParameters)
                {
                    var dmRowFilter = dmTableFilterParameters.NewRow();
                    dmRowFilter["Name"] = p.Name;

                    var objType   = p.Value.GetType();
                    var converter = objType.GetConverter();

                    dmRowFilter["Value"]     = converter.ConvertToInvariantString(p.Value);
                    dmRowFilter["ValueType"] = objType.GetAssemblyQualifiedName();
                    dmTableFilterParameters.Rows.Add(dmRowFilter);
                }
            }

            if (configuration.Tables != null && configuration.Tables.Length > 0)
            {
                if (!set.Tables.Contains("DotmimSync__Table"))
                {
                    dmTableTables = new DmTable("DotmimSync__Table");
                    set.Tables.Add(dmTableTables);
                }

                dmTableTables = set.Tables["DotmimSync__Table"];
                dmTableTables.Columns.Add <String>("Name");

                foreach (var p in configuration.Tables)
                {
                    var dmRowTable = dmTableTables.NewRow();
                    dmRowTable["Name"] = p;
                    dmTableTables.Rows.Add(dmRowTable);
                }
            }
        }
Exemple #2
0
        public static ServiceConfiguration DeserializeFromDmSet(DmSet set)
        {
            if (set == null)
            {
                return(null);
            }

            if (!set.Tables.Contains("DotmimSync__ServiceConfiguration"))
            {
                return(null);
            }

            ServiceConfiguration configuration = new ServiceConfiguration();
            var dmRowConfiguration             = set.Tables["DotmimSync__ServiceConfiguration"].Rows[0];

            configuration.BatchDirectory           = dmRowConfiguration["BatchDirectory"] as String;;
            configuration.ConflictResolutionPolicy = (ConflictResolutionPolicy)dmRowConfiguration["ConflictResolutionPolicy"];
            configuration.DownloadBatchSizeInKB    = (int)dmRowConfiguration["DownloadBatchSizeInKB"];
            configuration.EnableDiagnosticPage     = (bool)dmRowConfiguration["EnableDiagnosticPage"];
            configuration.UseBulkOperations        = (bool)dmRowConfiguration["UseBulkOperations"];
            configuration.UseVerboseErrors         = (bool)dmRowConfiguration["UseVerboseErrors"];
            configuration.OverwriteConfiguration   = (bool)dmRowConfiguration["OverwriteConfiguration"];
            configuration.SerializationConverter   = (SerializationFormat)dmRowConfiguration["SerializationConverter"];

            if (set.Tables.Contains("DotmimSync__FilterParameter"))
            {
                configuration.FilterParameters = new List <SyncParameter>();
                var dmTableFilterParameters = set.Tables["DotmimSync__FilterParameter"];

                foreach (var dmRowFilter in dmTableFilterParameters.Rows)
                {
                    SyncParameter syncParameter = new SyncParameter();
                    syncParameter.Name = dmRowFilter["Name"] as String;

                    var valueType = dmRowFilter["ValueType"] as String;
                    var value     = dmRowFilter["Value"] as String;
                    var objType   = DmUtils.GetTypeFromAssemblyQualifiedName(valueType);
                    var converter = objType.GetConverter();
                    var objValue  = converter.ConvertFromInvariantString(valueType);
                    syncParameter.Value = objValue;

                    configuration.FilterParameters.Add(syncParameter);
                }
            }

            if (set.Tables.Contains("DotmimSync__Table"))
            {
                var dmTableTables = set.Tables["DotmimSync__Table"];
                configuration.Tables = new string[dmTableTables.Rows.Count];

                for (int i = 0; i < dmTableTables.Rows.Count; i++)
                {
                    var dmRowTable = dmTableTables.Rows[i];
                    var tableName  = dmRowTable["Name"] as String;
                    configuration.Tables[i] = tableName;
                }
            }

            var configTables = set.Tables.Where(tbl => !tbl.TableName.StartsWith("DotmimSync__"));

            if (configTables != null)
            {
                foreach (var configTable in configTables)
                {
                    configuration.ScopeSet.Tables.Add(configTable.Clone());
                }
            }

            return(configuration);
        }