public void Read(string id) { Feed <FeedEntry> result = new Feed <FeedEntry>(); //result.Updated = GetRandomDate(); result.Url = _request.Uri.ToString(); result.Author.Name = "Northwind Adapter"; string resource = TrimApostophes(id); if (resource != null) { _request.Response.FeedEntry = _wrapper.GetFeedEntry(resource); if (_request.Response.FeedEntry != null && !_request.Response.FeedEntry.IsDeleted && isActive(_request.Response.FeedEntry)) { _request.Response.FeedEntry.Title = _request.Response.FeedEntry.ToString(); } else { throw new DiagnosesException(Severity.Error, resource + " not found", DiagnosisCode.DatasetNotFound); } } else { result.Category.Scheme = "http://schemas.sage.com/sdata/categories"; result.Category.Term = "collection"; result.Category.Label = "Resource Collection"; string[] ids = _wrapper.GetFeed(); long start = Math.Max(0, _request.Uri.StartIndex - 1); //Startindex is 1-based long max = _request.Uri.Count == null ? ids.Length : Math.Min((long)_request.Uri.Count + start, (long)ids.Length); long entryCount = _request.Uri.Count == null ? DEFAULT_COUNT : (long)_request.Uri.Count; _request.Uri.Count = entryCount; for (long i = start; result.Entries.Count < entryCount && i < ids.Length; i++) { string entryId = ids[i]; FeedEntry entry = _wrapper.GetFeedEntry(entryId); if (entry != null) { entry.Title = entry.ToString(); entry.Links.AddRange(LinkFactory.CreateEntryLinks(_context, entry)); entry.Updated = DateTime.Now; result.Entries.Add(entry); } } result.Title = result.Entries.Count + " " + _context.ResourceKind.ToString(); HandlePaging(_request, result, ids); //FeedLink link = new FeedLink(_request.Uri.AppendPath("$schema").ToString(), LinkType.Schema, MediaType.Xml, "Schema"); FeedLink[] links = LinkFactory.CreateFeedLinks(_context, _request.Uri.ToString()); result.Links.AddRange(links); result.Updated = DateTime.Now; _request.Response.Feed = result; } }
public override Sage.Common.Syndication.FeedEntry GetTransformedPayload(Application.Base.Document document) { PriceFeedEntry result = _transform.GetTransformedPayload(document as PriceDocument); result.commodity = (CommodityFeedEntry)_commodityFeedEntryWrapper.GetFeedEntry(document.Id); return(result); }
private SalesOrderLineFeedEntry GetLineItem(Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.CalculatedOrderDetailsRow row, NorthwindConfig config) { #region Declarations SalesOrderLineFeedEntry payload; string id; decimal discountPercentage; #endregion id = row.OrderID.ToString() + "-" + row.ProductID.ToString(); payload = new SalesOrderLineFeedEntry(); payload.UUID = GetUuid(id, "", SupportedResourceKinds.salesOrderLines); payload.commodity = (CommodityFeedEntry)_commoditiesFeedEntryWrapper.GetFeedEntry(row.ProductID.ToString()); /* payload.commodity = new CommodityFeedEntry(); * payload.commodity.UUID = GetUuid(row.ProductID.ToString(), "", SupportedResourceKinds.commodities);*/ payload.salesOrder = new SalesOrderFeedEntry(); payload.salesOrder.UUID = GetUuid(row.OrderID.ToString(), "", SupportedResourceKinds.salesOrders); payload.unitOfMeasure = (UnitOfMeasureFeedEntry)_unitsOfMeasureFeedEntryWrapper.GetFeedEntry(row.ProductID.ToString()); /*payload.unitOfMeasure = new UnitOfMeasureFeedEntry(); * payload.unitOfMeasure.UUID = GetUuid(row.ProductID.ToString(), "", SupportedResourceKinds.unitsOfMeasure);*/ payload.quantity = row.IsQuantityNull() ? Convert.ToInt16(0) : row.Quantity; payload.initialPrice = row.IsUnitPriceNull() ? new decimal(0) : row.UnitPrice; payload.orderLineDiscountPercent = row.IsDiscountNull() ? (decimal)0 : Convert.ToDecimal(row.Discount); payload.discountTotal = payload.initialPrice * (decimal)payload.orderLineDiscountPercent; payload.costTotal = (decimal)payload.initialPrice * (1 - payload.orderLineDiscountPercent); payload.netTotal = Convert.ToDecimal(payload.quantity) * Convert.ToDecimal(payload.costTotal); SetCommonProperties(id, payload, SupportedResourceKinds.salesOrderLines); return(payload); }
protected FeedEntry BuildFeedEntryForCorrelation(CorrelatedResSyncInfo corrResSyncInfo, IFeedEntryEntityWrapper wrapper) { FeedEntry feedEntry; #region Payload if (null != wrapper) { // Get resource data feedEntry = wrapper.GetFeedEntry(corrResSyncInfo.LocalId); } else { // Create an empty payload container feedEntry = new FeedEntry(); feedEntry.IsDeleted = false; feedEntry.Key = corrResSyncInfo.LocalId; } if (feedEntry != null) { // modify url and set uuid as we are requesting linked resources here. feedEntry.Uri = string.Format("{0}{1}('{2}')", _requestContext.DatasetLink, _requestContext.ResourceKind.ToString(), corrResSyncInfo.LocalId); feedEntry.UUID = corrResSyncInfo.ResSyncInfo.Uuid; #endregion // set id tag feedEntry.Id = feedEntry.Uri; // set title tag feedEntry.Title = string.Format("{0}('{1}') : {2}", _requestContext.ResourceKind.ToString(), corrResSyncInfo.LocalId, corrResSyncInfo.ResSyncInfo.Uuid); feedEntry.Updated = corrResSyncInfo.ResSyncInfo.ModifiedStamp.ToLocalTime(); // set resource dependent links (self, edit, schema, template, post, service) feedEntry.Links.AddRange(LinkFactory.CreateEntryLinks(_requestContext, feedEntry)); } return(feedEntry); }
protected FeedEntry BuildFeedEntryForCorrelation(CorrelatedResSyncInfo corrResSyncInfo, IFeedEntryEntityWrapper wrapper) { FeedEntry feedEntry; #region Payload if (null != wrapper) { // Get resource data feedEntry = wrapper.GetFeedEntry(corrResSyncInfo.LocalId); } else { // Create an empty payload container feedEntry = new FeedEntry(); feedEntry.IsDeleted = false; feedEntry.Key = corrResSyncInfo.LocalId; } if (feedEntry != null) { // modify url and set uuid as we are requesting linked resources here. feedEntry.Uri = string.Format("{0}{1}('{2}')", _requestContext.DatasetLink, _requestContext.ResourceKind.ToString() , corrResSyncInfo.LocalId); feedEntry.UUID = corrResSyncInfo.ResSyncInfo.Uuid; #endregion // set id tag feedEntry.Id = feedEntry.Uri; // set title tag feedEntry.Title = string.Format("{0}('{1}') : {2}", _requestContext.ResourceKind.ToString(), corrResSyncInfo.LocalId, corrResSyncInfo.ResSyncInfo.Uuid); feedEntry.Updated = corrResSyncInfo.ResSyncInfo.ModifiedStamp.ToLocalTime(); // set resource dependent links (self, edit, schema, template, post, service) feedEntry.Links.AddRange(LinkFactory.CreateEntryLinks(_requestContext, feedEntry)); } return feedEntry; }
private SalesOrderFeedEntry GetPayload(Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.CalculatedOrdersRow row, Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.CalculatedOrderDetailsDataTable detailDataTable, NorthwindConfig config) { #region Declarations SalesOrderFeedEntry payload; string id; CountryCodes countryCodes = new CountryCodes(); #endregion id = row.OrderID.ToString(); payload = new SalesOrderFeedEntry(); payload.UUID = GetUuid(id, "", SupportedResourceKinds.salesOrders); payload.active = true; payload.currency = config.CurrencyCode; payload.pricelist = new PriceListFeedEntry(); payload.pricelist.UUID = GetUuid(id, "", SupportedResourceKinds.priceLists); if (!row.IsCustomerIDNull()) { /*payload.tradingAccount = new TradingAccountFeedEntry(); * payload.tradingAccount.Key = Sage.Integration.Northwind.Application.API.Constants.CustomerIdPrefix + row.CustomerID; * payload.tradingAccount.UUID = GetUuid(payload.tradingAccount.Key, "", SupportedResourceKinds.tradingAccounts); * payload.tradingAccount.Id = GetSDataId(payload.tradingAccount.Key, SupportedResourceKinds.tradingAccounts); * payload.tradingAccount.Uri = payload.tradingAccount.Id;*/ payload.tradingAccount = (TradingAccountFeedEntry)_tradingAccountsFeedEntryWrapper.GetFeedEntry(Sage.Integration.Northwind.Application.API.Constants.CustomerIdPrefix + row.CustomerID); } if (!row.IsOrderDateNull()) { payload.date = row.OrderDate; } //payload.lineCount = detailDataTable.Rows.Count; payload.discountTotal = row.IsDiscountAmountNull() ? new decimal(0) : Convert.ToDecimal(row.DiscountAmount); payload.netTotal = row.IsTotalNetPriceNull() ? new decimal(0) : Convert.ToDecimal(row.TotalNetPrice); payload.carrierTotalPrice = row.IsFreightNull() ? new decimal(0) : row.Freight; payload.grossTotal = payload.netTotal; if (!row.IsRequiredDateNull()) { payload.dueDate = row.RequiredDate; } if (!row.IsShipViaNull()) { payload.deliveryMethod = row.ShipVia.ToString();; } PostalAddressFeedEntry address = new PostalAddressFeedEntry(); address.active = true; address.address1 = row.IsShipAddressNull() ? null : row.ShipAddress; address.country = row.IsShipCountryNull() ? null : row.ShipCountry; address.townCity = row.IsShipCityNull() ? null : row.ShipCity; address.zipPostCode = row.IsShipPostalCodeNull() ? null : row.ShipPostalCode; address.type = postalAddressTypeenum.Shipping; payload.postalAddresses = new PostalAddressFeed(); //TODO: check if valid Address? payload.postalAddresses.Entries.Add(address); payload.salesOrderLines = new SalesOrderLineFeed(); foreach (Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.CalculatedOrderDetailsRow detailRow in detailDataTable.Rows) { SalesOrderLineFeedEntry soPayload = GetLineItem(detailRow, config); payload.salesOrderLines.Entries.Add(soPayload); } return(payload); }