Example #1
0
        void UpdateServer(string startpath = "")
        {
            Log = "Идет загрузка...";
            treeView1.Nodes.Clear();
            new Thread(() => ld.ShowDialog()).Start();

            var DeviceInfo = Downloading.GetDeviceParams(setting.URLToHTTPPort, setting.Name, setting.Password);

            label1.Text          = "Свободно места на SD (" + formatFileSize(int.Parse(DeviceInfo["sdfreespace"])) + ") из " + formatFileSize(int.Parse(DeviceInfo["sdtotalspace"]));
            progressBar2.Maximum = int.Parse(DeviceInfo["sdtotalspace"]);
            progressBar2.Value   = int.Parse(DeviceInfo["sdtotalspace"]) - int.Parse(DeviceInfo["sdfreespace"]);
            label2.Text          = (DeviceInfo["sdstatus"].Contains("Ready")) ? "SD карта работает исправно" : "Ошибка SD карты";
            label3.Text          = "Камера запущенна: " + DeviceInfo["startdate"];
            label6.Text          = "Камера работает: " + (DateTime.Now - DateTime.Parse(DeviceInfo["startdate"])).ToString().Split('.')[0];

            checkBox1.Checked       = DeviceInfo["planrec_enable"].Contains("1");
            numericUpDown1.Value    = int.Parse(DeviceInfo["planrec_time"]);
            comboBox1.SelectedIndex = DeviceInfo["planrec_chn"] == "11" ? 1 : 0;

            var web = (Downloading.GetHTML(DownloadingPaths.ToPath(setting.URLToHTTPPort) + DownloadingPaths.SD + startpath, setting.Name, setting.Password));

            HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();
            html.LoadHtml(web);

            var table   = html.DocumentNode.SelectSingleNode("/html/body/pre/table");
            var tabletr = table.ChildNodes.Where(x => x.Name == "tr").ToList();

            tabletr.RemoveRange(0, 3);

            foreach (var item in tabletr)
            {
                if (item.ChildNodes.Count > 2)
                {
                    var path = item.ChildNodes[0].ChildNodes[0].InnerHtml.Replace(" ", "");
                    var date = item.ChildNodes[1].ChildNodes[0].InnerHtml.Replace(" ", "");
                    var size = item.ChildNodes[2].ChildNodes[0].InnerHtml.Replace(" ", "");

                    //Console.WriteLine(path);
                    //Console.WriteLine(date);
                    //Console.WriteLine(type);
                    //Console.WriteLine("----------");

                    FileTreeNode tr = new FileTreeNode(path, GetServer(startpath + "" + path), FileTreeNode.TypeNode.Directory, startpath + "" + path);
                    tr.ToolTipText      = date + " (" + size + ")";
                    tr.ContextMenuStrip = contextMenuStrip1;
                    treeView1.Nodes.Add(tr);
                }
            }
            if (backgroundWorker1.IsBusy)
            {
                backgroundWorker1.CancelAsync();
            }
            if (!backgroundWorker1.IsBusy)
            {
                backgroundWorker1.RunWorkerAsync(DateTime.Now - DateTime.Parse(DeviceInfo["startdate"]));
            }
            ld.Invoke(new Action(() => ld.Close()));
            Log = "Загрузка завершена";
        }