public JSONObject ToJson()
        {
            JSONObject obj = new JSONObject();

            obj.Add("status", new JSONString(status.ToString()));
            obj.Add("requestInfo", new JSONString(requestInfo));
            obj.Add("time", new JSONString(requestTime.ToFileTime().ToString()));
            obj.Add("requestor", requestor.ToString());
            obj.Add("song", song);
            return(obj);
        }
示例#2
0
        private static Status universalRetriver(string query, SqlCommand cmd, int type)
        {
            SqlConnection con    = new SqlConnection(ConnectionInit.ConnectionString);
            Status        status = new Status();

            status.State     = 0;
            status.Exception = "not found";
            status.Json_data = "[";

            try
            {
                con.Open();
                cmd.Connection  = con;
                cmd.CommandText = query;

                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            if (type == GET_USERS_AND_CHATS)
                            {
                                ChatUser chat = initChatUser(reader);
                                status.Json_data += chat.ToString() + ",";
                            }
                            else if (type == GET_CHATS)
                            {
                                Chat chat = initChat(reader);
                                status.Json_data += chat.ToString() + ",";
                            }
                            else if (type == UNREADED_MESSAGE)
                            {
                                Message message = initMessage(reader);
                                status.Json_data += message + ",";
                            }
                        }

                        reader.NextResult();
                    }
                    status.Json_data  = status.Json_data.Remove(status.Json_data.Length - 1);
                    status.State      = 1;
                    status.Exception  = "Done";
                    status.Json_data += "]";
                }
                else
                {
                    status.State     = 0;
                    status.Exception = "not found";
                    status.Json_data = "";
                }

                reader.Close();
            }
            catch (Exception e1)
            {
                status.State     = -1;
                status.Exception = e1.Message;
            }
            finally
            {
                con.Close();
            }

            return(status);
        }
示例#3
0
        public void ToStringTest()
        {
            ChatUser user = new ChatUser(1, "name");

            Assert.AreEqual("name#1", user.ToString());
        }