/// <summary>
        /// Called by the  to indicate that a
        /// synchronization session has started.
        /// </summary>
        public virtual Task <(SyncContext, SyncConfiguration)> BeginSessionAsync(SyncContext context, MessageBeginSession message)
        {
            try
            {
                lock (this)
                {
                    if (this.syncInProgress)
                    {
                        throw new InProgressException("Synchronization already in progress");
                    }

                    this.syncInProgress = true;
                }

                // Set stage
                context.SyncStage = SyncStage.BeginSession;

                // Event progress
                var progressEventArgs = new BeginSessionEventArgs(this.ProviderTypeName, context.SyncStage, null, null);
                this.TryRaiseProgressEvent(progressEventArgs, this.BeginSession);

                return(Task.FromResult((context, message.Configuration)));
            }
            catch (Exception ex)
            {
                throw new SyncException(ex, SyncStage.BeginSession, this.ProviderTypeName);
            }
        }
 public async Task <(SyncContext, SyncConfiguration)> BeginSessionAsync(SyncContext ctx, MessageBeginSession message)
 => await this.LocalProvider.BeginSessionAsync(ctx, message);
Beispiel #3
0
        /// <summary>
        /// Called by the  to indicate that a
        /// synchronization session has started.
        /// </summary>
        public virtual async Task <(SyncContext, SyncConfiguration)> BeginSessionAsync(SyncContext context, MessageBeginSession message)
        {
            try
            {
                lock (this)
                {
                    if (this.syncInProgress)
                    {
                        throw new InProgressException("Synchronization already in progress");
                    }

                    this.syncInProgress = true;
                }

                // Progress & interceptor
                context.SyncStage = SyncStage.BeginSession;
                var sessionArgs = new SessionBeginArgs(context, null, null);
                this.ReportProgress(context, sessionArgs);
                await this.InterceptAsync(sessionArgs);

                return(context, message.Configuration);
            }
            catch (Exception ex)
            {
                throw new SyncException(ex, SyncStage.BeginSession);
            }
        }
        public async Task <(SyncContext, SyncConfiguration)> BeginSessionAsync(SyncContext context, MessageBeginSession message)
        {
            HttpMessage httpMessage = new HttpMessage
            {
                Step        = HttpStep.BeginSession,
                SyncContext = context,
                Content     = new HttpMessageBeginSession
                {
                    SyncConfiguration = message.SyncConfiguration
                }
            };

            //Post request and get response
            // This first request is always JSON based, to be able to get the format from the server side
            var httpMessageResponse = await this.httpRequestHandler.ProcessRequest(httpMessage, SerializationFormat.Json, cancellationToken);

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

            HttpMessageBeginSession httpMessageContent;

            if (httpMessageResponse.Content is HttpMessageBeginSession)
            {
                httpMessageContent = httpMessageResponse.Content as HttpMessageBeginSession;
            }
            else
            {
                httpMessageContent = (httpMessageResponse.Content as JObject).ToObject <HttpMessageBeginSession>();
            }

            return(httpMessageResponse.SyncContext, httpMessageContent.SyncConfiguration);
        }