コード例 #1
0
 protected virtual void OnQueuedTransferClient(TransferQueue queue)
 {
     if (QueuedTransferClient != null)
     {
         QueuedTransferClient(this, queue);
     }
 }
コード例 #2
0
 protected virtual void OnChangedProgress(TransferQueue queue)
 {
     if (ChangedProgress != null)
     {
         ChangedProgress(this, queue);
     }
 }
コード例 #3
0
 private void OnTransferClientProgressChanged(object sender, TransferQueue queue)
 {
     if (InvokeRequired)
     {
         Invoke(new TransferEventHandler(OnTransferClientProgressChanged), sender, queue);
     }
     progressSet(queue);
 }
コード例 #4
0
        public void StartTransfer(TransferQueue queue)
        {
            PacketWriter pw = new PacketWriter();

            pw.Write((byte)Headers.Start);
            pw.Write(queue.ID);
            Send(pw.GetBytes());
        }
コード例 #5
0
 private void OnTransferClientStopped(object sender, TransferQueue queue)
 {
     if (InvokeRequired)
     {
         Invoke(new TransferEventHandler(OnTransferClientStopped), sender, queue);
         return;
     }
     lstTransfers.Items[queue.ID.ToString()].Remove();
 }
コード例 #6
0
 private void progressSet(TransferQueue queue)
 {
     if (InvokeRequired)
     {
         Invoke(new Action <TransferQueue>(progressSet), queue);
         return;
     }
     lstTransfers.Items[queue.ID.ToString()].SubItems[3].Text = queue.Progress + "%";
 }
コード例 #7
0
        public void PauseTransfer(TransferQueue queue)
        {
            queue.Pause();

            PacketWriter pw = new PacketWriter();

            pw.Write((byte)Headers.Pause);
            pw.Write(queue.ID);
            Send(pw.GetBytes());
        }
コード例 #8
0
        private void transferClient_Queued_(object sender, TransferQueue queue)
        {
            OnQueuedTransferClient(queue);

            queueList.Add(queue);

            if (queue.Type == QueueType.Download)
            {
                transferManager.StartTransfer(queue);
            }
        }
コード例 #9
0
        private void btnClearComplete_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem i in lstTransfers.Items)
            {
                TransferQueue queue = (TransferQueue)i.Tag;

                if (mc.getProgressOf(queue) == 100 || !mc.isQueueRunninig(queue)) ////
                {
                    i.Remove();
                }
            }
        }
コード例 #10
0
        public void StopTransfer(TransferQueue queue)
        {
            if (queue.Type == QueueType.Upload)
            {
                queue.Stop();
            }

            PacketWriter pw = new PacketWriter();

            pw.Write((byte)Headers.Stop);
            pw.Write(queue.ID);
            Send(pw.GetBytes());
            queue.Close();
        }
コード例 #11
0
        private void btnPauseTransfer_Click(object sender, EventArgs e)
        {
            if (!mc.hasTransferClientInitialized()) ////
            {
                return;
            }



            foreach (ListViewItem i in lstTransfers.SelectedItems)
            {
                TransferQueue queue = (TransferQueue)i.Tag;
                mc.pauseOrStartQueue(queue); ////
            }
        }
コード例 #12
0
        private void btnStopTransfer_Click(object sender, EventArgs e)
        {
            if (!mc.hasTransferClientInitialized()) ////
            {
                return;
            }

            foreach (ListViewItem i in lstTransfers.SelectedItems)
            {
                TransferQueue queue = (TransferQueue)i.Tag;
                mc.stopQueue(queue); ////
                i.Remove();
            }

            progressBar.Value = 0;
        }
コード例 #13
0
        private static void transferProc(object o)
        {
            TransferQueue queue = (TransferQueue)o;

            while (queue.Running && queue.Index < queue.Length)
            {
                queue.pauseEvent.WaitOne();

                if (!queue.Running)
                {
                    break;
                }
                lock (file_buffer)
                {
                    queue.FS.Position = queue.Index;

                    int read = queue.FS.Read(file_buffer, 0, file_buffer.Length);

                    PacketWriter pw = new PacketWriter();

                    pw.Write((byte)Headers.Chunk);
                    pw.Write(queue.ID);
                    pw.Write(queue.Index);
                    pw.Write(read);
                    pw.Write(file_buffer, 0, read);

                    queue.Transferred += read;
                    queue.Index       += read;

                    queue.Client.Send(pw.GetBytes());

                    queue.Progress = (int)((queue.Transferred * 100) / queue.Length);

                    if (queue.LastProgress < queue.Progress)
                    {
                        queue.LastProgress = queue.Progress;

                        queue.Client.callProgressChanged(queue);
                    }

                    Thread.Sleep(1);
                }
            }
            queue.Close();
        }
コード例 #14
0
        private void OnTransferClientQueued(object sender, TransferQueue queue)
        {
            if (InvokeRequired)
            {
                Invoke(new TransferEventHandler(OnTransferClientQueued), sender, queue);
                return;
            }
            ListViewItem i = new ListViewItem();

            i.Text = queue.ID.ToString();
            i.SubItems.Add(queue.FileName);
            i.SubItems.Add(queue.Type == QueueType.Download ? "Download" : "Upload");
            i.SubItems.Add("0%");
            i.Tag  = queue;
            i.Name = queue.ID.ToString();
            lstTransfers.Items.Add(i);
            i.EnsureVisible();
        }
コード例 #15
0
 public static TransferQueue CreateDownloadQueue(TransferManager client, int id, string saveName, long length)
 {
     try
     {
         var queue = new TransferQueue();
         queue.FileName = Path.GetFileName(saveName);
         queue.Client   = client;
         queue.Type     = QueueType.Download;
         queue.FS       = new FileStream(saveName, FileMode.Create);
         queue.FS.SetLength(length);
         queue.Length = length;
         queue.ID     = id;
         return(queue);
     }
     catch
     {
         return(null);
     }
 }
コード例 #16
0
 public static TransferQueue CreateUploadQueue(TransferManager client, string fileName)
 {
     try
     {
         var queue = new TransferQueue();
         queue.FileName            = Path.GetFileName(fileName);
         queue.Client              = client;
         queue.Type                = QueueType.Upload;
         queue.FS                  = new FileStream(fileName, FileMode.Open);
         queue.Thread              = new Thread(new ParameterizedThreadStart(transferProc));
         queue.Thread.IsBackground = true;
         queue.ID                  = Program.Rand.Next();
         queue.Length              = queue.FS.Length;
         return(queue);
     }
     catch
     {
         return(null);
     }
 }
コード例 #17
0
 public void QueueTransfer(string fileName)
 {
     try
     {
         TransferQueue queue = TransferQueue.CreateUploadQueue(this, fileName);
         _transfers.Add(queue.ID, queue);
         PacketWriter pw = new PacketWriter();
         pw.Write((byte)Headers.Queue);
         pw.Write(queue.ID);
         pw.Write(queue.FileName);
         pw.Write(queue.Length);
         Send(pw.GetBytes());
         if (Queued != null)
         {
             Queued(this, queue);
         }
     }
     catch
     {
     }
 }
コード例 #18
0
 private void transferClient_ProgressChanged_(object sender, TransferQueue queue)
 {
     OnChangedProgress(queue);
 }
コード例 #19
0
 public bool isQueueRunninig(TransferQueue queue)
 {
     return(queue.Running);
 }
コード例 #20
0
 private void transferClient_Complete(object sender, TransferQueue queue)
 {
     System.Media.SystemSounds.Asterisk.Play();
 }
コード例 #21
0
 public void stopQueue(TransferQueue queue)
 {
     queue.Client.StopTransfer(queue);
 }
コード例 #22
0
 public void pauseOrStartQueue(TransferQueue queue)
 {
     queue.Client.PauseTransfer(queue);
 }
コード例 #23
0
 private void transferClient_Stopped_(object sender, TransferQueue queue)
 {
     OnStopedTransferClient(queue);
 }
コード例 #24
0
        private void process()
        {
            PacketReader pr = new PacketReader(_buffer);

            Headers header = (Headers)pr.ReadByte();

            switch (header)
            {
            case Headers.Queue:
            {
                int    id       = pr.ReadInt32();
                string fileName = pr.ReadString();
                long   length   = pr.ReadInt64();

                TransferQueue queue = TransferQueue.CreateDownloadQueue(this, id, Path.Combine(OutputFolder,
                                                                                               Path.GetFileName(fileName)), length);
                _transfers.Add(id, queue);

                if (Queued != null)
                {
                    Queued(this, queue);
                }
            }
            break;

            case Headers.Start:
            {
                int id = pr.ReadInt32();
                if (_transfers.ContainsKey(id))
                {
                    _transfers[id].Start();
                }
            }
            break;

            case Headers.Stop:
            {
                int id = pr.ReadInt32();
                if (_transfers.ContainsKey(id))
                {
                    TransferQueue queue = _transfers[id];
                    queue.Stop();
                    queue.Close();
                    if (Stopped != null)
                    {
                        Stopped(this, queue);
                        _transfers.Remove(id);
                    }
                }
            }
            break;

            case Headers.Pause:
            {
                int id = pr.ReadInt32();
                if (_transfers.ContainsKey(id))
                {
                    _transfers[id].Pause();
                }
            }
            break;

            case Headers.Chunk:
            {
                int    id     = pr.ReadInt32();
                long   index  = pr.ReadInt64();
                int    size   = pr.ReadInt32();
                byte[] buffer = pr.ReadBytes(size);

                TransferQueue queue = _transfers[id];
                queue.Write(buffer, index);
                queue.Progress = (int)((queue.Transferred * 100) / queue.Length);
                if (queue.LastProgress < queue.Progress)
                {
                    if (ProgressChanged != null)
                    {
                        ProgressChanged(this, queue);
                    }
                    if (queue.Progress == 100)
                    {
                        queue.Close();
                        if (Complete != null)
                        {
                            Complete(this, queue);
                        }
                    }
                }
            }
            break;
            }
            pr.Dispose();
        }
コード例 #25
0
 public int getProgressOf(TransferQueue queue)
 {
     return(queue.Progress);
 }