locked
Determining which tables were synchronized RRS feed

  • Question

  • Is there a way to determine which tables have or had changes either before or after a sync?

    In our application, certain data in cache in memory, and I would like to know what data needs to be refreshed from the local cash after a sync.  SyncStatistics appears to only give me broad information about the total number of changes up or down, and I would prefer not to refresh all my in memory data every time any change was pulled down. 

    Any ideas? Thanks!
    • Moved by Max Wang_1983 Friday, April 22, 2011 8:35 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Wednesday, February 27, 2008 10:53 PM

Answers

  • Hi Lee,

    in the current implementation you can subsribe to several event of the ClientSyncProvider (and the ServerSyncProvider has the same set of events). I have used a CustomClientSyncProvider (as in some of the demos) but you can use of course directly the ClientSyncProvider.

    Code snippet below:

    ((CustomClientSyncProvider)syncAgent.LocalProvider).OnChangesSelected += LogEvents;
    ((CustomClientSyncProvider)syncAgent.LocalProvider).OnChangesApplied +=   LogEvents;

    You can then get specific Information from the parameter Information like below ( if you are only interested in the tables use the args.Table property.

    Hope that helps

    Thomas

     public void LogEvents(object sender, EventArgs e)
            {
                string site = String.Empty;
                string logFile = "ClientLogFile.txt";
                site = "client";

                StreamWriter streamWriter = File.AppendText(logFile);
               
                if (e is ChangesSelectedEventArgs)
                {
                    ChangesSelectedEventArgs args = (ChangesSelectedEventArgs)e;
                    sessionId = args.Session.SessionId;
                    LogProtocol.Add("Client ID: " + args.Session.ClientId);
                    LogProtocol.Add("Changes selected from " + site + " for group " + args.GroupMetadata.GroupName);
          LogProtocol.Add("Inserts selected from " + site + " for group: " +  
          args.Context.GroupProgress.TotalInserts.ToString());
                    LogProtocol.Add("Updates selected from " + site + " for group: " +
          args.Context.GroupProgress.TotalUpdates.ToString());
                    LogProtocol.Add("Deletes selected from " + site + " for group: " +
                    args.Context.GroupProgress.TotalDeletes.ToString());
                }

                else if (e is ChangesAppliedEventArgs)
                {

                    ChangesAppliedEventArgs args = (ChangesAppliedEventArgs)e;
                    sessionId = args.Session.SessionId;
                    LogProtocol.Add("Client ID: " + args.Session.ClientId);
                    LogProtocol.Add("Changes applied to " + site + " for group " + args.GroupMetadata.GroupName);
                    LogProtocol.Add("Inserts applied to " + site + " for group: " + args.Context.GroupProgress.TotalInserts.ToString());
                    LogProtocol.Add("Updates applied to " + site + " for group: " + args.Context.GroupProgress.TotalUpdates.ToString());
                    LogProtocol.Add("Deletes applied to " + site + " for group: " + args.Context.GroupProgress.TotalDeletes.ToString());

                }

                else if (e is SchemaCreatedEventArgs)
                {

                    SchemaCreatedEventArgs args = (SchemaCreatedEventArgs)e;
                    LogProtocol.Add("Schema creation for group: " + args.Table.SyncGroup.GroupName);
                    LogProtocol.Add("Table: " + args.Table.TableName);
                    LogProtocol.Add("Direction : " + args.Table.SyncTableTransferOption);
                    LogProtocol.Add("Creation Option: " + args.Table.CreationOption);
                }

                else if (e is ApplyChangeFailedEventArgs)
                {

                    ApplyChangeFailedEventArgs args = (ApplyChangeFailedEventArgs)e;
                    sessionId = args.Session.SessionId;
                    LogProtocol.Add("** APPLY CHANGE FAILURE AT " + site.ToUpper() + " **");
                    LogProtocol.Add("Table for which failure occurred: " + args.TableMetadata.TableName);
                    LogProtocol.Add("Error message: " + args.Error.Message);

                }

                else
                {
                    LogProtocol.Add("Unknown event occurred");
                }

                streamWriter.WriteLine(DateTime.Now.ToShortTimeString() + " | " + LogProtocol.ToString());
                streamWriter.Flush();
                streamWriter.Dispose();
            }
        }
    Thursday, February 28, 2008 4:35 PM

All replies

  • Hi Lee,

    in the current implementation you can subsribe to several event of the ClientSyncProvider (and the ServerSyncProvider has the same set of events). I have used a CustomClientSyncProvider (as in some of the demos) but you can use of course directly the ClientSyncProvider.

    Code snippet below:

    ((CustomClientSyncProvider)syncAgent.LocalProvider).OnChangesSelected += LogEvents;
    ((CustomClientSyncProvider)syncAgent.LocalProvider).OnChangesApplied +=   LogEvents;

    You can then get specific Information from the parameter Information like below ( if you are only interested in the tables use the args.Table property.

    Hope that helps

    Thomas

     public void LogEvents(object sender, EventArgs e)
            {
                string site = String.Empty;
                string logFile = "ClientLogFile.txt";
                site = "client";

                StreamWriter streamWriter = File.AppendText(logFile);
               
                if (e is ChangesSelectedEventArgs)
                {
                    ChangesSelectedEventArgs args = (ChangesSelectedEventArgs)e;
                    sessionId = args.Session.SessionId;
                    LogProtocol.Add("Client ID: " + args.Session.ClientId);
                    LogProtocol.Add("Changes selected from " + site + " for group " + args.GroupMetadata.GroupName);
          LogProtocol.Add("Inserts selected from " + site + " for group: " +  
          args.Context.GroupProgress.TotalInserts.ToString());
                    LogProtocol.Add("Updates selected from " + site + " for group: " +
          args.Context.GroupProgress.TotalUpdates.ToString());
                    LogProtocol.Add("Deletes selected from " + site + " for group: " +
                    args.Context.GroupProgress.TotalDeletes.ToString());
                }

                else if (e is ChangesAppliedEventArgs)
                {

                    ChangesAppliedEventArgs args = (ChangesAppliedEventArgs)e;
                    sessionId = args.Session.SessionId;
                    LogProtocol.Add("Client ID: " + args.Session.ClientId);
                    LogProtocol.Add("Changes applied to " + site + " for group " + args.GroupMetadata.GroupName);
                    LogProtocol.Add("Inserts applied to " + site + " for group: " + args.Context.GroupProgress.TotalInserts.ToString());
                    LogProtocol.Add("Updates applied to " + site + " for group: " + args.Context.GroupProgress.TotalUpdates.ToString());
                    LogProtocol.Add("Deletes applied to " + site + " for group: " + args.Context.GroupProgress.TotalDeletes.ToString());

                }

                else if (e is SchemaCreatedEventArgs)
                {

                    SchemaCreatedEventArgs args = (SchemaCreatedEventArgs)e;
                    LogProtocol.Add("Schema creation for group: " + args.Table.SyncGroup.GroupName);
                    LogProtocol.Add("Table: " + args.Table.TableName);
                    LogProtocol.Add("Direction : " + args.Table.SyncTableTransferOption);
                    LogProtocol.Add("Creation Option: " + args.Table.CreationOption);
                }

                else if (e is ApplyChangeFailedEventArgs)
                {

                    ApplyChangeFailedEventArgs args = (ApplyChangeFailedEventArgs)e;
                    sessionId = args.Session.SessionId;
                    LogProtocol.Add("** APPLY CHANGE FAILURE AT " + site.ToUpper() + " **");
                    LogProtocol.Add("Table for which failure occurred: " + args.TableMetadata.TableName);
                    LogProtocol.Add("Error message: " + args.Error.Message);

                }

                else
                {
                    LogProtocol.Add("Unknown event occurred");
                }

                streamWriter.WriteLine(DateTime.Now.ToShortTimeString() + " | " + LogProtocol.ToString());
                streamWriter.Flush();
                streamWriter.Dispose();
            }
        }
    Thursday, February 28, 2008 4:35 PM
  • That works perfectly!  Thanks Thomas!

    Lee
    Saturday, March 1, 2008 12:07 AM