Пример #1
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            taskInstance.Canceled += OnCanceled;
            _deferral              = taskInstance.GetDeferral();

            try
            {
                var fileSystem = new FileSystemAdapter(true, null);
                var webDav     = new WebDavAdapter(true, Configuration.ServerUrl, Configuration.Credential, fileSystem);
                fileSystem.LinkedAdapter = webDav;
                _worker = new BackgroundSyncProcess(fileSystem, webDav, true);
                await _worker.Run();
            }
            catch (Exception e)
            {
                await LogHelper.Write($"BackgroundTask Exception: {e.Message}" + Environment.NewLine +
                                      $"{e.StackTrace}" + Environment.NewLine +
                                      $"Status:{ExecutionContext.Instance.Status.ToString()}" + Environment.NewLine +
                                      $"File: {ExecutionContext.Instance.CurrentFileNumber}" + Environment.NewLine +
                                      $"of {ExecutionContext.Instance.TotalFileCount}");
            }
            finally
            {
                await LogHelper.Write("BackgroundTask finished");

                _deferral.Complete();
            }
        }
        private void _Initialize()
        {
            var fileSystem = new FileSystemAdapter(false, null);
            var webDav     = new WebDavAdapter(false, Configuration.ServerUrl, Configuration.Credential, fileSystem);

            fileSystem.LinkedAdapter = webDav;
            _worker = new BackgroundSyncProcess(fileSystem, webDav, false);
        }
Пример #3
0
        public async Task Download()
        {
            //arrange
            var options = new DbContextOptionsBuilder <StorageContext>()
                          .UseInMemoryDatabase(databaseName: "SavesFile")
                          .Options;

            var context           = new StorageContext(options);
            var dummyBinaryObject = new BinaryObject
            {
                Id                  = new Guid("e7d99328-b5f0-4356-80df-2dd61a82505c"),
                Name                = "Test Binary Object",
                OrganizationId      = new Guid("04a348ec-2968-4406-bf4a-4a5fda73df00"),
                ContentType         = "Test Content Type",
                CorrelationEntityId = new Guid("04a348ec-2968-4406-bf4a-4a5fda73df00"),
                CorrelationEntity   = "Test Correlation Entity",
                StoragePath         = @"BinaryObjects\04a348ec-2968-4406-bf4a-4a5fda73df00\TestAPI\e7d99328-b5f0-4356-80df-2dd61a82505c",
                StorageProvider     = "Test Provider",
                SizeInBytes         = 28,
                HashCode            = 55555.ToString()
            };

            Seed(context, dummyBinaryObject);

            var logger = Mock.Of <ILogger <BinaryObject> >();
            var httpContextAccessor = new Mock <IHttpContextAccessor>();

            httpContextAccessor.Setup(req => req.HttpContext.User.Identity.Name).Returns(It.IsAny <string>());
            var personEmailRepository        = Mock.Of <IPersonEmailRepository>();
            var organizationMemberRepository = Mock.Of <IOrganizationMemberRepository>();
            var usersRepository     = Mock.Of <IAspNetUsersRepository>();
            var organizationManager = Mock.Of <IOrganizationManager>();
            var repo = new BinaryObjectRepository(context, logger, httpContextAccessor.Object);

            var blobStorageAdapter = new BlobStorageAdapter(repo);
            var directoryManager   = new DirectoryManager();
            var fileSystemAdapter  = new FileSystemAdapter(directoryManager);
            var mockOptions        = Mock.Of <IOptions <ConfigurationValue> >();
            var configuration      = new Mock <IConfiguration>();

            configuration.Setup(req => req.GetSection(ConfigurationValue.Values)).Returns(It.IsAny <IConfigurationSection>());
            var manager = new BinaryObjectManager(blobStorageAdapter, fileSystemAdapter, httpContextAccessor.Object, organizationMemberRepository, organizationManager, configuration.Object, usersRepository);

            string validBinaryObjectId   = dummyBinaryObject.Id.ToString();
            string invalidBinaryObjectId = "9999bbf9-9327-48f7-a5e3-36cdfe4eb6a6";

            //act
            var validFile   = manager.Download(validBinaryObjectId);
            var invalidFile = manager.Download(invalidBinaryObjectId);

            //assert
            var storagePath = validFile.Result.StoragePath;

            Assert.True(validFile.Result.StoragePath.Equals("BinaryObjects\\04a348ec-2968-4406-bf4a-4a5fda73df00\\TestAPI\\e7d99328-b5f0-4356-80df-2dd61a82505c"));
            Assert.Null(invalidFile.Result.StoragePath);
        }
Пример #4
0
        public void DirectoryExists_GivenFolderDoesNotExist_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            var fileSystemAdapter = new FileSystemAdapter();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var folderExists = fileSystemAdapter.DirectoryExists(Guid.NewGuid().ToString());

            //---------------Test Result -----------------------
            Assert.IsFalse(folderExists);
        }
Пример #5
0
        public void DirectoryExists_GivenFolderExists_ShouldReturnTrue()
        {
            using (var sandboxPath = new SandboxPath())
            {
                //---------------Set up test pack-------------------
                var fileSystemAdapter = new FileSystemAdapter();
                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------
                var folderExists = fileSystemAdapter.DirectoryExists(sandboxPath.FullPath);
                //---------------Test Result -----------------------
                Assert.IsTrue(folderExists);
            }
        }
Пример #6
0
        public void GetDirectoryName_ShouldReturnName()
        {
            using (var sandboxPath = new SandboxPath())
            {
                //---------------Set up test pack-------------------
                var fileSystemAdapter = new FileSystemAdapter();
                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------
                var folderName = fileSystemAdapter.GetDirectoryName(sandboxPath.FullPath);
                //---------------Test Result -----------------------
                Assert.IsTrue(folderName.EndsWith("Temp"));
            }
        }
Пример #7
0
        public void ReadAllText_ShouldReturnAllTextInFile()
        {
            using (var sandboxPath = new SandboxPath())
            {
                //---------------Set up test pack-------------------
                var filePath          = CreateDefaultConfigFile(sandboxPath);
                var fileSystemAdapter = new FileSystemAdapter();
                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------
                var fileContents = fileSystemAdapter.ReadAllText(filePath);
                //---------------Test Result -----------------------
                Assert.AreEqual("Line 1\\r\\nLine2", fileContents);
            }
        }
Пример #8
0
        public void FileExists_GivenFileDoesNotExist_ShouldReturnFalse()
        {
            using (var sandboxPath = new SandboxPath())
            {
                //---------------Set up test pack-------------------
                var filePath          = CreateDefaultConfigFile(sandboxPath);
                var fileSystemAdapter = new FileSystemAdapter();
                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------
                var fileExists = fileSystemAdapter.FileExists(Guid.NewGuid().ToString());
                //---------------Test Result -----------------------
                Assert.IsFalse(fileExists);
            }
        }
Пример #9
0
        public void Combine_ShouldReturnCombinedPath()
        {
            using (var sandboxPath = new SandboxPath())
            {
                //---------------Set up test pack-------------------
                CreateDefaultConfigFile(sandboxPath);
                var fileSystemAdapter = new FileSystemAdapter();
                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------
                var fullPath = fileSystemAdapter.Combine("location", "mypath");
                //---------------Test Result -----------------------
                Assert.AreEqual("location\\mypath", fullPath);
            }
        }
Пример #10
0
        public void CreateDirectory_ShouldCreateDirectory()
        {
            using (var sandboxPath = new SandboxPath())
            {
                //---------------Set up test pack-------------------
                var fileSystemAdapter = new FileSystemAdapter();
                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------
                var newDirectory = Path.Combine(sandboxPath.FullPath, Guid.NewGuid().ToString());
                fileSystemAdapter.CreateDirectory(newDirectory);
                //---------------Test Result -----------------------
                Assert.IsTrue(fileSystemAdapter.DirectoryExists(newDirectory));
            }
        }
Пример #11
0
        public void AppendAllLines_ShouldWriteToFile()
        {
            using (var sandboxPath = new SandboxPath())
            {
                //---------------Set up test pack-------------------
                const string expected          = "This is text";
                var          fileSystemAdapter = new FileSystemAdapter();
                //---------------Assert Precondition----------------

                //---------------Execute Test ----------------------
                var newFile = Path.Combine(sandboxPath.FullPath, Guid.NewGuid().ToString());
                fileSystemAdapter.AppendAllLines(newFile, new [] { expected });
                //---------------Test Result -----------------------
                var actual = fileSystemAdapter.ReadAllText(newFile).Trim();
                Assert.AreEqual(expected, actual);
            }
        }
Пример #12
0
        private static IFixture CreateFixture()
        {
            var fixture = new Fixture();

            var fs    = new MockFileSystem();
            var libfs = new FileSystemAdapter(fs);

            fixture.Inject <MyAccounts.Business.IO.IFileSystem>(libfs);
            fixture.Inject <IMockFileDataAccessor>(fs);

            var mock = new Mock <IWorkingCopy>();

            mock.Setup(w => w.Fs).Returns(libfs);
            var settingsPath = fixture.Create <string>();

            mock.Setup(w => w.SettingsPath).Returns(settingsPath);
            fixture.Inject(mock.Object);

            return(fixture);
        }
 public InstantUploadProcess(FileSystemAdapter fileSystemAdapter, AbstractAdapter targetEntityAdapter, bool isBackgroundTask) : base(fileSystemAdapter, targetEntityAdapter, isBackgroundTask)
 {
     _adapter = fileSystemAdapter;
 }
Пример #14
0
        public async Task Upload()
        {
            //arrange
            var options = new DbContextOptionsBuilder <StorageContext>()
                          .UseInMemoryDatabase(databaseName: "SavesFile")
                          .Options;

            var context           = new StorageContext(options);
            var dummyBinaryObject = new BinaryObject
            {
                Id                  = new Guid("EC84D245-0E7C-4CA7-AFA6-DB177BCBB2EE"),
                Name                = "Test Binary Object",
                OrganizationId      = new Guid("04a348ec-2968-4406-bf4a-4a5fda73df00"),
                ContentType         = "Test Content Type",
                CorrelationEntityId = new Guid("04a348ec-2968-4406-bf4a-4a5fda73df00"),
                CorrelationEntity   = "Test Correlation Entity",
                StoragePath         = @"BinaryObjects\04a348ec-2968-4406-bf4a-4a5fda73df00\TestAPI\bb9a2279-b9b3-47ea-92d5-4c2766a6c232",
                StorageProvider     = "Test Provider",
                SizeInBytes         = 28,
                HashCode            = 55555.ToString()
            };

            Seed(context, dummyBinaryObject);

            var logger = Mock.Of <ILogger <BinaryObject> >();
            var httpContextAccessor = new Mock <IHttpContextAccessor>();

            httpContextAccessor.Setup(req => req.HttpContext.User.Identity.Name).Returns(It.IsAny <string>());
            var directoryManager             = new DirectoryManager();
            var blobStorageAdapter           = Mock.Of <IBlobStorageAdapter>();
            var personEmailRepository        = Mock.Of <IPersonEmailRepository>();
            var organizationMemberRepository = Mock.Of <IOrganizationMemberRepository>();
            var usersRepository     = Mock.Of <IAspNetUsersRepository>();
            var organizationManager = Mock.Of <IOrganizationManager>();
            var fileSystemAdapter   = new FileSystemAdapter(directoryManager);

            var myConfiguration = new Dictionary <string, string>
            {
                { "BinaryObjects:Adapter", "FileSystemAdapter" },
                { "BinaryObjects:Path", "BinaryObjects" },
                { "BinaryObjects:StorageProvider", "FileSystem.Default" }
            };

            var configuration = new ConfigurationBuilder()
                                .AddInMemoryCollection(myConfiguration)
                                .Build();

            var manager = new BinaryObjectManager(blobStorageAdapter, fileSystemAdapter, httpContextAccessor.Object, organizationMemberRepository, organizationManager, configuration, usersRepository);

            var testFile = new Mock <IFormFile>();

            testFile.Setup(f => f.Length).Returns(1111);
            testFile.Setup(f => f.FileName).Returns("testFile");
            var nullFile = new Mock <IFormFile>();

            nullFile.Setup(f => f.Length).Returns(0);
            nullFile.Setup(f => f.FileName).Returns("nullFile");

            var organizationId = "04a348ec-2968-4406-bf4a-4a5fda73df00";
            var apiComponent   = "TestAPI";

            //act
            var validFile   = manager.Upload(testFile.Object, organizationId, apiComponent, dummyBinaryObject.Id.ToString());
            var invalidFile = manager.Upload(nullFile.Object, organizationId, apiComponent, dummyBinaryObject.Id.ToString());

            //assert
            Assert.IsType <Guid>(Guid.Parse(validFile));
            Assert.Equal("No file exists.", invalidFile);

            File.Delete(Path.Combine("BinaryObjects", organizationId, apiComponent, validFile));
        }
Пример #15
0
 public AudioPlayerViewModel()
 {
     FileAccess = new FileSystemAdapter();
     _currentPositionText = "00:00";
 }