protected virtual void OnChangesSelected(ChangesSelectedEventArgs args) { if (ChangesSelected != null) { ChangesSelected(this, args); } }
public void SampleServerSyncProvider_ChangesSelected(object sender, ChangesSelectedEventArgs e) { Console.WriteLine("Total number of batches: " + e.Context.BatchCount); Console.WriteLine("Changes applied for group " + e.GroupMetadata.GroupName); Console.WriteLine("Inserts applied for group: " + e.Context.GroupProgress.TotalInserts.ToString()); Console.WriteLine("Updates applied for group: " + e.Context.GroupProgress.TotalUpdates.ToString()); Console.WriteLine("Deletes applied for group: " + e.Context.GroupProgress.TotalDeletes.ToString()); }
/// <summary> /// Selects for a table in the server database the inserts, updates, and deletes to apply to the client database for a synchronization group. /// </summary> /// <param name="groupMetadata">A SyncGroupMetadata object that contains metadata about the synchronization group.</param> /// <param name="syncSession">A SyncSession object that contains synchronization session variables, such as the ID of the client that is synchronizing.</param> /// <returns>A SyncContext object that contains synchronization data and metadata.</returns> public override SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession) {//#DOWNLOAD a batch 1 if (groupMetadata == null) { throw new ArgumentNullException("groupMetadata"); } if (syncSession == null) { throw new ArgumentNullException("syncSession"); } SyncContext syncContext = new SyncContext(); DataSet dataSet = new DataSet(); groupMetadata = InitializeMetadata(groupMetadata, dataSet, syncContext); SelectingChangesEventArgs selectingArgs = new SelectingChangesEventArgs(groupMetadata, syncSession, syncContext, Connection, null); OnSelectingChanges(selectingArgs); SyncSchema schema = new SyncSchema(); Collection <string> tables = new Collection <string>(); Collection <string> missingTables = new Collection <string>(); foreach (var tableMetadata in groupMetadata.TablesMetadata) { tables.Add(tableMetadata.TableName); } if (tables.Count > 0) { schema = GetSchemaInternal(tables, out missingTables); } if (missingTables != null) { string[] tableArray = new string[missingTables.Count]; missingTables.CopyTo(tableArray, 0); SchemaException e = new SchemaException(String.Format(CultureInfo.CurrentCulture, Messages.MissingTables, String.Join(", ", tableArray))); e.SyncStage = SyncStage.ReadingSchema; e.ErrorNumber = SyncErrorNumber.MissingTableSchema; throw e; } // FIX: Get schema from somewhere (possibly the adapter or a temporary schema) // Possible performance hit when in mobile EnumerateChanges(groupMetadata, syncSession, syncContext, schema); ChangesSelectedEventArgs selectedArgs = new ChangesSelectedEventArgs(groupMetadata, syncSession, syncContext, Connection, null);//sYNC tODO OnChangesSelected(selectedArgs); return(syncContext); }
//Create client and server log files, and write to them //based on data from several EventArgs classes. public static void LogEvents(object sender, EventArgs e) { string logFile = String.Empty; string site = String.Empty; if (sender is SampleServerSyncProvider) { logFile = "ServerLogFile.txt"; site = "server"; } else if (sender is SampleClientSyncProvider) { logFile = "ClientLogFile.txt"; site = "client"; } StreamWriter streamWriter = File.AppendText(logFile); StringBuilder outputText = new StringBuilder(); if (e is ChangesSelectedEventArgs) { ChangesSelectedEventArgs args = (ChangesSelectedEventArgs)e; outputText.AppendLine("Client ID: " + args.Session.ClientId); outputText.AppendLine("Changes selected from " + site + " for group " + args.GroupMetadata.GroupName); outputText.AppendLine("Inserts selected from " + site + " for group: " + args.Context.GroupProgress.TotalInserts.ToString()); outputText.AppendLine("Updates selected from " + site + " for group: " + args.Context.GroupProgress.TotalUpdates.ToString()); outputText.AppendLine("Deletes selected from " + site + " for group: " + args.Context.GroupProgress.TotalDeletes.ToString()); } else if (e is ChangesAppliedEventArgs) { ChangesAppliedEventArgs args = (ChangesAppliedEventArgs)e; outputText.AppendLine("Client ID: " + args.Session.ClientId); outputText.AppendLine("Changes applied to " + site + " for group " + args.GroupMetadata.GroupName); outputText.AppendLine("Inserts applied to " + site + " for group: " + args.Context.GroupProgress.TotalInserts.ToString()); outputText.AppendLine("Updates applied to " + site + " for group: " + args.Context.GroupProgress.TotalUpdates.ToString()); outputText.AppendLine("Deletes applied to " + site + " for group: " + args.Context.GroupProgress.TotalDeletes.ToString()); } else if (e is SchemaCreatedEventArgs) { SchemaCreatedEventArgs args = (SchemaCreatedEventArgs)e; outputText.AppendLine("Schema creation for group: " + args.Table.SyncGroup.GroupName); outputText.AppendLine("Table: " + args.Table.TableName); outputText.AppendLine("Direction : " + args.Table.SyncDirection); outputText.AppendLine("Creation Option: " + args.Table.CreationOption); } //<snippetOCS_CS_Events_ApplyChangeFailedEventArgs> else if (e is ApplyChangeFailedEventArgs) { ApplyChangeFailedEventArgs args = (ApplyChangeFailedEventArgs)e; outputText.AppendLine("** APPLY CHANGE FAILURE AT " + site.ToUpper() + " **"); outputText.AppendLine("Table for which failure occurred: " + args.TableMetadata.TableName); outputText.AppendLine("Error message: " + args.Error.Message); } //</snippetOCS_CS_Events_ApplyChangeFailedEventArgs> else { outputText.AppendLine("Unknown event occurred"); } streamWriter.WriteLine(DateTime.Now.ToShortTimeString() + " | " + outputText.ToString()); streamWriter.Flush(); streamWriter.Dispose(); }