private void ThreadUploadFile()
        {
            FileInfo finfo = new FileInfo(FilePath);

            Invoke(new Action(() =>
            {
                label_now_info.Text = "正在上传文件...";
                label_filesize.Text = SoftBasic.GetSizeDescription(finfo.Length);
                progressBar1.Value  = 0;
            }));

            OperateResult result = AdvancedFileClient.UploadFile(
                FilePath,
                finfo.Name,
                Factory,
                Group,
                Id,
                "",
                UserClient.UserAccount.UserName,
                ReportProgress);

            if (result.IsSuccess)
            {
                Invoke(new Action(() =>
                {
                    label_now_info.Text = "文件上传成功";
                }));
            }
            else
            {
                WrongTextShow("异常:" + result.Message);
            }

            IsOperateFinished = true;
        }
Esempio n. 2
0
        private void RefreshKey( )
        {
            if (redisClient == null)
            {
                MessageBox.Show("当前的连接为空,无法读取!"); return;
            }
            OperateResult <string[]> read = redisClient.Redis.ListRange(stringKeyName, 0, -1);

            if (!read.IsSuccess)
            {
                MessageBox.Show("读取失败:" + read.Message);
            }
            else
            {
                int size = 0;
                for (int i = 0; i < read.Content.Length; i++)
                {
                    size += Encoding.UTF8.GetBytes(read.Content[i]).Length;
                }
                label2.Text = "大小:" + SoftBasic.GetSizeDescription(size);
                label3.Text = read.Content.Length.ToString( );

                Utils.ControlDataGridViewRow(dataGridView1, read.Content.Length);
                for (int i = 0; i < read.Content.Length; i++)
                {
                    dataGridView1.Rows[i].Cells[0].Value = i;
                    dataGridView1.Rows[i].Cells[1].Value = read.Content[i];
                }
            }
        }
Esempio n. 3
0
        private void ShowValue( )
        {
            try
            {
                int size = Encoding.UTF8.GetBytes(value).Length;
                label2.Text = "大小: " + SoftBasic.GetSizeDescription(size);

                if (radioButton1.Checked)
                {
                    textBox1.Text = value;
                }
                else if (radioButton2.Checked)
                {
                    textBox1.Text = JsonConvert.DeserializeObject(value).ToString( );
                }
                else if (radioButton3.Checked)
                {
                    textBox1.Text = XElement.Parse(value).ToString( );
                }
            }
            catch
            {
                textBox1.Text = value;
            }
        }
        public void GetSizeDescriptionExample( )
        {
            #region GetSizeDescriptionExample

            string size = SoftBasic.GetSizeDescription(1234254123);

            // 1.15 Gb
            Console.WriteLine(size);


            #endregion
        }
        public void GetSizeDescriptionTest( )
        {
            long value = 123564357;

            Assert.AreEqual("117.84 Mb", SoftBasic.GetSizeDescription(value));
            value = 345;
            Assert.AreEqual("345 B", SoftBasic.GetSizeDescription(value));
            value = 453268;
            Assert.AreEqual("442.64 Kb", SoftBasic.GetSizeDescription(value));
            value = 452342343424;
            Assert.AreEqual("421.28 Gb", SoftBasic.GetSizeDescription(value));
        }
        /// <summary>
        /// 用于更新文件下载进度的方法,该方法是线程安全的
        /// </summary>
        /// <param name="receive">已经接收的字节数</param>
        /// <param name="totle">总字节数</param>
        private void DownloadReportProgress(long receive, long totle)
        {
            if (progressBar2.InvokeRequired)
            {
                progressBar2.Invoke(new Action <long, long>(DownloadReportProgress), receive, totle);
                return;
            }

            // 此处代码是线程安全的
            // thread-safe code
            int value = (int)(receive * 100L / totle);

            progressBar2.Value = value;
            label9.Text        = SoftBasic.GetSizeDescription(receive) + "/" + SoftBasic.GetSizeDescription(totle);
        }
        private void ReportProgress(long current, long count)
        {
            Invoke(new Action(() =>
            {
                long percent = 0;
                if (count > 0)
                {
                    percent = current * 100 / count;
                }

                progressBar1.Value  = (int)percent;
                label_now_info.Text = "已完成:" + percent.ToString() + "%";

                label_filesize.Text = SoftBasic.GetSizeDescription(count);
            }));
        }
        /// <summary>
        /// 用于更新上传进度的方法,该方法是线程安全的
        /// </summary>
        /// <param name="sended">已经上传的字节数</param>
        /// <param name="totle">总字节数</param>
        private void UpdateReportProgress(long sended, long totle)
        {
            if (progressBar1.InvokeRequired)
            {
                progressBar1.Invoke(new Action <long, long>(UpdateReportProgress), sended, totle);
                return;
            }


            // 此处代码是安全的
            // thread-safe code
            int value = (int)(sended * 100L / totle);

            label10.Text       = SoftBasic.GetSizeDescription(sended) + "/" + SoftBasic.GetSizeDescription(totle);
            progressBar1.Value = value;
        }
Esempio n. 9
0
        private void Timer1s_Tick(object sender, EventArgs e)
        {
            if (mqttServer != null)
            {
                label2.Text = "Online Count:" + mqttServer.OnlineCount;

                HslCommunication.Core.MqttFileMonitorItem[] monitorItems = mqttServer.GetMonitorItemsSnapShoot( );
                DataGridSpecifyRowCount(monitorItems.Length);

                long upload   = 0;
                long download = 0;
                for (int i = 0; i < monitorItems.Length; i++)
                {
                    DataGridViewRow row = dataGridView1.Rows[i];
                    HslCommunication.Core.MqttFileMonitorItem item = monitorItems[i];
                    row.Cells[0].Value  = item.UniqueId.ToString( );
                    row.Cells[1].Value  = item.EndPoint.ToString( );
                    row.Cells[2].Value  = item.ClientId;
                    row.Cells[3].Value  = item.UserName;
                    row.Cells[4].Value  = item.Operate;
                    row.Cells[5].Value  = item.Groups;
                    row.Cells[6].Value  = item.FileName;
                    row.Cells[7].Value  = item.StartTime.ToString( );
                    row.Cells[8].Value  = SoftBasic.GetSizeDescription(item.TotalSize);
                    row.Cells[9].Value  = item.TotalSize == 0 ? "-" : SoftBasic.GetSizeDescription(item.SpeedSecond) + "/s";
                    row.Cells[10].Value = item.TotalSize == 0 ? "-" : (item.LastUpdateProgress * 100 / item.TotalSize).ToString( ) + "%";

                    if (item.Operate == "Upload")
                    {
                        upload += item.SpeedSecond;
                    }
                    if (item.Operate == "Download")
                    {
                        download += item.SpeedSecond;
                    }
                }

                label6.Text = "Upload:" + SoftBasic.GetSizeDescription(upload) + "/s";
                label7.Text = "Download:" + SoftBasic.GetSizeDescription(download) + "/s";
            }
        }
 /// <summary>
 /// 获取大小
 /// </summary>
 /// <returns>文件大小的字符串描述形式</returns>
 public string GetTextFromFileSize( )
 {
     return(SoftBasic.GetSizeDescription(FileSize));
 }