/// <summary> /// 角色登录请求 /// </summary> public static void DoClientLoginRequest(string rToken) { JsonNode rLoginMsg = new JsonClass(); rLoginMsg.Add("token", new JsonData(rToken)); Debug.Log(rLoginMsg.ToString()); NetworkClient.Instance.ClientRequest("connector.entryHandler.ClientLoginRequest", rLoginMsg, OnClientLoginResponse); }
public static T ReceiveAsset <T>(string rAssetPath) where T : new() { if (!File.Exists(rAssetPath)) { var rJsonNode = new JsonClass(); var rJsonStr = rJsonNode.ToString(); UtilTool.WriteAllText(rAssetPath, rJsonStr); return(new T()); } else { var rJsonStr = File.ReadAllText(rAssetPath); var rJsonNode = JsonParser.Parse(rJsonStr); return(rJsonNode.ToObject <T>()); } }
/// <summary> /// Generates a json representation of the manifest; /// </summary> /// <param name="name">The name.</param> /// <param name="version">The version.</param> /// <param name="dependencies">The dependencies.</param> /// <returns>Returns a task representing the asynchronous operation. The result contains the generated json manifest.</returns> public static async Task <string> GenerateJson(string name, string version, ParsedDependencies dependencies) { JsonClass rootJson = new JsonClass(); rootJson.Add("nameVersion", Constants.NAME_ASSEMBLY_VERSION); rootJson.Add("name", name); if (version.Count(c => c == '.') > 2) { version = string.Join(".", version.Split('.').Take(3)); } rootJson.Add("version", version); List <Task <JsonNode> > infrastructureTasks = new List <Task <JsonNode> >(); foreach (var dependency in dependencies.InfrastructureDependencies) { infrastructureTasks.Add(dependency.ToJson()); } List <Task <JsonNode> > serviceTasks = new List <Task <JsonNode> >(); foreach (var dependency in dependencies.ServiceDependencies) { serviceTasks.Add(dependency.ToJson()); } await Task.WhenAll(Task.WhenAll(serviceTasks), Task.WhenAll(infrastructureTasks)).ConfigureAwait(false); JsonArray infrastructureDependencies = new JsonArray(); JsonArray serviceDependencies = new JsonArray(); foreach (var task in serviceTasks) { serviceDependencies.Add(task.Result); } foreach (var task in infrastructureTasks) { infrastructureDependencies.Add(task.Result); } rootJson.Add("infrastructure_dependencies", infrastructureDependencies); rootJson.Add("service_dependencies", serviceDependencies); return(rootJson.ToString()); }
/// <summary> /// 导出Excel /// </summary> public void Export(ExcelFormat rExcelFormat) { string rConfigFile = UtilTool.PathCombine(this.ExcelConfigRootPath, "Excel", rExcelFormat.ExcelName); string rExportDir = UtilTool.PathCombine(this.ExcelConfigRootPath, "Text"); FileStream rStream = File.Open(rConfigFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); IExcelDataReader rExcelReader = ExcelReaderFactory.CreateOpenXmlReader(rStream); DataSet rResult = rExcelReader.AsDataSet(); DataTable rDataTable = rResult.Tables[rExcelFormat.SheetName]; if (rDataTable == null) { Debug.LogErrorFormat("Excel {0} has not sheet {1}.", rExcelFormat.ExcelName, rExcelFormat.SheetName); rExcelReader.Close(); rStream.Close(); return; } int rColumns = rDataTable.Columns.Count; int rRows = rDataTable.Rows.Count; if (rRows == 0) { Debug.LogErrorFormat("Excel {0} has empty rows.", rExcelFormat.ExcelName); rExcelReader.Close(); rStream.Close(); return; } Type rDataType = MainAssemblyExpand.GetType(rExcelFormat.ClassName); if (rDataType == null) { Debug.LogErrorFormat("Excel {0} can not find Class {1}, please check it.", rExcelFormat.ExcelName, rExcelFormat.ClassName); rExcelReader.Close(); rStream.Close(); return; } var rTitleRow = rDataTable.Rows[0]; var rFields = new Dict <string, FieldInfo>(); var rKeyIDs = new Dict <string, int>(); for (int i = 0; i < rColumns; i++) { FieldInfo rFileInfo = rDataType.GetField(rTitleRow[i].ToString()); rFields.Add(rTitleRow[i].ToString(), rFileInfo); rKeyIDs.Add(rTitleRow[i].ToString(), i); } JsonNode rDataJson = new JsonClass(); for (int i = 1; i < rRows; i++) { JsonNode rItemJson = new JsonClass(); foreach (var rPair in rFields) { string rFieldValue = rDataTable.Rows[i][rKeyIDs[rPair.Key]].ToString(); JsonParser rJsonParser = new JsonParser(rFieldValue); JsonNode rTempNode = null; try { rTempNode = rJsonParser.Parser(); } catch (Exception) { rJsonParser.isValid = false; } if (!rJsonParser.isValid) { rTempNode = new JsonData(rFieldValue); } rItemJson.Add(rPair.Key, rTempNode); } rDataJson.Add(rDataTable.Rows[i][rKeyIDs[rExcelFormat.PrimaryKey]].ToString(), rItemJson); } File.WriteAllText(UtilTool.PathCombine(rExportDir, rExcelFormat.SheetName + ".json"), rDataJson.ToString()); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); rExcelReader.Close(); rStream.Close(); }