Пример #1
0
        private int Upload(string Handle, string FileName, byte[] buffer)
        {
            org.lsleditor.www.Service1 webservice = new org.lsleditor.www.Service1();
            if (Handle == null)
            {
                return(0);
            }

            SetMaximum(buffer.Length);
            int intOffset = 0;
            int intTotal  = 0;

            byte[] smallbuffer = new byte[1024];
            while (this.blnRunning)
            {
                int intLength = Math.Min(smallbuffer.Length, buffer.Length - intOffset);
                if (intLength <= 0)
                {
                    break;
                }
                Array.Copy(buffer, intOffset, smallbuffer, 0, intLength);
                intOffset += intLength;
                string strError = webservice.Write(Handle, FileName, smallbuffer, intLength);
                if (strError != null)
                {
                    MessageBox.Show("Error:" + strError, "Oops...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }
                intTotal += intLength;
                SetValue(intTotal);
            }
            return(intTotal);
        }
Пример #2
0
        private void Worker()
        {
            int intTotal = 0;

            try
            {
                org.lsleditor.www.Service1 webservice = new org.lsleditor.www.Service1();

                string Handle = webservice.Open();
                if (Handle == null)
                {
                    MessageBox.Show("Can't get an upload handle", "Oops...");
                    this.blnRunning = false;
                    return;
                }

                if (Properties.Settings.Default.Bugreports == null)
                {
                    Properties.Settings.Default.Bugreports = new StringCollection();
                }
                Properties.Settings.Default.Bugreports.Add(Handle);

                // Properties.Settings.Default.Save();

                int intNumber = 0;
                foreach (FileToUpload file in this.list)
                {
                    string strFileName = string.Format("{0}-{1}", intNumber, file.FileName);
                    if (file.Path == null)
                    {
                        intTotal += Upload(Handle, strFileName, Encoding.ASCII.GetBytes(file.Body));
                    }
                    else
                    {
                        intTotal += Upload(Handle, strFileName, file.Path);
                    }
                    intNumber++;
                }
            }
            catch
            {
                intTotal = -1;
            }
            if (this.blnRunning)
            {
                if (OnComplete != null)
                {
                    OnComplete(this, new UploadCompleteEventArgs(intTotal));
                }
            }
            this.blnRunning = false;
        }