private CommodityIdentity[] GetCommodityIds(SyncFeedEntry requestEntry) { List <CommodityIdentity> identities = new List <CommodityIdentity>(); // To be able to receive commodity data we need the local commodity ids. // These ids can be requested in 2 ways: // 1a) Using reference link: If attribute 'href' is a valid url of this adapter and has a resource key we can use the given resourceKey. // 1b) Using reference link: Otherwise we use the attribute 'uuid' and use the correlation repository. // 2) Using the value contained in line property 'uuid' and using the correlation repository. // If 1) and 2) do not succeed we add an empty object. ComputePriceRequestPayload payload = (ComputePriceRequestPayload)requestEntry.Payload; int noOflines = payload.ComputePriceRequest.pricingDocumentLines.Length; for (int i = 0; i < noOflines; i++) { string payloadPath = string.Format("computePrice/pricingDocumentLines[{0}]/commodity", i); SyncFeedEntryLink feedLink = Helper.FindLinkByPayloadPath(requestEntry.SyncLinks.ToArray(), payloadPath); //if (null == feedLink) // throw new RequestException(string.Format("Link for payloadPath '{0}' missing", payloadPath)); if (null != feedLink) { // validate string strRel = SyncFeedEntryLink.GetRelString(Sage.Integration.Northwind.Feeds.RelEnum.related); if (feedLink.LinkRel != strRel) { throw new RequestException(string.Format("Parsing link with payloadPath '{0}' failed: Attribute 'rel' must contain value '{1}'.", payloadPath, strRel)); } // TODO: excluded because condition linktype could have valid space character and we cannot check this in a simple way. //string strType = SyncFeedEntryLink.GetTypeString(Sage.Integration.Northwind.Feeds.LinkTypeEnum.entry); //if (feedLink.LinkType != strType) // throw new RequestException(string.Format("Parsing link with payloadPath '{0}' failed: Invalid media type defined in attribute 'type'. Value '{1}' expected.", payloadPath, strType)); string url = feedLink.Href; // 1a) Try to parse href if (url.StartsWith(_requestContext.DatasetLink + SupportedResourceKinds.commodities.ToString())) { RequestContext tmpRequestContext = new RequestContext(new SDataUri(url)); if (tmpRequestContext.RequestType == RequestType.Resource) { identities.Add(new CommodityIdentity(tmpRequestContext.ResourceKey)); continue; // continue iteration (parse next line item) } } // 1b) Try to get uuid from link and to get the local id using synch correlation (linking) if (!string.IsNullOrEmpty(feedLink.Uuid)) { Guid uuid = (Guid)TypeDescriptor.GetConverter(typeof(Guid)).ConvertFrom(feedLink.Uuid); ICorrelatedResSyncInfoStore correlationStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetCorrelatedResSyncStore(_requestContext.SdataContext); CorrelatedResSyncInfo[] correlations = correlationStore.GetByUuid(SupportedResourceKinds.commodities.ToString(), new Guid[] { uuid }); if (correlations.Length == 1) { identities.Add(new CommodityIdentity(correlations[0].LocalId)); continue; // continue iteration (parse next line item) } } } else { // 2) Try to get uuid from property named 'uuid' string strLineUuid = payload.ComputePriceRequest.pricingDocumentLines[i].uuid; if (!string.IsNullOrEmpty(strLineUuid)) { Guid uuid = (Guid)TypeDescriptor.GetConverter(typeof(Guid)).ConvertFrom(strLineUuid); // get the local id using synch correlation (linking) ICorrelatedResSyncInfoStore correlationStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetCorrelatedResSyncStore(_requestContext.SdataContext); CorrelatedResSyncInfo[] correlations = correlationStore.GetByUuid(SupportedResourceKinds.commodities.ToString(), new Guid[] { uuid }); if (correlations.Length == 1) { identities.Add(new CommodityIdentity(correlations[0].LocalId)); continue; // continue iteration (parse next line item) } } } // If 1) and 2) failed add an empty CommodityIdentity identities.Add(CommodityIdentity.Empty); } return(identities.ToArray()); }