Exemple #1
0
 public SyncException(String message, SyncStage stage, string providerName, SyncExceptionType type = SyncExceptionType.Unknown, int errorCode = -1) : base(message)
 {
     this.SyncStage    = stage;
     this.ProviderName = providerName;
     this.ErrorCode    = errorCode;
     this.Type         = type;
 }
Exemple #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 public BaseProgressEventArgs(string providerTypeName, SyncStage stage, DbConnection connection, DbTransaction transaction)
 {
     this.ProviderTypeName = providerTypeName;
     this.Stage            = stage;
     this.Connection       = connection;
     this.Transaction      = transaction;
 }
Exemple #3
0
 protected SyncException(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     this.Type         = (SyncExceptionType)info.GetInt32("SyncType");
     this.SyncStage    = (SyncStage)info.GetInt32("SyncStage");
     this.ErrorCode    = info.GetInt32("ErrorCode");
     this.ProviderName = info.GetString("ProviderName");
 }
Exemple #4
0
        internal static SyncException CreateArgumentException(SyncStage syncStage, string paramName, string message = null)
        {
            var           m             = message ?? $"Argument exception on parameter {paramName}";
            SyncException syncException = new SyncException(m, syncStage, SyncExceptionType.Argument);

            syncException.Argument = paramName;
            return(syncException);
        }
Exemple #5
0
        public SyncException(Exception exception, SyncStage stage = SyncStage.None) : base(exception.Message, exception)
        {
            this.SyncStage = stage;

            if (exception is null)
            {
                return;
            }

            this.TypeName = exception.GetType().Name;
        }
Exemple #6
0
 public SyncProgressEvent(SyncStage stage, TimeSpan duration, Boolean isLastBatch = true,
                          ICollection <IOfflineEntity> changes      = null,
                          ICollection <Conflict> conflicts          = null,
                          ICollection <IOfflineEntity> updatedItems = null)
 {
     this.SyncStage   = stage;
     this.Duration    = duration;
     this.IsLastBatch = IsLastBatch;
     this.Changes     = changes;
     this.Conflicts   = conflicts;
     this.UpdatedItemsAfterInsertOnServer = updatedItems;
 }
        public SyncProgressEvent(SyncStage stage, TimeSpan duration, Boolean isLastBatch = true,
                                 ICollection<IOfflineEntity> changes = null,
                                 ICollection<Conflict> conflicts = null,
                                 ICollection<IOfflineEntity> updatedItems = null)
        {
            this.SyncStage = stage;
            this.Duration = duration;
            this.IsLastBatch = IsLastBatch;
            this.Changes = changes;
            this.Conflicts = conflicts;
            this.UpdatedItemsAfterInsertOnServer = updatedItems;

        }
Exemple #8
0
        internal static SessionVariableException FailedToMapOriginatorId(SyncStage stage, string source, string helpLink)
        {
            SessionVariableException variableException = new SessionVariableException(SyncResource.GetString("FailedToMapOriginatorId"));

            variableException.ErrorNumber = SyncErrorNumber.MissingSessionVariable;
            variableException.SyncSource  = source;
            variableException.HelpLink    = helpLink;
            variableException.SyncStage   = stage;
            SyncTracer.Warning("{0}", new object[1]
            {
                (object)variableException
            });
            return(variableException);
        }
        /// <summary>
        /// Try to raise a generalist progress event
        /// </summary>
        private void TryRaiseProgressEvent(SyncStage stage, String message, Dictionary <String, String> properties = null)
        {
            ProgressEventArgs progressEventArgs = new ProgressEventArgs(this.ProviderTypeName, stage, message);

            if (properties != null)
            {
                progressEventArgs.Properties = properties;
            }

            SyncProgress?.Invoke(this, progressEventArgs);

            if (progressEventArgs.Action == ChangeApplicationAction.Rollback)
            {
                throw new RollbackException();
            }
        }
        /// <summary>
        /// Try to raise a generalist progress event
        /// </summary>
        private void TryRaiseProgressEvent(SyncStage stage, string message, Dictionary <string, string> properties = null, DbConnection connection = null, DbTransaction transaction = null)
        {
            var progressEventArgs = new ProgressEventArgs(this.ProviderTypeName, stage, message, connection, transaction);

            if (properties != null)
            {
                progressEventArgs.Properties = properties;
            }

            SyncProgress?.Invoke(this, progressEventArgs);

            if (progressEventArgs.Action == ChangeApplicationAction.Rollback)
            {
                throw new RollbackException();
            }
        }
Exemple #11
0
        internal static SchemaException PrimaryKeyNotFoundError(string tableName, SyncStage stage, string source, string helpLink)
        {
            SchemaException schemaException = new SchemaException(SyncResource.FormatString("PrimaryKeyNotFound", new object[1]
            {
                (object)tableName
            }));

            schemaException.SyncSource  = source;
            schemaException.SyncStage   = stage;
            schemaException.ErrorNumber = SyncErrorNumber.PrimaryKeyNotFound;
            schemaException.HelpLink    = helpLink;
            schemaException.TableName   = tableName;
            SyncTracer.Warning("{0}", new object[1]
            {
                (object)schemaException
            });
            return(schemaException);
        }
Exemple #12
0
        internal static SchemaException ClientSchemaNotMatchError(string tableName, SyncStage stage, string source, string helpLink)
        {
            SchemaException schemaException = new SchemaException(SyncResource.FormatString("ApplyChanges_ClientSchemaNotMatchError", new object[1]
            {
                (object)tableName
            }));

            schemaException.SyncSource  = source;
            schemaException.SyncStage   = stage;
            schemaException.ErrorNumber = SyncErrorNumber.StoreException;
            schemaException.HelpLink    = helpLink;
            schemaException.TableName   = tableName;
            SyncTracer.Warning("{0}", new object[1]
            {
                (object)schemaException
            });
            return(schemaException);
        }
Exemple #13
0
        public async Task <T> RunInTransactionAsync2 <T>(SyncStage stage         = SyncStage.None, Func <SyncContext, DbConnection, DbTransaction, Task <T> > actionTask = null,
                                                         DbConnection connection = null, DbTransaction transaction = null, CancellationToken cancellationToken = default)
        {
            if (!this.StartTime.HasValue)
            {
                this.StartTime = DateTime.UtcNow;
            }

            // Get context or create a new one
            var ctx = this.GetContext();

            T result = default;

            using (var c = this.Provider.CreateConnection())
            {
                try
                {
                    await c.OpenAsync();

                    using (var t = c.BeginTransaction(this.Provider.IsolationLevel))
                    {
                        if (actionTask != null)
                        {
                            result = await actionTask(ctx, c, t);
                        }

                        t.Commit();
                    }
                    c.Close();
                    c.Dispose();

                    return(result);
                }
                catch (Exception ex)
                {
                    RaiseError(ex);
                }
            }

            return(default);
Exemple #14
0
        public static async Task <DbConnectionRunner> GetConnectionAsync(this BaseOrchestrator orchestrator,
                                                                         SyncContext context,
                                                                         SyncMode syncMode                   = SyncMode.Writing,
                                                                         SyncStage syncStage                 = SyncStage.None,
                                                                         DbConnection connection             = default,
                                                                         DbTransaction transaction           = default,
                                                                         CancellationToken cancellationToken = default,
                                                                         IProgress <ProgressArgs> progress   = default)
        {
            // Get context or create a new one
            context.SyncStage = syncStage;

            if (orchestrator.Provider == null)
            {
                return(new DbConnectionRunner(null, context, null, null, true, true, cancellationToken, progress));
            }

            if (connection == null)
            {
                connection = orchestrator.Provider.CreateConnection();
            }

            var alreadyOpened        = connection.State == ConnectionState.Open;
            var alreadyInTransaction = transaction != null && transaction.Connection == connection;

            // Open connection
            if (!alreadyOpened)
            {
                await orchestrator.OpenConnectionAsync(context, connection, cancellationToken, progress).ConfigureAwait(false);
            }

            // Create a transaction
            if (!alreadyInTransaction && syncMode == SyncMode.Writing)
            {
                transaction = connection.BeginTransaction(orchestrator.Provider.IsolationLevel);
                await orchestrator.InterceptAsync(new TransactionOpenedArgs(context, connection, transaction), progress, cancellationToken).ConfigureAwait(false);
            }

            return(new DbConnectionRunner(orchestrator, context, connection, transaction, alreadyOpened, alreadyInTransaction, cancellationToken, progress));
        }
 public DatabaseApplyingEventArgs(string providerTypeName, SyncStage stage, DmSet schema) : base(providerTypeName, stage)
 {
     this.Schema = schema;
 }
Exemple #16
0
        /// <summary>
        /// Create a rollback exception to rollback the Sync session
        /// </summary>
        /// <param name="context"></param>
        internal static SyncException CreateRollbackException(SyncStage stage)
        {
            SyncException syncException = new SyncException("User rollback action.", stage, SyncExceptionType.Rollback);

            return(syncException);
        }
Exemple #17
0
        internal static SyncException CreateUnknowException(SyncStage stage, Exception ex)
        {
            SyncException syncException = new SyncException("Unknown error has occured", stage, ex, SyncExceptionType.Unknown);

            return(syncException);
        }
Exemple #18
0
 public override string ToString()
 {
     return($@"Error occured during {SyncStage.ToString()} of type {ExceptionType.ToString()}: {Message}");
 }
 public DatabaseAppliedEventArgs(string providerTypeName, SyncStage stage, string script) : base(providerTypeName, stage)
 {
     this.Script = script;
 }
 public EndSessionEventArgs(string providerTypeName, SyncStage stage) : base(providerTypeName, stage)
 {
 }
 public ProgressEventArgs(string providerTypeName, SyncStage stage, string message) : base(providerTypeName, stage)
 {
     this.Message = message;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 public BaseProgressEventArgs(string providerTypeName, SyncStage stage)
 {
     this.ProviderTypeName = providerTypeName;
     this.Stage            = stage;
 }
 public SchemaAppliedEventArgs(string providerTypeName, SyncStage stage, DmSet schema) : base(providerTypeName, stage)
 {
     this.Schema = schema;
 }
Exemple #24
0
        internal static Exception CreateInProgressException(SyncStage syncStage)
        {
            SyncException syncException = new SyncException("Session already in progress", syncStage, SyncExceptionType.Rollback);

            return(syncException);
        }
Exemple #25
0
 internal static void AssertConnectionAndTransaction(BaseOrchestrator orchestrator, SyncStage stage)
 {
     orchestrator.OnConnectionOpen(args =>
     {
         Assert.IsType <ConnectionOpenedArgs>(args);
         Assert.Equal(stage, args.Context.SyncStage);
         Assert.Equal(orchestrator.ScopeName, args.Context.ScopeName);
         Assert.NotNull(args.Connection);
         Assert.Null(args.Transaction);
         Assert.Equal(ConnectionState.Open, args.Connection.State);
     });
     orchestrator.OnTransactionOpen(args =>
     {
         Assert.IsType <TransactionOpenedArgs>(args);
         Assert.Equal(stage, args.Context.SyncStage);
         Assert.Equal(orchestrator.ScopeName, args.Context.ScopeName);
         Assert.NotNull(args.Connection);
         Assert.NotNull(args.Transaction);
         Assert.Equal(ConnectionState.Open, args.Connection.State);
         Assert.Same(args.Connection, args.Transaction.Connection);
     });
     orchestrator.OnTransactionCommit(args =>
     {
         Assert.IsType <TransactionCommitArgs>(args);
         Assert.Equal(stage, args.Context.SyncStage);
         Assert.Equal(orchestrator.ScopeName, args.Context.ScopeName);
         Assert.NotNull(args.Connection);
         Assert.NotNull(args.Transaction);
         Assert.Equal(ConnectionState.Open, args.Connection.State);
         Assert.Same(args.Connection, args.Transaction.Connection);
     });
     orchestrator.OnConnectionClose(args =>
     {
         Assert.IsType <ConnectionClosedArgs>(args);
         Assert.Equal(stage, args.Context.SyncStage);
         Assert.Equal(orchestrator.ScopeName, args.Context.ScopeName);
         Assert.NotNull(args.Connection);
         Assert.Null(args.Transaction);
         Assert.Equal(ConnectionState.Closed, args.Connection.State);
     });
 }
Exemple #26
0
        internal static SyncException CreateOperationCanceledException(SyncStage syncStage, OperationCanceledException oce)
        {
            SyncException syncException = new SyncException("Operation canceled.", syncStage, SyncExceptionType.OperationCanceled);

            return(syncException);
        }
Exemple #27
0
        internal static SyncException CreateNotSupportedException(SyncStage syncStage, string notSupportedMessage)
        {
            SyncException syncException = new SyncException(notSupportedMessage, syncStage, SyncExceptionType.NotSupported);

            return(syncException);
        }
Exemple #28
0
 public SyncException(string message, SyncStage stage) : base(message)
 {
     this.SyncStage = stage;
 }
 public DatabaseTableApplyingEventArgs(string providerTypeName, SyncStage stage, string tableName) : base(providerTypeName, stage)
 {
     TableName = tableName;
 }
Exemple #30
0
 public SyncException(Exception exception, SyncStage stage, string providerName) : base(exception.Message, exception)
 {
     this.SyncStage    = stage;
     this.ProviderName = providerName;
     if (exception is SyncException)
     {
         this.ErrorCode = ((SyncException)exception).ErrorCode;
         this.Type      = ((SyncException)exception).Type;
     }
     if (exception is DbException)
     {
         this.ErrorCode = ((DbException)exception).ErrorCode;
         this.Type      = SyncExceptionType.Data;
     }
     if (exception is DataException)
     {
         this.Type = SyncExceptionType.Data;
     }
     else if (exception is ArgumentException)
     {
         this.Type = SyncExceptionType.Argument;
     }
     else if (exception is ArgumentOutOfRangeException)
     {
         this.Type = SyncExceptionType.ArgumentOutOfRange;
     }
     else if (exception is FormatException)
     {
         this.Type = SyncExceptionType.Format;
     }
     else if (exception is IndexOutOfRangeException)
     {
         this.Type = SyncExceptionType.IndexOutOfRange;
     }
     else if (exception is InsufficientMemoryException)
     {
         this.Type = SyncExceptionType.InsufficientMemory;
     }
     else if (exception is InProgressException)
     {
         this.Type = SyncExceptionType.InProgress;
     }
     else if (exception is InvalidCastException)
     {
         this.Type = SyncExceptionType.InvalidCast;
     }
     else if (exception is InvalidExpressionException)
     {
         this.Type = SyncExceptionType.InvalidExpression;
     }
     else if (exception is InvalidOperationException)
     {
         this.Type = SyncExceptionType.InvalidOperation;
     }
     else if (exception is KeyNotFoundException)
     {
         this.Type = SyncExceptionType.KeyNotFound;
     }
     else if (exception is NotImplementedException)
     {
         this.Type = SyncExceptionType.NotImplemented;
     }
     else if (exception is NotSupportedException)
     {
         this.Type = SyncExceptionType.NotSupported;
     }
     else if (exception is NullReferenceException)
     {
         this.Type = SyncExceptionType.NullReference;
     }
     else if (exception is ObjectDisposedException)
     {
         this.Type = SyncExceptionType.ObjectDisposed;
     }
     else if (exception is OperationCanceledException)
     {
         this.Type = SyncExceptionType.OperationCanceled;
     }
     else if (exception is TaskCanceledException)
     {
         this.Type = SyncExceptionType.TaskCanceled;
     }
     else if (exception is OutOfDateException)
     {
         this.Type = SyncExceptionType.OutOfDate;
     }
     else if (exception is OutOfMemoryException)
     {
         this.Type = SyncExceptionType.OutOfMemory;
     }
     else if (exception is OverflowException)
     {
         this.Type = SyncExceptionType.Overflow;
     }
     else if (exception is PlatformNotSupportedException)
     {
         this.Type = SyncExceptionType.PlatformNotSupported;
     }
     else if (exception is TimeoutException)
     {
         this.Type = SyncExceptionType.Timeout;
     }
     else if (exception is UnauthorizedAccessException)
     {
         this.Type = SyncExceptionType.UnauthorizedAccess;
     }
     else if (exception is UriFormatException)
     {
         this.Type = SyncExceptionType.UriFormat;
     }
     else
     {
         this.Type = SyncExceptionType.Unknown;
     }
 }
 public ScopeEventArgs(string providerTypeName, SyncStage stage, ScopeInfo scope) : base(providerTypeName, stage)
 {
     this.ScopeInfo = scope;
 }