Beispiel #1
0
        private void SyncCompletedCallback(IAsyncResult ar)
        {
            try
            {
                SqlCeReplication repl = (SqlCeReplication)ar.AsyncState;

                repl.EndSynchronize(ar);
                repl.SaveProperties();
                string result = "Successfully completed sync" + Environment.NewLine;
                result += string.Format("Number of changes downloaded: {0}{1}", repl.PublisherChanges.ToString(), Environment.NewLine);
                result += string.Format("Number of changes uploaded: {0}{1}", repl.SubscriberChanges.ToString(), Environment.NewLine);
                result += string.Format("Number of conflicts at Publisher:   {0}{1}", repl.PublisherConflicts.ToString(), Environment.NewLine);
#if V40
                SyncArgs4 args = new SyncArgs4(result, null);
#else
                SyncArgs args = new SyncArgs(result, null);
#endif
                Completed(this, args);
            }
            catch (SqlCeException e)
            {
#if V40
                SyncArgs4 args = new SyncArgs4("Errors occured during sync", e);
#else
                SyncArgs args = new SyncArgs("Errors occured during sync", e);
#endif
                Completed(this, args);
            }
        }
Beispiel #2
0
 internal void EndSync()
 {
     try
     {
         replication.EndSynchronize(asyncResult);
     }
     finally
     {
         asyncResult = null;
         replication.Dispose();
         replication = null;
     }
 }
Beispiel #3
0
        private void SyncCompletedCallback(IAsyncResult ar)
        {
            SqlCeReplication repl = (SqlCeReplication)ar.AsyncState;

            try
            {
                repl.EndSynchronize(ar);
                repl.SaveProperties();
                var result = "Successfully completed sync" + Environment.NewLine;
                result += string.Format("Number of changes downloaded: {0}{1}", repl.PublisherChanges.ToString(), Environment.NewLine);
                result += string.Format("Number of changes uploaded: {0}{1}", repl.SubscriberChanges.ToString(), Environment.NewLine);
                result += string.Format("Number of conflicts at Publisher:   {0}{1}", repl.PublisherConflicts.ToString(), Environment.NewLine);
                var args = new SyncArgs(result, null, 100, SyncStatus.SyncComplete, null);
                Completed?.Invoke(this, args);
                InsertSyncLog(_connection, _hostName, _additionalId, "Success", _additionalInfo);
            }
            catch (SqlCeException e)
            {
                InsertSyncLog(_connection, _hostName, _additionalId, "Error", _additionalInfo + Environment.NewLine + ShowErrors(e));
                SyncArgs args;
                if (e.NativeError == 29006)
                {
                    args = new SyncArgs("Publication may have expired, or the snapshot is invalid", new PublicationMayHaveExpiredException("Publication may have expired, or the snapshot is invalid", e), 100, SyncStatus.SyncFailed, null);
                }
                else
                {
                    args = new SyncArgs("Errors occured during sync", e, 100, SyncStatus.SyncFailed, null);
                }
                Completed?.Invoke(this, args);
            }
            finally
            {
                if (repl != null)
                {
                    repl.Dispose();
                }
                if (_connection != null)
                {
                    _connection.Close();
                    _connection.Dispose();
                }
            }
        }