public static void IncrementListSelectedCount(Folder phoneClient, ClientEntity list) { // get, increment, and store the selected count for a list string countString = GetListMetadataValue(phoneClient, list, ExtendedFieldNames.SelectedCount); int count = Convert.ToInt32(countString); count++; countString = count.ToString(); StoreListMetadataValue(phoneClient, list, ExtendedFieldNames.SelectedCount, countString); }
public static string GetListMetadataValue(Folder phoneClient, ClientEntity list, string fieldName) { if (phoneClient == null) return null; var listsMetadata = GetListMetadataList(phoneClient); var listID = list.ID.ToString(); string value = null; if (phoneClient.Items.Any(i => i.ParentID == listsMetadata.ID && i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == listID))) { var metadataItem = phoneClient.Items.Single(i => i.ParentID == listsMetadata.ID && i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == listID)); if (metadataItem.FieldValues.Any(fv => fv.FieldName == fieldName)) { var fieldValue = metadataItem.FieldValues.Single(fv => fv.FieldName == fieldName); value = (fieldValue != null) ? fieldValue.Value : null; } } return value; }
public static void StoreListMetadataValue(Folder phoneClient, ClientEntity list, string fieldName, string value) { if (phoneClient == null) return; var listsMetadata = GetListMetadataList(phoneClient); var listID = list.ID.ToString(); if (phoneClient.Items.Any(i => i.ParentID == listsMetadata.ID && i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == listID))) { var metadataItem = phoneClient.Items.Single(i => i.ParentID == listsMetadata.ID && i.FieldValues.Any(fv => fv.FieldName == FieldNames.EntityRef && fv.Value == listID)); Item copy = new Item(metadataItem); var fieldValue = metadataItem.GetFieldValue(fieldName, true); fieldValue.Value = value; // queue up a server request if (phoneClient.ID != Guid.Empty) { RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Update, Body = new List<Item>() { copy, metadataItem }, BodyTypeName = "Item", ID = metadataItem.ID, IsDefaultObject = true }); } } else { Guid id = Guid.NewGuid(); DateTime now = DateTime.UtcNow; var metadataItem = new Item() { ID = id, Name = list.Name, ItemTypeID = SystemItemTypes.Reference, FolderID = phoneClient.ID, ParentID = listsMetadata.ID, Created = now, LastModified = now, FieldValues = new ObservableCollection<FieldValue>() { new FieldValue() { ItemID = id, FieldName = FieldNames.EntityRef, Value = list.ID.ToString(), }, new FieldValue() { ItemID = id, FieldName = FieldNames.EntityType, Value = list.GetType().Name, }, new FieldValue() { ItemID = id, FieldName = fieldName, Value = value } } }; phoneClient.Items.Add(metadataItem); // queue up a server request if (phoneClient.ID != Guid.Empty) { RequestQueue.EnqueueRequestRecord(RequestQueue.SystemQueue, new RequestQueue.RequestRecord() { ReqType = RequestQueue.RequestRecord.RequestType.Insert, Body = metadataItem, ID = metadataItem.ID, IsDefaultObject = true }); } } // store the phone client folder StorageHelper.WritePhoneClient(phoneClient); }
public static string GetListSortOrder(Folder phoneClient, ClientEntity list) { return GetListMetadataValue(phoneClient, list, ExtendedFieldNames.SortBy); }
public static void StoreListSortOrder(Folder phoneClient, ClientEntity list, string listSortOrder) { StoreListMetadataValue(phoneClient, list, ExtendedFieldNames.SortBy, listSortOrder); }