当前位置: 首页>>代码示例>>C#>>正文


C# JObject.Put方法代码示例

本文整理汇总了C#中JObject.Put方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.Put方法的具体用法?C# JObject.Put怎么用?C# JObject.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JObject的用法示例。


在下文中一共展示了JObject.Put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FromException

        public static JObject FromException(Exception e, bool includeStackTrace)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            JObject error = new JObject();
            error.Put("message", e.GetBaseException().Message);

            if (includeStackTrace)
                error.Put("stackTrace", e.StackTrace);

            return error;
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:13,代码来源:JsonRpcError.cs

示例2: BuildCallTemplatesObject

        private JObject BuildCallTemplatesObject()
        {
            JObject info = new JObject();
            StringBuilder sb = new StringBuilder();
    
            foreach (JsonRpcMethod method in ServiceClass.GetMethods())
            {
                sb.Length = 0;
                sb.Append("[ ");

                JsonRpcParameter[] parameters = method.GetParameters();
                
                if (parameters.Length == 0)
                {
                    sb.Append("/* void */");
                }
                else
                {
                    foreach (JsonRpcParameter parameter in parameters)
                    {
                        if (parameter.Position > 0) 
                            sb.Append(", ");

                        sb.Append("/* ").Append(parameter.Name).Append(" = */ ?");
                    }
                }

                sb.Append(" ]");
                info.Put(method.Name, sb.ToString());
            }
            return info;
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:32,代码来源:JsonRpcTester.cs

示例3: ParseRequest

        protected virtual object ParseRequest(TextReader input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            JsonReader reader = (JsonReader) _serviceProvider.GetService(typeof(JsonReader));

            if (reader == null)
                reader = new JsonTextReader(input);
            
            JObject request = new JObject();
            JsonRpcMethod method = null;
            
            reader.ReadToken(JsonTokenClass.Object);
            
            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string memberName = reader.ReadMember();
                
                switch (memberName)
                {
                    case "id" :
                    {
                        request["id"] = reader.DeserializeNext();
                        break;
                    }
                    case "method" :
                    {
                        string methodName = reader.ReadString();
                        request["method"] = methodName;
                        method = _service.GetClass().GetMethodByName(methodName);
                        break;
                    }
                    case "params" :
                    {
                        object args;
                        
                        if (method == null)
                        {
                            args = reader.DeserializeNext();
                        }
                        else
                        {
                            JsonRpcParameter[] parameters = method.GetParameters();
                            
                            if (reader.TokenClass == JsonTokenClass.Array)
                            {
                                reader.Read();
                                ArrayList argList = new ArrayList(parameters.Length);
                                
                                // TODO: This loop could bomb when more args are supplied that parameters available.
                                                        
                                for (int i = 0; reader.TokenClass != JsonTokenClass.EndArray; i++)
                                    argList.Add(reader.Get(parameters[i].ParameterType));
                                
                                reader.Read();
                                args = argList.ToArray();
                            }
                            else if (reader.TokenClass == JsonTokenClass.Object)
                            {
                                reader.Read();
                                JObject argByName = new JObject();
                                
                                while (reader.TokenClass != JsonTokenClass.EndObject)
                                {
                                    // TODO: Imporve this lookup.
                                    
                                    JsonRpcParameter matchedParameter = null;

                                    foreach (JsonRpcParameter parameter in parameters)
                                    {
                                        if (parameter.Name.Equals(reader.Text))
                                        {
                                            matchedParameter = parameter;
                                            break;
                                        }
                                    }
                                    
                                    reader.Read();

                                    // TODO: This could bomb when if no matching parameter is found.
                                    
                                    argByName.Put(matchedParameter.Name, reader.Get(matchedParameter.ParameterType));
                                }
                                
                                reader.Read();
                                args = argByName;
                            }
                            else
                            {
                                args = reader.DeserializeNext();
                            }
                            
                            request["params"] = args;
                        }
                        
                        break;
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:101,代码来源:JsonRpcDispatcher.cs

示例4: ProcessRequest

        protected override void ProcessRequest()
        {
            if (!Modified())
            {
                Response.StatusCode = 304;
                return;
            }

            //
            // Generate the SMD object graph.
            //

            IRpcServiceDescriptor service = TargetService.GetDescriptor();

            JObject smd = new JObject();
            
            smd.Put("SMDVersion", ".1");
            smd.Put("objectName", JsonRpcServices.GetServiceName(TargetService));
            smd.Put("serviceType", "JSON-RPC");
            smd.Put("serviceURL", Request.FilePath); // TODO: Check whether this should be an absolute path from the protocol root.

            IRpcMethodDescriptor[] methods = service.GetMethods();

            if (methods.Length > 0) // TODO: Check if methods entry can be skipped if there are none.
            {
                JArray smdMethods = new JArray();

                foreach (IRpcMethodDescriptor method in methods)
                {
                    JObject smdMethod = new JObject();
                    smdMethod.Put("name", method.Name);
                
                    IRpcParameterDescriptor[] parameters = method.GetParameters();

                    if (parameters.Length > 0) // TODO: Check if parameters entry can be skipped if there are none.
                    {
                        JArray smdParameters = new JArray();

                        foreach (IRpcParameterDescriptor parameter in parameters)
                        {
                            JObject smdParameter = new JObject();
                            smdParameter.Put("name", parameter.Name);
                            smdParameters.Add(smdParameter);
                        }

                        smdMethod.Put("parameters", smdParameters);
                    }

                    smdMethods.Add(smdMethod);
                }

                smd.Put("methods", smdMethods);
            }

            //
            // Generate the response.
            //

            if (HasLastModifiedTime)
            {
                Response.Cache.SetCacheability(HttpCacheability.Public);
                Response.Cache.SetLastModified(LastModifiedTime);
            }

            Response.ContentType = "text/plain";

            Response.AppendHeader("Content-Disposition", 
                "attachment; filename=" + service.Name + ".smd");

            JsonTextWriter writer = new JsonTextWriter(Response.Output);
            writer.WriteValue(smd);
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:72,代码来源:JsonRpcSimpleMethodDescription.cs

示例5: ParseRequest

        protected virtual object ParseRequest(TextReader input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            JsonReader reader = (JsonReader) _serviceProvider.GetService(typeof(JsonReader));

            if (reader == null)
                reader = new JsonTextReader(input);
            
            JObject request = new JObject();
            IRpcMethodDescriptor method = null;
            
            reader.ReadToken(JsonToken.Object);
            while (reader.ReadToken() != JsonToken.EndObject)
            {
                switch (reader.Text)
                {
                    case "id" :
                    {
                        reader.Read();
                        request["id"] = reader.DeserializeNext();
                        break;
                    }
                    case "method" :
                    {
                        string methodName = reader.ReadString();
                        request["method"] = methodName;
                        method = _service.GetDescriptor().GetMethodByName(methodName);
                        break;
                    }
                    case "params" :
                    {
                        object args;
                        
                        if (method == null)
                        {
                            reader.Read();
                            args = reader.DeserializeNext();
                        }
                        else
                        {
                            reader.Read();

                            IRpcParameterDescriptor[] parameters = method.GetParameters();
                            
                            if (reader.Token == JsonToken.Array)
                            {
                                reader.Read();
                                ArrayList argList = new ArrayList(parameters.Length);
                                                        
                                for (int i = 0; reader.Token != JsonToken.EndArray; i++)
                                    argList.Add(reader.Get(parameters[i].ParameterType));
                            
                                args = argList.ToArray();
                            }
                            else if (reader.Token == JsonToken.Object)
                            {
                                reader.Read();
                                JObject argByName = new JObject();
                                
                                while (reader.Token != JsonToken.EndObject)
                                {
                                    IRpcParameterDescriptor matchedParameter = null;

                                    foreach (IRpcParameterDescriptor parameter in parameters)
                                    {
                                        if (parameter.Name.Equals(reader.Text))
                                        {
                                            matchedParameter = parameter;
                                            break;
                                        }
                                    }
                                    
                                    reader.Read();
                                    argByName.Put(matchedParameter.Name, reader.Get(matchedParameter.ParameterType));
                                }
                                
                                args = argByName;
                            }
                            else
                            {
                                args = reader.DeserializeNext();
                            }
                            
                            request["params"] = args;
                        }
                        
                        break;
                    }
                }
            }
            
            return request;
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:95,代码来源:JsonRpcDispatcher.cs

示例6: OnError

        protected virtual object OnError(Exception e)
        {
            if (JsonRpcTrace.Switch.TraceError)
                JsonRpcTrace.Error(e);

            JObject error = new JObject();
            error.Put("message", e.GetBaseException().Message);

            if (_localExecution)
                error.Put("stackTrace", e.StackTrace);

            return error;
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:13,代码来源:JsonRpcDispatcher.cs


注:本文中的JObject.Put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。