Example #1
0
 public override object ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
 {
     if (!(existingValue is PathPickerVM vm))
     {
         vm = new PathPickerVM();
     }
     if (!(reader.Value is string str))
     {
         throw new ArgumentException();
     }
     vm.TargetPath = str;
     return(vm);
 }
        public ExistingProjectInitVM()
        {
            SolutionPath.PathType         = PathPickerVM.PathTypeOptions.File;
            SolutionPath.ExistCheckOption = PathPickerVM.CheckOptions.On;
            SolutionPath.Filters.Add(new CommonFileDialogFilter("Solution", ".sln"));

            AvailableProjects = this.WhenAnyValue(x => x.SolutionPath.TargetPath)
                                .ObserveOn(RxApp.TaskpoolScheduler)
                                .Select(x => Utility.AvailableProjectSubpaths(x))
                                .Select(x => x.AsObservableChangeSet())
                                .Switch()
                                .ObserveOnGui()
                                .ToObservableCollection(this);

            InitializationCall = SelectedProjects.Connect()
                                 .Transform(subPath =>
            {
                if (subPath == null || this.SolutionPath.TargetPath == null)
                {
                    return(string.Empty);
                }
                try
                {
                    return(Path.Combine(Path.GetDirectoryName(SolutionPath.TargetPath) !, subPath));
                }
                catch (Exception)
                {
                    return(string.Empty);
                }
            })
                                 .Transform(path =>
            {
                var pathPicker = new PathPickerVM
                {
                    PathType         = PathPickerVM.PathTypeOptions.File,
                    ExistCheckOption = PathPickerVM.CheckOptions.On,
                    TargetPath       = path
                };
                pathPicker.Filters.Add(new CommonFileDialogFilter("Project", ".csproj"));
                return(pathPicker);
            })
                                 .DisposeMany()
                                 .QueryWhenChanged(q =>
            {
                if (q.Count == 0)
                {
                    return(GetResponse <InitializerCall> .Fail("No projects selected"));
                }
                var err = q
                          .Select(p => p.ErrorState)
                          .Where(e => e.Failed)
                          .And(ErrorResponse.Success)
                          .First();
                if (err.Failed)
                {
                    return(err.BubbleFailure <InitializerCall>());
                }
                return(GetResponse <InitializerCall> .Succeed(async(profile) =>
                {
                    return q.Select(i =>
                    {
                        var patcher = new SolutionPatcherVM(profile);
                        patcher.SolutionPath.TargetPath = SolutionPath.TargetPath;
                        patcher.ProjectSubpath = i.TargetPath.TrimStart($"{Path.GetDirectoryName(SolutionPath.TargetPath)}\\" !);
                        return patcher;
                    });
                }));
            });
        }