private void to_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e) { var toProvider = sender as RelationalSyncProvider; #if DEBUG if (toProvider.ScopeName == Scope.Icd.ToScopeString()) { return; } #endif if (e.Conflict.Type == DbConflictType.ErrorsOccurred) { Poster.PostMessage("ApplyChangeFailed. Error: {0}", e.Error); } else if (SyncTracer.IsVerboseEnabled() == false) { SyncTracer.Warning(1, "CONFLICT DETECTED FOR CLIENT {0}", toProvider.Connection); SyncTracer.Warning(2, "** Local change **"); SyncTracer.Warning(2, TableToStr(e.Conflict.LocalChange)); SyncTracer.Warning(2, "** Remote change **"); SyncTracer.Warning(2, TableToStr(e.Conflict.RemoteChange)); } if (!ConflictsCounter.Keys.Contains(e.Conflict.Type)) { ConflictsCounter[e.Conflict.Type] = 0; } ConflictsCounter[e.Conflict.Type]++; if (e.Conflict.Type != DbConflictType.ErrorsOccurred) { e.Action = ApplyAction.RetryWithForceWrite; } }
private static bool ProvisionSqlCe(SqlCeConnection con, Scope scope, DbConnection conToGetScopeDescr) { var sqlceProv = new SqlCeSyncScopeProvisioning(con); sqlceProv.ObjectPrefix = prefix; if (!sqlceProv.ScopeExists(scope.ToScopeString())) { var scopeDescr = new DbSyncScopeDescription(scope.ToScopeString()); var failedTables = AddTablesToScopeDescr(scope.ToTableNames(), scopeDescr, con); if (failedTables.Count > 0 && conToGetScopeDescr != null) { Poster.PostMessage("GetScopeDescription for scope '{0}' from '{1}'", scope.ToScopeString(), conToGetScopeDescr.ConnectionString); //use scope description from server to intitialize the client scopeDescr = GetScopeDescription(scope, conToGetScopeDescr); } sqlceProv.PopulateFromScopeDescription(scopeDescr); sqlceProv.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting); sqlceProv.Apply(); return(true); } return(false); }
public static void Provision(DbConnection con, Scope scope, DbConnection conToGetScopeDescr) { try { var applied = false; if (con is SqlCeConnection) { applied = ProvisionSqlCe(con as SqlCeConnection, scope, conToGetScopeDescr); } else if (con is SqlConnection) { applied = ProvisionSqlServer(con as SqlConnection, scope); } if (applied) { Poster.PostMessage("Provisioned scope '{0}' in '{1}'\n", scope.ToScopeString(), con.ConnectionString); } else { Poster.PostMessage("Scope '{0}' exists in '{1}'\n", scope.ToScopeString(), con.ConnectionString); } } catch (Exception ex) { Poster.PostMessage(ex); } }
/// <summary> /// Добавляет таблицы в область синхронизации. /// </summary> /// <param name="tableNames"></param> /// <param name="scope"></param> /// <param name="connection"></param> /// <returns>Таблицы, которые не были добавлены.</returns> private static IList <string> AddTablesToScopeDescr(IEnumerable <string> tableNames, DbSyncScopeDescription scope, DbConnection connection) { var failed = new List <string>(); Poster.PostMessage("Adding tables to scope '{0}' in '{1}'...", scope.ScopeName, connection.ConnectionString); foreach (var name in tableNames) { try { DbSyncTableDescription desc; // не создаем описание для таблицы повторно, после провизионирования другой области с этой таблицей var nameWithSchema = connection is SqlCeConnection ? name : name.GetSchemaForTable() + '.' + name; var nameWithConn = connection.ConnectionString + nameWithSchema; if (!map.TryGetValue(nameWithConn, out desc)) { if (connection is SqlCeConnection) { desc = SqlCeSyncDescriptionBuilder.GetDescriptionForTable(nameWithSchema, connection as SqlCeConnection); } else if (connection is SqlConnection) { desc = SqlSyncDescriptionBuilder.GetDescriptionForTable(nameWithSchema, connection as SqlConnection); } map[nameWithConn] = desc; } else { Poster.PostMessage("Reuse created Description For Table '{0}'", name); } desc.GlobalName = name; scope.Tables.Add(desc); Poster.PostMessage("Table '{0}' added, columns: {1}", name, string.Join(", ", desc.Columns.Select(x => x.UnquotedName))); } catch (Exception ex) { Poster.PostMessage(ex); failed.Add(name); } } return(failed); }
public static void Deprovision(DbConnection con, Scope scope) { try { if (con is SqlCeConnection) { DeprovisionSqlCe(con as SqlCeConnection, scope.ToScopeString()); } else if (con is SqlConnection) { DeprovisionSqlServer(con as SqlConnection, scope.ToScopeString()); } Poster.PostMessage("Deprovisioned '{0}'\n", scope.ToScopeString()); } catch (Exception ex) { Poster.PostMessage(ex); } }
public DownloadSyncOrchestrator(RelationalSyncProvider from, RelationalSyncProvider to) { ConflictsCounter = new Dictionary <DbConflictType, int>(); AddedIdsPerTable = new Dictionary <string, IEnumerable <object> >(); DeletedIdsPerTable = new Dictionary <string, IEnumerable <object> >(); this.RemoteProvider = from; this.LocalProvider = to; this.Direction = SyncDirectionOrder.Download; from.ChangesSelected += from_ChangesSelected; to.ApplyChangeFailed += to_ApplyChangeFailed; to.ChangesApplied += to_ChangesApplied; to.DbConnectionFailure += (s, e) => { Poster.PostMessage("DbConnectionFailure: {0}", e.FailureException.Message); }; TablesTrackAdding = Enumerable.Empty <string>(); TablesTrackDeleting = Enumerable.Empty <string>(); TableToIdsForSync = new Dictionary <string, IEnumerable <object> >(); TablesToIgnoreAddingFilter = new Dictionary <string, Func <DataRow, bool> >(); TableRowsShaper = new Dictionary <string, Action <DataRow> >(); }