コード例 #1
0
ファイル: DataManager.cs プロジェクト: wpdu/ControlTest
        public static ServerModel GetCurrData()
        {
            var conn = LocalDatabaseService.GetMainConnection();
            var data = conn.Table<ServerModel>().Where(c => c.Href.Equals(BaseUrl)).ToList();
            if (data.Count == 0)
            {
                ServerModel s = new ServerModel()
                {
                    _id = 0,
                    Title = "Windows",
                    Href = BaseUrl,
                    ToolTip = "Windows",
                    hassubtree = true,
                    parentid = 0,
                    level = 0
                };
                conn.Table<ServerModel>().Delete(c => 1 == 1);
                conn.Insert(s);
                conn.Dispose();
                return s;
            }
            else
            {
                return data[0];
            }

        }
コード例 #2
0
ファイル: MainPageViewModel.cs プロジェクト: wpdu/ControlTest
        public MainPageViewModel()
        {
            if (IsInDesignMode)
            {
                ServerModel s = new ServerModel()
                {
                    _id = 0,
                    Title = "Windows",
                    Href = "https://msdn.microsoft.com/zh-cn/library/windows/apps/hh703192.aspx",
                    ToolTip = "Windows",
                    hassubtree = true,
                    level = 0
                };
                CurrModel = new ClientModel(s, null);
                ObservableCollection<ClientModel> subs = new ObservableCollection<ClientModel>();
                subs.Add(new ClientModel(new ServerModel() { Title = "热门" }, CurrModel));
                subs.Add(new ClientModel(new ServerModel() { Title = "设计" }, CurrModel));
                subs.Add(new ClientModel(new ServerModel() { Title = "开发" }, CurrModel));
                subs.Add(new ClientModel(new ServerModel() { Title = "发布" }, CurrModel));
                CurrModel.Subs = subs;

            }

        }
コード例 #3
0
ファイル: MainPageViewModel.cs プロジェクト: wpdu/ControlTest
 public async void GoSugges(ServerModel sv)
 {
     ClientModel cm = new ClientModel(sv, null);
     if (cm.Subs.Count == 0 && cm.HaveChild)
     {
         List<ServerModel> sData = await Manager.DataManager.GetData(cm);
         sData.ForEach(c => cm.Subs.Add(new ClientModel(c, cm)));
     }
     if (cmBackUp == null)
         cmBackUp = CurrModel;
     CurrModel = cm;
 }
コード例 #4
0
ファイル: DataManager.cs プロジェクト: wpdu/ControlTest
        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;
        }
コード例 #5
0
ファイル: DataManager.cs プロジェクト: wpdu/ControlTest
 private bool GetNext(Queue<ServerModel> fileQueue, out ServerModel sm)
 {
     lock (syncObj)
     {
         sm = null;
         if (fileQueue.Count > 0)
         {
             sm = FileQueue.Dequeue();
             return true;
         }
         
         return false;
     }
 }
コード例 #6
0
ファイル: DataManager.cs プロジェクト: wpdu/ControlTest
        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;
        }