public void PostSyncSource(IRequest request, DigestFeedEntry entry) { //The FeedEntry Parameter on this method is intentionally omitted 1. because the framework fails in parsing the Digest and 2. the request.Stream is already read which will cause an error in subsequent calls PostSyncSourceRequestPerformer performer = NorthwindAdapter.RequestPerformerLocator.Resolve <PostSyncSourceRequestPerformer>(new RequestContext(request.Uri)); performer.DoWork(request, entry); }
public void DoWork(IRequest request, DigestFeedEntry entry) { //ReturnSample(request); //return; // If an asyncState object already exists, an exception is thrown as the performer only accepts // one call after each other. The Request receiver has to manage a queued execution. // Before calling the performers execution implementation method a new AsyncState object is created // and set to an initial tracking state. lock (_asyncStateObj) { if (null != _asyncStateObj.Tracking) { throw new InvalidOperationException("The performer cannot be executed because it is already running."); } ITracking tracking = new Tracking(); tracking.ElapsedSeconds = 1; tracking.Phase = TrackingPhase.INIT; tracking.PhaseDetail = "Tracking Id was: " + _requestContext.TrackingId.ToString(); tracking.PollingMillis = 100; tracking.RemainingSeconds = 100; _asyncStateObj.Tracking = tracking; } // *** Initialization for the async execution *** // - Read Feed from request stream. // - Read trackingId from request URL // convert tracking ID from request to type Guid string strTrackingId = request.Uri.TrackingID; if (String.IsNullOrEmpty(strTrackingId)) { throw new RequestException("TrackingId is missing"); } GuidConverter converter = new GuidConverter(); this.TrackingId = (Guid)converter.ConvertFrom(strTrackingId); if (null == entry.Digest) { throw new RequestException("Digest payload missing in payload element."); } Digest targetDigest = entry.Digest; // *** Do work asynchronously *** _asyncPerformer = new InternalAsyncPerformer(this); _asyncPerformer.DoWork(_requestContext.Config, targetDigest); // *** set the tracking to the request response *** this.GetTrackingState(request); }
public void DoWork(IRequest request) { // ReturnSample(request); //return; // DECLARATIONS string resourceKindName; string EndPoint; SdataContext sdataContext; ISyncSyncDigestInfoStore syncDigestStore; SyncDigestInfo syncDigestInfo; // INITIALIZATIONS sdataContext = _requestContext.SdataContext; resourceKindName = _requestContext.ResourceKind.ToString(); EndPoint = _requestContext.DatasetLink + resourceKindName; syncDigestStore = NorthwindAdapter.StoreLocator.GetSyncDigestStore(sdataContext); // Get the digest info from store syncDigestInfo = syncDigestStore.Get(resourceKindName); /* Create a digest payload and fill it with values retrived from digest store */ //DigestPayload digestPayload = new DigestPayload(); Digest digest = new Digest(); digest.Origin = EndPoint; // set digest entries if ((null == syncDigestInfo) || (syncDigestInfo.Count == 0)) { DigestEntry entry = new DigestEntry(); entry.ConflictPriority = 1; entry.EndPoint = EndPoint; entry.Stamp = DateTime.Now; entry.Tick = 1; digest.Entries = new DigestEntry[] { entry }; } else { digest.Entries = new DigestEntry[syncDigestInfo.Count]; for (int i = 0; i < syncDigestInfo.Count; i++) { DigestEntry entry = new DigestEntry(); entry.ConflictPriority = syncDigestInfo[i].ConflictPriority; entry.EndPoint = syncDigestInfo[i].EndPoint; entry.Stamp = syncDigestInfo[i].Stamp; entry.Tick = (int)syncDigestInfo[i].Tick; digest.Entries[i] = entry; } } // The url to this request string url = EndPoint + "/$syncDigest"; // Create self link FeedLink link = new FeedLink(url, LinkType.Self, MediaType.AtomEntry); // Create FeedEntry // Set Response DigestFeedEntry digestFeedEntry = new DigestFeedEntry(); digestFeedEntry.Digest = digest; digestFeedEntry.Title = "Synchronization digest"; //digestFeedEntry.Id = url; digestFeedEntry.Links.Add(link); request.Response.FeedEntry = digestFeedEntry; request.Response.ContentType = MediaType.AtomEntry; }