Exemplo n.º 1
0
        private static Solution RemoveNonExistingDocuments(Project project)
        {
            foreach (var documentId in project.DocumentIds.ToArray())
            {
                var document = project.GetDocument(documentId);
                if (!File.Exists(document.FilePath))
                {
                    Log.Message("Document doesn't exist on disk: " + document.FilePath);
                    project = project.RemoveDocument(documentId);
                }
            }

            return project.Solution;
        }
Exemplo n.º 2
0
        /// <summary>
        /// If there are two linked files both outside the project cone, and they have same names,
        /// they will logically appear as the same file in the project root. To disambiguate, we
        /// remove both files from the project's root and re-add them each into a folder chain that
        /// is formed from the full path of each document.
        /// </summary>
        private static Solution DisambiguateSameNameLinkedFiles(Project project)
        {
            var nameMap = project.Documents.Where(d => !d.Folders.Any()).ToLookup(d => d.Name);
            foreach (var conflictedItemGroup in nameMap.Where(g => g.Count() > 1))
            {
                foreach (var conflictedDocument in conflictedItemGroup)
                {
                    project = project.RemoveDocument(conflictedDocument.Id);
                    string filePath = conflictedDocument.FilePath;
                    DocumentId newId = DocumentId.CreateNewId(project.Id, filePath);
                    var folders = filePath.Split('\\').Select(p => p.TrimEnd(':'));
                    project = project.Solution.AddDocument(
                        newId,
                        conflictedDocument.Name,
                        conflictedDocument.GetTextAsync().Result,
                        folders,
                        filePath).GetProject(project.Id);
                }
            }

            return project.Solution;
        }
Exemplo n.º 3
0
        private static void AddPathToProject(ref Solution solution, ref Project project, string fileName, string contents)
        {
            var document = GetExistingDocument(project, fileName);
            if (document != null)
            {
                project = project.RemoveDocument(document.Id);
                solution = project.Solution;
            }

            Console.WriteLine($"\t - Adding {fileName} to project");
            document = project.AddDocument(fileName,
                contents,
                null,
                Path.Combine(Path.GetDirectoryName(project.FilePath), fileName));
            project = document.Project;
            solution = project.Solution;
        }
        private void ApplyChanges()
        {
            foreach (var doc in Tasks)
            {
                _project = _generatorWorkspace.Solution?.Projects.FirstOrDefault(x => x.Name == doc.Item4);

                var oldDocument = _project?.Documents.FirstOrDefault(x => x.Name == doc.Item1);

                if (oldDocument != null)
                {
                    if (oldDocument.GetTextAsync().Result.ToString() != doc.Item2.ToString())
                    {
                        bool isEqual = oldDocument.Folders.SequenceEqual(doc.Item3);

                        if (isEqual)
                        {
                            _project = _project.RemoveDocument(oldDocument.Id);
                        }

                        var newDocument = _project?.AddDocument(doc.Item1, doc.Item2, doc.Item3);
                        _project = newDocument?.Project;
                        _generatorWorkspace.Solution = _project?.Solution;
                    }
                }
                else
                {
                    var newDocument = _project?.AddDocument(doc.Item1, doc.Item2, doc.Item3);
                    _project = newDocument?.Project;
                    _generatorWorkspace.Solution = _project?.Solution;
                }
            }
        }
Exemplo n.º 5
0
        private void ApplyChanges()
        {
            var dirCompletedEventArgs = new DirectoryInfo(_project.FilePath.Remove(_project.FilePath.LastIndexOf("\\", StringComparison.Ordinal)) + "\\ServiceReferences\\CompletedEventArgs");

            foreach (FileInfo file in dirCompletedEventArgs.GetFiles())
            {
                var redundantDocument = _project?.Documents.FirstOrDefault(x => x.Name == file.Name);

                if (redundantDocument != null && _competedArgsMethods.All(x => (x.Service + "_" + x.Name + "CompletedEventArgs") != file.Name.Remove(file.Name.IndexOf(".", StringComparison.Ordinal))))
                    _project = _project?.RemoveDocument(redundantDocument.Id);

            }

            foreach (var doc in tasks)
            {
                _project = _generatorWorkspace.Solution?.Projects.FirstOrDefault(x => x.Name == doc.Item4);

                var oldDocument = _project?.Documents.FirstOrDefault(x => x.Name == doc.Item1);

                if (oldDocument != null)
                {
                    if (oldDocument.GetTextAsync().Result.ToString() != doc.Item2.ToString())
                    {
                        bool isEqual = oldDocument.Folders.SequenceEqual(doc.Item3);

                        if (isEqual)
                        {
                            _project = _project.RemoveDocument(oldDocument.Id);
                        }

                        var newDocument = _project?.AddDocument(doc.Item1, doc.Item2, doc.Item3);
                        _project = newDocument?.Project;
                        _generatorWorkspace.Solution = _project?.Solution;
                    }
                }
                else
                {
                    var newDocument = _project?.AddDocument(doc.Item1, doc.Item2, doc.Item3);
                    _project = newDocument?.Project;
                    _generatorWorkspace.Solution = _project?.Solution;
                }
            }

            _generatorWorkspace.Solution = _project.Solution;
            _generatorWorkspace.ApplyChanges();
        }