Exemplo n.º 1
0
 public void ConstructFromRelativePathTest()
 {
     BasePath path = new BasePath("C:/code/");
     RelativePath relPath = new RelativePath("test/", path);
     Assert.AreEqual("test/", relPath.RelativePathComponent, "Relative path from constructor.");
     Assert.AreEqual(path, relPath.RelativeTo, "Relative to from constructor.");
 }
Exemplo n.º 2
0
 public void ChainedPathTest()
 {
     BasePath path = new BasePath("C:/code/");
     RelativePath relPath = new RelativePath("test/", path);
     RelativePath relPath2 = new RelativePath("file.txt", relPath);
     Assert.AreEqual("C:/code/test/file.txt", relPath2.AbsolutePath, "Chained relative path.");
 }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context == null || context.Instance == null || !(context.Instance is InstallerAction))
            return value;

            InstallerAction action = (InstallerAction)context.Instance;
            ScriptPackage package = action.Configuration.Package;
            ScriptManifest manifest = package.Manifest;

            if (this.openFileDialog == null)
            {
            this.InitializeDialog();
            }

            if (value is String)
            {
            if (action.Configuration != null && action.Configuration.Package != null)
            {
                RelativePath path = new RelativePath((string)value, package.SourcePath);
                String pathStr = ScriptManifestTokens.Replace(path.AbsolutePath, manifest, manifest.LatestVersion);
                if (path.IsFilePath)
                {
                    this.openFileDialog.FileName = pathStr.Replace('/', '\\');
                }
                else
                {
                    this.openFileDialog.FileName = "";
                    this.openFileDialog.InitialDirectory = pathStr.Replace('/', '\\');
                }
            }
            else
                this.openFileDialog.FileName = (string)value;
            }

            if (this.openFileDialog.ShowDialog() == DialogResult.OK)
            {
            if (action.Configuration != null && action.Configuration.Package != null)
            {
                BasePath sourcePath = new BasePath(ScriptManifestTokens.Replace(package.SourcePath.AbsolutePath, manifest, manifest.LatestVersion));
                RelativePath relPath = new RelativePath(this.openFileDialog.FileName, sourcePath);
                value = relPath.RelativePathComponent;
            }
            else
                value = (new System.IO.FileInfo(this.openFileDialog.FileName)).Name;
            }

            return value;
        }
Exemplo n.º 4
0
        public void ConstructorIncorrectInputTest()
        {
            BasePath path = new BasePath("C:/code/");

            try
            {
                RelativePath relPath = new RelativePath(null, path);
                Assert.Fail("Passing null path to constructor should throw exception");
            }
            catch (ArgumentNullException e)
            {
                Assert.IsNotNull(e);
            }

            try
            {
                RelativePath relPath = new RelativePath("test/", null);
                Assert.Fail("Passing null relativeTo to constructor should throw exception");
            }
            catch (ArgumentNullException e)
            {
                Assert.IsNotNull(e);
            }

            BasePath filePath = new BasePath("C:/code/test.txt");
            Assert.IsTrue(filePath.IsFilePath);
            try
            {
                RelativePath relPath = new RelativePath("../folder/", filePath);
                Assert.Fail("Creating a path relative to a file should throw exception");
            }
            catch (ArgumentException e)
            {
                Assert.IsNotNull(e);
            }
        }
Exemplo n.º 5
0
 public override void PackResources(Ionic.Zip.ZipFile zip, String archiveTargetPath, IPath sourcePath)
 {
     RelativePath path = new RelativePath(this.Source, sourcePath);
     zip.AddFile(path.AbsolutePath, archiveTargetPath);
 }
Exemplo n.º 6
0
        public override void PackResources(Ionic.Zip.ZipFile zip, String archiveTargetPath, IPath sourcePath)
        {
            //Create selection criteria string from ExcludeFiles property.
            StringBuilder selectionCriteria = new StringBuilder();
            String[] splitExcludeFiles = this.ExcludeFiles.Replace(" ", "").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (String exludeFile in splitExcludeFiles)
            {
            if (selectionCriteria.Length > 0)
                selectionCriteria.Append(" AND ");
            selectionCriteria.Append("name != '");
            selectionCriteria.Append(exludeFile);
            selectionCriteria.Append("'");
            }

            //Create source path and archive path.
            RelativePath path = new RelativePath(this.Source, sourcePath);
            if (!archiveTargetPath.EndsWith("\\"))
            archiveTargetPath += "\\";
            archiveTargetPath += path.PathComponents[path.PathComponents.Count - 1];

            //Add files to zip.
            zip.AddSelectedFiles(selectionCriteria.ToString(), path.AbsolutePath.Replace('/', '\\'), archiveTargetPath, true);
        }
Exemplo n.º 7
0
        public void GetAbsolutePathTest()
        {
            BasePath path = new BasePath("C:/code/");
            RelativePath relPath = new RelativePath("test/", path);
            Assert.AreEqual("C:/code/test/", relPath.AbsolutePath, "Absolute path.");

            relPath = new RelativePath("../test/", path);
            Assert.AreEqual("C:/test/", relPath.AbsolutePath, "Absolute path 2.");
        }
Exemplo n.º 8
0
 public void ConstructFromAbsolutePathTest()
 {
     BasePath path = new BasePath("C:/code/");
     RelativePath relPath = new RelativePath("C:/code/test/", path);
     Assert.AreEqual("test/", relPath.RelativePathComponent, "Relative path from constructor when supplying absolute path.");
 }
Exemplo n.º 9
0
 public void CombineTest()
 {
     RelativePath path = new RelativePath("code/", new BasePath("C:/"));
     IPath newPath = path.Combine("../test/");
     Assert.AreEqual("C:/test/", newPath.AbsolutePath, "New path should include concatenated directory");
 }
Exemplo n.º 10
0
        public void SetRelativeToTest()
        {
            BasePath path = new BasePath("C:/code/");
            BasePath path2 = new BasePath("C:/path/");
            RelativePath relPath = new RelativePath("test/", path);
            Assert.AreEqual("C:/code/test/", relPath.AbsolutePath, "Initial path.");

            relPath.RelativeTo = path2;
            Assert.AreEqual("C:/path/test/", relPath.AbsolutePath, "Absolute path after changing RelativeTo.");

            try
            {
                relPath.RelativeTo = null;
                Assert.Fail("Setting RelativeTo to null should throw ArgumentNullException.");
            }
            catch (ArgumentNullException e)
            {
                Assert.IsNotNull(e);
            }
        }
Exemplo n.º 11
0
        public void SetRelativeComponentTest()
        {
            BasePath path = new BasePath("C:/code/");
            RelativePath relPath = new RelativePath("test/", path);
            Assert.AreEqual("C:/code/test/", relPath.AbsolutePath, "Initial path.");

            relPath.RelativePathComponent = "newPath/test/";
            Assert.AreEqual("newPath/test/", relPath.RelativePathComponent, "Changed RelativePathComponent.");
            Assert.AreEqual("C:/code/newPath/test/", relPath.AbsolutePath, "Absolute path after changing RelativePathComponent.");

            try
            {
                relPath.RelativePathComponent = null;
                Assert.Fail("Setting RelativePathComponent to null should throw ArgumentNullException.");
            }
            catch (ArgumentNullException e)
            {
                Assert.IsNotNull(e);
            }
        }
Exemplo n.º 12
0
        public void SetAbsolutePathTest()
        {
            BasePath path = new BasePath("C:/code/");
            RelativePath relPath = new RelativePath("test/", path);
            Assert.AreEqual("C:/code/test/", relPath.AbsolutePath, "Initial path.");

            relPath.AbsolutePath = "C:/test/newPath/";
            Assert.AreEqual("C:/test/newPath/", relPath.AbsolutePath, "Changed path.");
            Assert.AreEqual("../test/newPath/", relPath.RelativePathComponent, "Changed relativePathComponent.");
        }
Exemplo n.º 13
0
 public void PathComponentsTest()
 {
     BasePath root = new BasePath("C:/code/");
     RelativePath path = new RelativePath("test/", root);
     Assert.AreEqual(3, path.PathComponents.Count, "PathComponents count.");
     Assert.AreEqual("C:", path.PathComponents[0], "First PathComponent.");
     Assert.AreEqual("code", path.PathComponents[1], "Second PathComponent.");
     Assert.AreEqual("test", path.PathComponents[2], "Third PathComponent.");
 }