예제 #1
0
        public ContactPayload GetTransformedPayload(PersonDocument document, out List <SyncFeedEntryLink> links)
        {
            contacttype    contact = new contacttype();
            ContactPayload payload = new ContactPayload();

            links = new List <SyncFeedEntryLink>();

            contact.uuid          = GetUuid(document.Id, document.CrmId).ToString();
            contact.applicationID = document.Id;
            payload.SyncUuid      = StringToGuid(contact.uuid);
            payload.LocalID       = document.Id;
            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.contacts, document.Id));

            links.Add(selfLink);

            contact.familyName = (document.lastname.IsNull) ? null : document.lastname.Value.ToString();
            contact.firstName  = (document.firstname.IsNull) ? null : document.firstname.Value.ToString();
            contact.middleName = (document.middlename.IsNull) ? null : document.middlename.Value.ToString();
            contact.salutation = (document.salutation.IsNull) ? null : document.salutation.Value.ToString();
            contact.suffix     = (document.suffix.IsNull) ? null : document.suffix.Value.ToString();
            contact.title      = (document.title.IsNull) ? null : document.title.Value.ToString();
            contact.fullName   = (document.fullname.IsNull) ? null : document.fullname.Value.ToString();
            if ((!document.primaryperson.IsNull) && (document.primaryperson.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
            {
                contact.primacyIndicator = true;
            }



            payload.Contacttype = contact;
            return(payload);
        }
        public CommodityGroupPayload GetTransformedPayload(ProductFamilyDocument document, out List <SyncFeedEntryLink> links)
        {
            CommodityGroupPayload payload = new CommodityGroupPayload();

            links = new List <SyncFeedEntryLink>();
            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.commodityGroups, document.Id));

            links.Add(selfLink);
            payload.CommodityGrouptype.active = false;

            if ((!document.active.IsNull) &&
                document.active.Value.ToString().Equals(Sage.Integration.Northwind.Application.API.Constants.DefaultValues.Active, StringComparison.InvariantCultureIgnoreCase))
            {
                payload.CommodityGrouptype.active = true;
            }

            //payload.CommodityGrouptype.uuid = GetUuid(document.Id, document.CrmId).ToString();
            payload.SyncUuid = GetUuid(document.Id, document.CrmId);
            payload.LocalID  = document.Id;
            payload.CommodityGrouptype.applicationID = document.Id;

            payload.CommodityGrouptype.name        = (document.name.IsNull) ? null : document.name.Value.ToString();
            payload.CommodityGrouptype.label       = payload.CommodityGrouptype.name;
            payload.CommodityGrouptype.description = (document.description.IsNull) ? null : document.description.Value.ToString();

            return(payload);
        }
예제 #3
0
        public PostalAddressPayload GetTransformedPayload(AddressDocument document, out List <SyncFeedEntryLink> links)
        {
            PostalAddressPayload payload = new PostalAddressPayload();

            links = new List <SyncFeedEntryLink>();


            payload.SyncUuid = GetUuid(document.Id, document.CrmId);
            payload.LocalID  = document.Id;
            payload.PostalAddresstype.uuid          = payload.SyncUuid.ToString();
            payload.PostalAddresstype.applicationID = document.Id;
            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.postalAddresses, document.Id));

            links.Add(selfLink);

            payload.PostalAddresstype.active      = true;
            payload.PostalAddresstype.address1    = (document.address1.IsNull) ? null : document.address1.Value.ToString();
            payload.PostalAddresstype.address2    = (document.address2.IsNull) ? null : document.address2.Value.ToString();
            payload.PostalAddresstype.address3    = (document.address3.IsNull) ? null : document.address3.Value.ToString();
            payload.PostalAddresstype.address4    = (document.address4.IsNull) ? null : document.address4.Value.ToString();
            payload.PostalAddresstype.country     = (document.country.IsNull) ? null : document.country.Value.ToString();
            payload.PostalAddresstype.deleted     = false;
            payload.PostalAddresstype.stateRegion = (document.state.IsNull) ? null : document.state.Value.ToString();
            payload.PostalAddresstype.townCity    = (document.City.IsNull) ? null : document.City.Value.ToString();
            payload.PostalAddresstype.zipPostCode = (document.postcode.IsNull) ? null : document.postcode.Value.ToString();
            if ((!document.primaryaddress.IsNull) && (document.primaryaddress.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
            {
                payload.PostalAddresstype.primacyIndicator = true;
            }
            payload.PostalAddresstype.type = postalAddressTypeenum.Correspondance;
            return(payload);
        }
        public PricePayload GetTransformedPayload(PriceDocument document, out List <SyncFeedEntryLink> links)
        {
            PricePayload payload = new PricePayload();

            links = new List <SyncFeedEntryLink>();
            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.prices, document.Id));

            links.Add(selfLink);

            //payload.Pricetype.uuid = GetUuid(document.Id, document.CrmId).ToString();
            payload.SyncUuid = GetUuid(document.Id, document.CrmId);
            payload.LocalID  = document.Id;
            payload.Pricetype.applicationID = document.Id;

            if ((!document.active.IsNull) &&
                document.active.Value.ToString().Equals(Sage.Integration.Northwind.Application.API.Constants.DefaultValues.Active, StringComparison.InvariantCultureIgnoreCase))
            {
                payload.Pricetype.active = true;
            }

            payload.Pricetype.priceSpecified = !(document.price.IsNull);
            if (payload.Pricetype.priceSpecified)
            {
                payload.Pricetype.price = (decimal)document.price.Value;
            }

            return(payload);
        }
        public PhoneNumberPayload GetTransformedPayload(PhoneDocument document, out List <SyncFeedEntryLink> links)
        {
            links = new List <SyncFeedEntryLink>();
            PhoneNumberPayload payload = new PhoneNumberPayload();

            payload.PhoneNumbertype.areaCode    = (document.areacode.IsNull) ? null : document.areacode.Value.ToString();
            payload.PhoneNumbertype.countryCode = (document.countrycode.IsNull) ? null : document.countrycode.Value.ToString();
            payload.PhoneNumbertype.number      = (document.number.IsNull) ? null : document.number.Value.ToString();
            payload.PhoneNumbertype.text        = (document.fullnumber.IsNull) ? null : document.fullnumber.Value.ToString();

            if (!document.type.IsNull)
            {
                if (document.type.Value.ToString().Equals("Business", StringComparison.InvariantCultureIgnoreCase))
                {
                    payload.PhoneNumbertype.type = "general";
                }
                if (document.type.Value.ToString().Equals("Fax", StringComparison.InvariantCultureIgnoreCase))
                {
                    payload.PhoneNumbertype.type = "fax";
                }
            }

            payload.SyncUuid = GetUuid(document.Id, document.CrmId);
            payload.LocalID  = document.Id;
            payload.PhoneNumbertype.applicationID = document.Id;
            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.phoneNumbers, document.Id));

            links.Add(selfLink);

            return(payload);
        }
        public CommodityPayload GetTransformedPayload(ProductDocument document, out List <SyncFeedEntryLink> links)
        {
            CommodityPayload payload = new CommodityPayload();

            links = new List <SyncFeedEntryLink>();
            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.commodities, document.Id));

            links.Add(selfLink);
            if (!document.productfamilyid.IsNull)
            {
                string commodityGroupUuid = GetCommodityGroupUuid(document.productfamilyid.Value.ToString());
                if (!String.IsNullOrEmpty(commodityGroupUuid))
                {
                    SyncFeedEntryLink commodityGroupLink = SyncFeedEntryLink.CreateRelatedLink(selfLink.Href, SupportedResourceKinds.commodityGroups.ToString(), _commodityGroupUuidPayloadPath, commodityGroupUuid);
                    links.Add(commodityGroupLink);
                }
            }
            if (!document.uomcategory.IsNull)
            {
                string uomGroupUuid = GetUnitOfMeasureGroupUuid(document.uomcategory.Value.ToString());
                if (!String.IsNullOrEmpty(uomGroupUuid))
                {
                    SyncFeedEntryLink uomGroupLink = SyncFeedEntryLink.CreateRelatedLink(selfLink.Href, SupportedResourceKinds.unitsOfMeasureGroup.ToString(), _commodityGroupUuidPayloadPath, uomGroupUuid);
                    links.Add(uomGroupLink);
                }
            }
            payload.SyncUuid = GetUuid(document.Id, document.CrmId);
            payload.LocalID  = document.Id;

            payload.Commoditytype.uuid          = payload.SyncUuid.ToString();
            payload.Commoditytype.applicationID = document.Id;

            if ((!document.active.IsNull) &&
                document.active.Value.ToString().Equals(Sage.Integration.Northwind.Application.API.Constants.DefaultValues.Active, StringComparison.InvariantCultureIgnoreCase))
            {
                payload.Commoditytype.active = true;
            }

            payload.Commoditytype.name = (document.name.IsNull) ? null : document.name.Value.ToString();


            return(payload);
        }
예제 #7
0
        public override SyncFeedEntry GetFeedEntry(string id)
        {
            SyncFeedEntry result = new SyncFeedEntry();

            result.Payload = PayloadFactory.CreatePayload(_resourceKind);

            Identity        identity;
            AccountDocument accountDocument;
            Account         account = new Account();

            identity        = new Identity(account.EntityName, id);
            accountDocument = (AccountDocument)_entity.GetDocument(identity, _emptyToken, _context.Config);
            if (accountDocument.LogState == LogState.Deleted)
            {
                return(null);
            }
            if (accountDocument.addresses.documents.Count == 0)
            {
                return(null);
            }

            Document document = accountDocument.addresses.documents[0];
            List <SyncFeedEntryLink> links;

            result.Payload = GetTransformedPayload(document, out links);

            string taUuid = GetTradingAccountUuid(accountDocument.Id);

            if (!String.IsNullOrEmpty(taUuid))
            {
                SyncFeedEntryLink tradingAccountLink = SyncFeedEntryLink.CreateRelatedLink(
                    String.Format("{0}{1}('{2}')", _context.DatasetLink, SupportedResourceKinds.tradingAccounts.ToString(), accountDocument.Id),
                    SupportedResourceKinds.tradingAccounts.ToString(),
                    _tradingAccountUuidPayloadPath, taUuid);
                links.Add(tradingAccountLink);
            }
            result.SyncLinks = links;
            result.Id        = String.Format("{0}{1}('{2}')", _context.DatasetLink, _resourceKind.ToString(), id);
            result.Title     = String.Format("{0}: {1}", _resourceKind.ToString(), id);
            result.Updated   = DateTime.Now;
            return(result);
        }
        private List <SyncFeedEntryLink> GetLinks(Dictionary <string, string> foreignIds)
        {
            List <SyncFeedEntryLink> result = new List <SyncFeedEntryLink>();

            foreach (string key in foreignIds.Keys)
            {
                string value;
                if (foreignIds.TryGetValue(key, out value))
                {
                    SupportedResourceKinds tmpResKind = ResourceKindHelpers.GetResourceKind(key);
                    Guid guid = GetUuid(value, "", tmpResKind);
                    SyncFeedEntryLink link = SyncFeedEntryLink.CreateRelatedLink(
                        Common.ResourceKindHelpers.GetSingleResourceUrl(_context.DatasetLink, key, value),
                        tmpResKind.ToString(),
                        key, guid.ToString());
                    result.Add(link);
                }
            }
            return(result);
        }
        public EmailPayload GetTransformedPayload(EmailDocument document, out List <SyncFeedEntryLink> links)
        {
            emailtype email = new emailtype();

            links = new List <SyncFeedEntryLink>();
            EmailPayload payload = new EmailPayload();

            payload.SyncUuid    = GetUuid(document.Id, document.CrmId);
            payload.LocalID     = document.Id;
            email.uuid          = payload.SyncUuid.ToString();
            email.applicationID = document.Id;
            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.emails, document.Id));

            links.Add(selfLink);
            email.type    = (document.type.IsNull) ? null : document.type.Value.ToString();;
            email.address = (document.emailaddress.IsNull) ? null : document.emailaddress.Value.ToString();;

            payload.Emailtype = email;

            return(payload);
        }
예제 #10
0
        public override SyncFeed GetFeed()
        {
            bool includeUuid;

            string whereClause = string.Empty;

            OleDbParameter[] oleDbParameters = null;

            if (this is IEntityQueryWrapper)
            {
                QueryFilterBuilder queryFilterBuilder = new QueryFilterBuilder((IEntityQueryWrapper)this);

                queryFilterBuilder.BuildSqlStatement(_context, out whereClause, out oleDbParameters);
            }

            SyncFeed feed = new SyncFeed();

            feed.Title = _resourceKind.ToString() + ": " + DateTime.Now.ToString();

            Token emptyToken = new Token();


            List <Identity> identities = new List <Identity>();

            if (String.IsNullOrEmpty(_context.ResourceKey))
            {
                identities = _entity.GetAll(_context.Config, whereClause, oleDbParameters);
            }
            else
            {
                identities.Add(new Identity(_entity.EntityName, _context.ResourceKey));
            }


            int totalResult = identities.Count;

            #region PAGING & OPENSEARCH

            /* PAGING */
            feed.Links = FeedMetadataHelpers.CreatePageFeedLinks(_context, totalResult, FeedMetadataHelpers.RequestKeywordType.none);

            /* OPENSEARCH */
            PageController pageController = FeedMetadataHelpers.GetPageLinkBuilder(_context, totalResult, FeedMetadataHelpers.RequestKeywordType.none);

            feed.Opensearch_ItemsPerPageElement = pageController.GetOpensearch_ItemsPerPageElement();
            feed.Opensearch_StartIndexElement   = pageController.GetOpensearch_StartIndexElement();
            feed.Opensearch_TotalResultsElement = pageController.GetOpensearch_TotalResultsElement();

            #endregion


            feed.Id = _context.SdataUri.ToString();

            string tmpValue;
            // ?includeUuid
            includeUuid = false;    // default value, but check for settings now
            if (_context.SdataUri.QueryArgs.TryGetValue("includeUuid", out tmpValue))
            {
                includeUuid = System.Xml.XmlConvert.ToBoolean(tmpValue);
            }

            ICorrelatedResSyncInfoStore correlatedResSyncStore = null;
            if (includeUuid)
            {
                // get store to request the correlations
                correlatedResSyncStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetCorrelatedResSyncStore(_context.SdataContext);
            }

            for (int pageIndex = pageController.StartIndex; pageIndex <= pageController.LastIndex; pageIndex++)
            //for (int index = startIndex; index < startIndex + count; index++)
            {
                int             zeroBasedIndex  = pageIndex - 1;
                Identity        identity        = identities[zeroBasedIndex];
                AccountDocument accountDocument = (AccountDocument)_entity.GetDocument(identity, emptyToken, _context.Config);
                if (accountDocument.LogState == LogState.Deleted)
                {
                    continue;
                }


                SyncFeedEntry entry = new SyncFeedEntry();
                if (accountDocument.addresses.documents.Count == 0)
                {
                    return(null);
                }


                entry.Id = String.Format("{0}{1}('{2}')", _context.DatasetLink, _resourceKind.ToString(), identity.Id);

                entry.Title   = String.Format("{0}: {1}", _resourceKind.ToString(), identity.Id);
                entry.Updated = DateTime.Now;

                if (_context.SdataUri.Precedence == null)
                {
                    List <SyncFeedEntryLink> links;
                    Document document = accountDocument.addresses.documents[0];
                    entry.Payload = GetTransformedPayload(document, out links);
                    string taUuid = GetTradingAccountUuid(accountDocument.Id);
                    if (!String.IsNullOrEmpty(taUuid))
                    {
                        SyncFeedEntryLink tradingAccountLink = SyncFeedEntryLink.CreateRelatedLink(
                            String.Format("{0}{1}('{2}')", _context.DatasetLink, SupportedResourceKinds.tradingAccounts.ToString(), accountDocument.Id),
                            SupportedResourceKinds.tradingAccounts.ToString(),
                            _tradingAccountUuidPayloadPath, taUuid);
                        links.Add(tradingAccountLink);
                    }

                    entry.SyncLinks = links;
                }

                if (includeUuid)
                {
                    CorrelatedResSyncInfo[] infos = correlatedResSyncStore.GetByLocalId(_context.ResourceKind.ToString(), new string[] { identity.Id });
                    entry.Uuid = (infos.Length > 0) ? infos[0].ResSyncInfo.Uuid : Guid.Empty;
                }

                if (entry != null)
                {
                    feed.Entries.Add(entry);
                }
            }

            return(feed);
        }
        public SalesOrderPayload GetTransformedPayload(OrderDocument document, out List <SyncFeedEntryLink> links)
        {
            SalesOrderPayload payload    = new SalesOrderPayload();
            salesOrdertype    salesOrder = new salesOrdertype();

            #region initial values

            //salesOrder.active = true;
            //salesOrder.activeSpecified = true;
            //salesOrder.allocationStatus = null;
            //salesOrder.allocationStatusSpecified = false;
            //salesOrder.applicationID = null;
            //salesOrder.buyerContact = new contacttype();
            //salesOrder.carrierCompany = new operatingCompanylist();
            //salesOrder.carrierNetPrice = null;
            //salesOrder.carrierNetPriceSpecified = false;
            //salesOrder.carrierPurchaseInvoice = new purchaseInvoicelist();
            //salesOrder.carrierReference = null;
            //salesOrder.carrierSalesInvoice = new salesInvoicelist();
            //salesOrder.carrierTaxCodes = new taxCodelist();
            //salesOrder.carrierTaxPrice = null;
            //salesOrder.carrierTaxPriceSpecified = false;
            //salesOrder.carrierTotalPrice = null;
            //salesOrder.carrierTotalPriceSpecified = false;
            //salesOrder.carrierTradingAccount = new tradingAccountlist();
            //salesOrder.cases = new caselist();
            //salesOrder.chargesTotal = null;
            //salesOrder.chargesTotalSpecified = false;
            //salesOrder.contract = null;
            //salesOrder.copyFlag = false;
            //salesOrder.copyFlagSpecified = false;
            //salesOrder.costTotal = null;
            //salesOrder.costTotalSpecified = false;
            //salesOrder.

            //salesOrder.accountingType = tradingAccountAccountingTypeenum.Unknown;
            //salesOrder.customerSupplierFlag = (document.type.IsNull) ? null : document.type.Value.ToString();
            //salesOrder.active = true;
            //salesOrder.postalAddresses = new postalAddresslist();
            //salesOrder.contacts = new contactlist();
            //salesOrder.phones = new phoneNumberlist();
            //salesOrder.deleted = false;
            //salesOrder.deliveryContact = null;
            //salesOrder.deliveryMethod = null;
            //salesOrder.deliveryRule = false;
            //salesOrder.emails = new emaillist();
            //salesOrder.applicationID = document.Id;
            //salesOrder.uuid = GetUuid(document.Id, document.CrmId).ToString();
            //salesOrder.label = SupportedResourceKinds.TradingAccounts.ToString();
            //salesOrder.name = (document.name.IsNull) ? null : document.name.Value.ToString();

            //Many more things should set to default values

            #endregion

            #region salesorder lines

            int salesOrderLinesCount = document.orderitems.documents.Count;
            salesOrder.salesOrderLines = new salesOrderLinetype[salesOrderLinesCount];
            for (int index = 0; index < salesOrderLinesCount; index++)
            {
                List <SyncFeedEntryLink> dummyLinks;
                LineItemDocument         lineItem = document.orderitems.documents[index] as LineItemDocument;
                SalesOrderLinePayload    salesOrderLinePayload;
                salesOrderLinePayload             = _salesOrderLineTransformation.GetTransformedPayload(lineItem, out dummyLinks);
                salesOrder.salesOrderLines[index] = salesOrderLinePayload.SalesOrderLinetype;
            }

            #endregion

            payload.SalesOrdertype = salesOrder;
            links = new List <SyncFeedEntryLink>();
            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.salesOrders, document.Id));
            links.Add(selfLink);

            return(payload);
        }
        public override SyncFeedEntry GetFeedEntry(string id)
        {
            SyncFeedEntry result = new SyncFeedEntry();

            result.Payload = PayloadFactory.CreatePayload(_resourceKind);

            Identity        identity;
            AccountDocument accountDocument;
            Account         account = new Account();
            string          accountId;

            if (id.EndsWith(Sage.Integration.Northwind.Application.API.Constants.PhoneIdPostfix))
            {
                accountId = id.Replace(Sage.Integration.Northwind.Application.API.Constants.PhoneIdPostfix, "");
            }
            else if (id.EndsWith(Sage.Integration.Northwind.Application.API.Constants.FaxIdPostfix))
            {
                accountId = id.Replace(Sage.Integration.Northwind.Application.API.Constants.FaxIdPostfix, "");
            }
            else
            {
                return(null);
            }

            identity = new Identity(account.EntityName, accountId);


            accountDocument = (AccountDocument)_entity.GetDocument(identity, _emptyToken, _context.Config);

            if (accountDocument.LogState == LogState.Deleted)
            {
                return(null);
            }
            if (accountDocument.addresses.documents.Count == 0)
            {
                return(null);
            }
            Document document = null;

            foreach (Document phoneDoc in accountDocument.phones.documents)
            {
                if (phoneDoc.Id.Equals(id, StringComparison.InvariantCultureIgnoreCase))
                {
                    document = phoneDoc;
                    break;
                }
            }
            if (document == null)
            {
                return(null);
            }


            List <SyncFeedEntryLink> links;

            result.Payload = GetTransformedPayload(document, out links);

            string taUuid = GetTradingAccountUuid(accountDocument.Id);

            if (!String.IsNullOrEmpty(taUuid))
            {
                SyncFeedEntryLink tradingAccountLink = SyncFeedEntryLink.CreateRelatedLink(
                    String.Format("{0}{1}('{2}')", _context.DatasetLink, SupportedResourceKinds.tradingAccounts.ToString(), accountDocument.Id),
                    SupportedResourceKinds.tradingAccounts.ToString(),
                    _tradingAccountUuidPayloadPath, taUuid);
                links.Add(tradingAccountLink);
            }
            result.SyncLinks = links;
            result.Id        = String.Format("{0}{1}('{2}')", _context.DatasetLink, _resourceKind.ToString(), id);
            result.Title     = String.Format("{0}: {1}", _resourceKind.ToString(), id);
            result.Updated   = DateTime.Now;
            return(result);
        }
예제 #13
0
        public TradingAccountPayload GetTransformedPayload(AccountDocument document, out List <SyncFeedEntryLink> links)
        {
            links = new List <SyncFeedEntryLink>();
            TradingAccountPayload payload        = new TradingAccountPayload();
            tradingAccounttype    tradingAccount = new tradingAccounttype();

            tradingAccount.accountingType       = tradingAccountAccountingTypeenum.Unknown;
            tradingAccount.customerSupplierFlag = (document.customerSupplierFlag.IsNull) ? null : document.customerSupplierFlag.Value.ToString();
            tradingAccount.active = true;
            //tradingAccount.postalAddresses = new postalAddresstype[0]();
            //tradingAccount.contacts = new contacttype[0]();
            //tradingAccount.phones = new phoneNumbertype[0]();
            tradingAccount.deleted         = false;
            tradingAccount.deliveryContact = null;
            tradingAccount.deliveryMethod  = null;
            tradingAccount.deliveryRule    = false;
            //tradingAccount.emails = new emailtype[0]();
            tradingAccount.applicationID = document.Id;
            payload.SyncUuid             = GetUuid(document.Id, document.CrmId);
            payload.LocalID      = document.Id;
            tradingAccount.uuid  = payload.SyncUuid.ToString();
            tradingAccount.label = SupportedResourceKinds.tradingAccounts.ToString();
            tradingAccount.name  = (document.name.IsNull) ? null : document.name.Value.ToString();


            //Many more things should set to default values


            // adresses
            int adressCount = document.addresses.documents.Count;

            tradingAccount.postalAddresses = new postalAddresstype[adressCount];
            for (int index = 0; index < adressCount; index++)
            {
                List <SyncFeedEntryLink> addressLinks;
                AddressDocument          address = document.addresses.documents[index] as AddressDocument;
                PostalAddressPayload     postalAdressPayload;
                postalAdressPayload = _postalAdressTransformation.GetTransformedPayload(address, out addressLinks);
                tradingAccount.postalAddresses[index] = postalAdressPayload.PostalAddresstype;
                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.postalAddresses.ToString(), postalAdressPayload.LocalID),
                              "postalAddresses",
                              "postalAddresses[" + index.ToString() + "]",
                              postalAdressPayload.SyncUuid.ToString()));
            }

            //emails
            int emailsCount = document.emails.documents.Count;

            tradingAccount.emails = new emailtype[emailsCount];
            for (int index = 0; index < emailsCount; index++)
            {
                List <SyncFeedEntryLink> emailLinks;
                EmailDocument            email = document.emails.documents[index] as EmailDocument;
                EmailPayload             EmailPayload;
                EmailPayload = _emailAdressTransformation.GetTransformedPayload(email, out emailLinks);
                tradingAccount.emails[index] = EmailPayload.Emailtype;

                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.emails.ToString(), EmailPayload.LocalID),
                              "emails",
                              "emails[" + index.ToString() + "]",
                              EmailPayload.SyncUuid.ToString()));
            }


            //phones
            int phonesCount = document.phones.documents.Count;

            tradingAccount.phones = new phoneNumbertype[phonesCount];
            for (int index = 0; index < phonesCount; index++)
            {
                List <SyncFeedEntryLink> phoneLinks;
                PhoneDocument            phone = document.phones.documents[index] as PhoneDocument;
                PhoneNumberPayload       phoneNumberPayload;
                phoneNumberPayload           = _phoneNumberTransformation.GetTransformedPayload(phone, out phoneLinks);
                tradingAccount.phones[index] = phoneNumberPayload.PhoneNumbertype;

                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.phoneNumbers.ToString(), phoneNumberPayload.LocalID),
                              "phones",
                              "phones[" + index.ToString() + "]",
                              phoneNumberPayload.SyncUuid.ToString()));
            }

            //contacts
            int contactsCount = document.people.documents.Count;

            tradingAccount.contacts = new contacttype[contactsCount];
            for (int index = 0; index < contactsCount; index++)
            {
                List <SyncFeedEntryLink> contactLinks;
                PersonDocument           person = document.people.documents[index] as PersonDocument;
                ContactPayload           contactPayload;
                contactPayload = _contactTransformation.GetTransformedPayload(person, out contactLinks);
                tradingAccount.contacts[index] = contactPayload.Contacttype;
                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.contacts.ToString(), contactPayload.LocalID),
                              "contacts",
                              "contacts[" + index.ToString() + "]",
                              contactPayload.SyncUuid.ToString()));
            }


            payload.TradingAccount = tradingAccount;

            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.tradingAccounts, document.Id));

            links.Add(selfLink);
            return(payload);
        }
        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());
        }