Esempio n. 1
0
        /// <summary>
        /// 从json获取oauth数据
        /// </summary>
        /// <param name="jsonString">json字符串</param>
        /// /// <param name="isError">是否错误</param>
        /// <returns></returns>
        new  public static OauthData Create(string jsonString, bool isError)
        {
            if (jsonString == null)
            {
                return(null);
            }

            OauthData data = new OauthData();

            try
            {
                var json = (IDictionary <string, object>)SimpleJson.DeserializeObject(jsonString);
                if (isError)
                {
                    var code = json[KEY_ERROR_CODE];
                    data.ErrorCode    = int.Parse(code.ToString());
                    data.ErrorMessage = (string)json[KEY_ERROR_MSG];
                }
                else
                {
                    data.Token = (string)json[KEY_TOKEN];
                }
                return(data);
            }
            catch (Exception e)
            {
                UtilDebug.ShowException(e, "SimpleJson.DeserializeObject", LOG_TAG);
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 返回数据读取
        /// </summary>
        /// <param name="jsonString"></param>
        /// <param name="isError">是否错误</param>
        /// <returns></returns>
        public static BaseData Create(string jsonString, bool isError)
        {
            if (jsonString == null)
            {
                return(null);
            }

            BaseData data = new BaseData();

            try
            {
                var json = (IDictionary <string, object>)SimpleJson.DeserializeObject(jsonString);
                if (isError)
                {
                    data.ErrorCode    = Convert.ToInt32(json[KEY_ERROR_CODE]);
                    data.ErrorMessage = (string)json[KEY_ERROR_MSG];
                }
                return(data);
            }
            catch (Exception e)
            {
                UtilDebug.ShowException(e, "SimpleJson.DeserializeObject", LOG_TAG);
                return(null);
            }
        }
Esempio n. 3
0
        new public static CallBackData Create(string jsonString, bool isError)
        {
            if (jsonString == null)
            {
                return(null);
            }

            CallBackData data = new CallBackData();

            try
            {
                JsonObject json = (JsonObject)(IDictionary <string, object>)SimpleJson.DeserializeObject(jsonString);
                if (isError)
                {
                    var code = json[KEY_ERROR_CODE];
                    data.ErrorCode    = int.Parse(code.ToString());
                    data.ErrorMessage = Util.jsonOptString(KEY_ERROR_MSG, json);
                }
                else
                {
                    data.FileHash = Util.jsonOptString(KEY_FILEHASH, json);
                    data.FileSize = Convert.ToInt64(json[KEY_FILEHASH]);
                    data.FullPath = Util.jsonOptString(KEY_FULLPATH, json);
                    data.Hash     = Util.jsonOptString(KEY_HASH, json);
                }
                return(data);
            }
            catch (Exception e)
            {
                UtilDebug.ShowException(e, "SimpleJson.DeserializeObject", LOG_TAG);
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 异步响应回调函数
        /// </summary>
        /// <param name="asyncResult">异步请求参数</param>
        private void handleResponse(IAsyncResult asyncResult)
        {
            string result  = "";
            bool   iserror = false;

            try
            {
                HttpWebRequest  webRequest   = asyncResult.AsyncState as HttpWebRequest;
                HttpWebResponse webResponse  = (HttpWebResponse)webRequest.EndGetResponse(asyncResult);
                Stream          streamResult = webResponse.GetResponseStream(); //获取响应流
                StreamReader    reader       = new StreamReader(streamResult);
                result = reader.ReadToEnd();

                //if (RequestMethod == RequestType.GET && DownloadPath != null)
                //{
                //    IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
                //    myStore.CreateDirectory(Util.getParentPath(Util.ROOT_PATH+DownloadPath.Replace("/","\\"),"\\").Trim());

                //    byte[] bytes = Util.ReadToEnd(streamResult);
                //    using (IsolatedStorageFileStream stream = myStore.CreateFile(Util.ROOT_PATH+DownloadPath.Replace("/","\\")))
                //    {
                //        stream.Write(bytes, 0, bytes.Length);
                //    }

                //}
            }
            catch (WebException ex)
            {
                HttpWebResponse response = ((HttpWebResponse)ex.Response);
                int             code     = (int)response.StatusCode;
                try
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            result = reader.ReadToEnd();
                        }
                    }
                }
                catch (WebException e)
                {
                    UtilDebug.ShowException(e, null, null);
                }

                iserror = true;
            }
            finally
            {
                WP7HttpEventArgs e = new WP7HttpEventArgs();
                e.IsError = iserror;
                e.Result  = result;
                //进行异步回调操作
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(delegate()
                {
                    OnHttpCompleted(e);
                });
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 单文件数据
        /// </summary>
        /// <param name="jsonString"></param>
        /// <param name="isError"></param>
        /// <returns></returns>
        new public static FileData Create(string jsonString, bool isError)
        {
            if (jsonString == null)
            {
                return(null);
            }

            FileData data = new FileData();

            try
            {
                JsonObject json = (JsonObject)(IDictionary <string, object>)SimpleJson.DeserializeObject(jsonString);
                if (isError)
                {
                    data.ErrorCode    = Convert.ToInt32(json[KEY_ERROR_CODE]);
                    data.ErrorMessage = (string)json[KEY_ERROR_MSG];
                }
                else
                {
                    data.Dir            = Util.jsonOptInt(KEY_DIR, json, 0);
                    data.FileHash       = Util.jsonOptString(KEY_FILEHASH, json);
                    data.FileName       = Util.jsonOptString(KEY_FILENAME, json);
                    data.FileSize       = Util.jsonOptlong(KEY_FILESIZE, json, 0);
                    data.FullPath       = Util.jsonOptString(KEY_FULLPATH, json);
                    data.Hash           = Util.jsonOptString(KEY_HASH, json);
                    data.LastDateline   = Util.jsonOptlong(KEY_LAST_DATELINE, json, 0);
                    data.LastMemberName = Util.jsonOptString(KEY_LAST_MEMBER_NAME, json);
                    data.Preview        = Util.jsonOptString(KEY_PREVIEW, json);
                    data.Thumbnail      = Util.jsonOptString(KEY_THUMBNAIL, json);
                    data.Uri            = Util.jsonOptString(KEY_URI, json);
                }
                return(data);
            }
            catch (Exception e)
            {
                UtilDebug.ShowException(e, "SimpleJson.DeserializeObject", LOG_TAG);
                return(null);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 文件列表读取
        /// </summary>
        /// <param name="jsonString"></param>
        /// <param name="isError"></param>
        /// <returns></returns>
        new public static FileListData Create(string jsonString, bool isError)
        {
            if (jsonString == null)
            {
                return(null);
            }

            FileListData data = new FileListData();

            try
            {
                var json = (IDictionary <string, object>)SimpleJson.DeserializeObject(jsonString);
                if (isError)
                {
                    var code = json[KEY_ERROR_CODE];
                    data.ErrorCode    = int.Parse(code.ToString());
                    data.ErrorMessage = (string)json[KEY_ERROR_MSG];
                }
                else
                {
                    var count = json[KEY_COUNT];
                    data.Count = int.Parse(json[KEY_COUNT].ToString());
                    List <FileData> list      = new List <FileData>();
                    JsonArray       jsonArray = (JsonArray)json[KEY_LIST];
                    foreach (JsonObject jsonobject in jsonArray)
                    {
                        list.Add(FileData.Create(jsonobject));
                    }
                    data.DataList = list;
                }
                return(data);
            }
            catch (Exception e)
            {
                UtilDebug.ShowException(e, "SimpleJson.DeserializeObject", LOG_TAG);
                return(null);
            }
        }