public void UpdateMasterData(SheetInfo sheetInfo) { EditorUtility.DisplayProgressBar(sheetInfo.Title, "", 0); ValueRange result = GetSheetService().Spreadsheets.Values.Get(sheetInfo.SpreadSheetId, sheetInfo.Title).Execute(); IList <IList <object> > sheetValues = result.Values; string repositoryName = "Master" + sheetInfo.Title.Replace("[D]", "").SnakeToUpperCamel() + "Repository"; Debug.Log($"repository name : {repositoryName}"); Type repositoryType = repositoryName.ToType(); Debug.Log($"repository type : {repositoryType.Name}"); IList <string> fieldKeys = sheetValues[1].Select(x => x.ToString()).ToList(); List <Dictionary <string, object> > values = new List <Dictionary <string, object> >(); for (var index = 3; index < sheetValues.Count; index++) { IList <object> row = sheetValues[index]; Dictionary <string, object> dictionary = new Dictionary <string, object>(); for (var i = 0; i < fieldKeys.Count; i++) { string key = fieldKeys[i]; object value = row.ElementAtOrDefault(i); if (string.IsNullOrEmpty(key) || value == null) { continue; } dictionary.Add(key, value); } values.Add(dictionary); } try { object repositoryInstance = Activator.CreateInstance(repositoryType); DatabaseReflection.InsertAll(repositoryType, repositoryInstance, values); string json = JsonUtility.ToJson(repositoryInstance, true); IDatabase database = repositoryInstance as IDatabase; ExIO.WriteAllText(Path.Combine(Application.dataPath, "../", DatabaseSettings.Location.FolderName, database.Schema, database.KName + ".json"), json); } catch (Exception e) { Debug.LogError(e.ToString()); throw; } finally { ExUnityEditor.AssetDataBaseRefresh(); EditorUtility.ClearProgressBar(); } }
void GenerateEnumScript() { var list = TableDefinitionRepository.Instance.FindAllBy(x => x.SchemaType.IsEnumeration()); for (var index = 0; index < list.Count; index++) { TableDefinitionEntity entity = list[index]; float progress = (float)index / list.Count; EditorUtility.DisplayProgressBar("Generate Enumeration...", entity.PhysicalName, progress); string script = entity.GenerateEnumScript(); string enumFilePath = Path.Combine("Assets/App/Database/Enumerations", entity.GetEnumScriptFileName); ExIO.WriteAllText(enumFilePath, script); ExUnityEditor.AssetDataBaseRefresh(); string[] labels = { entity.SchemaType.ToString() }; AssetDatabase.SetLabels(AssetDatabase.LoadAssetAtPath <TextAsset>(enumFilePath), labels); } }
/// <summary> /// Save to local. /// </summary> /// <param name="database"></param> /// <param name="filePath"></param> /// <param name="isPrettyPrint"></param> /// <param name="isDeleteContent"></param> public static void Save(this IDatabase database, string filePath, bool isPrettyPrint, bool isDeleteContent) { ExIO.WriteAllText(filePath, isDeleteContent ? "" : database.ToJson(isPrettyPrint)); ExUnityEditor.AssetDataBaseRefresh(); }
void GenerateTableDefinitionScript() { List <TableDefinitionEntity> list = TableDefinitionRepository.Instance.FindAllBy(x => !x.SchemaType.IsEnumeration()); for (var index = 0; index < list.Count; index++) { TableDefinitionEntity entity = list[index]; float progress = (float)index / list.Count; EditorUtility.DisplayProgressBar("Generate TableDefinition...", entity.PhysicalName, progress); string entityScript = entity.GenerateEntityScript(); string entityFilePath = Path.Combine("Assets/App/Database", entity.SchemaType.ToString(), entity.GetEntityScriptFileName); ExIO.WriteAllText(entityFilePath, entityScript); string entityServiceScript = entity.GenerateEntityServiceScript(); string entityServiceFilePath = Path.Combine("Assets/App/Database/", entity.SchemaType.ToString(), entity.GetEntityServiceScriptFileName); if (!File.Exists(entityServiceFilePath)) { ExIO.WriteAllText(entityServiceFilePath, entityServiceScript); } string repositoryScript = ""; string repositoryServiceScript = ""; string fileName = ""; string serviceFilePath = ""; if (entity.PersistentObjectType.IsRepository()) { repositoryScript = entity.GenerateRepositoryScript(); fileName = entity.GetRepositoryScriptFileName; repositoryServiceScript = entity.GenerateRepositoryServiceScript(); serviceFilePath = Path.Combine("Assets/App/Database/", entity.SchemaType.ToString(), entity.GetRepositoryServiceScriptFileName); } else if (entity.PersistentObjectType.IsDataMapper()) { repositoryScript = entity.GenerateDataMapperScript(); fileName = entity.GetDataMapperScriptFileName; repositoryServiceScript = entity.GenerateDataMapperServiceScript(); serviceFilePath = Path.Combine("Assets/App/Database/", entity.SchemaType.ToString(), entity.GetDataMapperServiceScriptFileName); } string repositoryFilePath = Path.Combine("Assets/App/Database/", entity.SchemaType.ToString(), fileName); ExIO.WriteAllText(repositoryFilePath, repositoryScript); if (!File.Exists(serviceFilePath)) { ExIO.WriteAllText(serviceFilePath, repositoryServiceScript); } ExUnityEditor.AssetDataBaseRefresh(); string[] entityLabels = { entity.SchemaType.ToString(), "Entity", "Database" }; AssetDatabase.SetLabels(AssetDatabase.LoadAssetAtPath <TextAsset>(entityFilePath), entityLabels); string[] repositoryLabels = { entity.SchemaType.ToString(), entity.PersistentObjectType.ToString(), "Database" }; AssetDatabase.SetLabels(AssetDatabase.LoadAssetAtPath <TextAsset>(repositoryFilePath), repositoryLabels); } }