public bool CopyFrom(IInventoryCollection other) { var currentIDs = Items.Select(item => item.ID).ToArray(); var newIDs = other.Items.Select(item => item.ID).ToArray(); var idsToRemove = currentIDs.Except(newIDs).ToArray(); foreach (var id in idsToRemove) { RemoveItemByID(id); } bool anyItemUpdated = false; var idsToUpdate = newIDs.Intersect(idsToRemove); foreach (var id in idsToUpdate) { if (this[id].CopyFrom(other[id])) { anyItemUpdated = true; } } var idsToAdd = newIDs.Except(currentIDs).ToArray(); foreach (var id in idsToAdd) { AddItem(other[id]); } return(anyItemUpdated || (0 < idsToRemove.Length) || (0 < idsToAdd.Length)); }
private void ParseDataFromFeedOrEntry(IInventoryCollection dataCollection, ODataReader reader) { while (reader.Read()) { if (reader.State == ODataReaderState.EntryEnd) { { var entry = reader.Item as ODataEntry; if (entry != null) { if (entry.MediaResource != null) { WriteValue(null, "OData_MediaResource", entry.Properties); } var item = WriteProperties(entry.Properties); if (item.IsValid) { dataCollection.AddItem(item); } } } } } }
public IQueryable <InventoryItem> GetFilteredCarInventory(string searchParam, string sortColumn, int?sortOrder, int?pageParam) { BoxXDataReader dataReader = BoxXDataReader.Instance; IInventoryCollection dataCollection = ModelFactory.CreateInventoryCollection(dataReader.SchemaPropertyNames); IInventoryQuery query = QueryFactory.CreateQuery(); SortOrder? parsedSortOrder = ParseSortOrder(sortOrder); if (parsedSortOrder.HasValue) { var propertyName = BoxXDataReader.GetPropertyNameFromColumnName(sortColumn); if (propertyName.HasValue) { query.SortWith(propertyName.Value, parsedSortOrder.Value); } } if (pageParam.HasValue) { query.PagingWith(pageParam.Value, DataNumPerPage); } foreach (var propertyName in dataReader.SchemaPropertyNames) { query.FilterWith(propertyName.ValueLikes(searchParam)); } dataReader.GetData(dataCollection, query); return(dataCollection.Items.Cast <InventoryItem>().AsQueryable()); }
public IQueryable <InventoryItem> GetAllCarInventory() { BoxXDataReader dataReader = BoxXDataReader.Instance; IInventoryCollection dataCollection = ModelFactory.CreateInventoryCollection(dataReader.SchemaPropertyNames); IInventoryQuery query = QueryFactory.CreateQuery(); dataReader.GetData(dataCollection, query); return(dataCollection.Items.Cast <InventoryItem>().AsQueryable()); }
public IInventoryCollection Filter(Predicate <IInventoryItem> match) { IInventoryCollection newCollection = ModelFactory.CreateInventoryCollection(QueriedPropertyNames); foreach (IInventoryItem inventoryItem in _inventoriesItems.Where(inventoryItem => match(inventoryItem))) { newCollection.AddItem(inventoryItem); } return(newCollection); }
public void GetData(IInventoryCollection dataCollection, IInventoryQuery query) { GetValueWithoutLocallyFiltering(dataCollection, query); if (query.Filters.Any()) { var filteredCollection = dataCollection.Filter(inventoryItem => query.Filters.Any(filter => filter.Match(inventoryItem))); dataCollection.CopyFrom(filteredCollection); } }
// TODO: Remove this method once the test failed. public void GetValueWithoutLocallyFiltering(IInventoryCollection dataCollection, IInventoryQuery query) { if (dataCollection == null) { throw new ArgumentNullException("dataCollection"); } if (_model == null) { _model = BoxXDataCRUDHelpers.GetMetadata(BoxXDataCRUDHelpers.MetadataUrl); } var requestMessage = new ODataClientRequestMessage(new Uri(BoxXDataCRUDHelpers.DataCollectionUrl + query.GetQueryUriOptions()), ODataConstants.MethodGet); BoxXDataCRUDHelpers.GetFeedOrEntryRequsetHeaderSetter(requestMessage, AuthUtil.Instance.AccessToken); IODataResponseMessage responseMessage = requestMessage.GetResponse(); using (var messageReader = new ODataMessageReader(responseMessage, new ODataMessageReaderSettings(), _model)) { switch (GetMessageType(responseMessage)) { case ODataMessageType.Feed: { ODataReader reader = messageReader.CreateODataFeedReader(); ParseDataFromFeedOrEntry(dataCollection, reader); break; } case ODataMessageType.Entry: { ODataReader reader = messageReader.CreateODataEntryReader(); ParseDataFromFeedOrEntry(dataCollection, reader); break; } default: { throw new ArgumentOutOfRangeException(); } } } }
private Inventory(IInventoryCollection inventory, ILog logger) { this.inventory = inventory; this.logger = logger; }
public IInventory Dispense(string id, IAmount amount, int count) { inventory = inventory.Dispense(id, amount, count); return(this); }
public IInventory Refill(IEnumerable <IItemInventory> items) { inventory = inventory.Refill(items); return(this); }