예제 #1
0
        public void WatchFolder_Typical(
            DirectoryPath existingDir,
            FilePath existingFile,
            [Frozen] MockFileSystemWatcher mockFileWatcher,
            [Frozen] MockFileSystem fs)
        {
            FilePath fileB = Path.Combine(existingDir.Path, "FileB");

            fs.File.WriteAllText(existingFile, string.Empty);
            var live = ObservableExt.WatchFolderContents(existingDir.Path, fileSystem: fs)
                       .RemoveKey();
            var list = live.AsObservableList();

            list.Count.Should().Be(1);
            list.Items.ToExtendedList()[0].Should().Be(existingFile);
            fs.File.WriteAllText(fileB, string.Empty);
            mockFileWatcher.MarkCreated(fileB);
            list = live.AsObservableList();
            list.Count.Should().Be(2);
            list.Items.ToExtendedList()[0].Should().Be(existingFile);
            list.Items.ToExtendedList()[1].Should().Be(fileB);
            fs.File.Delete(existingFile);
            mockFileWatcher.MarkDeleted(existingFile);
            list = live.AsObservableList();
            list.Count.Should().Be(1);
            list.Items.ToExtendedList()[0].Should().Be(fileB);
        }
예제 #2
0
        public static IObservable <IChangeSet <LoadOrderListing> > GetLiveLoadOrder(
            FilePath cccFilePath,
            DirectoryPath dataFolderPath,
            out IObservable <ErrorResponse> state,
            bool orderListings = true)
        {
            var raw = ObservableExt.WatchFile(cccFilePath.Path)
                      .StartWith(Unit.Default)
                      .Select(_ =>
            {
                try
                {
                    return(GetResponse <IObservable <IChangeSet <ModKey> > > .Succeed(
                               File.ReadAllLines(cccFilePath.Path)
                               .Select(x => ModKey.FromNameAndExtension(x))
                               .AsObservableChangeSet()));
                }
                catch (Exception ex)
                {
                    return(GetResponse <IObservable <IChangeSet <ModKey> > > .Fail(ex));
                }
            })
                      .Replay(1)
                      .RefCount();

            state = raw
                    .Select(r => (ErrorResponse)r);
            var ret = ObservableListEx.And(
                raw
                .Select(r =>
            {
                return(r.Value ?? Observable.Empty <IChangeSet <ModKey> >());
            })
                .Switch(),
                ObservableExt.WatchFolderContents(dataFolderPath.Path)
                .Transform(x =>
            {
                if (ModKey.TryFromNameAndExtension(Path.GetFileName(x), out var modKey))
                {
                    return(TryGet <ModKey> .Succeed(modKey));
                }
                return(TryGet <ModKey> .Failure);
            })
                .Filter(x => x.Succeeded)
                .Transform(x => x.Value)
                .RemoveKey())
                      .Transform(x => new LoadOrderListing(x, true));

            if (orderListings)
            {
                ret = ret.OrderListings();
            }
            return(ret);
        }
예제 #3
0
        public void WatchFolder_ATypicalSeparator(
            DirectoryPath someDirectory,
            [Frozen] FilePath file,
            [Frozen] MockFileSystemWatcher mockFileWatcher,
            [Frozen] MockFileSystem fs)
        {
            fs.Directory.CreateDirectory(someDirectory);
            var live = ObservableExt.WatchFolderContents(someDirectory.Path.Replace('\\', '/'), fileSystem: fs)
                       .RemoveKey();
            var list = live.AsObservableList();

            list.Count.Should().Be(0);
            fs.File.WriteAllText(file, string.Empty);
            mockFileWatcher.MarkCreated(file);
            list.Count.Should().Be(1);
            list.Items.ToExtendedList()[0].Should().Be(file);
        }
        public IObservable <IChangeSet <ModKey, ModKey> > Get()
        {
            if (!_fileSystem.Directory.Exists(DataDirectory.Path))
            {
                return(Observable.Empty <IChangeSet <ModKey, ModKey> >());
            }
            return(ObservableExt
                   .WatchFolderContents(DataDirectory.Path, fileSystem: _fileSystem)
                   .Transform(x =>
            {
                if (ModKey.TryFromNameAndExtension(Path.GetFileName(x), out var modKey))
                {
                    return TryGet <ModKey> .Succeed(modKey);
                }

                return TryGet <ModKey> .Failure;
            })
                   .Filter(x => x.Succeeded)
                   .Transform(x => x.Value)
                   .ChangeKey(x => x)
                   .Catch <IChangeSet <ModKey, ModKey>, DirectoryNotFoundException>(_ => Observable.Empty <IChangeSet <ModKey, ModKey> >()));
        }
예제 #5
0
        public void WatchFolder_OnlySubfolder(
            [Frozen] DirectoryPath existingDir,
            [Frozen] MockFileSystemWatcher mockFileWatcher,
            [Frozen] MockFileSystem fs)
        {
            FilePath fileA = Path.Combine(existingDir.Path, "SomeFolder", "FileA");
            FilePath fileB = Path.Combine(existingDir.Path, "FileB");

            fs.Directory.CreateDirectory(Path.GetDirectoryName(fileA) !);
            fs.File.WriteAllText(fileA, string.Empty);
            var live = ObservableExt.WatchFolderContents(Path.Combine(existingDir.Path, "SomeFolder"), fileSystem: fs)
                       .RemoveKey();
            var list = live.AsObservableList();

            list.Count.Should().Be(1);
            list.Items.ToExtendedList()[0].Should().Be(fileA);
            fs.File.WriteAllText(fileB, string.Empty);
            mockFileWatcher.MarkCreated(fileB);
            list = live.AsObservableList();
            list.Count.Should().Be(1);
            list.Items.ToExtendedList()[0].Should().Be(fileA);
        }