Beispiel #1
0
        public void TestParallelUploads()
        {
            // Initialize parameters.
            string             sourceOneTag           = "TestSource1";
            ImageSource        source                 = new ImageSource(true, false, true, ImageSource.source);
            ImageSource        root                   = new ImageSource(false, false, false, ImageSource.storeRoot);
            ImageSource        sourceOne              = new ImageSource(true, false, true, sourceOneTag);
            AutoResetEvent     operationFinishedEvent = new AutoResetEvent(false);
            AutoResetEvent     operationToStartEvent  = new AutoResetEvent(false);
            DelegateParameters param                  = new DelegateParameters()
            {
                operationFinishedEvent = operationFinishedEvent, operationToStartEvent = operationToStartEvent, result = false
            };

            // Start the other thread.
            Thread thread = new Thread(FileImageStoreTest.UploadDelegate);

            thread.Start(param);

            // Initialize parameters of this thread.
            FileImageStore store         = new FileImageStore("file:.\\TestRoot");
            string         sourceOnePath = Path.Combine(sourceOneTag, ImageSource.sourceFile);

            // Wait for the other thread to start.
            operationToStartEvent.WaitOne();
            Thread.Sleep(100);
            // Start upload
            bool result = true;

            try
            {
                store.UploadContent(ImageSource.sourceFile, sourceOnePath, TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true);
            }
            catch (Exception)
            {
                result = false;
            }

            // Wait for the other upload to complete.
            operationFinishedEvent.WaitOne();
            // Ensure only one of the uploads passes.
            Verify.IsTrue(result != param.result, String.Format("Result from other thread is {0}, this thread is {1}", result, param.result));
            Verify.IsTrue(File.Exists(sourceOnePath));

            // Ensure that you can upload.
            store.UploadContent(ImageSource.sourceFile, sourceOnePath, TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true);
            Verify.IsTrue(File.Exists(sourceOnePath));
            sourceOne.Delete();
            source.Delete();
            root.Delete();
        }
Beispiel #2
0
        public void TestUploadContent()
        {
            ImageSource    root   = new ImageSource(false, false, false, ImageSource.storeRoot);
            ImageSource    source = new ImageSource(false, true, true, ImageSource.source);
            FileImageStore store  = new FileImageStore("file:.\\TestRoot");

            store.UploadContent(ImageSource.sourceFile, Path.Combine(ImageSource.source, ImageSource.sourceFile), TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true);
            store.UploadContent(ImageSource.sourceFile, Path.Combine(ImageSource.source, ImageSource.sourceFile), TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true);
            Verify.IsTrue(File.Exists(Path.Combine(ImageSource.storeRoot, ImageSource.sourceFile)));
            store.UploadContent(ImageSource.sourceDir, Path.Combine(ImageSource.source, ImageSource.sourceDir), TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true);
            Verify.IsTrue(File.Exists(Path.Combine(ImageSource.storeRoot, ImageSource.sourceDir, ImageSource.sourceFile)));
            root.Delete();
            source.Delete();
        }
Beispiel #3
0
        public static void UploadDelegate(object delegateParameters)
        {
            DelegateParameters param = (DelegateParameters)delegateParameters;
            FileImageStore     store = new FileImageStore("file:.\\TestRoot");

            param.operationToStartEvent.Set();
            Console.WriteLine("Event to upload to start");

            bool success = true;

            try
            {
                store.UploadContent(ImageSource.sourceFile, Path.Combine(ImageSource.source, ImageSource.sourceFile), TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true);
            }
            catch (Exception)
            {
                success = false;
            }
            param.result = success;
            param.operationFinishedEvent.Set();
        }