示例#1
0
        /// <summary>
        /// Launches a new synchronizations to download documents.
        /// </summary>
        /// <param name="customerAccountId">The customer account identifier</param>
        /// <param name="customerUserId">The customer user identifier</param>
        /// <param name="isForced">If true, sets the synchronization as forced, thus overriding the document unicity check.</param>
        /// <returns></returns>
        public List <Synchronization> CreateSynchronizations(string customerAccountId, string customerUserId, bool isForced)
        {
            var requestUri = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}", _apiVersion, _path));

            var synchRequest = new SynchronizationRequest(customerAccountId, isForced, customerUserId);
            var response     = _authenticatedClient.HttpClient.ApiPost(requestUri, Newtonsoft.Json.JsonConvert.SerializeObject(synchRequest));

            return(response.GetObjectFromResponse <List <Synchronization> >());
        }
示例#2
0
        /// <summary>
        /// Launches the synchronization for a specific account.
        /// </summary>
        /// <param name="customerAccountId">The customer account identifier.</param>
        /// <param name="isForced">if set to <c>true</c> [is forced].</param>
        /// <returns>A Synchronization object.</returns>
        public Synchronization SynchronizeAccount(string customerAccountId, bool isForced)
        {
            if (string.IsNullOrEmpty(customerAccountId))
            {
                throw new ApiClientHttpException((int)System.Net.HttpStatusCode.BadRequest, "CustomerAccountId missing.");
            }

            var requestUri   = new Uri(_authenticatedClient.BaseUri, string.Format("api/{0}/{1}/{2}/synchronizations", _apiVersion, _path, customerAccountId));
            var synchRequest = new SynchronizationRequest(customerAccountId, isForced);
            var response     = _authenticatedClient.HttpClient.ApiPost(requestUri, Newtonsoft.Json.JsonConvert.SerializeObject(synchRequest));

            return(response.GetObjectFromResponse <Synchronization>());
        }
示例#3
0
        /// <summary>
        /// Begin Synchronization process
        /// </summary>
        private void BeginSynchronization()
        {
            if (reSyncTimer != null)
            {
                reSyncTimer.Stop();
            }

            Task.Factory.StartNew(() =>
            {
                var synchronizationRequest = new SynchronizationRequest
                {
                    FullDetailedResponse = businessLogic.IsNeedFullSynchronization,
                };
                Proxy.SynchronizationRequest(synchronizationRequest);
            }).HandleException();

            alreadySynchronizationDetailedRequest = false;
            alreadySynchronizationDetailsResponse = false;
        }
示例#4
0
        /// <summary>
        /// The first request usually from the peer that joined to the mesh
        /// that ask for synchronization
        /// </summary>
        /// <param name="request">the request from the peer to his neighbors</param>
        void ISynchronizedState.SynchronizationRequest(SynchronizationRequest request)
        {
            if (request.IsOwnMessage)
            {
                return;
            }

            if (request.FullDetailedResponse)
            {
                Task <BusinessLogicMessageBase> .Factory.StartNew(() =>
                                                                  businessLogic.ProvideFullSynchronizationDetailResponse()).ContinueWith(task =>
                {
                    //exception handling
                    if (task.IsFaulted)
                    {
                        task.Exception.Handle(exception =>
                        {
                            LogManager.Fatal(exception);
                            return(true);
                        });
                        return;
                    }

                    if (task.Result == null)
                    {
                        LogManager.GetCurrentClassLogger().Debug("businessLogic.ProvideFullSynchronizationDetailResponse() return null - SynchronizationDetailsResponse will not sent to neighbors peers - its legal , but for debugging information for the implementer should consider if this is the correct behavior");
                        return;
                    }

                    var response = new SynchronizationDetailsResponseContainer
                    {
                        Response = task.Result
                    };
                    //send the response
                    Proxy.SynchronizationDetailsResponse(response);
                });
            }
            else
            {
                Task <BusinessLogicMessageBase> .Factory.StartNew(() =>
                                                                  businessLogic.ProvideSynchronizationResponse(request)).ContinueWith(task =>
                {
                    //exception handling
                    if (task.IsFaulted)
                    {
                        task.Exception.Handle(exception =>
                        {
                            LogManager.Fatal(exception);
                            return(true);
                        });
                        return;
                    }

                    if (task.Result == null)
                    {
                        LogManager.GetCurrentClassLogger().Debug("businessLogic.ProvideSynchronizationResponse() return null - SynchronizationKeysResponse will not sent to neighbors peers - its legal , but for debugging information for the implementer should consider if this is the correct behavior");
                        return;
                    }

                    //send the response
                    var response = new SynchronizationResponseContainer
                    {
                        Response = task.Result
                    };
                    Proxy.SynchronizationKeysResponse(response);
                });
            }
        }
 /// <summary>
 /// The first request usually from the peer that joined to the mesh
 /// that ask for synchronization
 /// </summary>
 /// <param name="request">the request from the peer to his neighbors</param>
 void ISynchronizedState.SynchronizationRequest(SynchronizationRequest request)
 {
     Contract.Requires <ArgumentNullException>(request != null);
 }
        /// <summary>
        /// Generate SynchronizationResponse message that will be returned back to the mesh based on given synchronizationRequest message
        /// should override to produce application specific response
        /// </summary>
        /// <remarks>this method will invoked On receiver peer side based on prior SynchronizationRequest operation</remarks>
        /// <param name="synchronizationRequest">the request received from the mesh</param>
        /// <returns>SynchronizationResponse instance or null if don't want to response</returns>
        BusinessLogicMessageBase ISynchronizationBusinessLogic.ProvideSynchronizationResponse(SynchronizationRequest synchronizationRequest)
        {
#if DEBUG
            LogManager.GetCurrentClassLogger().Debug("ProvideSynchronizationResponse: {0}", synchronizationRequest);
#endif
            lock (syncLock)
            {
                //return all keys
                return(new MyKeysStateIdsContainer
                {
                    StateIds = MyStateDictionary.Select(kvp => kvp.Key).ToList()
                });
            }
        }