Beispiel #1
0
 public static async Task<string> DownloadPage(ClientModel value)
 {
     string path = value.GetPath();
     string absolutePath = "ms-appdata:///local/" + path.Replace("\\", "/");
     if (!await StorageHelper.CheckFileExist(path))
     {
         WebRequestAgent request = new WebRequestAgent();
         var res = await request.DownloadAsync(value.serverModel.Href, path);
         if (res.Success)
         {
             return absolutePath;
         }
     }
     else
     {
         return absolutePath;
     }
     return null;
 }
Beispiel #2
0
        public static async Task<List<ServerModel>> DownloadData(ServerModel value)
        {
            List<ServerModel> data = new List<ServerModel>();

            string url = string.Format("{0}{1}", value.Href, "?toc=1");

            WebRequestAgent request = new WebRequestAgent();
            var res = await request.GetAsync(url);
            if (res.Success)
            {
                try
                {
                    string hasSub;
                    data = JsonNetSerializer.DeserializeList<ServerModel>(res.Result);
                    //Debug.Write(res.Result);

                    foreach (var item in data)
                    {
                        hasSub = item.ExtendedAttributes.data_tochassubtree;
                        if (!string.IsNullOrEmpty(hasSub) && hasSub.Equals("true"))
                            item.hassubtree = true;
                        else
                            item.hassubtree = false;
                        item.parentid = value._id;
                        item.level = value.level + 1;
                    }
                    lock (DBSynchObj)
                    {
                        var conn = LocalDatabaseService.GetMainConnection();
                        conn.InsertAll(data);
                        value.subtreesaved = true;
                        conn.Update(value);
                        conn.Dispose();

                    }
                }
                catch (Exception ex)
                {
                    if (data.Count == 0)
                        Debug.Write("Error: " + "数据反序列话错误。");
                    else
                    {
                        Debug.Write("Error: " + "数据库插入数据错误。");
                    }
                }
            }

            return data;
        }
Beispiel #3
0
        public static async Task<KeyValuePair<ServerModel, List<ServerModel>>> GetDataFromServer(ServerModel sm)
        {
            List<ServerModel> value = new List<ServerModel>();
            KeyValuePair<ServerModel, List<ServerModel>> data = new KeyValuePair<ServerModel, List<ServerModel>>(sm, value);

            string url = string.Format("{0}{1}", sm.Href, "?toc=1");

            WebRequestAgent request = new WebRequestAgent();
            var res = await request.GetAsync(url);
            if (res.Success)
            {
                try
                {
                    string hasSub;
                    
                    value = JsonNetSerializer.DeserializeList<ServerModel>(res.Result);
                    //Debug.Write(res.Result);

                    foreach (var item in value)
                    {
                        hasSub = item.ExtendedAttributes.data_tochassubtree;
                        if (!string.IsNullOrEmpty(hasSub) && hasSub.Equals("true"))
                            item.hassubtree = true;
                        else
                            item.hassubtree = false;
                        item.parentid = sm._id;
                        item.level = sm.level + 1;
                    }
                    value.ForEach(c => data.Value.Add(c));
                }
                catch (Exception ex)
                {
                    if (value.Count == 0)
                        Debug.Write("Error: " + "数据反序列话错误。");
                    else
                    {
                        Debug.Write("Error: " + "数据库插入数据错误。");
                    }
                }
            }

            return data;
        }