public ProjectMutator(MutatingEngine <MutatingContext <ProjectFile> > engine, ProjectFileWorkspace workspace)
        {
            _engine    = engine;
            _workspace = workspace;

            NewProject = engine.EventSource(mc => new AddProject(mc.GetChange <NewProjectChange>().Project),
                                            context => context.Change is NewProjectChange);
            RemovedProject = engine.EventSource(mc => new RemoveProject(mc.GetChange <RemoveProjectChange>().Project),
                                                context => context.Change is RemoveProjectChange);
            NewLanguage = engine.EventSource(mc => mc.GetChange <LanguageChange>().ToEventData(),
                                             context => context.Change is LanguageChange);
            NewImport = engine.EventSource(mc => mc.GetChange <AddImportChange>().ToEventData(),
                                           context => context.Change is AddImportChange);
            RemoveImport = engine.EventSource(mc => mc.GetChange <RemoveImportChange>().ToData(),
                                              context => context.Change is RemoveImportChange);

            NewLanguage.RespondOn(null, newLang =>
            {
                if (workspace.ProjectFile.GlobalLanguages.Contains(newLang.ActiveLanguage))
                {
                    return;
                }

                if (!Projects.All(p => p.ActiveLanguages.Contains(newLang.ActiveLanguage)))
                {
                    return;
                }

                _engine.Mutate(nameof(AddLanguage) + "Global-Single",
                               obs => obs.Select(context => context.Update(new GlobalLanguageChange(newLang.ActiveLanguage),
                                                                           context.Data with
                {
                    GlobalLanguages = context.Data.GlobalLanguages.Add(newLang.ActiveLanguage)
                })));
            });
Ejemplo n.º 2
0
        private void HandleEasyIdProject(Project project)
        {
            if (!string.IsNullOrWhiteSpace(project.ProjectId))
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(project.ProjectShort))
            {
                project.ProjectId = Guid.NewGuid().ToString();
                return;
            }

            var easyId = Util.IdGenerator.AsPrimaryKey(project.ProjectShort);

            if (string.IsNullOrWhiteSpace(easyId))
            {
                return;
            }

            if (Projects.All(n => n.ProjectId != easyId))
            {
                project.ProjectId = easyId;
            }
            else
            {
                project.ProjectId = Guid.NewGuid().ToString();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the list of projects contained in this profile from the related <see cref="PackageProfile"/>.
        /// </summary>
        /// <remarks>The actions undertaken by this method are not cancellable via the action stack.</remarks>
        internal bool UpdateProjectList()
        {
            bool changed = false;

            foreach (var projectReference in profile.ProjectReferences.Where(x => Projects.All(y => y.Id != x.Id)))
            {
                var viewModel = new ProjectViewModel(projectReference, this);
                Projects.Add(viewModel);
                changed = true;
            }

            // Remove projects deleted
            var projectsToRemove = Projects.Where(projectViewModel => profile.ProjectReferences.All(projectReference => projectReference.Id != projectViewModel.Id)).ToList();

            foreach (var projectToRemove  in projectsToRemove)
            {
                projectToRemove.Delete();
                changed = true;
            }
            return(changed);
        }
Ejemplo n.º 4
0
        public ProjectMutator(MutatingEngine <MutatingContext <ProjectFile> > engine, ProjectFileWorkspace workspace)
        {
            _engine    = engine;
            _workspace = workspace;

            NewProject = engine.EventSource(
                c => c.Select(mc => new AddProject(mc.GetChange <NewProjectChange>().Project)),
                c => from context in c
                from change in context.Change
                select change is NewProjectChange);

            RemovedProject = engine.EventSource(c => c.Select(mc => new RemoveProject(mc.GetChange <RemoveProjectChange>().Project)),
                                                c => from context in c
                                                from change in context.Change
                                                select change is RemoveProjectChange);

            NewLanguage = engine.EventSource(c => c.Select(mc => mc.GetChange <LanguageChange>().ToEventData()),
                                             c => from context in c
                                             from change in context.Change
                                             select change is LanguageChange);

            NewImport = engine.EventSource(c => c.Select(mc => mc.GetChange <AddImportChange>().ToEventData()),
                                           c => from context in c
                                           from change in context.Change
                                           select change is AddImportChange);

            RemoveImport = engine.EventSource(c => c.Select(mc => mc.GetChange <RemoveImportChange>().ToData()),
                                              c => from context in c
                                              from change in context.Change
                                              select change is RemoveImportChange);

            NewLanguage.RespondOn(null, mayNewLang =>
                                  Do(from newlang in mayNewLang
                                     where !workspace.ProjectFile.GlobalLanguages.Contains(newlang.ActiveLanguage)
                                     where Projects.All(p => p.ActiveLanguages.Contains(newlang.ActiveLanguage))
                                     select Action(() => _engine.Mutate(nameof(AddLanguage) + "Global-Single",
                                                                        c => from context in c
                                                                        select context.WithChange(new GlobalLanguageChange(newlang.ActiveLanguage))))));
        }
Ejemplo n.º 5
0
        private void _parseSolutionFile()
        {
            _solutionDirectoryInfo = new DirectoryInfo(Path.GetDirectoryName(SolutionFilename));
            SolutionDirectoryname  = _solutionDirectoryInfo.FullName;

            Elements.Solution solutionElement       = Elements.Solution.Parse(SolutionFilename);
            IEnumerable <Elements.Project> projects = solutionElement.Elements
                                                      .OfType <Elements.Project>()
                                                      .Where(p => p.TypeID == Elements.Project.ProjectTypeID);

            IEnumerable <Elements.Project> folders = solutionElement.Elements
                                                     .OfType <Elements.Project>()
                                                     .Where(p => p.TypeID == Elements.Project.FolderTypeID);

            foreach (Elements.Project projectElement in projects)
            {
                string filename = Path.Combine(SolutionDirectoryname, projectElement.Location);
                if (File.Exists(filename))
                {
                    Project project = Project.Parse(this, filename);
                    if (Projects.Any(p => p.ProjectGuid == project.ProjectGuid))
                    {
                        throw new InvalidOperationException(string.Format("Duplicate project found: {0} ({1})", project.ProjectGuid, project.ProjectName));
                    }
                    Projects.Add(project);
                }
                else
                {
                    Project p = new Project(this, projectElement);
                    Projects.Add(p);
                }
            }

            foreach (Elements.Project folder in folders)
            {
                Folders.Add(new Folder(folder.DisplayName, folder.ProjectGuid));
            }

            DistinctReferences = new ObservableCollection <Reference>(Projects.Where(p => p.IsLoaded).SelectMany(p => p.References).OrderBy(r => r.Name)); //.Where(p => p.HasHintPath);

            foreach (Project project in Projects.Where(p => p.IsLoaded))
            {
                foreach (ProjectReference projectReference in project.ProjectReferences)
                {
                    if (Projects.All(p => p.ProjectGuid != projectReference.ProjectGuid))
                    {
                        var byPath = Projects.FirstOrDefault(p => string.Compare(p.ProjectFilename, projectReference.RootedPath, StringComparison.InvariantCultureIgnoreCase) == 0);
                        if (byPath == null)
                        {
                            projectReference.IsNotInSolution    = true;
                            project.HasMissingProjectReferences = true;
                        }
                        else
                        {
                            projectReference.HasIncorrectProjectGuid  = true;
                            project.HasIncorrectProjectReferenceGuids = true;
                        }
                    }
                }
            }

            IsDirty = false;
        }