public static void RemoveFieldFromSchema(string schemaKey, string deletedFieldKey, bool deleteFromItem = true) { Dictionary <string, object> schemaData; if (AllSchemas.TryGetValue(schemaKey, out schemaData)) { RemoveFieldFromSchema(schemaKey, schemaData, deletedFieldKey, deleteFromItem); } }
public static bool IsFieldNameValid(string schemaKey, string fieldName, out string error) { bool result = true; error = ""; Dictionary <string, object> data; if (AllSchemas.TryGetValue(schemaKey, out data)) { result = IsFieldNameValid(data, fieldName, out error); } else { result = false; error = "Error reading item data."; } return(result); }
public static bool RenameSchema(string oldSchemaKey, string newSchemaKey, out string error) { bool result = true; if (IsSchemaNameValid(newSchemaKey, out error)) { Dictionary <string, object> schemaData; if (AllSchemas.TryGetValue(oldSchemaKey, out schemaData)) { List <string> itemsWithSchema = GetItemsOfSchemaType(oldSchemaKey); Dictionary <string, object> schemaDataCopy = schemaData.DeepCopy(); // First remove the schema from the dictionary RemoveSchema(oldSchemaKey, false); // Then add the schema data under the new schema key if (AddSchema(newSchemaKey, schemaDataCopy, out error)) { List <string> itemBySchemaList; ItemListBySchema.TryGetValue(newSchemaKey, out itemBySchemaList); // Update the schema key on any existing items foreach (string itemKey in itemsWithSchema) { Dictionary <string, object> itemData; if (AllItems.TryGetValue(itemKey, out itemData)) { itemData.TryAddOrUpdateValue(GDEConstants.SchemaKey, newSchemaKey); } itemBySchemaList.Add(itemKey); } // Update any custom fields in schemas that had the old schema name foreach (string curSchemaKey in AllSchemas.Keys) { List <string> fieldsOfSchemaType = SchemaFieldKeysOfType(curSchemaKey, oldSchemaKey); fieldsOfSchemaType.AddRange(SchemaListFieldKeysOfType(curSchemaKey, oldSchemaKey)); if (fieldsOfSchemaType.Count > 0) { Dictionary <string, object> curSchemaData; AllSchemas.TryGetValue(curSchemaKey, out curSchemaData); if (curSchemaData == null) { continue; } foreach (string schemaFieldKey in fieldsOfSchemaType) { curSchemaData.TryAddOrUpdateValue(string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, schemaFieldKey), newSchemaKey); } } } // Lastly, update any custom fields that had the old schema name foreach (string curItemKey in AllItems.Keys) { List <string> fieldsOfSchemaType = ItemFieldKeysOfType(curItemKey, oldSchemaKey); fieldsOfSchemaType.AddRange(ItemListFieldKeysOfType(curItemKey, oldSchemaKey)); if (fieldsOfSchemaType.Count > 0) { Dictionary <string, object> curItemData; AllItems.TryGetValue(curItemKey, out curItemData); if (curItemData == null) { continue; } foreach (string itemFieldKey in fieldsOfSchemaType) { curItemData.TryAddOrUpdateValue(string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, itemFieldKey), newSchemaKey); } } } } else { // Add the schema back under the old key if this step failed AddSchema(oldSchemaKey, schemaDataCopy, out error); result = false; } } else { error = "Failed to read schema data."; result = false; } } else { result = false; } SchemasNeedSave |= result; ItemsNeedSave |= result; return(result); }