Ejemplo n.º 1
0
        /// <summary>
        /// 用于从服务器读取短信数据
        /// </summary>
        public static async Task <string> GetMessage(NetWork net, string username)
        {
            //执行页面请求
            string result = await net.GetMessageList(username);

            //处理字符串
            result = result.Trim(new char[] { '[', ']' });
            MessageList.Clear();
            if (result == "")
            {
                return("用户短信列表为空!");
            }
            if (result[0] != '{')
            {
                return("获取失败!请检查网络设置");
            }
            //false为错误信息或者只有一条短信,true为正常数据
            bool flag  = false;
            int  count = 0;

            foreach (char c in result)
            {
                if (c == '{')
                {
                    count++;
                }
                if (count >= 2)
                {
                    flag = true;
                    break;
                }
            }
            //如果为正常数据
            if (flag)
            {
                JsonData jd = null;
                //用于记录临时字符串
                string temp = string.Empty;
                for (int i = 0; i < result.Length; i++)
                {
                    if (result[i] == '}')
                    {
                        temp += result[i];
                        jd    = JsonMapper.ToObject(temp);
                        MessageList.Add(new Message()
                        {
                            SenderNum   = (string)jd["sender_number"],
                            ReceiveTime = (string)jd["receive_time"],
                            Content     = (string)jd["content"]
                        });
                        //跳过逗号
                        i++;
                        temp = string.Empty;
                        continue;
                    }
                    temp += result[i];
                }
                return(string.Empty);
            }
            //如果是错误信息或者只有一条短信
            else
            {
                JsonData jd = JsonMapper.ToObject(result);
                //判断是否存在message字段
                if ((string)jd["message"] == string.Empty)
                {
                    MessageList.Add(new Message()
                    {
                        SenderNum   = (string)jd["sender_number"],
                        ReceiveTime = (string)jd["receive_time"],
                        Content     = (string)jd["content"]
                    });
                    return(string.Empty);
                }
                else
                {
                    return("获取失败!" + (string)jd["message"]);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取联系人列表
        /// </summary>
        /// <returns></returns>
        public static async Task <string> GetContacterList(string username, NetWork net)
        {
            //执行页面请求
            string result = await net.GetContacterList(username);

            //处理字符串
            result = result.Trim(new char[] { '[', ']' });
            ContacterList.Clear();
            if (result == "")
            {
                return("短信列表为空!");
            }
            if (result[0] != '{')
            {
                return("获取失败!请检查网络设置");
            }
            //判断是否为错误信息,false为错误信息,true为正常数据
            bool flag  = false;
            int  count = 0;

            foreach (char c in result)
            {
                if (c == '{')
                {
                    count++;
                }
                if (count >= 2)
                {
                    flag = true;
                    break;
                }
            }
            //如果为正常数据
            if (flag)
            {
                JsonData jd = null;
                //用于记录临时字符串
                string temp = string.Empty;
                for (int i = 0; i < result.Length; i++)
                {
                    if (result[i] == '}')
                    {
                        temp += result[i];
                        jd    = JsonMapper.ToObject(temp);
                        ContacterList.Add(new Contacter()
                        {
                            ContactorName     = (string)jd["contacter_name"],
                            ContactorNum      = (string)jd["contacter_num"],
                            ContactorLocation = (string)jd["contacter_location"]
                        });
                        //跳过逗号
                        i++;
                        temp = string.Empty;
                        continue;
                    }
                    temp += result[i];
                }
                return(string.Empty);
            }
            //如果是错误信息
            else
            {
                JsonData jd = JsonMapper.ToObject(result);
                //判断是否存在message字段
                if ((string)jd["message"] == string.Empty)
                {
                    ContacterList.Add(new Contacter()
                    {
                        ContactorName     = (string)jd["contacter_name"],
                        ContactorNum      = (string)jd["contacter_num"],
                        ContactorLocation = (string)jd["contacter_location"]
                    });
                    return(string.Empty);
                }
                else
                {
                    return("获取失败!" + (string)jd["message"]);
                }
            }
        }
Ejemplo n.º 3
0
 public MainWindow()
 {
     InitializeComponent();
     //初始化Network
     network = NetWork.Create();
 }
Ejemplo n.º 4
0
 //私有构造函数
 private NetWork()
 {
     this.Time = DateTime.Now.ToString("yy-MM-dd hh:mm:ss");
     network   = this;
     created   = true;
 }