Exemplo n.º 1
0
 protected virtual void OnChangesApplied(ChangesAppliedEventArgs args)
 {
     if (ChangesApplied != null)
     {
         ChangesApplied(this, args);
     }
 }
Exemplo n.º 2
0
        private void SampleServerSyncProvider_ChangesApplied(object sender, ChangesAppliedEventArgs e)
        {
            //If _updateConflictGuids contains at least one GUID, update the UpdateId
            //column so that each change is downloaded to the client. For more
            //information, see SampleServerSyncProvider_ApplyChangeFailed.
            if (_updateConflictGuids.Count > 0)
            {
                SqlCommand updateTable = new SqlCommand();
                updateTable.Connection  = (SqlConnection)e.Connection;
                updateTable.Transaction = (SqlTransaction)e.Transaction;
                updateTable.CommandText = String.Empty;

                for (int i = 0; i < _updateConflictGuids.Count; i++)
                {
                    updateTable.CommandText +=
                        " UPDATE Sales.Customer SET UpdateId = '00000000-0000-0000-0000-000000000000' " +
                        " WHERE CustomerId='" + _updateConflictGuids[i].ToString() + "'";
                }

                updateTable.ExecuteNonQuery();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Applies inserts, updates, and deletes for a synchronization group to the server database.
        /// </summary>
        /// <param name="groupMetadata">A SyncGroupMetadata object that contains metadata about the synchronization group.</param>
        /// <param name="dataSet">A DataSet object that contains the changes to be applied to the server database for each table in 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>
        /// #UPLOAD 1
        public override SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession)
        {
            if (groupMetadata == null)
            {
                throw new ArgumentNullException("groupMetadata");
            }
            if (syncSession == null)
            {
                throw new ArgumentNullException("syncSession");
            }

            SyncContext syncContext = new SyncContext();

            groupMetadata = InitializeMetadata(groupMetadata, dataSet, syncContext);

            // connect to database
            Connection.Open();

            // create transaction

            ApplyingChangesEventArgs applyingArgs = new ApplyingChangesEventArgs(groupMetadata, dataSet, syncSession, syncContext, Connection, null);

            OnApplyingChanges(applyingArgs);

            ApplyChangesInternal(groupMetadata, dataSet, syncSession, syncContext);
            // commit transaction

            ChangesAppliedEventArgs appliedArgs = new ChangesAppliedEventArgs(groupMetadata, syncSession, syncContext, Connection, null);

            OnChangesApplied(appliedArgs);

            // disconnect from database
            Connection.Close();

            return(syncContext);
        }
Exemplo n.º 4
0
 protected override void OnChangesApplied(ChangesAppliedEventArgs value)
 {
     Console.Write("on changes applied on client..");
     base.OnChangesApplied(value);
 }
Exemplo n.º 5
0
        //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();
        }