public static async Task SetCategoryOrderAsync(List <Guid> uuids) { // Check if the order already exists List <TableObject> tableObjects = await GetAllOrdersAsync(); TableObject tableObject = tableObjects.Find(obj => obj.GetPropertyValue(FileManager.OrderTableTypePropertyName) == FileManager.CategoryOrderType); if (tableObject == null) { // Create a new table object List <Property> properties = new List <Property> { // Set the type property new Property { Name = FileManager.OrderTableTypePropertyName, Value = FileManager.CategoryOrderType } }; int i = 0; foreach (var uuid in uuids) { properties.Add(new Property { Name = i.ToString(), Value = uuid.ToString() }); i++; } await TableObject.CreateAsync(Guid.NewGuid(), FileManager.OrderTableId, properties); } else { // Update the existing object int i = 0; Dictionary <string, string> newProperties = new Dictionary <string, string>(); foreach (var uuid in uuids) { newProperties.Add(i.ToString(), uuid.ToString()); i++; } await tableObject.SetPropertyValuesAsync(newProperties); // Remove the properties that are outside of the uuids range List <string> removedProperties = new List <string>(); foreach (var property in tableObject.Properties) { if (int.TryParse(property.Name, out int propertyIndex) && propertyIndex >= uuids.Count) { removedProperties.Add(property.Name); } } for (int j = 0; j < removedProperties.Count; j++) { await tableObject.RemovePropertyAsync(removedProperties[j]); } } }
public static async Task SetSoundOrderAsync(Guid categoryUuid, bool favourite, List <Guid> uuids) { // Check if the order object already exists List <TableObject> tableObjects = await GetAllOrdersAsync(); TableObject tableObject = tableObjects.Find((TableObject obj) => { // Check if the object is of type Sound if (obj.GetPropertyValue(FileManager.OrderTableTypePropertyName) != FileManager.SoundOrderType) { return(false); } // Check if the object has the right category uuid string categoryUuidString = obj.GetPropertyValue(FileManager.OrderTableCategoryPropertyName); Guid?cUuid = FileManager.ConvertStringToGuid(categoryUuidString); if (!cUuid.HasValue) { return(false); } string favString = obj.GetPropertyValue(FileManager.OrderTableFavouritePropertyName); bool.TryParse(favString, out bool fav); return(Equals(categoryUuid, cUuid) && favourite == fav); }); if (tableObject == null) { // Create a new table object List <Property> properties = new List <Property> { // Set the type property new Property { Name = FileManager.OrderTableTypePropertyName, Value = FileManager.SoundOrderType }, // Set the category property new Property { Name = FileManager.OrderTableCategoryPropertyName, Value = categoryUuid.ToString() }, // Set the favourite property new Property { Name = FileManager.OrderTableFavouritePropertyName, Value = favourite.ToString() } }; int i = 0; foreach (var uuid in uuids) { properties.Add(new Property { Name = i.ToString(), Value = uuid.ToString() }); i++; } await TableObject.CreateAsync(Guid.NewGuid(), FileManager.OrderTableId, properties); } else { // Update the existing object int i = 0; Dictionary <string, string> newProperties = new Dictionary <string, string>(); foreach (var uuid in uuids) { newProperties.Add(i.ToString(), uuid.ToString()); i++; } await tableObject.SetPropertyValuesAsync(newProperties); bool removeNonExistentSounds = FileManager.itemViewHolder.User == null || !FileManager.itemViewHolder.User.IsLoggedIn || (FileManager.itemViewHolder.User.IsLoggedIn && FileManager.syncFinished); if (removeNonExistentSounds) { // Remove the properties that are outside of the uuids range List <string> removedProperties = new List <string>(); foreach (var property in tableObject.Properties) { if (int.TryParse(property.Name, out int propertyIndex) && propertyIndex >= uuids.Count) { removedProperties.Add(property.Name); } } for (int j = 0; j < removedProperties.Count; j++) { await tableObject.RemovePropertyAsync(removedProperties[j]); } } } }