Пример #1
0
        void UploadPartialDo()
        {
            FileTransferWS.ServiceWse serviceWse = new Remwave.Client.FileTransferWS.ServiceWse();
            serviceWse.RequireMtom = true;
            mUploadFile.ChunkSize  = mPreferredChunkSize;
            using (FileStream stream = new FileStream(mUploadFile.LocalFileName, FileMode.Open))
            {
                mUploadFile.Size = stream.Length;
                while (mUploadFile.Size > mUploadFile.Offset && mUploadFile.ErrorCount < 60)
                {
                    byte[] buffer = new byte[mUploadFile.ChunkSize];

                    stream.Position       = mUploadFile.Offset;
                    mUploadFile.ChunkSize = stream.Read(buffer, 0, buffer.Length);
                    Array.Resize(ref buffer, mUploadFile.ChunkSize);

                    try
                    {
                        mUploadFile.TimeMarker = DateTime.Now;
                        serviceWse.PutFileChunk(mUploadFile.FromJID, "", mUploadFile.ID, buffer, mUploadFile.Offset);
                        mUploadFile.Offset   += mUploadFile.ChunkSize;
                        mUploadFile.ChunkSize = OptimizeChunkSize(mUploadFile.ChunkSize, mUploadFile.TimeMarker);
                    }
                    catch (Exception)
                    {
                        Thread.Sleep(5000);
                        mUploadFile.ErrorCount++;
                    }
                    this.mUploadFile.Progress = 100 * Convert.ToInt32(mUploadFile.Offset / mUploadFile.Size);
                    mUploadBackgroundWorker.ReportProgress(this.mUploadFile.Progress);
                }
            }
        }
Пример #2
0
        public SharedFile Download(String filename, String username, String password, String fromJID, String id)
        {
            try
            {
                mDownloadFile               = new SharedFile();
                mDownloadFile.FileName      = Path.GetFileName(filename);
                mDownloadFile.FromJID       = fromJID;
                mDownloadFile.ToJID         = username;
                mDownloadFile.ID            = id;
                mDownloadFile.LocalFileName = Path.GetTempFileName();

                FileTransferWS.ServiceWse serviceWse = new Remwave.Client.FileTransferWS.ServiceWse();
                serviceWse.RequireMtom = true;

                mDownloadFile.Size = serviceWse.GetFileSize(username, password, id);

                mDownloadBackgroundWorker = new BackgroundWorker();
                mDownloadBackgroundWorker.WorkerReportsProgress = true;
                mDownloadBackgroundWorker.DoWork             += new DoWorkEventHandler(mDownloadBackgroundWorker_DoWork);
                mDownloadBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(mDownloadBackgroundWorker_RunWorkerCompleted);
                mDownloadBackgroundWorker.ProgressChanged    += new ProgressChangedEventHandler(mDownloadBackgroundWorker_ProgressChanged);
                mDownloadBackgroundWorker.RunWorkerAsync();
            }
            catch (Exception)
            {
            }
            return(mDownloadFile);
        }
Пример #3
0
        void DownloadPartialDo()
        {
            FileTransferWS.ServiceWse serviceWse = new Remwave.Client.FileTransferWS.ServiceWse();
            serviceWse.RequireMtom  = true;
            mDownloadFile.ChunkSize = mPreferredChunkSize;
            using (FileStream stream = new FileStream(mDownloadFile.LocalFileName, FileMode.Create))
            {
                while (mDownloadFile.Size > mDownloadFile.Offset && mDownloadFile.ErrorCount < 60)
                {
                    if (mDownloadFile.Offset + mDownloadFile.ChunkSize > mDownloadFile.Size)
                    {
                        mDownloadFile.ChunkSize = Convert.ToInt32(mDownloadFile.Size - mDownloadFile.Offset);
                    }

                    byte[] buffer = new byte[mDownloadFile.ChunkSize];
                    try
                    {
                        stream.Position = mDownloadFile.Offset;

                        mDownloadFile.TimeMarker = DateTime.Now;
                        buffer = serviceWse.GetFileChunk(mDownloadFile.FromJID, "", mDownloadFile.ID, mDownloadFile.Offset, mDownloadFile.ChunkSize);
                        mDownloadFile.Offset   += buffer.Length; //we might download less data than we want
                        mDownloadFile.ChunkSize = OptimizeChunkSize(buffer.Length, mDownloadFile.TimeMarker);

                        stream.Write(buffer, 0, buffer.Length);
                    }
                    catch (Exception)
                    {
                        Thread.Sleep(5000);
                        mDownloadFile.ErrorCount++;
                    }
                    this.mDownloadFile.Progress = 100 * Convert.ToInt32(mDownloadFile.Offset / mDownloadFile.Size);
                    mDownloadBackgroundWorker.ReportProgress(this.mDownloadFile.Progress);
                }
            }
        }
Пример #4
0
        void DownloadPartialDo()
        {
            FileTransferWS.ServiceWse serviceWse = new Remwave.Client.FileTransferWS.ServiceWse();
            serviceWse.RequireMtom = true;
            mDownloadFile.ChunkSize = mPreferredChunkSize;
            using (FileStream stream = new FileStream(mDownloadFile.LocalFileName, FileMode.Create))
            {
                while (mDownloadFile.Size > mDownloadFile.Offset && mDownloadFile.ErrorCount < 60)
                {

                    if (mDownloadFile.Offset + mDownloadFile.ChunkSize > mDownloadFile.Size)
                    {
                        mDownloadFile.ChunkSize = Convert.ToInt32(mDownloadFile.Size - mDownloadFile.Offset);
                    }

                    byte[] buffer = new byte[mDownloadFile.ChunkSize];
                    try
                    {
                        stream.Position = mDownloadFile.Offset;

                        mDownloadFile.TimeMarker = DateTime.Now;
                        buffer = serviceWse.GetFileChunk(mDownloadFile.FromJID, "", mDownloadFile.ID, mDownloadFile.Offset, mDownloadFile.ChunkSize);
                        mDownloadFile.Offset += buffer.Length; //we might download less data than we want
                        mDownloadFile.ChunkSize = OptimizeChunkSize(buffer.Length, mDownloadFile.TimeMarker);

                        stream.Write(buffer, 0, buffer.Length);
                    }
                    catch (Exception)
                    {
                        Thread.Sleep(5000);
                        mDownloadFile.ErrorCount++;
                    }
                    this.mDownloadFile.Progress = 100*Convert.ToInt32( mDownloadFile.Offset / mDownloadFile.Size);
                    mDownloadBackgroundWorker.ReportProgress(this.mDownloadFile.Progress);
                }
            }
        }
Пример #5
0
        void UploadPartialDo()
        {
            FileTransferWS.ServiceWse serviceWse = new Remwave.Client.FileTransferWS.ServiceWse();
            serviceWse.RequireMtom = true;
            mUploadFile.ChunkSize = mPreferredChunkSize;
            using (FileStream stream = new FileStream(mUploadFile.LocalFileName, FileMode.Open))
            {
                mUploadFile.Size = stream.Length;
                while (mUploadFile.Size > mUploadFile.Offset && mUploadFile.ErrorCount < 60)
                {
                    byte[] buffer = new byte[mUploadFile.ChunkSize];

                    stream.Position = mUploadFile.Offset;
                    mUploadFile.ChunkSize = stream.Read(buffer, 0, buffer.Length);
                    Array.Resize(ref buffer, mUploadFile.ChunkSize);

                    try
                    {
                        mUploadFile.TimeMarker = DateTime.Now;
                        serviceWse.PutFileChunk(mUploadFile.FromJID, "", mUploadFile.ID, buffer, mUploadFile.Offset);
                        mUploadFile.Offset += mUploadFile.ChunkSize;
                        mUploadFile.ChunkSize = OptimizeChunkSize(mUploadFile.ChunkSize, mUploadFile.TimeMarker);
                    }
                    catch (Exception)
                    {
                        Thread.Sleep(5000);
                        mUploadFile.ErrorCount++;
                    }
                    this.mUploadFile.Progress = 100*Convert.ToInt32(mUploadFile.Offset / mUploadFile.Size);
                    mUploadBackgroundWorker.ReportProgress(this.mUploadFile.Progress);
                }

            }
        }
Пример #6
0
        public SharedFile Download(String filename, String username, String password, String fromJID, String id)
        {
            try
            {
                mDownloadFile = new SharedFile();
                mDownloadFile.FileName = Path.GetFileName(filename);
                mDownloadFile.FromJID = fromJID;
                mDownloadFile.ToJID = username;
                mDownloadFile.ID = id;
                mDownloadFile.LocalFileName = Path.GetTempFileName();

                FileTransferWS.ServiceWse serviceWse = new Remwave.Client.FileTransferWS.ServiceWse();
                serviceWse.RequireMtom = true;

                mDownloadFile.Size = serviceWse.GetFileSize(username, password, id);

                mDownloadBackgroundWorker = new BackgroundWorker();
                mDownloadBackgroundWorker.WorkerReportsProgress = true;
                mDownloadBackgroundWorker.DoWork += new DoWorkEventHandler(mDownloadBackgroundWorker_DoWork);
                mDownloadBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(mDownloadBackgroundWorker_RunWorkerCompleted);
                mDownloadBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(mDownloadBackgroundWorker_ProgressChanged);
                mDownloadBackgroundWorker.RunWorkerAsync();
            }
            catch (Exception)
            {

            }
            return mDownloadFile;
        }