Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var mgr = new BackgroundCopyManager();

            mgr.CreateJob("My managed Job", BG_JOB_TYPE.BG_JOB_TYPE_DOWNLOAD, out var guid, out var job);
            job.AddFile("http://speedtest.ftp.otenet.gr/files/test10Mb.db", @"c:\temp\test.db");
            job.Resume();

            BG_JOB_STATE state;

            while (true)
            {
                job.GetState(out state);
                if (state == BG_JOB_STATE.BG_JOB_STATE_TRANSFERRED || state == BG_JOB_STATE.BG_JOB_STATE_ERROR)
                {
                    break;
                }
                Thread.Sleep(500);
                Console.Write(".");
            }
            Console.WriteLine();
            if (state == BG_JOB_STATE.BG_JOB_STATE_TRANSFERRED)
            {
                job.Complete();
                Console.WriteLine("Transferred successfully.");
            }
            else
            {
                Console.WriteLine("Error!");
            }
        }
Ejemplo n.º 2
0
        public void CopyAsyncCancelReportTest()
        {
            using var tempRoot = new TemporaryDirectory();

            var srcFile = tempRoot.CreateFile(100 * TemporaryDirectory.OneMebibyte).FullName;

            var dstFile = tempRoot.RandomTxtFileFullPath;


            using var cts = new CancellationTokenSource();

            var collection = new Collection <string>();

            var prog = new Progress <Tuple <BackgroundCopyJobState, byte> >(t => collection.Add($"{t.Item2}% : {t.Item1}"));

            cts.CancelAfter(TimeSpan.FromMilliseconds(50));


            Assert.That(() => BackgroundCopyManager.CopyAsync(srcFile, dstFile, cts.Token, prog), Throws.TypeOf <OperationCanceledException>());

            Assert.That(File.Exists(dstFile), Is.False);

            Assert.That(collection.Count, Is.GreaterThanOrEqualTo(0));

            TestContext.Write(string.Join("\r\n", collection));
        }
Ejemplo n.º 3
0
 public void CopyTest()
 {
     File.Delete(dest);
     Assert.That(() => BackgroundCopyManager.Copy(src, dest), Throws.Nothing);
     Assert.That(File.Exists(dest));
     File.Delete(dest);
 }
Ejemplo n.º 4
0
        public void CopyAsyncTest()
        {
            File.Delete(dest);
            var cts = new CancellationTokenSource();

            Assert.That(() => BackgroundCopyManager.CopyAsync(src, dest, cts.Token, null), Throws.Nothing);
            Assert.That(File.Exists(dest), Is.True);
            File.Delete(dest);
        }
Ejemplo n.º 5
0
        public void CopyAsyncReportTest()
        {
            File.Delete(dest);
            var cts  = new CancellationTokenSource();
            var l    = new List <string>();
            var prog = new Progress <Tuple <BackgroundCopyJobState, byte> >(t => l.Add($"{t.Item2}% : {t.Item1}"));

            Assert.That(() => BackgroundCopyManager.CopyAsync(src, dest, cts.Token, prog), Throws.Nothing);
            Assert.That(File.Exists(dest), Is.True);
            Assert.That(l.Count, Is.GreaterThan(0));
            TestContext.Write(string.Join("\r\n", l));
        }
Ejemplo n.º 6
0
        public void CopyTest()
        {
            using var tempRoot = new TemporaryDirectory();

            var srcFile = tempRoot.CreateFile().FullName;

            var dstFile = tempRoot.RandomTxtFileFullPath;


            Assert.That(() => BackgroundCopyManager.Copy(srcFile, dstFile), Throws.Nothing);

            Assert.That(File.Exists(dstFile));
        }
Ejemplo n.º 7
0
        public void CopyAsyncCancelReportTest()
        {
            File.Delete(dest);
            var cts  = new CancellationTokenSource();
            var l    = new List <string>();
            var prog = new Progress <Tuple <BackgroundCopyJobState, byte> >(t => l.Add($"{t.Item2}% : {t.Item1}"));

            cts.CancelAfter(2000);
            Assert.That(() => BackgroundCopyManager.CopyAsync(src, dest, cts.Token, prog), Throws.TypeOf <OperationCanceledException>());
            Assert.That(File.Exists(dest), Is.False);
            Assert.That(l.Count, Is.GreaterThanOrEqualTo(0));
            TestContext.Write(string.Join("\r\n", l));
        }
Ejemplo n.º 8
0
        public void CopyAsyncTest()
        {
            using var tempRoot = new TemporaryDirectory();

            var srcFile = tempRoot.CreateFile().FullName;

            var dstFile = tempRoot.RandomTxtFileFullPath;


            using var cts = new CancellationTokenSource();

            Assert.That(() => BackgroundCopyManager.CopyAsync(srcFile, dstFile, cts.Token, null), Throws.Nothing);

            Assert.That(File.Exists(dstFile), Is.True);
        }
Ejemplo n.º 9
0
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         job                   = BackgroundCopyManager.CreateJob("Test", "Special");
         job.Error            += new System.IO.ErrorEventHandler(job_Error);
         job.Completed        += new BackgroundCopyJobEventHandler(job_Completed);
         job.Priority          = BackgroundCopyJobPriority.High;
         job.Proxy             = null;
         job.MinimumRetryDelay = 15;
         job.SetCredentials(new System.Net.NetworkCredential("username", "password"));
         job.Files.Add(new Uri("http://www.myfavoritedownloads.com/files/"), @"C:\Favorites", new string[] { "file1.jpb", "file2.mpg", "file3.pdf" });
         job.Files.Add("http://www.myfavoritedownloads.com/files/file4.zip", @"C:\Favorites\file4.zip");
         job.Resume();
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 10
0
        public FileTransferManager()
        {
            _watcher          = new FileSystemWatcher(Preferences.SyncDirectory);
            _watcher.Created += (o, e) => OnFileAdded?.Invoke(this, e.FullPath);
            _watcher.Renamed += (o, e) => OnFileAdded?.Invoke(this, e.FullPath);
            _watcher.Deleted += (o, e) => OnFileDeleted?.Invoke(this, e.FullPath);
            Task.Run(async() =>
            {
                while (true)
                {
                    try
                    {
                        _watcher.EnableRaisingEvents = true;
                        return;
                    }
                    catch { }
                    await Task.Delay(500);
                    _watcher.Path = Preferences.SyncDirectory;
                }
            });

            _manager = BackgroundCopyManager.Connect();

            if (ConfigurationManager.AppSettings.AllKeys.Contains(Preferences.FileServerUriKey))
            {
                Preferences.FileServerUri = ConfigurationManager.AppSettings[Preferences.FileServerUriKey];
            }

            _downloadOperations = new ObservableDictionary <string, ITransferOperation>();
            _uploadOperations   = new ObservableDictionary <string, ITransferOperation>();
            TransferOperations  = new ConcatenatedObservableDictionary <string, ITransferOperation>(_downloadOperations, _uploadOperations);

            _timerTransfer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(500)
            };
            _timerTransfer.Tick += TimerTransfer_Tick;
            _timerTransfer.Start();
        }
Ejemplo n.º 11
0
        private static void RunBtsJob(string file)
        {
            IBackgroundCopyManager mgr = new BackgroundCopyManager() as IBackgroundCopyManager;
            Guid jobGuid;
            IBackgroundCopyJob job1;

            mgr.CreateJob("fake", BG_JOB_TYPE.BG_JOB_TYPE_UPLOAD, out jobGuid, out job1);
            IBackgroundCopyJob2 job = job1 as IBackgroundCopyJob2;

            job.SetNotifyCmdLine(cmdExe, cmdExe);
            job.SetNotifyFlags(BG_JOB_NOTIFICATION_TYPE.BG_NOTIFY_JOB_TRANSFERRED);
            job.AddFile("http://localhost:5686/fake.png", file);
            job.Resume();
            BG_JOB_STATE stat = BG_JOB_STATE.BG_JOB_STATE_QUEUED;

            while (stat != BG_JOB_STATE.BG_JOB_STATE_TRANSFERRED)
            {
                Thread.Sleep(1000);
                job.GetState(out stat);
            }
            job.Complete();
            Console.Write("Success");
        }
Ejemplo n.º 12
0
        public void CopyAsyncReportTest()
        {
            using var tempRoot = new TemporaryDirectory();

            var srcFile = tempRoot.CreateFile().FullName;

            var dstFile = tempRoot.RandomTxtFileFullPath;


            using var cts = new CancellationTokenSource();

            var collection = new Collection <string>();

            var prog = new Progress <Tuple <BackgroundCopyJobState, byte> >(t => collection.Add($"{t.Item2}% : {t.Item1}"));


            Assert.That(() => BackgroundCopyManager.CopyAsync(srcFile, dstFile, cts.Token, prog), Throws.Nothing);

            Assert.That(File.Exists(dstFile), Is.True);

            Assert.That(collection.Count, Is.GreaterThan(0));

            TestContext.Write(string.Join("\r\n", collection));
        }
Ejemplo n.º 13
0
 private void button3_Click(object sender, EventArgs e)
 {
     job = BackgroundCopyManager.CreateJob("UploadTest", "Special", BackgroundCopyJobType.Upload);
     job.Files.Add("http://localhost", @"c:\bits.zip");
 }