Beispiel #1
0
    private void Connect()
    {
        client = new PomeloClient();
        client.initClient(url, port, () =>
        {
            Debug.Log("Pomelo client init success!");
        });

        JsonNode user = new JsonClass();

        user.Add("user", new JsonData("Winddy"));
        user.Add("pwd", new JsonData("123"));

        bool result = client.connect(user, new System.Action <JsonNode>(OnConnection));

        if (result)
        {
            Debug.Log("Connect success!");
        }
        else
        {
            Debug.Log("Connect failed!");
        }

        //ClientTest.loginTest("127.0.0.1", 3014);
    }
Beispiel #2
0
        /// <summary>
        /// 创建角色的请求
        /// </summary>
        public static void DoClientCreatePlayerRequest(long rAccountID, string rActorName, int rProfessionalID, int rServerID)
        {
            JsonNode rMsg = new JsonClass();

            rMsg.Add("accountID", new JsonData(rAccountID));
            rMsg.Add("playerName", new JsonData(rActorName));
            rMsg.Add("professionalID", new JsonData(rProfessionalID));
            rMsg.Add("serverID", new JsonData(rServerID));
            NetworkClient.Instance.ClientRequest("connector.entryHandler.ClientCreatePlayerRequest", rMsg, OnPlayerCreateResponse);
        }
Beispiel #3
0
        /// <summary>
        /// 查询Gate进行登陆,返回Connector的服务器
        /// </summary>
        public static void DoClientQueryGateEntryRequest(string rAccount)
        {
            JsonNode rGateMsg = new JsonClass();

            rGateMsg.Add("userName", new JsonData(rAccount));
            NetworkClient.Instance.ClientRequest("gate.gateHandler.queryEntry", rGateMsg, OnClientQueryGateEntryResponse);
        }
    public override void Add(string aKey, JsonNode aItem)
    {
        var tmp = new JsonClass();

        tmp.Add(aKey, aItem);
        Set(tmp);
    }
Beispiel #5
0
    private void SendMessage()
    {
        JsonNode msg = new JsonClass();

        msg.Add("content", new JsonData("Hello unity pomelo !!!"));
        client.request("connector.entryHandler.helloWinddy", msg, new System.Action <JsonNode>(OnSendMessage));
    }
Beispiel #6
0
        /// <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);
        }
Beispiel #7
0
        /// <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());
        }
 public override JsonNode this [string aKey] {
     get {
         return(new JsonLazyCreator(this, aKey));
     }
     set {
         var tmp = new JsonClass();
         tmp.Add(aKey, value);
         Set(tmp);
     }
 }
 private void ParseProperties(JsonClass jsonClass, string json)
 {
     var matches = PropertyRegex.Matches(json);
     foreach (Match match in matches)
     {
         var name = match.Groups["name"].Value;
         var value = match.Groups["value"].Value.Trim();
         jsonClass.Add(name, JsonObjectFactory.BuildJsonObject(value));
     }
 }
Beispiel #10
0
        internal async override Task<JsonNode> ToJson()
        {
            var rootJson = new JsonClass();
            var arrayJson = new JsonArray();
            rootJson.Add("oneOf", arrayJson);
            foreach (var inner in this.Dependencies)
            {
                arrayJson.Add(await inner.ToJson().ConfigureAwait(false));
            }

            return rootJson;
        }
Beispiel #11
0
        private JsonNode buildMsg(JsonNode user)
        {
            if (user == null)
            {
                user = new JsonClass();
            }

            JsonNode msg = new JsonClass();

            //Build sys option
            JsonNode sys = new JsonClass();

            sys.Add("version", new JsonData(Version));
            sys.Add("type", new JsonData(Type));

            //Build handshake message
            msg.Add("sys", sys);
            msg.Add("user", user);

            UnityEngine.Debug.Log(msg);

            return(msg);
        }
Beispiel #12
0
        internal override async Task <JsonNode> ToJson()
        {
            JsonClass jsonDependency = new JsonClass
            {
                { "name", this.ToString() }
            };
            DependencyCheckStatus status = await this.GetStatus().ConfigureAwait(false);

            if (status.Version != null)
            {
                jsonDependency.Add("version", status.Version.ToString());
            }

            if (status.CheckStatus != NAMEStatusLevel.Ok)
            {
                jsonDependency.Add("error", status.Message ?? "Unhandled error");
            }
            jsonDependency.Add("status", status.CheckStatus.ToString());

            jsonDependency.Add("min_version", this.MinimumVersion.ToString());
            jsonDependency.Add("max_version", this.MaximumVersion?.ToString() ?? "*");

            if (status.Version?.ManifestNode != null)
            {
                JsonNode infrastructureDependencies = status.Version.ManifestNode["infrastructure_dependencies"];
                JsonNode serviceDependencies        = status.Version.ManifestNode["service_dependencies"];

                if (infrastructureDependencies != null)
                {
                    jsonDependency.Add("infrastructure_dependencies", infrastructureDependencies);
                }
                if (serviceDependencies != null)
                {
                    jsonDependency.Add("service_dependencies", serviceDependencies);
                }
            }

            return(jsonDependency);
        }
Beispiel #13
0
        public static JsonNode ToJsonNode(object rObject)
        {
            Type     rType     = rObject.GetType();
            JsonNode rRootNode = null;

            if (rType.IsGenericType && typeof(IList).IsAssignableFrom(rType.GetGenericTypeDefinition()))
            {
                rRootNode = new JsonArray();
                IList rListObj = (IList)rObject;
                foreach (var rItem in rListObj)
                {
                    JsonNode rNode = ToJsonNode(rItem);
                    rRootNode.Add(rNode);
                }
            }
            else if (rType.IsArray)
            {
                rRootNode = new JsonArray();
                Array rArrayObj = (Array)rObject;
                foreach (var rItem in rArrayObj)
                {
                    JsonNode rNode = ToJsonNode(rItem);
                    rRootNode.Add(rNode);
                }
            }
            else if (rType.IsGenericType && typeof(IDictionary).IsAssignableFrom(rType.GetGenericTypeDefinition()))
            {
                rRootNode = new JsonClass();
                IDictionary rDictObj = (IDictionary)rObject;
                foreach (var rKey in rDictObj.Keys)
                {
                    JsonNode rValueNode = ToJsonNode(rDictObj[rKey]);
                    rRootNode.Add(rKey.ToString(), rValueNode);
                }
            }
            else if (rType.IsGenericType && typeof(IDict).IsAssignableFrom(rType.GetGenericTypeDefinition()))
            {
                rRootNode = new JsonClass();
                IDict rDictObj = (IDict)rObject;
                foreach (var rItem in rDictObj.OriginCollection)
                {
                    JsonNode rValueNode = ToJsonNode(rItem.Value);
                    rRootNode.Add(rItem.Key.ToString(), rValueNode);
                }
            }
            else if (rType.IsClass)
            {
                if (rType == typeof(string))
                {
                    rRootNode = new JsonData((string)rObject);
                }
                else
                {
                    rRootNode = new JsonClass();
                    PropertyInfo[] rPropInfos = rType.GetProperties(ReflectionAssist.flags_public);
                    for (int i = 0; i < rPropInfos.Length; i++)
                    {
                        object   rValueObj  = rPropInfos[i].GetValue(rObject, null);
                        JsonNode rValueNode = ToJsonNode(rValueObj);
                        rRootNode.Add(rPropInfos[i].Name, rValueNode);
                    }
                    FieldInfo[] rFieldInfos = rType.GetFields(ReflectionAssist.flags_public);
                    for (int i = 0; i < rFieldInfos.Length; i++)
                    {
                        object   rValueObj  = rFieldInfos[i].GetValue(rObject);
                        JsonNode rValueNode = ToJsonNode(rValueObj);
                        rRootNode.Add(rFieldInfos[i].Name, rValueNode);
                    }
                }
            }
            else if (rType.IsPrimitive)
            {
                if (rType.Equals(typeof(int)))
                {
                    rRootNode = new JsonData((int)rObject);
                }
                else if (rType.Equals(typeof(uint)))
                {
                    rRootNode = new JsonData((uint)rObject);
                }
                else if (rType.Equals(typeof(long)))
                {
                    rRootNode = new JsonData((long)rObject);
                }
                else if (rType.Equals(typeof(ulong)))
                {
                    rRootNode = new JsonData((ulong)rObject);
                }
                else if (rType.Equals(typeof(float)))
                {
                    rRootNode = new JsonData((float)rObject);
                }
                else if (rType.Equals(typeof(double)))
                {
                    rRootNode = new JsonData((double)rObject);
                }
                else if (rType.Equals(typeof(bool)))
                {
                    rRootNode = new JsonData((bool)rObject);
                }
                else if (rType.Equals(typeof(string)))
                {
                    rRootNode = new JsonData((string)rObject);
                }
                else
                {
                    Debug.LogError(string.Format("Type = {0}, 不支持序列化的变量类型!", rObject.GetType()));
                }
            }
            return(rRootNode);
        }
Beispiel #14
0
        /// <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();
        }