Exemplo n.º 1
0
        private IEnumerable <ProfileTypeInfo> RefreshProfileTypesImpl()
        {
            var gsts         = Datafiles.Where(x => x.Document.Kind == XmlDocumentKind.Gamesystem);
            var datafiles    = gsts.Concat(SelectedDatafiles).Distinct();
            var profileTypes = datafiles
                               .SelectMany(file =>
            {
                var root = (CatalogueBaseNode)file.Document.GetRoot();
                return(root.ProfileTypes.Select(x => new ProfileTypeInfo(x)));
            })
                               .ToList();

            return(profileTypes);
        }
Exemplo n.º 2
0
        public void CanDeserializeSampleResponse()
        {
            using (var server = CreateServer("/" + TravelMagicPath.DepartureSearch, async httpCtx =>
            {
                httpCtx.Response.ContentType = HttpWellKnownMediaType.ApplicationXml;
                using (var dataStream = Datafiles.DepartureSearch().CreateReadStream())
                    await dataStream.CopyToAsync(httpCtx.Response.Body).ConfigureAwait(false);
            }))
            {
                var client = new TravelMagicClient(new Uri("http://example.com/"), server.CreateClient());

                var result = client
                             .GetDepartureSearch(new DepartureSearchRequest("Test"))
                             .ConfigureAwait(false).GetAwaiter().GetResult();

                Assert.NotNull(result);
            }
        }
Exemplo n.º 3
0
        private XmlWorkspace(ProjectConfigurationInfo info)
        {
            var files = info.Configuration.SourceDirectories
                        .SelectMany(x => info.GetDirectoryInfoFor(x).EnumerateFiles());

            Datafiles = files.Select(XmlFileExtensions.GetDatafileInfo).ToImmutableArray();
            Documents =
                Datafiles
                .Select(file => new XmlDocument(file.Filepath.GetXmlDocumentKind(), file, this))
                .ToImmutableArray();
            DocumentsByKind =
                Documents
                .GroupBy(doc => doc.Kind)
                .ToImmutableDictionary(
                    group => group.Key,
                    group => group.ToImmutableArray());
            Info = info;
        }
Exemplo n.º 4
0
        public MainWindowViewModel()
        {
            SelectFolder = ReactiveCommand.CreateFromTask(async ct =>
            {
                var dialog = new OpenFolderDialog
                {
                    Title = "Select folder with datafiles"
                };
                var path = await dialog.ShowAsync();
                return(path);
            });
            SelectFolder.Subscribe(path => FolderPath = path);

            LoadFolder = ReactiveCommand.Create(LoadFolderImpl);
            LoadFolder.ThrownExceptions
            .Subscribe(exception =>
            {
                if (exception is DirectoryNotFoundException dirNotFound)
                {
                    FolderPathError = dirNotFound.Message;
                }
                Log.Warning(exception, "Error when loading folder");
            });
            LoadFolder.Subscribe(results =>
            {
                Datafiles.Clear();
                Datafiles.AddRange(results);
                FolderPathError = null;
            });

            this.WhenAnyValue(x => x.FolderPathError)
            .DistinctUntilChanged()
            .Subscribe(x => ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(nameof(FolderPath))));

            this.WhenAnyValue(x => x.FolderPath)
            .Throttle(TimeSpan.FromSeconds(0.5), RxApp.MainThreadScheduler)
            .Select(x => Unit.Default)
            .InvokeCommand(this, x => x.LoadFolder);

            DatafilesToLoad = new Subject <DatafileInfo>();

            Datafiles.ActOnEveryObject(item => DatafilesToLoad.OnNext(item), item => { });

            this.WhenAnyObservable(x => x.DatafilesToLoad)
            .ObserveOn(RxApp.TaskpoolScheduler)
            .Select(info => (info, LoadFileRoot(info)))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(tuple =>
            {
                var(info, node) = tuple;
                info.Name       = $"{node.Name} (v{node.Revision.ToString()})";
                info.Root       = node;
            });

            RefreshRuleSelections = ReactiveCommand.Create(RefreshRuleSelectionsImpl);
            RefreshRuleSelections
            .Subscribe(results =>
            {
                Rules.Clear();
                Rules.AddRange(results);
            });

            MarkAllRules = ReactiveCommand.Create(MarkAllRulesImpl, Rules.IsEmptyChanged.Select(x => !x));

            Rules.ItemChanged
            .WithLatestFrom(MarkAllRules.IsExecuting, (changed, isExecuting) => isExecuting ? null : changed)
            .Where(x => x != null)
            .Subscribe(e =>
            {
                if (!e.Sender.IsSelected)
                {
                    AllRulesSelected = false;
                }
            });

            SelectedDatafiles.Changed
            .Select(x => Unit.Default)
            .InvokeCommand(RefreshRuleSelections);

            RefreshProfileTypes = ReactiveCommand.Create(RefreshProfileTypesImpl);
            RefreshProfileTypes
            .Subscribe(results =>
            {
                ProfileTypes.Clear();
                ProfileTypes.AddRange(results);
                SelectedProfileType = ProfileTypes.FirstOrDefault();
            });

            SelectedDatafiles.Changed
            .Select(x => Unit.Default)
            .InvokeCommand(RefreshProfileTypes);

            RefreshCharacteristicTypeInfos = ReactiveCommand.Create(RefreshCharacteristicTypeInfosImpl);
            RefreshCharacteristicTypeInfos
            .Subscribe(results =>
            {
                CharacteristicInfos.Clear();
                CharacteristicInfos.AddRange(results);
                SelectedCharacteristicType = CharacteristicInfos.FirstOrDefault();
            });

            this.WhenAnyValue(x => x.SelectedProfileType)
            .Select(x => Unit.Default)
            .InvokeCommand(RefreshCharacteristicTypeInfos);

            DatafileConversionStatuses = SelectedDatafiles
                                         .CreateDerivedCollection(
                x => new DatafileConversionStatus(x),
                filter: null,
                orderer: (left, right) => left.Info.Name.CompareTo(right.Info.Name));

            var canConvert =
                this.WhenAnyValue(
                    x => x.FolderPath,
                    x => x.FolderPathError,
                    x => x.SelectedDatafiles.IsEmpty,
                    x => x.SelectedProfileType,
                    x => x.SelectedCharacteristicType,
                    x => x.Rules.IsEmpty,
                    (path, error, emptyFiles, profileType, chType, emptyRules)
                    => !string.IsNullOrWhiteSpace(path) && error == null && !emptyFiles && profileType != null && chType != null && !emptyRules);

            Convert = ReactiveCommand.Create(ConvertImpl, canConvert);
            Convert.InvokeCommand(LoadFolder);
        }