예제 #1
0
        /// <summary>
        /// Encrypt Load from local. and initialize database instance.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="filePath"></param>
        /// <param name="isEncrypt"></param>
        /// <param name="password"></param>
        /// <param name="salt"></param>
        public static void EncryptLoad(this IDatabase database, string filePath, string password, string salt)
        {
            byte[] contents = ExIO.ReadAllBytes(filePath);
            string jsonData = System.Text.Encoding.UTF8.GetString(Aes128.Decrypt(contents, password, salt));

            database.FromJson(jsonData);
        }
예제 #2
0
 public void x(int ID)
 {
     try {
         String path = Assembly.GetExecutingAssembly().Location;
         path = path.Substring(0, path.LastIndexOf('\\')) + "\\TempOrder.txt";//删除文件名
         if (!ExIO.Exists(path))
         {
             ExIO.CreateFile(path);
         }
         String str = ExIO.Read(path);
         if (str.Contains(ID + ","))
         {
             return;
         }
         str += ID + ",";
         if (str.Length > 20000)
         {
             str = str.Substring(10000);
             str = str.TrimStart(new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' });
             str = str.TrimStart(',');
         }
         if (!ExIO.Write(path, str))
         {
             return;
         }
     } catch (Exception ex) {
         throw;
     }
 }
예제 #3
0
        /// <summary>
        /// Load from local. and initialize database instace.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="filePath"></param>
        public static void Load(this IDatabase database, string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                ExDebug.LogWarning($"File path is null or empty. Database name is {database.KName}");
                return;
            }

            database.FromJson(ExIO.ReadAllText(filePath));
        }
예제 #4
0
        private void OnEnable()
        {
            if (ExAssetDatabase.FindAllAssetByTypeName <SpreadSheetSettingAsset>().IsNullOrEmpty())
            {
                SpreadSheetSettingAsset asset = CreateInstance(typeof(SpreadSheetSettingAsset)) as SpreadSheetSettingAsset;
                ExIO.CreateDirectoryNotExist("Assets/App/Editor/");
                AssetDatabase.CreateAsset(asset, Path.Combine("Assets/App/Editor/", typeof(SpreadSheetSettingAsset).Name + ".asset"));
                AssetDatabase.SaveAssets();
            }

            Initialize();
        }
        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);
            }
        }
예제 #7
0
 /// <summary>
 /// Encrypt Save to local.
 /// </summary>
 /// <param name="database"></param>
 /// <param name="filePath"></param>
 /// <param name="password"></param>
 /// <param name="salt"></param>
 /// <param name="isDeleteContent"></param>
 public static void EncryptSave(this IDatabase database, string filePath, string password, string salt, bool isDeleteContent)
 {
     byte[] contents = Aes128.Encrypt(isDeleteContent ? "" : database.ToJson(false), password, salt);
     ExIO.WriteAllBytes(filePath, contents);
     ExUnityEditor.AssetDataBaseRefresh();
 }
예제 #8
0
 /// <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);
            }
        }