コード例 #1
0
 public static void WriteFile(object rootObject, ParsedPath xnbFile)
 {
     using (FileStream fileStream = new FileStream(xnbFile, FileMode.Create))
     {
         new XnbFileWriterV5(fileStream).Write(rootObject);
     }
 }
コード例 #2
0
        public static PinboardFileV1 Load(ParsedPath pinboardFileName)
        {
            PinboardFileV1 data = null;

            if (pinboardFiles == null)
                pinboardFiles = new Dictionary<ParsedPath, PinboardFileV1>();

            if (pinboardFiles.TryGetValue(pinboardFileName, out data))
            {
                return data;
            }

            try
            {
                data = PinboardFileReaderV1.ReadFile(pinboardFileName);
            }
            catch
            {
                throw new ContentFileException("Unable to read pinboard file '{0}'".CultureFormat(pinboardFileName));
            }

            pinboardFiles.Add(pinboardFileName, data);

            return data;
        }
コード例 #3
0
 public static PinboardFileV1 ReadFile(ParsedPath contentFile)
 {
     using (XmlReader reader = XmlReader.Create(contentFile))
     {
         return new PinboardFileReaderV1(reader).ReadPinboardXml();
     }
 }
コード例 #4
0
        /// <summary>
        /// See <see cref="DirectoryInfoUtility.GetFiles(string, SearchScope)"/>.
        /// </summary>
        /// <param name="fileSpec"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        public static IList<ParsedPath> GetFiles(ParsedPath fileSpec, SearchScope scope)
        {
            IList<FileInfo> fileInfos = DirectoryInfoUtility.GetFiles(fileSpec, scope);

            ParsedPath[] files = new ParsedPath[fileInfos.Count];

            for (int i = 0; i < fileInfos.Count; i++)
                files[i] = new ParsedPath(fileInfos[i].FullName, PathType.File);

            return files;
        }
コード例 #5
0
        /// <summary>
        /// See <see cref="DirectoryInfoUtility.GetDirectories(string, SearchScope)"/>
        /// </summary>
        /// <param name="dirSpec"></param>
        /// <param name="scope"></param>
        /// <returns></returns>
        public static IList<ParsedPath> GetDirectories(ParsedPath dirSpec, SearchScope scope)
        {
            IList<DirectoryInfo> dirInfos = DirectoryInfoUtility.GetDirectories(dirSpec, scope);

            ParsedPath[] dirs = new ParsedPath[dirInfos.Count];

            for (int i = 0; i < dirInfos.Count; i++)
                dirs[i] = new ParsedPath(dirInfos[i].FullName, PathType.Directory);

            return dirs;
        }
コード例 #6
0
        private static void RecursiveGetParentDirectories(ParsedPath rootPath, ref List<DirectoryInfo> dirs)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(rootPath.VolumeAndDirectory);
            DirectoryInfo [] dirInfos = dirInfo.GetDirectories(rootPath.FileAndExtension);

            dirs.AddRange(dirInfos);

            if (!rootPath.IsRootDirectory)
            {
                RecursiveGetParentDirectories(rootPath.MakeParentPath(), ref dirs);
            }
        }
コード例 #7
0
ファイル: ToolPaths.cs プロジェクト: jlyonsmith/Playroom
        static ToolPaths()
        {
            try
            {
            #if WINDOWS
                RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"svgfile\shell\Inkscape\command", false);

                if (key != null)
                {
                    string s = (string)key.GetValue("");

                    if (s != null && s.Length > 0)
                    {
                        if (s[0] == '"')
                            s = s.Substring(1, s.IndexOf('"', 1) - 1);

                        ParsedPath path  = new ParsedPath(s, PathType.File).WithExtension(".com");

                        if (File.Exists(path))
                            Inkscape = path;
                    }
                }

                key = Registry.ClassesRoot.OpenSubKey(@"svgfile\shell\Edit with GIMP\command", false);

                if (key != null)
                {
                    string s = (string)key.GetValue("");

                    if (s != null && s.Length > 0)
                    {
                        if (s[0] == '"')
                            s = s.Substring(1, s.IndexOf('"', 1) - 1);

                        ParsedPath path = new ParsedPath(s, PathType.File).WithFileAndExtension("rsvg-convert.exe");

                        if (File.Exists(path))
                            RSvgConvert = path;
                    }
                }
            #elif OSX
                ParsedPath path = new ParsedPath("/Applications/Inkscape.app/Contents/Resources/bin/inkscape", PathType.File);

                if (File.Exists(path))
                    Inkscape = path;
            #else
                throw new NotImplementedException();
            #endif
            }
            catch
            {
            }
        }
コード例 #8
0
ファイル: SlnDocument.cs プロジェクト: jlyonsmith/CSharpTools
        private SlnDocument(ParsedPath filePath, string content)
        {
            projects = new List<SlnProject>();
            globalSections = new List<SlnGlobalSection>();
            solutionConfigs = new List<SlnConfiguration>();
            projectConfigs = new List<SlnProjectConfiguration>();

            Regex slnProjectRegex = new Regex("Project\\(\"(?'type'{.*?})\"\\) = \"(?'name'.*?)\", \"(?'path'.*?)\", \"(?'guid'{.*?})\"[\\t\\r ]*\\n(?'content'(.*\\n)*?)EndProject[\\t\\r ]*\\n",
                RegexOptions.Multiline | RegexOptions.ExplicitCapture);
            MatchCollection matches = slnProjectRegex.Matches(content);

            foreach (Match match in matches)
            {
                this.projects.Add(new SlnProject
                {
                    TypeGuid = match.Groups["type"].Value,
                    Name = match.Groups["name"].Value,
                    Path = new ParsedFilePath(match.Groups["path"].Value).MakeFullPath(filePath),
                    ProjectGuid = match.Groups["guid"].Value,
                    Content = match.Groups["content"].Value
                });
            }

            Regex slnGlobalSectionRegex = new Regex("[\\t ]*GlobalSection\\((?'name'.*?)\\) = (?'order'(pre|post)Solution)[\\t\\r ]*\\n(?'content'([\\t ]*.*[\\t ]*\\n)+?)[\\t ]*EndGlobalSection[\\t\\r ]*\\n",
                RegexOptions.Multiline | RegexOptions.ExplicitCapture);

            matches = slnGlobalSectionRegex.Matches(content);

            foreach (Match match in matches)
            {
                var name = match.Groups["name"].Value;
                var groupContent = match.Groups["content"].Value;

                if (name == "SolutionConfigurationPlatforms")
                {
                    ParseSolutionConfigurationPlatforms(groupContent);
                }
                else if (name == "ProjectConfigurationPlatforms")
                {
                    ParseProjectConfigurationPlatforms(groupContent);
                }
                else
                {
                    this.globalSections.Add(new SlnGlobalSection
                    {
                        Name = name,
                        Order = match.Groups["order"].Value,
                        Content = groupContent
                    });
                }
            }
        }
コード例 #9
0
ファイル: PngFileReader.cs プロジェクト: jlyonsmith/Playroom
        public static PngFile ReadFile(ParsedPath pngFileName)
        {
            PngFile pngFile = new PngFile();

            ImageSurface image = new ImageSurface(pngFileName);

            if (image.Format != Format.ARGB32)
                throw new NotSupportedException("Only PNG's in ARGB32 format currently supported");

            pngFile.Width = image.Width;
            pngFile.Height = image.Height;
            pngFile.RgbaData = GetRgbaData(image);

            return pngFile;
        }
コード例 #10
0
 public static void AssertBadPath(
     string path, 
     PathType type)
 {
     try
     {
         ParsedPath pp = new ParsedPath(path, type);
         Assert.IsNotNull(pp);
         Assert.Fail("Badly formed path not caught");
     }
     catch (Exception e)
     {
         Assert.IsTrue(e is ArgumentException);
     }
 }
コード例 #11
0
 public static ContentFileV2 ReadFile(ParsedPath contentFile)
 {
     using (XmlReader reader = XmlReader.Create(contentFile))
     {
         try
         {
             return new ContentFileReaderV2(reader).ReadContentElement();
         }
         catch (Exception e)
         {
             e.Data["LineNumber"] = ((IXmlLineInfo)reader).LineNumber;
             throw;
         }
     }
 }
コード例 #12
0
        public static void AssertParentPath(
            string path,
            int level,
            string machine,
            string share,
            string drive,
            string directory,
            string file,
            string extension)
        {
            ParsedPath pp;

            // Test out specific entry points based on the values passed in
            if (level < -1)
            {
                pp = new ParsedPath(path, PathType.Unknown).MakeParentPath(level);

                if (pp == null)
                {
                    Assert.IsNull(directory, "Expected result was not null");
                    return;
                }
            }
            else
            {
                pp = new ParsedPath(path, PathType.Unknown).MakeParentPath();

                if (pp == null)
                {
                    Assert.IsNull(directory, "Expected result was not null");
                    return;
                }
            }

            #if MACOS
            // We have to compare to OS specific paths
            machine = machine.Replace(@"\", "/");
            share = share.Replace(@"\", "/");
            directory = directory.Replace(@"\", "/");
            #endif

            Assert.AreEqual(machine, pp.Machine.ToString());
            Assert.AreEqual(share, pp.Share.ToString());
            Assert.AreEqual(drive, pp.Drive.ToString());
            Assert.AreEqual(directory, pp.Directory.ToString());
            Assert.AreEqual(file, pp.File.ToString());
            Assert.AreEqual(extension, pp.Extension.ToString());
        }
コード例 #13
0
 public static StringsFileV1 ReadFile(ParsedPath fileName)
 {
     using (XmlReader reader = XmlReader.Create(fileName))
     {
         try
         {
             return new StringsFileReaderV1(reader).ReadStringsElement();
         }
         catch (Exception e)
         {
             e.Data["ContentFile"] = fileName;
             e.Data["LineNumber"] = ((IXmlLineInfo)reader).LineNumber;
             throw;
         }
     }
 }
コード例 #14
0
 public static void AssertBadPathFull(
     string path, 
     string baseDir)
 {
     try
     {
         ParsedPath pp = new ParsedPath(path, PathType.Unknown).MakeFullPath(
             baseDir == null ? null : new ParsedPath(baseDir, PathType.Directory));
         Assert.IsNotNull(pp);
         Assert.Fail("Badly formed path not caught");
     }
     catch (Exception e)
     {
         Assert.IsTrue(e is ArgumentException);
     }
 }
コード例 #15
0
ファイル: DoozerTool.cs プロジェクト: jlyonsmith/CSharpTools
        private void ProcessDirectory(ParsedPath dir)
        {
            var files = DirectoryUtility.GetFiles(dir, SearchScope.DirectoryOnly);

            foreach (var file in files)
            {
                if (file.Extension == ".cs")
                    ScanFile(file);
            }

            var dirs = DirectoryUtility.GetDirectories(dir, SearchScope.DirectoryOnly);

            foreach (var subDir in dirs)
            {
                ProcessDirectory(subDir);
            }
        }
コード例 #16
0
        public static void CombinePngs(List<ImagePlacement> placements, ParsedPath pngPath)
        {
            try
            {
                int w = 0;
                int h = 0;

                foreach (var placement in placements)
                {
                    int wt = (int)placement.TargetRectangle.Width;
                    int ht = (int)placement.TargetRectangle.Height;

                    if (wt > w)
                        w = wt;

                    if (ht > h)
                        h = ht;
                }

                using (ImageSurface combinedImage = new ImageSurface(Format.Argb32, w, h))
                {
                    using (Cairo.Context g = new Cairo.Context(combinedImage))
                    {
                        foreach (var placement in placements)
                        {
                            using (ImageSurface image = new ImageSurface(placement.ImageFile))
                            {
                                int x = (int)placement.TargetRectangle.X;
                                int y = (int)placement.TargetRectangle.Y;

                                g.SetSourceSurface(image, x, y);
                                g.Paint();
                            }
                        }
                    }

                    combinedImage.WriteToPng(pngPath);
                }
            }
            catch (Exception e)
            {
                throw new ArgumentException("Unable to combine images into file '{0}'".CultureFormat(pngPath), e);
            }
        }
コード例 #17
0
        private CsprojDocument(ParsedPath csprojPath, string content)
        {
            refs = new List<CsprojReference>();
            projRefs = new List<CsprojProjectReference>();

            this.xdoc = XDocument.Parse(content);

            XElement firstItemGroup;
            var refElems = GetElements(ns + "Reference", out firstItemGroup);

            this.refItemGroup = firstItemGroup;

            foreach (var refElem in refElems)
            {
                var hintPath = refElem.Element(ns + "HintPath");

                refs.Add(new CsprojReference
                {
                    Name = refElem.Attribute("Include").Value,
                    HintPath = (hintPath != null ? new ParsedPath(hintPath.Value, PathType.File).MakeFullPath(csprojPath) : null)
                });
            }

            refElems.Remove();

            var projRefElems = GetElements(ns + "ProjectReference", out firstItemGroup);

            this.projRefItemGroup = firstItemGroup;

            foreach (var projRefElem in xdoc.Descendants(ns + "ProjectReference"))
            {
                projRefs.Add(new CsprojProjectReference
                {
                    Include = new ParsedPath(projRefElem.Attribute("Include").Value, PathType.File).MakeFullPath(csprojPath),
                    Guid = projRefElem.Element(ns + "Project").Value,
                    Name = projRefElem.Element(ns + "Name").Value
                });
            }

            projRefElems.Remove();

            this.projectGuid = xdoc.Descendants(ns + "ProjectGuid").First().Value;
        }
コード例 #18
0
        /// <summary>
        /// Returns a list of files given a file search pattern.  Will also search sub-directories.
        /// </summary>
        /// <param name="searchPattern">Search pattern.  Can include a full or partial path and standard wildcards for the file name.</param>
        /// <param name="scope">The scope of the search.</param>
        /// <param name="baseDir">Base directory to use for partially qualified paths</param>
        /// <returns>An array of <c>FileInfo</c> objects for files matching the search pattern. </returns>
        public static IList<FileInfo> GetFiles(ParsedPath fileSpec, SearchScope scope)
        {
            ParsedPath rootPath = fileSpec.MakeFullPath();

            if (scope != SearchScope.DirectoryOnly)
            {
                List<FileInfo> files = new List<FileInfo>();

                if (scope == SearchScope.RecurseParentDirectories)
                    RecursiveGetParentFiles(rootPath, ref files);
                else
                    RecursiveGetSubFiles(rootPath, (scope == SearchScope.RecurseSubDirectoriesBreadthFirst), ref files);

                return files.ToArray();
            }
            else
            {
                return NonRecursiveGetFiles(rootPath);
            }
        }
コード例 #19
0
        public static void AssertBadParentPath(
            string path,
            int level)
        {
            try
            {
                ParsedPath pp;

                if (level <= -1 || level > 0)
                    pp = new ParsedPath(path, PathType.Unknown).MakeParentPath(level);
                else
                    pp = new ParsedPath(path, PathType.Unknown).MakeParentPath();

                Assert.IsNotNull(pp);
                Assert.Fail("Get parent succeeded and should have failed");
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is ArgumentException || e is InvalidOperationException);
            }
        }
コード例 #20
0
        /// <summary>
        /// Returns a list of directories given a file search pattern.  Will also search sub-directories and 
        /// parent directories.
        /// </summary>
        /// <param name="dirSpec">Search specification with with optional directory and wildcards</param>
        /// <param name="scope">The scope of the search. <see cref="SearchScope"/></param>
        /// <returns>An array of <c>DirectoryInfo</c> objects for files matching the search pattern. </returns>
        public static IList<DirectoryInfo> GetDirectories(ParsedPath dirSpec, SearchScope scope)
        {
            if (!dirSpec.HasFilename)
                throw new ArgumentException("Path does not have a filename");

            ParsedPath rootPath = dirSpec.MakeFullPath();

            if (scope != SearchScope.DirectoryOnly)
            {
                List<DirectoryInfo> dirs = new List<DirectoryInfo>();

                if (scope == SearchScope.RecurseParentDirectories)
                    RecursiveGetParentDirectories(rootPath, ref dirs);
                else
                    RecursiveGetSubDirectories(rootPath, (scope == SearchScope.RecurseSubDirectoriesBreadthFirst), ref dirs);

                return dirs.ToArray();
            }
            else
            {
                return NonRecursiveGetDirectories(rootPath);
            }
        }
コード例 #21
0
ファイル: ParsedPathTests.cs プロジェクト: rluethy/ToolBelt
 private void AssertPathPartsRelative(
     string path,
     string basePath,
     string directory)
 {
     ParsedPath pp = new ParsedPath(path, PathType.Unknown).MakeRelativePath(new ParsedPath(basePath, PathType.Unknown));
     Assert.AreEqual(directory, pp.Directory);
 }
コード例 #22
0
ファイル: SlnDocument.cs プロジェクト: jlyonsmith/CSharpTools
        public void Save(ParsedPath fileName)
        {
            using (var writer = new StreamWriter(fileName))
            {
                writer.Write("\r\nMicrosoft Visual Studio Solution File, Format Version 12.00\r\n");
                writer.Write("# Visual Studio 2012\r\n");

                foreach (var project in this.projects)
                {
                    var projectPath = project.Path.MakeRelativePath(fileName).ToString("\\");
                    var prefix = ".\\";

                    if (projectPath.StartsWith(prefix))
                        projectPath = projectPath.Substring(prefix.Length);

                    writer.Write("Project(\"{0}\") = \"{1}\", \"{2}\", \"{3}\"\r\n{4}EndProject\r\n",
                        project.TypeGuid, project.Name,
                        projectPath,
                        project.ProjectGuid, project.Content);
                }

                writer.Write("Global\r\n");

                writer.Write("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\r\n");
                foreach (var solutionConfig in this.solutionConfigs)
                {
                    writer.Write("\t\t{0}|{1} = {0}|{1}\r\n", solutionConfig.Configuration, solutionConfig.Platform);
                }
                writer.Write("\tEndGlobalSection\r\n");

                writer.Write("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n");
                foreach (var projectConfig in this.projectConfigs)
                {
                    writer.Write("\t\t{0}.{1}|{2}.ActiveCfg = {3}|{4}\r\n",
                        projectConfig.Guid,
                        projectConfig.SolutionConfiguration.Configuration,
                        projectConfig.SolutionConfiguration.Platform,
                        projectConfig.ProjectConfiguration.Configuration,
                        projectConfig.ProjectConfiguration.Platform);
                    writer.Write("\t\t{0}.{1}|{2}.Build.0 = {3}|{4}\r\n",
                        projectConfig.Guid,
                        projectConfig.SolutionConfiguration.Configuration,
                        projectConfig.SolutionConfiguration.Platform,
                        projectConfig.ProjectConfiguration.Configuration,
                        projectConfig.ProjectConfiguration.Platform);
                }
                writer.Write("\tEndGlobalSection\r\n");

                foreach (var globalSection in this.globalSections)
                {
                    writer.Write("\tGlobalSection({0}) = {1}\r\n", globalSection.Name, globalSection.Order);
                    writer.Write(globalSection.Content);
                    writer.Write("\tEndGlobalSection\r\n");
                }

                writer.Write("EndGlobal\r\n");
            }
        }
コード例 #23
0
ファイル: SlnDocument.cs プロジェクト: jlyonsmith/CSharpTools
 public static SlnDocument Parse(ParsedPath filePath)
 {
     return new SlnDocument(filePath, File.ReadAllText(filePath));
 }
コード例 #24
0
 public ImagePlacement(ParsedPath pngPath, Cairo.Rectangle targetRectangle)
 {
     this.ImageFile = pngPath;
     this.TargetRectangle = targetRectangle;
 }
コード例 #25
0
        public static void RotatePng(ParsedPath pngPath, ImageRotation rotation)
        {
            if (rotation == ImageRotation.None)
                return;

            using (ImageSurface originalImage = new ImageSurface(pngPath))
            {
                int w;
                int h;

                if (rotation == ImageRotation.Left || rotation == ImageRotation.Right)
                {
                    w = originalImage.Height;
                    h = originalImage.Width;
                }
                else
                {
                    w = originalImage.Width;
                    h = originalImage.Height;
                }

                double[] rotationRadians = {0, -Math.PI / 2, Math.PI / 2, Math.PI };

                using (ImageSurface rotatedImage = new ImageSurface(Format.Argb32, w, h))
                {
                    using (Cairo.Context g = new Cairo.Context(rotatedImage))
                    {
                        g.Translate(rotatedImage.Width / 2.0, rotatedImage.Height / 2.0);
                        g.Rotate(rotationRadians[(int)rotation]);
                        g.Translate(-originalImage.Width / 2.0, -originalImage.Height / 2.0);

                        g.SetSourceSurface(originalImage, 0, 0);
                        g.Paint();
                    }

                    rotatedImage.WriteToPng(pngPath);
                }
            }
        }
コード例 #26
0
        public static void CompressPngToTexture2DContent(
			ParsedPath pngFileName, 
			string compressionType, 
			out Texture2DContent textureContent)
        {
            PngFile pngFile = PngFileReader.ReadFile(pngFileName);

            SquishMethod? squishMethod = null;
            SurfaceFormat surfaceFormat = SurfaceFormat.Color;

            switch (compressionType.ToLower())
            {
            case "dxt1":
                squishMethod = SquishMethod.Dxt1;
                surfaceFormat = SurfaceFormat.Dxt1;
                break;
            case "dxt3":
                squishMethod = SquishMethod.Dxt3;
                surfaceFormat = SurfaceFormat.Dxt3;
                break;
            case "dxt5":
                squishMethod = SquishMethod.Dxt5;
                surfaceFormat = SurfaceFormat.Dxt5;
                break;
            default:
            case "none":
                surfaceFormat = SurfaceFormat.Color;
                break;
            }

            BitmapContent bitmapContent;

            if (surfaceFormat != SurfaceFormat.Color)
            {
                byte[] rgbaData = Squish.CompressImage(
                    pngFile.RgbaData, pngFile.Width, pngFile.Height,
                    squishMethod.Value, SquishFit.IterativeCluster, SquishMetric.Default, SquishExtra.None);

                bitmapContent = new BitmapContent(surfaceFormat, pngFile.Width, pngFile.Height, rgbaData);
            }
            else
            {
                bitmapContent = new BitmapContent(SurfaceFormat.Color, pngFile.Width, pngFile.Height, pngFile.RgbaData);
            }

            textureContent = new Texture2DContent(bitmapContent);
        }
コード例 #27
0
ファイル: ParsedPathTests.cs プロジェクト: rluethy/ToolBelt
        public void MakeFullPath()
        {
            // Test some good paths
            AssertPathPartsFull(@".txt",
                @"c:\temp\", "", "", @"c:", @"\temp\", "", ".txt");
            AssertPathPartsFull(@"c:\test\..\temp\??.txt",
                null, "", "", @"c:", @"\temp\", @"??", @".txt");
            AssertPathPartsFull(@"\test\..\temp\abc.txt",
                @"c:\a\b\", "", "", "c:", @"\temp\", @"abc", @".txt");
            AssertPathPartsFull(@"test\..\temp\abc.txt",
                @"c:\a\b\", "", "", @"c:", @"\a\b\temp\", @"abc", @".txt");
            AssertPathPartsFull(@".\test\....\temp\abc.txt",
                @"c:\a\b\c\", "", "", "c:", @"\a\temp\", @"abc", @".txt");
            AssertPathPartsFull(@"...\test\abc.txt",
                @"c:\a\b\c\", "", "", "c:", @"\a\test\", @"abc", @".txt");
            AssertPathPartsFull(@"C:\temp\..yes...this...is.a..legal.file.name....\and...\so...\...is\.this.\blah.txt",
                null, "", "", @"C:",
                @"\temp\..yes...this...is.a..legal.file.name\and\so\...is\.this\",
                @"blah", @".txt");

            // Test that using the current directory works
            ParsedPath pp = new ParsedPath(Environment.CurrentDirectory, PathType.Directory);
            AssertPathPartsFull(@"test.txt", null, pp.Machine, pp.Share, pp.Drive, pp.Directory, "test", ".txt");

            // Test some bad paths
            AssertBadPathFull(@"c:\test\..\..\temp\abc.txt", null);  // Too many '..'s
            AssertBadPathFull(@"test\......\temp\.\abc.txt", @"c:\");  // Too many '....'s
        }
コード例 #28
0
ファイル: PopperTool.cs プロジェクト: jlyonsmith/CSharpTools
        private ParsedPath FindNugetLibrary(ParsedPath slnPath, ParsedPath csprojPath)
        {
            var projectName = ProjectName;
            var packagesConfigPath = csprojPath.WithFileAndExtension("packages.config");

            if (!File.Exists(packagesConfigPath))
                throw new PopperToolExeception("Cannot find '{0}'".InvariantFormat(packagesConfigPath));

            var doc = XDocument.Parse(File.ReadAllText(packagesConfigPath));
            var element = doc.Root.Elements("package").Where(e => e.Attribute("id").Value == projectName).FirstOrDefault();

            if (element == null)
                throw new PopperToolExeception("Cannot find project '{0}' in '{1}'".InvariantFormat(projectName, packagesConfigPath));

            var s = "packages/{0}.{1}/lib/{2}/{0}.dll".InvariantFormat(
                projectName, element.Attribute("version").Value, element.Attribute("targetFramework").Value);

            return slnPath.VolumeAndDirectory.Append(s , PathType.File);
        }
コード例 #29
0
ファイル: PopperTool.cs プロジェクト: jlyonsmith/CSharpTools
        private ParsedPath GetSlnForProject(ParsedPath csprojPath)
        {
            var files = DirectoryUtility.GetFiles(csprojPath.WithFileAndExtension("*.sln"), SearchScope.RecurseParentDirectories);

            if (files.Count == 0)
                throw new PopperToolExeception("Cannot find .sln for project '{0}'".InvariantFormat(csprojPath));

            return files[0];
        }
コード例 #30
0
ファイル: ParsedPathTests.cs プロジェクト: rluethy/ToolBelt
        private void AssertPathPartsFull(
            string path,
            string baseDir,
            string machine,
            string share,
            string drive,
            string directory,
            string file,
            string extension)
        {
            ParsedPath pp;

            if (baseDir != null)
                pp = new ParsedPath(path, PathType.Unknown).MakeFullPath(new ParsedPath(baseDir, PathType.Directory));
            else
                pp = new ParsedPath(path, PathType.Unknown).MakeFullPath();

            Assert.AreEqual(machine, pp.Machine);
            Assert.AreEqual(share, pp.Share);
            Assert.AreEqual(drive, pp.Drive);
            Assert.AreEqual(directory, pp.Directory);
            Assert.AreEqual(file, pp.File);
            Assert.AreEqual(extension, pp.Extension);
        }