Ejemplo n.º 1
0
        public void Remove(Project project, IFile file)
        {
            var document = new XmlDocument();

            if (!tryOpen(document, project.Content.ToString()))
            {
                Console.WriteLine("Could not remove file. Invalid project file {0}", project.File);
                return;
            }

            if (!_fs.FileExists(file.Fullpath))
            {
                return;
            }

            var relativePath = PathExtensions.GetRelativePath(project.File, file.Fullpath).Replace("/", "\\");
            var node         = getNode(document, relativePath);

            if (node == null)
            {
                return;
            }
            node.ParentNode.RemoveChild(node);
            project.SetContent(document.OuterXml);
        }
Ejemplo n.º 2
0
        public void Reference(Project project, IFile file)
        {
            if (!_fs.FileExists(file.Fullpath))
            {
                Console.WriteLine("Could not reference unexisting assembly {0}", file.Fullpath);
                return;
            }

            if (!tryOpen(project.Content.ToString()))
            {
                return;
            }

            var relativePath = PathExtensions.GetRelativePath(
                project.File,
                file.Fullpath).Replace("/", "\\");

            if (alreadyReferenced(relativePath))
            {
                return;
            }
            var parent        = getReferenceGroup(project.File);
            var node          = _document.CreateNode(XmlNodeType.Element, "Reference", parent.NamespaceURI);
            var fileAttribute = _document.CreateAttribute("Include");

            fileAttribute.Value = relativePath;
            node.Attributes.Append(fileAttribute);
            parent.AppendChild(node);
            project.SetContent(_document.OuterXml);
        }
Ejemplo n.º 3
0
        public void Append(Project project, IFile file)
        {
            var document = new XmlDocument();

            if (!tryOpen(document, project.Content.ToString()))
            {
                Console.WriteLine("Could not append file. Invalid project file {0}", project.File);
                return;
            }

            if (!_fs.FileExists(file.Fullpath))
            {
                Console.WriteLine("Could not append unexisting file {0}", file.Fullpath);
                return;
            }

            _appenders
            .Where(x => x.AppendsFor(file)).ToList()
            .ForEach(x => x.Append(document, project, file));

            project.SetContent(document.OuterXml);
        }
Ejemplo n.º 4
0
        public void Reference(Project project, IFile file)
        {
            if (!_fs.FileExists(file.Fullpath))
            {
                Console.WriteLine("Could not reference unexisting project {0}", file.Fullpath);
                return;
            }

            if (!tryOpen(project.Content.ToString()))
            {
                return;
            }

            var relativePath = PathExtensions.GetRelativePath(
                project.File,
                file.Fullpath).Replace("/", "\\");

            if (alreadyReferenced(relativePath))
            {
                return;
            }

            var handler = new ProjectHandler();

            handler.Read(file.Fullpath, _getTypesProviderByProject);

            var parent        = getReferenceGroup(project.File);
            var node          = _document.CreateNode(XmlNodeType.Element, "ProjectReference", parent.NamespaceURI);
            var fileAttribute = _document.CreateAttribute("Include");

            fileAttribute.Value = relativePath;
            node.Attributes.Append(fileAttribute);
            node.AppendChild(createNode("Project", "{" + handler.Guid.ToString() + "}", parent));
            node.AppendChild(createNode("Name", Path.GetFileNameWithoutExtension(file.Fullpath), parent));
            parent.AppendChild(node);
            project.SetContent(_document.OuterXml);
        }