Esempio n. 1
0
        public static bool RenameSchemaField(string oldFieldKey, string newFieldKey, string schemaKey, Dictionary <string, object> schemaData, out string error)
        {
            bool result = true;

            if (!IsFieldNameValid(schemaData, newFieldKey, out error))
            {
                result = false;
            }
            else if (schemaData.ContainsKey(newFieldKey))
            {
                result = false;
                error  = "Field name already exists.";
            }
            else
            {
                // Do rename
                RenameField(oldFieldKey, newFieldKey, schemaData);

                // Remove the schema key from the listbyfieldname List
                List <string> schemaKeyList;
                if (ListByFieldName.TryGetValue(oldFieldKey, out schemaKeyList))
                {
                    schemaKeyList.Remove(schemaKey);
                    if (schemaKeyList.Count == 0)
                    {
                        ListByFieldName.Remove(oldFieldKey);
                    }
                }

                // Add the schema key to the listbyfieldname List under the new field name
                if (ListByFieldName.TryGetValue(newFieldKey, out schemaKeyList))
                {
                    schemaKeyList.Add(schemaKey);
                }
                else
                {
                    List <string> newListByFieldName = new List <string>()
                    {
                        schemaKey
                    };
                    ListByFieldName.Add(newFieldKey, newListByFieldName);
                }

                // Rename the fields in any existing items with this schema
                List <string> itemKeys = GetItemsOfSchemaType(schemaKey);
                foreach (string itemKey in itemKeys)
                {
                    Dictionary <string, object> itemData;
                    if (AllItems.TryGetValue(itemKey, out itemData))
                    {
                        RenameField(oldFieldKey, newFieldKey, itemData);
                    }
                }
            }

            ItemsNeedSave   |= result;
            SchemasNeedSave |= result;

            return(result);
        }
        public static void ClearAll()
        {
            AllItems.Clear();

            AllSchemas.Clear();
            ListByFieldName.Clear();
            ItemListBySchema.Clear();
            FilterSchemaKeyArray = null;
            SchemaKeyArray       = null;

            ItemsNeedSave   = true;
            SchemasNeedSave = true;
        }
Esempio n. 3
0
        private static void AddFieldToListByFieldName(string fieldKey, string schemaKey)
        {
            List <string> schemaKeyList;

            if (ListByFieldName.TryGetValue(fieldKey, out schemaKeyList))
            {
                schemaKeyList.Add(schemaKey);
            }
            else
            {
                schemaKeyList = new List <string>();
                schemaKeyList.Add(schemaKey);
                ListByFieldName.Add(fieldKey, schemaKeyList);
            }
        }
Esempio n. 4
0
        private static void LoadSchemas()
        {
            try
            {
                string json = File.ReadAllText(DataFilePath);
                _dataFileMD5 = json.Md5Sum();

                Dictionary <string, object> data = Json.Deserialize(json) as Dictionary <string, object>;

                // Clear all schema related lists
                AllSchemas.Clear();
                ListByFieldName.Clear();
                ItemListBySchema.Clear();
                FilterSchemaKeyArray = null;
                SchemaKeyArray       = null;

                string error;
                string schemaName;
                foreach (KeyValuePair <string, object> pair in data)
                {
                    if (!pair.Key.StartsWith(GDEConstants.SchemaPrefix))
                    {
                        continue;
                    }

                    Dictionary <string, object> schemaData = pair.Value as Dictionary <string, object>;
                    schemaName = pair.Key.Replace(GDEConstants.SchemaPrefix, "");
                    AddSchema(schemaName, schemaData, out error, false);
                }

                SchemaKeyArray       = BuildSchemaKeyArray();
                FilterSchemaKeyArray = BuildSchemaFilterKeyArray();

                SchemasNeedSave = false;
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
Esempio n. 5
0
        public static void RemoveFieldFromSchema(string schemaKey, Dictionary <string, object> schemaData, string deletedFieldKey, bool deleteFromItem = true)
        {
            schemaData.Remove(deletedFieldKey);
            schemaData.Remove(string.Format(GDEConstants.MetaDataFormat, GDEConstants.TypePrefix, deletedFieldKey));
            schemaData.Remove(string.Format(GDEConstants.MetaDataFormat, GDEConstants.IsListPrefix, deletedFieldKey));

            // Remove the schema key from the listbyfieldname List
            List <string> schemaKeyList;

            if (ListByFieldName.TryGetValue(deletedFieldKey, out schemaKeyList))
            {
                schemaKeyList.Remove(schemaKey);
                if (schemaKeyList.Count == 0)
                {
                    ListByFieldName.Remove(deletedFieldKey);
                }
            }

            if (deleteFromItem)
            {
                RemoveFieldFromItems(schemaKey, deletedFieldKey);
            }
        }