示例#1
0
        /// <summary>
        /// Write scope in the provider datasource
        /// </summary>
        public virtual async Task <SyncContext> WriteScopesAsync(SyncContext context,
                                                                 MessageWriteScopes message)
        {
            DbConnection  connection  = null;
            DbTransaction transaction = null;

            try
            {
                // Open the connection
                using (connection = this.CreateConnection())
                {
                    await connection.OpenAsync();

                    await this.InterceptAsync(new ConnectionOpenArgs(context, connection));

                    using (transaction = connection.BeginTransaction())
                    {
                        await this.InterceptAsync(new TransactionOpenArgs(context, connection, transaction));

                        var scopeBuilder     = this.GetScopeBuilder();
                        var scopeInfoBuilder = scopeBuilder.CreateScopeInfoBuilder(message.ScopeInfoTableName, connection, transaction);

                        var lstScopes = new List <ScopeInfo>();

                        foreach (var scope in message.Scopes)
                        {
                            lstScopes.Add(scopeInfoBuilder.InsertOrUpdateScopeInfo(scope));
                        }

                        // Progress & Interceptor
                        context.SyncStage = SyncStage.ScopeSaved;
                        var scopeArgs = new ScopeArgs(context, lstScopes.FirstOrDefault(s => s.IsLocal), connection, transaction);
                        this.ReportProgress(context, scopeArgs);
                        await this.InterceptAsync(scopeArgs);

                        await this.InterceptAsync(new TransactionCommitArgs(context, connection, transaction));

                        transaction.Commit();
                    }

                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                throw new SyncException(ex, SyncStage.ScopeSaved);
            }
            finally
            {
                if (connection != null && connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }

                await this.InterceptAsync(new ConnectionCloseArgs(context, connection, transaction));
            }
            return(context);
        }
示例#2
0
        /// <summary>
        /// Write scope in the provider datasource
        /// </summary>
        public virtual async Task <SyncContext> WriteScopesAsync(SyncContext context,
                                                                 MessageWriteScopes message)
        {
            DbConnection connection = null;

            try
            {
                // Open the connection
                using (connection = this.CreateConnection())
                {
                    await connection.OpenAsync();

                    using (var transaction = connection.BeginTransaction())
                    {
                        var scopeBuilder     = this.GetScopeBuilder();
                        var scopeInfoBuilder = scopeBuilder.CreateScopeInfoBuilder(message.ScopeInfoTableName, connection, transaction);

                        var lstScopes = new List <ScopeInfo>();

                        foreach (var scope in message.Scopes)
                        {
                            lstScopes.Add(scopeInfoBuilder.InsertOrUpdateScopeInfo(scope));
                        }

                        context.SyncStage = SyncStage.ScopeSaved;

                        // Event progress
                        this.TryRaiseProgressEvent(
                            new ScopeEventArgs(this.ProviderTypeName, context.SyncStage,
                                               lstScopes.FirstOrDefault(s => s.IsLocal)), ScopeSaved);

                        transaction.Commit();
                    }

                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                throw new SyncException(ex, SyncStage.ScopeSaved, this.ProviderTypeName);
            }
            finally
            {
                if (connection != null && connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }
            return(context);
        }
        public async Task <SyncContext> WriteScopesAsync(SyncContext context, MessageWriteScopes message)
        {
            HttpMessage httpMessage = new HttpMessage
            {
                Step        = HttpStep.WriteScopes,
                SyncContext = context,
                Content     = new HttpMessageWriteScopes
                {
                    ScopeInfoTableName  = message.ScopeInfoTableName,
                    Scopes              = message.Scopes,
                    SerializationFormat = message.SerializationFormat
                }
            };

            //Post request and get response
            var httpMessageResponse = await this.httpRequestHandler.ProcessRequest(httpMessage, message.SerializationFormat, cancellationToken);

            if (httpMessageResponse == null)
            {
                throw new Exception("Can't have an empty body");
            }

            return(httpMessageResponse.SyncContext);
        }
 public async Task <SyncContext> WriteScopesAsync(SyncContext ctx, MessageWriteScopes message)
 => await this.LocalProvider.WriteScopesAsync(ctx, message);