Пример #1
0
 public static string ConvertFillTypeFromEvenOddToWinding([CanBeNull] string pathData, out bool separatePathForStroke)
 {
     ConvertQuality.SetDefault();
     while (true)
     {
         ConvertTimer.Restart();
         try
         {
             if (!string.IsNullOrEmpty(pathData))
             {
                 var path = new PathParser().Parse(pathData);
                 path = PathPreprocessor.Preprocess(path);
                 var convert0 = PathFormatter.ToString(path);
                 path = PathConverter.EliminateIntersections(path);
                 var convert1 = PathFormatter.ToString(path);
                 path = PathConverter.FixDirections(path);
                 var convert2 = PathFormatter.ToString(path);
                 if (convert2 != convert0)
                 {
                     separatePathForStroke = convert1 != convert0;
                     return(convert2);
                 }
             }
             separatePathForStroke = false;
             return(pathData);
         }
         catch (ConvertOvertimeException)
         {
             ConvertQuality.Degrade();
         }
     }
 }
        public void Test_Retrieve_SpecifyStatus()
        {
            // Copy the nuget.exe file into the current test directory so the retriever can skip downloading it
            new FileCopier(
                OriginalDirectory,
                CurrentDirectory
                ).Copy(
                "lib/nuget.exe"
                );

            new FileNodeManager().EnsureNodes();

            new MockNugetPackageCreator().Create("TestPackage", new Version("1.0.0"), "beta");
            new MockNugetPackageCreator().Create("TestPackage", new Version("1.0.1"), "alpha");

            var retriever = new InstallerNugetPackageRetriever()
            {
                NugetSourcePath = PathConverter.ToAbsolute("pkg"),
                NugetPath       = Path.Combine(OriginalDirectory, "lib/nuget.exe") // This shouldn't be required but leave it in just to ensure the test never tries to download the file from the web
            };

            retriever.Retrieve("TestPackage", new Version(0, 0, 0, 0), "beta");

            var expectedDir = PathConverter.ToAbsolute("lib/TestPackage.1.0.0-beta");

            Assert.IsTrue(Directory.Exists(expectedDir), "The expected lib directory wasn't found.");
        }
        public void LoadFont()
        {
            Styles.Clear();

            var a = Assembly.GetExecutingAssembly();

            var document = XDocument.Load(a.GetManifestResourceStream("MathematicsTypesetting.Fonts.LatinModern.font.xml"));
            var root     = document.Root;

            foreach (var s in root.Elements())
            {
                var style = new Style();

                style.Weight   = s.Attribute(XName.Get("weight", "")).Value;
                style.Emphasis = s.Attribute(XName.Get("emphasis", "")).Value;

                foreach (var g in s.Elements())
                {
                    var glyph = new Glyph();

                    glyph.Character = g.Attribute(XName.Get("character", "")).Value;
                    glyph.Path      = g.Attribute(XName.Get("path", "")).Value;

                    glyph.PathCommands = PathConverter.ParsePath(glyph.Path).Commands;
                    SetGlyphWidth(glyph);

                    style.Glyphs.Add(glyph);
                }

                Styles.Add(style);
            }
        }
        public void DrawString(Graphics graphics, string text, float fontSize, string fontEmphasis, string fontWeight, Brush brush, PointF point)
        {
            var x             = point.X;
            var y             = point.Y;
            var letterSpacing = 0.01f;

            foreach (var c in text)
            {
                var g = GetGlyph(fontWeight, fontEmphasis, c.ToString());

                if (g != null)
                {
                    var p = PathConverter.ConvertPath(new SVG.Path()
                    {
                        Commands = g.PathCommands
                    });

                    var m = new System.Drawing.Drawing2D.Matrix();

                    var sf = fontSize / 20.0f;

                    m.Scale(sf, sf);
                    m.Translate(x / sf, y / sf + 25f);

                    p.Transform(m);

                    graphics.FillPath(brush, p);

                    x += g.Width * sf + letterSpacing * fontSize * sf;
                }
            }
        }
Пример #5
0
        public void Create(string name, Version version, string status)
        {
            var spec = new NugetPackageSpec();

            spec.MetaData.ID      = name;
            spec.MetaData.Version = version.ToString();

            if (!String.IsNullOrEmpty(status))
            {
                spec.MetaData.Version += "-" + status;
            }

            var helloWorldFile = "HelloWorld.txt";

            File.WriteAllText(
                PathConverter.ToAbsolute(helloWorldFile),
                "Hello world"
                );

            spec.AddFiles(helloWorldFile);

            spec.Save();

            Packer.PackageFile(spec.FilePath);
        }
Пример #6
0
        public override void RegisterRealTasks(PhysicalServer site)
        {
            var path = PathConverter.Convert(site, _path);

            var task = new ClearAclsTask(path, _groupsToPreserve, _groupsToRemove);

            site.AddTask(task);
        }
Пример #7
0
        public static PathF AsPathF(this CGPath target)
        {
            var path      = new PathF();
            var converter = new PathConverter(path);

            target.Apply(converter.ApplyCGPathFunction);
            return(path);
        }
        public override void RegisterRealTasks(PhysicalServer site)
        {
            var path = PathConverter.Convert(site, _path);

            var task = new RemoveAclsInheritanceTask(path);

            site.AddTask(task);
        }
Пример #9
0
        public string Backup(string relativeFilePath)
        {
            relativeFilePath = PathConverter.ToRelative(relativeFilePath);

            Console.WriteLine("");
            Console.WriteLine("Backing up file:");
            Console.WriteLine(" " + relativeFilePath);
            Console.WriteLine("");

            var fromFullFilePath = String.Empty;

            fromFullFilePath = PathConverter.ToAbsolute(relativeFilePath);

            var toFilePath = Environment.CurrentDirectory
                             + Path.DirectorySeparatorChar
                             + "_bak"
                             + Path.DirectorySeparatorChar
                             + relativeFilePath;

            var timeStamp = String.Format(
                "[{0}-{1}-{2}--{3}-{4}-{5}]",
                DateTime.Now.Year,
                DateTime.Now.Month,
                DateTime.Now.Day,
                DateTime.Now.Hour,
                DateTime.Now.Minute,
                DateTime.Now.Second
                );

            var ext = Path.GetExtension(toFilePath);

            var toFileName = Path.GetFileNameWithoutExtension(toFilePath);

            toFilePath = Path.GetDirectoryName(toFilePath)
                         + Path.DirectorySeparatorChar
                         + toFileName + ext
                         + Path.DirectorySeparatorChar
                         + toFileName
                         + "-" + timeStamp
                         + ext
                         + ".bak"; // Add .bak extention to disable certain files which are used based on their extension

            Console.WriteLine("To:");
            Console.WriteLine("  " + PathConverter.ToRelative(toFilePath));

            if (!Directory.Exists(Path.GetDirectoryName(toFilePath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(toFilePath));
            }

            File.Copy(
                fromFullFilePath,
                toFilePath
                );

            return(toFilePath);
        }
Пример #10
0
        public override void RegisterRealTasks(PhysicalServer site)
        {
            var path = PathConverter.Convert(site, _path);
            //path = RemotePathHelper.Convert(site, path);

            var task = new GrantReadWriteTask(path, _group, new DotNetPath());

            site.AddTask(task);
        }
Пример #11
0
        public override void RegisterRealTasks(PhysicalServer site)
        {
            string target  = PathConverter.Convert(site, _target);
            string newName = PathConverter.Convert(site, _newName);

            var o = new RenameTask(target, newName, new DotNetPath());

            site.AddTask(o);
        }
Пример #12
0
 /// <summary>
 /// Копирует файл из указанного пути в директорию проекта
 /// </summary>
 /// <param name="path"></param>
 private static void CopyAudio(string path)
 {
     if (!Directory.Exists(_path))
     {
         Directory.CreateDirectory(_path);
     }
     try { File.Copy(path, _path + @"\" + PathConverter.GetFileNameOfPath(path)); }
     catch (Exception ex) { MessageBox.Show(ex.Message); }
 }
Пример #13
0
        public static GraphicsPath GetSquareRootPath(Length innerHeight, Length innerWidth)
        {
            // True LaTeX square-root shape
            var svg = "M 9.64216 21.1929 L 5.27964 11.5508 C 5.10613 11.1542 4.9822 11.1542 4.90784 11.1542 C 4.88305 11.1542 4.75911 11.1542 4.48646 11.3525 L 2.13169 13.1371 C 1.80945 13.385 1.80945 13.4594 1.80945 13.5337 C 1.80945 13.6577 1.88382 13.8064 2.05733 13.8064 C 2.20605 13.8064 2.62743 13.4594 2.90009 13.2611 C 3.04881 13.1371 3.42061 12.8645 3.69327 12.6662 L 8.57632 23.399 C 8.74983 23.7956 8.87377 23.7956 9.09685 23.7956 C 9.46865 23.7956 9.54302 23.6468 9.71652 23.2998 L 20.9698 0 C 21.1434 -0.347019 21.1434 -0.446167 21.1434 -0.495741 C 21.1434 -0.743612 20.9451 -0.991482 20.6476 -0.991482 C 20.4493 -0.991482 20.2758 -0.867547 20.0775 -0.470954 L 9.64216 21.1929 Z";

            var p = PathConverter.ConvertPath(PathConverter.ParsePath(svg));

            return(p);
        }
Пример #14
0
        public void TestConvertWindowsPathToWSLEquivalent()
        {
            // Example windows path
            string windowsPath = "C:\\Program Files (x86)\\Microsoft Visual Studio\\testfile.txt";
            // The equivalent WSL path
            string unixPath = "/mnt/c/Program\\ Files\\ \\(x86\\)/Microsoft\\ Visual\\ Studio/testfile.txt";

            // assert that the converter method correctly converts the Windows path to its WSL style equivalent.
            Assert.AreEqual(unixPath, PathConverter.convertPathFromWindowsToLinux(windowsPath), false, "Windows path converted correctly to WSL equivalent.");
        }
Пример #15
0
        public void ConvertUrlToPath()
        {
            string baseUrl   = "http://sourcecontrol/svn/Gis/Development/";
            string workspace = @"C:\Users\tkoehler\Desktop\workspace";
            string expected  = Path.Combine(workspace, "this\\is\\a\\test\\test.build");

            string actual = PathConverter.ConvertUrlToPath(baseUrl + "this/is/a/test/test.build", baseUrl, workspace);

            Assert.AreEqual(expected, actual);
        }
Пример #16
0
        public void ConvertPathToUrl()
        {
            string baseUrl   = "http://sourcecontrol/svn/Gis/Development/";
            string workspace = @"C:\Users\tkoehler\Desktop\workspace";
            string expected  = "http://sourcecontrol/svn/Gis/Development/this/is/a/test";

            string actual = PathConverter.ConvertPathToUrl(@"C:\Users\tkoehler\Desktop\workspace\this\is\a\test", baseUrl, workspace);

            Assert.AreEqual(expected, actual);
        }
Пример #17
0
        public void UpdateCsProjFile(string id, string fromVersion, string toVersion, string file)
        {
            XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003";

            XDocument doc     = XDocument.Load(file);
            var       element = doc
                                .Element(msbuild + "Project")
                                .Elements(msbuild + "ItemGroup")
                                .Elements(msbuild + "Reference")
                                .Where(
                r => (
                    r.Attribute("Include").Value == id ||
                    r.Attribute("Include").Value.EndsWith("." + id)
                    )
                ).SingleOrDefault();

            if (element != null)
            {
                var elements = element.Elements().ToArray();

                if (elements.Length > 0)
                {
                    var hintPathNode = elements[0];

                    var path = hintPathNode.Value;

                    var parts = path.Split('\\');

                    for (int i = 0; i < parts.Length; i++)
                    {
                        var part = parts[i];

                        var matches = part.StartsWith(id) ||
                                      part.EndsWith("." + id);

                        if (matches)
                        {
                            part = id + "." + toVersion;

                            parts[i] = part;

                            break;
                        }
                    }

                    path = String.Join("\\", parts);

                    hintPathNode.Value = path;

                    Console.WriteLine("  " + PathConverter.ToRelative(file));

                    doc.Save(file);
                }
            }
        }
Пример #18
0
        /// <summary>
        /// 删除文件夹
        /// </summary>
        /// <param name="remotePath"></param>
        /// <returns></returns>
        public int DeleteDirectory(string remotePath)
        {
            //所有传入的路径都进行一次转换
            remotePath = PathConverter.LocalPathToRemotePath(remotePath);

            foreach (ICloudDiskAPI api in _loadedCloudDiskApi)
            {
                api.DeleteDirectory(remotePath);
            }
            return(0);
        }
Пример #19
0
    void lbtnParentFolder_Click(object sender, EventArgs e)
    {
        String parFolder = PathConverter.GetInstance().GetParentDirectory(path);

        if (parFolder == this.parentDirectory)
        {
            parFolder = PathConverter.GetInstance().GetParentDirectory(parFolder);
        }

        Response.Redirect(String.Format("{0}{1}?Path={2}", baseUrl, pageFilename, parFolder));
    }
Пример #20
0
        public override object ConvertFrom(ITypeDescriptorContext context,
                                           CultureInfo culture, object valueObject)
        {
            if (!(valueObject is string value))
            {
                throw new InvalidOperationException($"Cannot convert from type {valueObject.GetType()}");
            }

            IPathGeometry pathGeometry = PathConverter.ParsePathGeometry(value, GeometryFactory.Instance);

            return(pathGeometry);
        }
Пример #21
0
        public void CopyFileToUncPath()
        {
            var sourceUncPath      = PathConverter.Convert(Environment.MachineName, _path.GetFullPath(_sourceFilePath));
            var destinationUncPath = PathConverter.Convert(Environment.MachineName, _path.GetFullPath(_destinationFolderPath));

            var t = new CopyFileTask(sourceUncPath, destinationUncPath, null, new DotNetPath());

            t.Execute();

            string s = File.ReadAllText(_path.Combine(destinationUncPath, "test.txt"));

            Assert.AreEqual("the test\r\n", s);
        }
Пример #22
0
        public void TestConvertWSLPathToWindowsEquivalent()
        {
            // Example WSL Path
            string unixPath = "/mnt/c/Program Files (x86)/Microsoft Visual Studio/testfile.txt";

            // Equivalent Windows path
            string windowsPath = "C:\\Program Files (x86)\\Microsoft Visual Studio\\testfile.txt";

            string convertedPath = PathConverter.convertPathFromLinuxToWindows(unixPath);

            // assert correct conversion
            Assert.AreEqual(unixPath, PathConverter.convertPathFromLinuxToWindows(unixPath), false, "WSL path converted correctly to Windows equivalent.");
        }
        public void Test_GetVersionFromPackageFileName()
        {
            var currentVersion = new Version(2, 0, 0, 0);

            var checker = new PackageChecker(currentVersion);

            var version = "1.2.3.4";

            var fileName = PathConverter.ToAbsolute("pkg/csAnt/csAnt." + version + ".nupkg");

            var returnedVersion = checker.GetVersionFromPackageFileName(fileName);

            Assert.AreEqual(version, returnedVersion.ToString(), "Wrong version.");
        }
Пример #24
0
        public void RunAssemblyTests(string assemblyFile, string testName)
        {
            string assemblyFileName = Path.GetFileName(assemblyFile);

            string xmlResult = XmlFileNamer.GetResultsDirectory(Script)
                               + Path.DirectorySeparatorChar
                               + Path.GetFileNameWithoutExtension(assemblyFileName).Replace(".", "-")
                               + ".xml";

            if (!Directory.Exists(Path.GetDirectoryName(xmlResult)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(xmlResult));
            }

            string command = "mono";

            List <string> arguments = new List <string>();

            // TODO: Remove if not needed
            arguments.Add("--runtime=v4.0");

            // TODO: Make configurable
            arguments.Add("lib/NUnit.Runners.2.6.0.12051/tools/nunit-console.exe");

            arguments.Add("\"" + PathConverter.ToRelative(assemblyFile) + "\"");

            arguments.Add("-xml=" + PathConverter.ToRelative(xmlResult));

            if (!String.IsNullOrEmpty(testName))
            {
                arguments.Add("-run=" + testName);
            }

            if (IncludeCategories != null && IncludeCategories.Length > 0)
            {
                arguments.Add("-include=" + String.Join(",", IncludeCategories));
            }

            if (ExcludeCategories != null && ExcludeCategories.Length > 0)
            {
                arguments.Add("-exclude=" + String.Join(",", ExcludeCategories));
            }

            Script.StartProcess(
                command,
                arguments.ToArray()
                );
        }
        protected void ExportBracketExpression(Graphics graphics, BracketExpression bracketExpression)
        {
            ExportElement(graphics, bracketExpression.InnerExpression);

            var g1 = _fontLoader.GetGlyph("normal", "none", "(");
            var g2 = _fontLoader.GetGlyph("normal", "none", ")");

            var w = g1.Width;
            var h = bracketExpression.InnerExpression.OuterHeight;

            var x1 = (float)(bracketExpression.Position.X.Quantity);
            var y1 = (float)bracketExpression.Position.Y.Quantity;

            var x2 = (float)(bracketExpression.Position.X.Quantity + bracketExpression.InnerExpression.OuterWidth.Quantity);
            var y2 = (float)bracketExpression.Position.Y.Quantity;

            var p1 = PathConverter.ConvertPath(new Path()
            {
                Commands = g1.PathCommands
            });                                                                            // Paths.GetBracketPath(new PointF(, , (float)h.Quantity);

            var p2 = PathConverter.ConvertPath(new Path()
            {
                Commands = g2.PathCommands
            });                                                                            // Paths.GetBracketPath(new PointF(, ), (float)h.Quantity, ")");

            var m1 = new System.Drawing.Drawing2D.Matrix();
            var m2 = new System.Drawing.Drawing2D.Matrix();

            var sf = (float)h.Quantity / (1.7f * 20.0f);

            m1.Scale(sf, sf);
            m1.Translate(x1 / sf, y1 / sf + 25f);

            m2.Scale(sf, sf);
            m2.Translate(x2 / sf, y2 / sf + 25f);

            p1.Transform(m1);
            p2.Transform(m2);

            graphics.FillPath(Brushes.Black, p1);
            graphics.FillPath(Brushes.Black, p2);

            if (bracketExpression.DrawConstructionLines == true)
            {
                DrawConstructionLines(graphics, bracketExpression.Position, bracketExpression.SizeIncludingOuterMargin);
            }
        }
Пример #26
0
        public void UpdateNuspecFile(string id, string fromVersion, string toVersion, string file)
        {
            var doc = new XmlDocument();

            doc.Load(file);
            var node = doc.SelectSingleNode("//dependency[@id='" + id + "']");

            if (node != null)
            {
                node.Attributes["version"].Value = "[" + toVersion + "]";

                Console.WriteLine("  " + PathConverter.ToRelative(file));

                doc.Save(file);
            }
        }
Пример #27
0
 public IEnumerable <Expression> ConvertTokensToExpressions(IEnumerable <object> tokens)
 {
     tokens = CommentAndLayoutConverter.Convert(tokens);
     tokens = LiteralConverter.Convert(tokens);
     tokens = HelperConverter.Convert(tokens, _configuration);
     tokens = HashParametersConverter.Convert(tokens);
     tokens = PathConverter.Convert(tokens);
     tokens = SubExpressionConverter.Convert(tokens);
     tokens = PartialConverter.Convert(tokens);
     tokens = HelperArgumentAccumulator.Accumulate(tokens);
     tokens = ExpressionScopeConverter.Convert(tokens);
     tokens = WhitespaceRemover.Remove(tokens);
     tokens = StaticConverter.Convert(tokens);
     tokens = BlockAccumulator.Accumulate(tokens, _configuration);
     return(tokens.Cast <Expression>());
 }
Пример #28
0
        public string GetPackageDir(string libDir, string packageName, Version versionQuery)
        {
            var pkgDir = String.Empty;

            if (versionQuery != null &&
                versionQuery > new Version(0, 0, 0, 0))
            {
                pkgDir = PathConverter.ToAbsolute(
                    libDir
                    + Path.DirectorySeparatorChar
                    + packageName
                    + "."
                    + versionQuery.ToString()
                    );
            }
            else
            {
                var versions = new List <SemanticVersion>();

                foreach (var dir in Directory.GetDirectories(PathConverter.ToAbsolute(libDir), packageName + ".*"))
                {
                    var versionString = Path.GetFileName(dir).Replace(packageName, "");
                    versionString = versionString.Trim('.');

                    if (!String.IsNullOrEmpty(versionString))
                    {
                        var version = new SemanticVersion(versionString);

                        versions.Add(version);
                    }
                }

                versions.Sort();

                var latestVersion = versions[versions.Count - 1];

                pkgDir = PathConverter.ToAbsolute(
                    libDir
                    + Path.DirectorySeparatorChar
                    + packageName
                    + "."
                    + latestVersion.ToString()
                    );
            }

            return(pkgDir);
        }
        public void CreateFile(string urlPath, string rootUrl)
        {
            urlPath = urlPath.Replace("about://", string.Empty);
            var url      = new Url(urlPath);
            var filePath = PathConverter.ToPhysicalPath(urlPath, rootUrl);

            if (url.IsRelative)
            {
                url = new Url(new Url(rootUrl), urlPath);
            }

            if (!filePath.StartsWith(_basePath))
            {
                filePath = $"{_basePath}\\{filePath}";
            }

            using (var client = new WebClient())
            {
                try
                {
                    if (!Directory.Exists(Path.GetDirectoryName(filePath)))
                    {
                        var dirPath = Path.GetDirectoryName(filePath);

                        if (File.Exists(dirPath))
                        {
                            dirPath += DateTime.Now.ToFileTime();
                        }

                        Directory.CreateDirectory(dirPath);
                    }

                    client.DownloadFile(url, filePath);
                }
                catch (WebException e)
                {
                    throw new Exception(
                              $"{DateTime.Now}: Failed to download file from url \"{url}\", to path \"{filePath}\"."
                              + $"{Environment.NewLine}[Error]: {e.Message}");
                }
                catch (PathTooLongException e)
                {
                    throw new Exception($"{DateTime.Now}: Too long path for windows." +
                                        $"{Environment.NewLine}[Error]: {e.Message}");
                }
            }
        }
        public void Test_FixArgument()
        {
            // TODO: Should this be moved to FixArgumentTestFixture
            var testFile = PathConverter.ToAbsolute("TestFile.txt");

            File.WriteAllText(testFile, "Hello world");

            var starter = new ProcessStarter();

            var toFileName = "Test File 2.txt";

            var fixedFileName = starter.FixArgument(toFileName);

            var expected = "\"" + toFileName + "\"";

            Assert.AreEqual(expected, fixedFileName, "The argument wasn't fixed.");
        }