private string GetLocalId(Guid uuid, SupportedResourceKinds resKind) { CorrelatedResSyncInfo[] results = _correlatedResSyncInfoStore.GetByUuid(resKind.ToString(), new Guid[] { uuid }); if (results.Length > 0) { return(results[0].LocalId); } return(string.Empty); }
public static string GetSingleResourceUrl(string baseUrl, string payloadpath, string id) { if (!baseUrl.EndsWith("/")) { baseUrl = baseUrl + "/"; } SupportedResourceKinds resKind = GetResourceKind(payloadpath); return(String.Format("{0}{1}('{2}')", baseUrl, resKind.ToString(), id)); }
public TransformationBase(RequestContext context, SupportedResourceKinds resourceKind) { _context = context; _datasetLink = _context.DatasetLink; _config = _context.Config; _resourceKind = resourceKind; _resourceKindString = _resourceKind.ToString(); _originApplication = _datasetLink + _resourceKindString; _correlatedResSyncInfoStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetCorrelatedResSyncStore(_context.SdataContext); }
public TransformationBase(RequestContext context, SupportedResourceKinds resourceKind) { _context = context; _datasetLink = _context.DatasetLink; _config = _context.Config; _resourceKind = resourceKind; _resourceKindString = _resourceKind.ToString(); _originApplication = _datasetLink + _resourceKindString; _correlatedResSyncInfoStore = NorthwindAdapter.StoreLocator.GetCorrelatedResSyncStore(_context.SdataContext); }
public virtual SyncFeedEntry GetFeedEntry(string id) { SyncFeedEntry result = new SyncFeedEntry(); result.Payload = PayloadFactory.CreatePayload(_resourceKind); Identity identity; Document document; identity = GetIdentity(id); document = _entity.GetDocument(identity, _emptyToken, _context.Config); if (document.LogState == LogState.Deleted) { return(null); } List <SyncFeedEntryLink> links; result.Payload = GetTransformedPayload(document, out 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; result.SyncLinks = links; return(result); }
private Guid GetUuid(string localId, string uuidString, SupportedResourceKinds resKind) { if (String.IsNullOrEmpty(localId)) { return(Guid.Empty); } CorrelatedResSyncInfo[] results = _correlatedResSyncInfoStore.GetByLocalId(resKind.ToString(), new string[] { localId }); if (results.Length > 0) { return(results[0].ResSyncInfo.Uuid); } Guid result; if (string.IsNullOrEmpty(uuidString)) { result = Guid.NewGuid(); } else { try { GuidConverter converter = new GuidConverter(); result = (Guid)converter.ConvertFromString(uuidString); if (Guid.Empty.Equals(result)) { result = Guid.NewGuid(); } } catch (Exception) { result = Guid.NewGuid(); } } ResSyncInfo newResSyncInfo = new ResSyncInfo(result, _context.DatasetLink + resKind.ToString(), 0, string.Empty, DateTime.Now); CorrelatedResSyncInfo newCorrelation = new CorrelatedResSyncInfo(localId, newResSyncInfo); _correlatedResSyncInfoStore.Put(resKind.ToString(), newCorrelation); 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); }
private void PersistRelations(List <TransactionResult> transactions) { GuidConverter guidConverter = new GuidConverter(); foreach (TransactionResult transaction in transactions) { if (transaction.Status == TransactionStatus.Success) { SupportedResourceKinds resourceKind = GetSupportedResourceKind(transaction.EntityName); if (resourceKind == SupportedResourceKinds.None) { continue; } string uuidString = transaction.CRMID; Guid uuid = Guid.Empty; try { uuid = (Guid)guidConverter.ConvertFromString(uuidString); } catch { continue; } if (uuid == Guid.Empty) { continue; } string localId = transaction.ID; ResSyncInfo resSyncInfo = new ResSyncInfo(uuid, _context.DatasetLink + resourceKind.ToString(), -1, "", DateTime.Now); CorrelatedResSyncInfo correlatedResSyncInfo = new CorrelatedResSyncInfo(localId, resSyncInfo); // store the new correlation to the sync store _correlatedResSyncInfoStore.Put(resourceKind.ToString(), correlatedResSyncInfo); } } }
private Guid GetUuid(string localId, string uuidString, SupportedResourceKinds resKind) { if (String.IsNullOrEmpty(localId)) { return Guid.Empty; } CorrelatedResSyncInfo[] results = _correlatedResSyncInfoStore.GetByLocalId(resKind.ToString(), new string[] { localId }); if (results.Length > 0) return results[0].ResSyncInfo.Uuid; Guid result; if (string.IsNullOrEmpty(uuidString)) result = Guid.NewGuid(); else try { GuidConverter converter = new GuidConverter(); result = (Guid)converter.ConvertFromString(uuidString); if (Guid.Empty.Equals(result)) result = Guid.NewGuid(); } catch (Exception) { result = Guid.NewGuid(); } ResSyncInfo newResSyncInfo = new ResSyncInfo(result, _context.DatasetLink + resKind.ToString(), 0, string.Empty, DateTime.Now); CorrelatedResSyncInfo newCorrelation = new CorrelatedResSyncInfo(localId, newResSyncInfo); _correlatedResSyncInfoStore.Put(resKind.ToString(), newCorrelation); return result; }
private string GetLocalId(Guid uuid, SupportedResourceKinds resKind) { CorrelatedResSyncInfo[] results = _correlatedResSyncInfoStore.GetByUuid(resKind.ToString(), new Guid[] { uuid }); if (results.Length > 0) return results[0].LocalId; return string.Empty; }
public virtual FeedEntry GetFeedEntry(string id) { FeedEntry result; Identity identity; Document document; identity = GetIdentity(id); document = _entity.GetDocument(identity, _emptyToken, _context.Config); if (document.LogState == LogState.Deleted) { #warning The empty Feed Entry should have a type... result = getNewFeedEntry(); result.IsDeleted = true; result.Key = id; CorrelatedResSyncInfo[] corr = _correlatedResSyncInfoStore.GetByLocalId(_resourceKind.ToString(), new string[] { id }); if ((corr != null) && (corr.Length > 0)) { result.UUID = corr[0].ResSyncInfo.Uuid; } return(result); } result = GetTransformedPayload(document); return(result); }
protected string GetSDataId(string id, SupportedResourceKinds resourceKind) { return String.Format("{0}{1}('{2}')", _context.DatasetLink, resourceKind.ToString(), id); }
protected string GetSDataId(string id) { return(String.Format("{0}{1}('{2}')", _context.DatasetLink, _resourceKind.ToString(), id)); }
public static T GetTransformation <T>(SupportedResourceKinds resourceKind, RequestContext context) { string endpoint = context.DatasetLink + resourceKind.ToString(); if (stat_transformations.ContainsKey(endpoint)) { return((T)stat_transformations[endpoint]); } // create new transformation instance ITransformation transformation = null; switch (resourceKind) { case SupportedResourceKinds.tradingAccounts: transformation = new TradingAccountTransformation(context); break; case SupportedResourceKinds.emails: transformation = new EmailAdressTransformation(context); break; case SupportedResourceKinds.contacts: transformation = new ContactTransformation(context); break; case SupportedResourceKinds.phoneNumbers: transformation = new PhoneNumberTransformation(context); break; case SupportedResourceKinds.postalAddresses: transformation = new PostalAdressTransformation(context); break; case SupportedResourceKinds.commodityGroups: transformation = new CommodityGroupTransformation(context); break; case SupportedResourceKinds.unitsOfMeasureGroup: transformation = new UnitOfMeasureGroupTransformation(context); break; case SupportedResourceKinds.unitsOfMeasure: transformation = new UnitOfMeasureTransformation(context); break; case SupportedResourceKinds.commodities: transformation = new CommodityTransformation(context); break; case SupportedResourceKinds.priceLists: transformation = new PriceListTransformation(context); break; case SupportedResourceKinds.prices: transformation = new PriceTransformation(context); break; case SupportedResourceKinds.salesOrders: transformation = new SalesOrderTransformation(context); break; case SupportedResourceKinds.salesOrderLines: transformation = new SalesOrderLineTransformation(context); break; default: throw new InvalidOperationException(string.Format("ResourceKind {0} not supported.", resourceKind.ToString())); } T resultTransformation = (T)transformation; if (transformation != null) { stat_transformations.Add(endpoint, transformation); } return(resultTransformation); }