public void Excute(object obj)
        {
            TransferTask task = (TransferTask)obj;

            task.NetSize = 0;
            capHelper.Reset();
            while (task.Status == TaskStatus.Loading)
            {
                ccc++;
                if (ccc == 10)
                {
                    if (task.Type == TaskType.Upload)
                    {
                        task.Speed = capHelper.ProcInfo.NetSendBytes;
                    }
                    else
                    {
                        task.Speed = capHelper.ProcInfo.NetRecvBytes;
                    }

                    task.ElapsedTime += 1;
                    if (task.Speed != 0)
                    {
                        task.LeftTime = (task.Size - task.Progress) / (task.Speed / 1024.0);
                    }
                    else
                    {
                        task.LeftTime = -1;
                    }

                    ccc = 0;
                }

                double tt = 0;
                if (task.Type == TaskType.Upload)
                {
                    tt = capHelper.ProcInfo.AccNetSendBytes;
                }
                else
                {
                    tt = capHelper.ProcInfo.AccNetRecvBytes;
                }

                task.NetSize = tt / 1024.0;

                if (task.NetSize >= task.Size * 0.99)
                {
                    task.Progress = (int)(task.Size * 0.99);
                }
                else
                {
                    task.Progress = (int)(task.NetSize);
                }
                task.Name = System.IO.Path.GetFileNameWithoutExtension(task.SourceFileName);

                task.Name = task.NetSize.ToString() + " / " + task.Size.ToString();

                capHelper.RefershInfo();
            }
        }
 public void CompleteTask(TransferTask currentTask)
 {
     currentTask.Progress = currentTask.Size;
     currentTask.Speed    = 0;
     currentTask.LeftTime = 0;
     currentTask.Status   = TaskStatus.Completed;
     RefreshDataSource();
 }
 public void AddTask(TransferTask task)
 {
     this.Tasks.Add(task);
     if (CurrentTaskID.Equals(Guid.Empty))
     {
         CurrentTaskID = task.ID;
     }
 }
 private bool IsCompletedOfUpload(TransferTask task)
 {
     if (task.Status == TaskStatus.Completed && task.Type == TaskType.Upload)
     {
         return(true);
     }
     return(false);
 }
 private bool IsPendingOrLoadingOfUpload(TransferTask task)
 {
     if (task.Status == TaskStatus.Loading || task.Status == TaskStatus.Pending)
     {
         if (task.Type == TaskType.Upload)
         {
             return(true);
         }
     }
     return(false);
 }
        private void Transfer(TransferTask task)
        {
            task.Status        = TaskStatus.Loading;
            this.CurrentTaskID = task.ID;
            task.Size          = CalculateSize(task);
            td = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Excute));
            td.Start(task);

            string         taskInfo    = string.Format("{0}#{1}#{2}#{3}#{4}#{5}", new string[] { task.ID.ToString(), task.SourceFileName, task.DestFileName, task.Type.ToString(), task.RenameMode.ToString(), task.Category.ToString() }).Replace(' ', '$');
            Int32          id          = 1;
            Int32          WM_COPYDATA = 0x004A;
            COPYDATASTRUCT cd          = new COPYDATASTRUCT();

            cd.dwData = (IntPtr)id;
            cd.lpData = taskInfo;
            cd.cbData = taskInfo.Length;
            SendMessage((int)FindWindow(null, "TransferForm"), WM_COPYDATA, 0, ref cd);
        }
        void refreshDSTM_Tick(object sender, EventArgs e)
        {
            RefreshDataSource();

            TransferTask currentTask = GetTaskByID(CurrentTaskID);

            if (currentTask != null)
            {
                if (currentTask.Status == TaskStatus.Pending)
                {
                    Transfer(currentTask);
                }
                else if (currentTask.Status == TaskStatus.Completed || currentTask.Status == TaskStatus.Canceled)
                {
                    TransferNext();
                }
            }
        }
        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.Column.FieldName.Equals("Speed"))
            {
                TransferTask task = GetTaskByID(new Guid(gridView1.GetRowCellValue(e.RowHandle, "ID").ToString()));
                switch (task.Status)
                {
                case TaskStatus.Completed:
                {
                    e.DisplayText = "已完成";
                    break;
                }

                case TaskStatus.Canceled:
                {
                    e.DisplayText = "已删除";
                    break;
                }

                case TaskStatus.Loading:
                {
                    int value = Convert.ToInt32(e.CellValue);
                    if (value / 1024 == 0)
                    {
                        e.DisplayText = string.Format("{0} B/s", value);
                    }
                    else if (value / (1024 * 1024) == 0)
                    {
                        e.DisplayText = string.Format("{0:F2} K/s", value / 1024.0);
                    }
                    else
                    {
                        e.DisplayText = string.Format("{0:F2} M/s", value / 1024.0 / 1024.0);
                    }
                    break;
                }

                case TaskStatus.Pending:
                {
                    e.DisplayText = "等待中";
                    break;
                }
                }
            }
            else if (e.Column.FieldName.Equals("LeftTime"))
            {
                try
                {
                    if (e.CellValue.ToString().Equals("Infinity"))
                    {
                        e.DisplayText = "Infinity";
                    }
                    else if (e.CellValue.ToString().Equals("-1"))
                    {
                        e.DisplayText = "--:--:--";
                    }
                    else
                    {
                        int value   = Convert.ToInt32(e.CellValue);
                        int seconds = value % 60;
                        int minutes = (value % 3600) / 60;
                        int hours   = (value % 216000) / 3600;
                        if (hours >= 24)
                        {
                            e.DisplayText = "多于1天";
                        }
                        else
                        {
                            e.DisplayText = string.Format("{0:D2}:{1:D2}:{2:D2}", new object[] { hours, minutes, seconds });
                        }
                    }
                }
                catch { }
            }
            else if (e.Column.FieldName.Equals("ElapsedTime"))
            {
                try
                {
                    if (e.CellValue.ToString().Equals("Infinity"))
                    {
                        e.DisplayText = "Infinity";
                    }
                    else
                    {
                        int value   = Convert.ToInt32(e.CellValue);
                        int seconds = value % 60;
                        int minutes = (value % 3600) / 60;
                        int hours   = (value % 216000) / 3600;
                        if (hours >= 24)
                        {
                            e.DisplayText = "多于1天";
                        }
                        else
                        {
                            e.DisplayText = string.Format("{0:D2}:{1:D2}:{2:D2}", new object[] { hours, minutes, seconds });
                        }
                    }
                }
                catch { }
            }
        }
        /// <summary>
        /// 获取文件大小
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        private int CalculateSize(TransferTask task)
        {
            if (task.Category == TaskCategory.Files)
            {
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(task.SourceFileName);
                return((int)(fileInfo.Length / 1024));
            }
            else if (task.Category == TaskCategory.Features)
            {
                DirectoryInfo dir      = new DirectoryInfo(System.IO.Path.GetDirectoryName(task.SourceFileName));
                string        nickName = System.IO.Path.GetFileNameWithoutExtension(task.SourceFileName);
                FileInfo[]    fs       = dir.GetFiles(string.Format("*{0}*", nickName));
                int           length   = 0;
                foreach (FileInfo f in fs)
                {
                    length += (int)f.Length;
                }

                if (task.DestFileName.ToLower().Contains(".gdb"))
                {
                    if (task.SourceFileName.ToLower().Contains(".gdb"))
                    {
                    }
                    else
                    {
                        return(length / 1024 + 1150);
                    }
                }
                else
                {
                    if (task.SourceFileName.ToLower().Contains(".gdb"))
                    {
                    }
                    else
                    {
                        return(length / 1024);
                    }
                }
            }
            else if (task.Category == TaskCategory.Raster)
            {
                if (task.DestFileName.ToLower().Contains(".gdb"))
                {
                    if (task.SourceFileName.ToLower().Contains(".gdb"))
                    {
                        IWorkspaceFactory inputWsF       = null;
                        IWorkspace        inputWs        = null;
                        IRasterWorkspace  inputRstWs     = null;
                        IRasterDataset2   inputRstDs     = null;
                        IRaster           inputRaster    = null;
                        string            inputDirectory = string.Empty;
                        string            inputRstName   = string.Empty;

                        string input = task.SourceFileName.Trim();
                        if (input.ToLower().Contains(".gdb"))
                        {
                            inputWsF       = new FileGDBWorkspaceFactoryClass();
                            inputDirectory = input.Substring(0, input.IndexOf(".gdb") + 4);
                        }
                        else
                        {
                            inputWsF       = new RasterWorkspaceFactoryClass();
                            inputDirectory = System.IO.Path.GetDirectoryName(input);
                        }
                        inputRstName = System.IO.Path.GetFileName(input);
                        inputWs      = inputWsF.OpenFromFile(inputDirectory, 0);
                        inputRstWs   = inputWs as IRasterWorkspace;
                        inputRstDs   = inputRstWs.OpenRasterDataset(inputRstName) as IRasterDataset2;
                        inputRaster  = inputRstDs.CreateDefaultRaster();

                        IRawBlocks  inputRawBlocks = (IRawBlocks)inputRstDs;
                        IRasterInfo inputRstInfo   = inputRawBlocks.RasterInfo;

                        IRasterProps in_rasterProps           = (IRasterProps)inputRaster;
                        int          Height                   = in_rasterProps.Height;
                        int          Width                    = in_rasterProps.Width;
                        rstPixelType in_rstPT                 = in_rasterProps.PixelType;
                        int          BandsCount               = inputRstInfo.BandCount;
                        Dictionary <rstPixelType, int> DictPT = new Dictionary <rstPixelType, int>();
                        DictPT.Clear();
                        DictPT.Add(rstPixelType.PT_DOUBLE, 64);
                        DictPT.Add(rstPixelType.PT_FLOAT, 32);
                        DictPT.Add(rstPixelType.PT_LONG, 32);
                        DictPT.Add(rstPixelType.PT_SHORT, 32);
                        DictPT.Add(rstPixelType.PT_UCHAR, 8);
                        DictPT.Add(rstPixelType.PT_ULONG, 32);
                        DictPT.Add(rstPixelType.PT_USHORT, 32);
                        DictPT.Add(rstPixelType.PT_CHAR, 8);

                        int Depth = 32;
                        DictPT.TryGetValue(in_rasterProps.PixelType, out Depth);

                        return((int)(1.0 * Height * Width * BandsCount * Depth / 8.0 / 1024));
                    }
                    else
                    {
                        System.IO.FileInfo fileInfo = new System.IO.FileInfo(task.SourceFileName);
                        return((int)(fileInfo.Length / 1024 + 1150));
                    }
                }
                else
                {
                    if (task.SourceFileName.ToLower().Contains(".gdb"))
                    {
                    }
                    else
                    {
                        System.IO.FileInfo fileInfo = new System.IO.FileInfo(task.SourceFileName);
                        return((int)(fileInfo.Length / 1024));
                    }
                }
            }
            return(task.Size);
        }