Esempio n. 1
0
 // create a new task to run
 private void startRunning(string fileName, TransferTask.TaskType type, long size)
 {
     PBRunning.Value = 0;
     LabelTask.Text  = string.Format(
         type == TransferTask.TaskType.upload ? LanguageConstant.UPLOADING_FMT : LanguageConstant.DOWNLOADING_FMT,
         fileName);
     runningPartBatch(false);
     task = new TransferTask(
         cmd, nsize =>
         PBRunning.Value = (int)(100 * nsize / size), () =>
     {
         task            = null;
         PBRunning.Value = 100;
         LabelTask.Text  = LanguageConstant.FINISHED_STRING;
         runningPartBatch(true);
         if (type == TransferTask.TaskType.upload)
         {
             refreshFtp();
         }
         else
         {
             refreshLocal();
         }
     }, s =>
     {
         MessageBox.Show(s);
         task           = null;
         LabelTask.Text = s;
         runningPartBatch(true);
     }, BoxLocalAddress.Text, BoxFtpPath.Text, fileName, type);
     task.run();
 }
Esempio n. 2
0
 // Just stop but not ready to continue the task
 private void ButtonStop_Click(object sender, EventArgs e)
 {
     if (task == null)
     {
         throw new FormatException("No Task Is Running");
     }
     task.stop();
     task             = null;
     PBRunning.Value  = 0;
     LabelTask.Text   = LanguageConstant.NO_TASK_STRING;
     ButtonPause.Text = LanguageConstant.PAUSE_STRING;
     runningPartBatch(true);
 }
Esempio n. 3
0
        // reload the server box of file
        private void refreshFtp()
        {
            LVFtp.Items.Clear();
            if (!BoxFtpPath.Text.Equals("\\"))
            {
                ListViewItem it = new ListViewItem();
                it.Text = "..";
                it.SubItems.Add("directory");
                LVFtp.Items.Add(it);
            }


            // rsy56640
            // consider when no task or no connection.
            // and use `Select` to detect the whether the connection is ok.
            if (cmd == null)
            {
                return;
            }

            ArrayList writeList = new ArrayList();

            writeList.Add(cmd.tcp.Client);
            ArrayList listenList = new ArrayList();

            listenList.Add(cmd.tcp.Client);
            Socket.Select(listenList, writeList, null, 1000);

            if (listenList.Count == 0)// || writeList.Count != 0)
            {
                cmd.passiveDataAction(CommandConstant.CMD_LIST, (send, data) =>
                {
                    StreamReader reader = new StreamReader(data.GetStream(), cmd.encoder);
                    string s;
                    while ((s = reader.ReadLine()) != null)
                    {
                        var size        = Convert.ToUInt64(Regex.Match(s.Substring(24), @"\d+").ToString());
                        ListViewItem it = new ListViewItem();

                        // a simple function for finding elements, does not consider generality and robustness
                        // for it's only used here.
                        Func <string, int, int> findNthSection = (str, n) =>
                        {
                            int start = 0;
                            while (str[start] == ' ')
                            {
                                ++start;
                            }
                            int count = 0;
                            bool cont = false;
                            while (start < str.Length)
                            {
                                if (str[start++] == ' ')
                                {
                                    if (!cont)
                                    {
                                        cont = true;
                                    }
                                    else
                                    {
                                        ;
                                    }
                                }
                                else if (cont)
                                {
                                    if (++count == n)
                                    {
                                        return(start - 1);
                                    }
                                    else
                                    {
                                        cont = false;
                                    }
                                }
                            }
                            return(start);
                        };
                        it.Text = s.Substring(findNthSection(s, 8));

                        ///*
                        // * Reeker - fix bug with FTP filename
                        // * before this, filename for files which are not modified this year will lose its first char
                        // * */
                        //// get the filename according to whether the file is modified this year
                        //if (s[48] == ':')
                        //    it.Text = s.Substring(52);
                        //else
                        //    it.Text = s.Substring(51);
                        ////end

                        if (s[0] == 'd')
                        {
                            it.SubItems.Add("directory");
                        }
                        else
                        {
                            it.SubItems.Add(size.ToString());
                        }
                        LVFtp.Items.Add(it);
                    }
                    return(true);
                }, true);
            }
            else
            {
                //cmd.tcp.Client.Close();
                task = null;
            }
        }