Example #1
0
 private IEnumerable<string> getFiles(XmlNodeList nodes)
 {
     var files = new List<string>();
     foreach (XmlNode node in nodes)
     {
         var relativePath = node.Attributes["Include"];
         if (relativePath == null)
             continue;
         var file = new PathParser(relativePath.InnerText.Replace('\\', Path.DirectorySeparatorChar)).ToAbsolute(Path.GetDirectoryName(_path));
         if (!File.Exists(file))
             continue;
         files.Add(file);
     }
     return files;
 }
Example #2
0
        public void Execute(IResponseWriter writer, string[] arguments)
        {
            if (arguments.Length < 1)
            {
                writer.Write("error|The handler needs the full path to the reference. " +
                                  "Usage: reference REFERENCE [PROJECT]");
                return;
            }

            if (arguments.Length > 1) {
                var projectFile = getFile(arguments[1]);
                if (!File.Exists(projectFile)) {
                    writer.Write("error|The project to add this reference to does not exist. " +
                                      "Usage: reference REFERENCE [PROJECT]");
                    return;
                }
                if (!_project.Read(projectFile, _provider))
                    return;
            } else {
                if (!_project.Read(Environment.CurrentDirectory, _provider)) {
                    writer.Write("error|Could not locate project within " + Environment.CurrentDirectory + ". " +
                                 "Usage: reference REFERENCE [PROJECT]");
                    return;
                }
            }

            var fullpath = new PathParser(arguments[0]).ToAbsolute(Environment.CurrentDirectory);
            IFile file;

            if (new VSProjectFile().SupportsExtension(fullpath))
                file = new VSProjectFile().New(fullpath);
            else
                file = new AssemblyFile().New(fullpath);

            _project.Reference(file);
            _project.Write();

            writer.Write("Added reference {0} to {1}", fullpath, _project.Fullpath);
        }
Example #3
0
        static ProviderSettings getTypesProvider(string location)
        {
            var path = "";
            if (location.Contains(".." + Path.DirectorySeparatorChar))
                path = new PathParser(Environment.CurrentDirectory).ToAbsolute(location);
            else
                path = Path.GetFullPath(location);

            if (File.Exists(path) || Path.GetFileName(path).Contains("*"))
                path = Path.GetDirectoryName(path);

            path = Path.GetFullPath(path);
            var projectFile = new ProjectLocator().Locate(path);
            if (projectFile == null)
            {
                Console.WriteLine("error|Could not locate a project file for {0}", path);
                return null;
            }
            return getTypesProviderByProject(projectFile);
        }
Example #4
0
        private List<string> getReferences()
        {
            var refs = new List<string>();
            try {
                foreach (XmlNode node in _xml.SelectNodes("b:Project/b:ItemGroup/b:Reference", _nsManager))
                {
                    var relativePath = node.Attributes["Include"];
                    if (relativePath == null)
                        continue;
                    var reference = relativePath.InnerText;
                    var hintPath = node.SelectSingleNode("b:HintPath", _nsManager);
                    if (hintPath != null)
                        reference = hintPath.InnerText;
                    var referenceFile =
                        new PathParser(reference.Replace('\\', Path.DirectorySeparatorChar))
                        .ToAbsolute(Path.GetDirectoryName(_path));
                    if (File.Exists(referenceFile))
                        refs.Add(referenceFile);
                    else
                        refs.Add(reference);
                }
            } catch {

            }
            return refs;
        }