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);
        }
예제 #2
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);
        }
예제 #4
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 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);
        }
예제 #6
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);
        }