Exemple #1
0
        public void ProcessRequest(HttpContext context)
        {
            var callback = context.Request.RequestContext.RouteData.Values["callback"] as Func<dynamic, object>;
            if (callback == null)
                return;

            var values = new Dictionary<string, object>(context.Request.RequestContext.RouteData.Values);
            foreach (var key in context.Request.Form.AllKeys) {
                values.Add(key, context.Request.Form[key]);
            }

            var arg = new DynamicJsonObject(values);
            object obj;
            try
            {
                obj = callback(arg);
            }
            catch (Exception ex)
            {
                obj = ex.Message;
                context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            }

            var res = JsonConvert.SerializeObject(
                obj,
                Formatting.Indented,
                new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }
            );

            context.Response.ContentType = "application/json";
            context.Response.Write(res);
        }
Exemple #2
0
 public override string Serialize()
 {
     var dct = new Dictionary<string, object>();
     dct["priority"] = Priority;
     var obj = new DynamicJsonObject(dct);
     var writer = new StringWriter();
     Json.Write(obj, writer);
     return writer.ToString();
 }
 public override string Serialize()
 {
     var dct = new Dictionary<string, object>();
     dct.Add("instanceId", InstanceId);
     var obj = new DynamicJsonObject(dct);
     var writer = new StringWriter();
     Json.Write(obj, writer);
     return writer.ToString();
 }
 public override string Serialize()
 {
     var dct = new Dictionary<string, object>();
     dct["received"] = Received;
     dct["message"] = Message;
     var obj = new DynamicJsonObject(dct);
     var writer = new StringWriter();
     Json.Write(obj, writer);
     return writer.ToString();
 }
Exemple #5
0
 public override string Serialize()
 {
     var dct = new Dictionary<string, object>();
     dct["id"] = Id;
     dct["message"] = Message;
     dct["fromInstanceId"] = FromInstanceId;
     var obj = new DynamicJsonObject(dct);
     var writer = new StringWriter();
     Json.Write(obj, writer);
     return writer.ToString();
 }
        public HttpResponseMessage CreateRoom(string friends)
        {
            if (friends == null || friends.Length < 1)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "未选择好友");
            }
            List<string> friendlist = friends.Split(',').ToList();
            try
            {
                string title = "";
                bool IsGroupChat = friendlist.Count > 1 ? true : false;
                foreach (string friend in friendlist)
                {
                    //Models.User user = db.Users.Find(friend);
                    //string nn = user.NickName;
                    title += db.Users.Find(new Guid(friend)).UserName+",";
                }
                Room room = new Room()
                {
                    RoomId=Guid.NewGuid(),
                    Title = title,
                    OwnerId = new Guid(SecurityController.Authentication.User.Identity.Name),
                    CreateDate = DateTime.Now,
                    IsGroupChat = IsGroupChat
                };
                db.Rooms.Add(room);
                db.SaveChanges();
                foreach (string friend in friendlist)
                {
                    db.UserRooms.Add(new UserRoom() {Guid=Guid.NewGuid(), RoomId = room.RoomId, UserId = new Guid(friend) });
                }
                db.UserRooms.Add(new UserRoom() { Guid = Guid.NewGuid(), RoomId = room.RoomId, UserId = new Guid(SecurityController.Authentication.User.Identity.Name) });
                db.SaveChanges();

                Dictionary<string, object> values = new Dictionary<string, object>();
                values.Add("roomId", room.RoomId.ToString());
                values.Add("title", title);
                DynamicJsonObject json = new DynamicJsonObject(values);
                return Request.CreateResponse(HttpStatusCode.Created,json);
            }
            catch(Exception e)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "创建群聊异常");
            }
        }
        public override string Serialize()
        {
            dynamic obj = new DynamicJsonObject(new Dictionary<string, object>());

            // we need to create nested objects that contain the dependency information
            foreach (string capability in Dependencies.Keys)
            {
                dynamic inner = new DynamicJsonObject(new Dictionary<string, object>());
                foreach (string instanceId in Dependencies[capability].Keys)
                {
                    inner[instanceId] = Dependencies[capability][instanceId];
                }
                obj[capability] = inner;
            }
            var writer = new StringWriter();
            Json.Write(obj, writer);
            return writer.ToString();
        }
Exemple #8
0
 public override string Serialize()
 {
     var dct = new Dictionary<string, object>();
     dct.Add("version", Version);
     dct.Add("API", API);
     dct.Add("description", Description);
     dct.Add("name", Name);
     if (DisplayName != null)
     {
         dct.Add("displayName", DisplayName);
     }
     if (InstanceId != null)
     {
         dct.Add("instanceId", InstanceId);
     }
     if (Capabilities.Count != 0)
     {
         dct.Add("capabilities", Capabilities);
     }
     if (Dependencies.Count != 0)
     {
         dct.Add("dependencies", Dependencies);
     }
     var obj = new DynamicJsonObject(dct);
     var writer = new StringWriter();
     Json.Write(obj, writer);
     return writer.ToString();
 }
Exemple #9
0
 public override string Serialize()
 {
     var dct = new Dictionary<string, object>();
     dct["id"] = Id;
     dct["capability"] = Capability;
     dct["action"] = Action;
     dct["data"] = Data;
     dct["instanceId"] = InstanceId;
     dct["priority"] = Priority;
     dct["fromInstanceId"] = FromInstanceId;
     var obj = new DynamicJsonObject(dct);
     var writer = new StringWriter();
     Json.Write(obj, writer);
     return writer.ToString();
 }
        private IEnumerable<object> ConvertDynamicJsonObjectToArgumentArray(DynamicJsonObject jsonObject)
        {
            var convertedProperties = new List<object>();

            var dynamicMemberNames = jsonObject.GetDynamicMemberNames();
            foreach (var dynamicMemberName in dynamicMemberNames)
            {
                object tempObject = GetDynamicMember(jsonObject, dynamicMemberName);
                convertedProperties.Add(new StringParameter(dynamicMemberName, tempObject.ToString()));
            }

            return convertedProperties.ToArray();
        }