public InMemoryDataRepositoryService() { var config = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed); _summaryMetadataSource = config.Get <IMetadataProvider <TSummaryType, TSummaryMetadataType> >( DataRepositoryServiceLocalConfig.SummaryMetadataProvider); _itemMetadataSource = config.Get <IMetadataProvider <TDataType, TItemMetadataType> >( DataRepositoryServiceLocalConfig.ItemMetadataProvider); _summarizer = config.Get <ISummarizer <TDataType, TSummaryType> >(DataRepositoryServiceLocalConfig.Summarizer); if (config.SettingExists(DataRepositoryServiceLocalConfig.ContextFilter)) { _contextFilter = config.Get <IContextFilter>(DataRepositoryServiceLocalConfig.ContextFilter); } IEnumerable <TDataType> initialData = null; if (config.SettingExists(InMemoryDataRepositoryServiceLocalConfig.OptionalInitialData)) { initialData = config.Get <IEnumerable <TDataType> >(InMemoryDataRepositoryServiceLocalConfig.OptionalInitialData); } if (null != initialData) { initialData.ForEach(d => _data.TryAdd(DataDocument.GetDocumentId(d), d)); } }
public virtual HttpResponseMessage PostNew(TDataType document) { _dataRepository.CreateNew(document); var response = Request.CreateResponse <TDataType>(HttpStatusCode.Created, document); string uri = Url.Link("DefaultApi", new { id = DataDocument.GetDocumentId(document) }); response.Headers.Location = new Uri(uri); return(response); }
public void CreateNewBatch(IList <TDataType> documents) { using (var trx = _client.BeginTransaction()) { var tbl = _client.OpenTable <TDataType>(_tableId); documents.ForEach(doc => tbl.AddNew(DataDocument.GetDocumentId(doc), doc)); _client.Commit(); } }
public string CreateNew(TDataType document) { using (var trx = _client.BeginTransaction()) { var tbl = _client.OpenTable <TDataType>(_tableId); tbl.AddNew(DataDocument.GetDocumentId(document), document); _client.Commit(); } return(DataDocument.GetDocumentId(document)); }
public IList <TItemPackageType> Load(IList <string> id) { var retval = new List <TItemPackageType>(); var items = from dt in _data.Values where id.Contains(DataDocument.GetDocumentId(dt)) select dt; retval.AddRange( items.Select(i => new TItemPackageType { Item = i, Metadata = _itemMetadataSource.Metadata })); return(retval); }
public void Store(TDataType document) { var key = DataDocument.GetDocumentId(document); if (!_data.ContainsKey(key)) { _data.TryAdd(key, document); } else { _data[DataDocument.GetDocumentId(document)] = document; } }
public void Update(TDataType document) { var id = DataDocument.GetDocumentId(document); using (var dc = DocumentStoreLocator.ContextualResolve()) { var existing = dc.Load <TDataType>(id); if (null == existing) { throw new InstanceNotFoundException(); } _updateAssignment(existing, document); dc.SaveChanges(); } }
public IList <TItemPackageType> Load(IList <TSummaryType> proxies) { var retval = new List <TItemPackageType>(); var ids = from p in proxies select _summarizer.Identify(p); var items = from dt in _data.Values where ids.Contains(DataDocument.GetDocumentId(dt)) select dt; retval.AddRange( items.Select(i => new TItemPackageType { Item = i, Metadata = _itemMetadataSource.Metadata })); return(retval); }
public void BatchUpdate(IList <TDataType> documents) { using (var dc = DocumentStoreLocator.ContextualResolve()) { var existing = dc.Load <TDataType>(documents.Select(DataDocument.GetDocumentId)); foreach (var item in existing) { var update = documents.First(d => DataDocument.GetDocumentId(d) == DataDocument.GetDocumentId(item)); if (null == update) { throw new InstanceNotFoundException(); } _updateAssignment(item, update); } dc.SaveChanges(); } }
public void Update(TDataType document) { TDataType oldData; if (!_data.TryGetValue(DataDocument.GetDocumentId(document), out oldData)) { throw new InstanceNotFoundException(); } if (DataDocument.HasEtag <TDataType>()) { if (DataDocument.GetDocumentEtag(oldData) != DataDocument.GetDocumentEtag(document)) { throw new DBConcurrencyException(); } } DataDocument.SetDocumentEtagNew(document); _data[DataDocument.GetDocumentId(document)] = document; }
public void Store(TDataType document) { using (var trx = _client.BeginTransaction()) { var tbl = _client.OpenTable <TDataType>(_tableId); var readData = tbl.Fetch(new string[] { DataDocument.GetDocumentId(document) }); if (readData.Any()) { InternalUpdate(document, tbl); } else { tbl.AddNew(DataDocument.GetDocumentId(document), document); } _client.Commit(); } }
private static void InternalUpdate(TDataType document, IStructuredDataDictionary <TDataType> tbl) { var fetchedData = tbl.Fetch(new string[] { DataDocument.GetDocumentId(document) }); if (!fetchedData.Any()) { throw new InstanceNotFoundException(); } var oldData = fetchedData.First().Data; var eTag = fetchedData.First().ETag; if (DataDocument.HasEtag <TDataType>()) { eTag = DataDocument.GetDocumentEtag(document); if (DataDocument.GetDocumentEtag(oldData) != eTag) { throw new DBConcurrencyException(); } } tbl.Update(DataDocument.GetDocumentId(document), document, eTag); }
public void Delete(TDataType document) { var id = DataDocument.GetDocumentId(document); IdDelete(id); }
public string CreateNew(TDataType document) { _data.TryAdd(DataDocument.GetDocumentId(document), document); return(DataDocument.GetDocumentId(document)); }
public void Delete(TDataType document) { IdDelete(DataDocument.GetDocumentId(document)); }