コード例 #1
0
        public void ArgumentJson()
        {
            var status = new Argument
            {
                Value = "Value"
            };
            var microsoft  = new JsonSerializeProxy();
            var newtonsoft = new NewtonJsonSerializeProxy();
            var json1      = newtonsoft.ToString(status, true);
            var status1    = newtonsoft.ToObject <Argument>(json1);

            Assert.IsTrue(status1.Value == status.Value, json1);

            var json2   = microsoft.ToString(status, true);
            var status2 = microsoft.ToObject <Argument>(json2);

            Assert.IsTrue(status2.Value == status.Value, json2);

            Assert.IsTrue(json2 == json1, json2);

            var xml     = new XmlSerializeProxy();
            var xml1    = xml.ToString(status);
            var status3 = xml.ToObject <Argument>(xml1);

            Assert.IsTrue(status3.Value == status.Value, xml1);

            var cdata   = new CDataXmlSerializeProxy();
            var xml2    = cdata.ToString(status);
            var status4 = cdata.ToObject <Argument>(xml2);

            Assert.IsTrue(status4.Value == status.Value, xml2);
        }
コード例 #2
0
        public void OperatorTraceJson()
        {
            var status = new OperatorTrace
            {
                RequestId = "RequestId",
                Point     = "Point",
                Guide     = "Guide",
            };
            var microsoft  = new JsonSerializeProxy();
            var newtonsoft = new NewtonJsonSerializeProxy();
            var json1      = newtonsoft.ToString(status, true);
            var json2      = microsoft.ToString(status, true);

            Assert.IsTrue(json2 == json1, json2);

            var status1 = newtonsoft.ToObject <OperatorTrace>(json1);

            Assert.IsTrue(status1.RequestId == status.RequestId, json1);

            var status2 = microsoft.ToObject <OperatorTrace>(json2);

            Assert.IsTrue(status2.Point == status.Point, json2);

            var xml     = new XmlSerializeProxy();
            var status3 = xml.ToObject <OperatorTrace>(xml.ToString(status));

            Assert.IsTrue(status3.Describe == status.Describe, json2);

            var cdata   = new CDataXmlSerializeProxy();
            var status4 = cdata.ToObject <OperatorTrace>(cdata.ToString(status));

            Assert.IsTrue(status4.Guide == status.Guide, json2);
        }
コード例 #3
0
        public void OperatorStatusJson()
        {
            var status = new OperatorStatus
            {
                Success      = true,
                Code         = 1,
                Message      = "Message",
                InnerMessage = "InnerMessage",
                Exception    = new System.Exception("Exception")
            };
            var microsoft  = new JsonSerializeProxy();
            var newtonsoft = new NewtonJsonSerializeProxy();
            var json1      = newtonsoft.ToString(status, true);
            var json2      = microsoft.ToString(status, true);

            Assert.IsTrue(json2 == json1, json2);
            var status1 = newtonsoft.ToObject <OperatorStatus>(json1);
            var status2 = microsoft.ToObject <OperatorStatus>(json2);

            Assert.IsTrue(status1.Message == status2.Message, json2);
            Assert.IsTrue(status1.Exception == null, json2);

            var xml     = new XmlSerializeProxy();
            var status3 = xml.ToObject <OperatorStatus>(xml.ToString(status));

            Assert.IsTrue(status3.Message == status.Message, json2);
            Assert.IsTrue(status3.Exception == null, json2);

            var cdata   = new CDataXmlSerializeProxy();
            var status4 = cdata.ToObject <OperatorStatus>(cdata.ToString(status));

            Assert.IsTrue(status4.Message == status.Message, json2);
            Assert.IsTrue(status4.Exception == null, json2);
        }
コード例 #4
0
        public void ApiResultJson()
        {
            var status = new ApiResult <string>
            {
                ResultData   = "data",
                Success      = true,
                Code         = 1,
                Message      = "Message",
                InnerMessage = "InnerMessage",
                Exception    = new System.Exception("Exception"),
                Trace        = new OperatorTrace
                {
                    RequestId = "RequestId",
                    Point     = "Point",
                    Guide     = "Guide",
                }
            };
            var microsoft  = new JsonSerializeProxy();
            var newtonsoft = new NewtonJsonSerializeProxy();
            var json1      = newtonsoft.ToString(status, true);
            var json2      = microsoft.ToString(status, true);

            Assert.IsTrue(json2 == json1, json2);
            var status1 = newtonsoft.ToObject <ApiResult <string> >(json1);
            var status2 = microsoft.ToObject <ApiResult <string> >(json2);

            Assert.IsTrue(status1.Message == status2.Message, json2);
            Assert.IsTrue(status1.Exception == null, json2);

            var xml     = new XmlSerializeProxy();
            var status3 = xml.ToObject <ApiResult <string> >(xml.ToString(status));

            Assert.IsTrue(status3.Message == status.Message, json2);
            Assert.IsTrue(status3.ResultData == status.ResultData, json2);

            var cdata   = new CDataXmlSerializeProxy();
            var status4 = cdata.ToObject <ApiResult <string> >(cdata.ToString(status));

            Assert.IsTrue(status4.Message == status.Message, json2);
            Assert.IsTrue(status4.Trace.Point == status.Trace.Point, json2);
        }
コード例 #5
0
        void CheckResult()
        {
            if (ResultType == null)
            {
                ResultSerializeType = SerializeType.None;
                return;
            }
            if (ResultType == typeof(void))
            {
                IsAsync             = false;
                ResultType          = null;
                ResultSerializeType = SerializeType.None;
                return;
            }
            if (ResultType == typeof(Task))
            {
                IsAsync             = true;
                ResultType          = null;
                ResultSerializeType = SerializeType.None;
                return;
            }
            if (ResultType.IsGenericType && ResultType.IsSubclassOf(typeof(Task)))
            {
                IsAsync    = true;
                ResultType = ResultType.GetGenericArguments()[0];
            }
            else
            {
                IsAsync = false;
            }
            if (ResultType.IsValueType)
            {
                //var def = ResultType.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);

                ResultCreater       = (code, msg) => msg;
                ResultSerializer    = new SerializeProxy();
                ResultSerializeType = SerializeType.Custom;
            }
            else if (ResultType == typeof(string))
            {
                ResultCreater       = (code, msg) => msg;
                ResultSerializer    = new SerializeProxy();
                ResultSerializeType = SerializeType.Custom;
            }
            else
            {
                if (ResultType.IsSupperInterface(typeof(IOperatorStatus)))
                {
                    ResultCreater = (code, msg) =>
                    {
                        var re = DependencyHelper.GetService <IOperatorStatus>();
                        re.Code    = code;
                        re.Message = msg;
                        return(re);
                    }
                }
                ;

                switch (ResultSerializeType)
                {
                case SerializeType.Json:
                    ResultSerializer = DependencyHelper.GetService <IJsonSerializeProxy>();
                    break;

                case SerializeType.NewtonJson:
                    ResultSerializer = new NewtonJsonSerializeProxy();
                    break;

                case SerializeType.Xml:
                    ResultSerializer = new XmlSerializeProxy();
                    break;

                case SerializeType.Custom:
                    ResultSerializer = new SerializeProxy();
                    break;

                case SerializeType.Bson:
                    throw new NotSupportedException($"{ResultSerializeType}序列化方式暂不支持");
                }
            }
        }