Beispiel #1
0
        /// <summary>
        /// Adds the given file path.  File path can be absolute, or relative to the package location.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <exception cref="System.ArgumentException">Thrown if path is empty.</exception>
        public void AddFile(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("Path not be empty.");
            }

            path = path.Replace('/', '\\');
            string relativePath = path;

            // Validate that the file exists:
            if (System.IO.Path.IsPathRooted(path))
            {
                System.IO.FileInfo info = new FileInfo(path);
                path = info.FullName;
                if (path.StartsWith(Location))
                {
                    relativePath = ".\\" + path.Remove(0, Location.Length + 1);
                }
                else
                {
                    throw new ArgumentException("An path must be within the Package's location.");
                }
            }

            if (!System.IO.File.Exists(System.IO.Path.Combine(Location, relativePath)))
            {
                throw new ArgumentException("File must exist.");
            }

            var file = new PackageFile(this, relativePath);

            m_files.Add(file);
        }
Beispiel #2
0
        private void ReadPackage(XPathNavigator nav)
        {
            var  id = nav.SelectSingleNode("./Package/@ID");
            Guid guid;

            if (id == null || Guid.TryParse(id.Value, out guid) == false)
            {
                throw new System.Xml.Schema.XmlSchemaException();
            }
            ID = id.Value;

            //bool isPacked = false;
            //var isPackedNode = nav.SelectSingleNode("./Package/@IsPacked");
            //if (isPackedNode != null)
            //{
            //    isPacked = true;
            //}

            Name = GetValue("./Package/@Name", nav);

            var filesXml = nav.Select("./Package/DataFiles/PackageFile");

            while (filesXml.MoveNext())
            {
                PackageFile file = new PackageFile(this, filesXml.Current);
                m_files.Add(file);
            }

            var references    = new List <IPackageReference>();
            var referencesXml = nav.Select("./Package/References/PackageReference");

            while (referencesXml.MoveNext())
            {
                var serializer             = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeof(PackageSystem.PackageReference), Type.EmptyTypes);
                PackageReference reference = (PackageReference)serializer.Deserialize(referencesXml.Current.ReadSubtree());
                references.Add(reference);
            }
            m_references = references;

            var componentLocations    = new List <string>();
            var componentLocationsXml = nav.Select("./Package/ComponentLocations/Location");

            while (componentLocationsXml.MoveNext())
            {
                componentLocations.Add(componentLocationsXml.Current.Value);
            }
            m_componentLocations = componentLocations;

            var typeLocations    = new List <string>();
            var typeLocationsXml = nav.Select("./Package/TypeLocations/Location");

            while (typeLocationsXml.MoveNext())
            {
                typeLocations.Add(typeLocationsXml.Current.Value);
            }
            m_typeLocations = typeLocations;
        }
Beispiel #3
0
        /// <summary>
        /// Adds the given file path.  File path can be absolute, or relative to the package location.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <exception cref="System.ArgumentException">Thrown if path is empty.</exception>
        public void AddFile(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("Path not be empty.");
            }

            // HERZUM SPRINT 3.1 TLAB-179
            if (TraceLabSDK.RuntimeInfo.OperatingSystem == RuntimeInfo.OS.Windows)
            {
                // END // HERZUM SPRINT 3.1 TLAB-179
                path = path.Replace('/', '\\');
            }
            string relativePath = path;

            // Validate that the file exists:
            if (System.IO.Path.IsPathRooted(path))
            {
                System.IO.FileInfo info = new FileInfo(path);
                path = info.FullName;
                if (path.StartsWith(Location))
                {
                    // HERZUM SPRINT 3.1 TLAB-179
                    // relativePath = ".\\" + path.Remove(0, Location.Length + 1);
                    if (TraceLabSDK.RuntimeInfo.OperatingSystem == RuntimeInfo.OS.Windows)
                    {
                        relativePath = ".\\" + path.Remove(0, Location.Length + 1);
                    }
                    else
                    {
                        relativePath = "./" + path.Remove(0, Location.Length + 1);
                    }
                    // END HERZUM SPRINT 3.1 TLAB-179
                }
                else
                {
                    throw new ArgumentException("An path must be within the Package's location.");
                }
            }

            if (!System.IO.File.Exists(System.IO.Path.Combine(Location, relativePath)))
            {
                throw new ArgumentException("File must exist.");
            }

            var file = new PackageFile(this, relativePath);

            m_files.Add(file);
        }
Beispiel #4
0
 internal string GetAbsolutePath(PackageFile file)
 {
     return(System.IO.Path.Combine(Location, file.Path));
 }
Beispiel #5
0
        public void RemoveFile(IPackageFile file)
        {
            PackageFile realFile = file as PackageFile;

            m_files.Remove(realFile);
        }
 internal string GetAbsolutePath(PackageFile file)
 {
     return System.IO.Path.Combine(Location, file.Path);
 }
        private void ReadPackage(XPathNavigator nav)
        {
            var id = nav.SelectSingleNode("./Package/@ID");
            Guid guid;
            if (id == null || Guid.TryParse(id.Value, out guid) == false)
            {
                throw new System.Xml.Schema.XmlSchemaException();
            }
            ID = id.Value;

            //bool isPacked = false;
            //var isPackedNode = nav.SelectSingleNode("./Package/@IsPacked");
            //if (isPackedNode != null)
            //{
            //    isPacked = true;
            //}

            Name = GetValue("./Package/@Name", nav);

            var filesXml = nav.Select("./Package/DataFiles/PackageFile");
            while (filesXml.MoveNext())
            {
                PackageFile file = new PackageFile(this, filesXml.Current);
                m_files.Add(file);
            }

            var references = new List<IPackageReference>();
            var referencesXml = nav.Select("./Package/References/PackageReference");
            while (referencesXml.MoveNext())
            {
                var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeof(PackageSystem.PackageReference), Type.EmptyTypes);
                PackageReference reference = (PackageReference)serializer.Deserialize(referencesXml.Current.ReadSubtree());
                references.Add(reference);
            }
            m_references = references;

            var componentLocations = new List<string>();
            var componentLocationsXml = nav.Select("./Package/ComponentLocations/Location");
            while (componentLocationsXml.MoveNext())
            {
                componentLocations.Add(componentLocationsXml.Current.Value);
            }
            m_componentLocations = componentLocations;

            var typeLocations = new List<string>();
            var typeLocationsXml = nav.Select("./Package/TypeLocations/Location");
            while (typeLocationsXml.MoveNext())
            {
                typeLocations.Add(typeLocationsXml.Current.Value);
            }
            m_typeLocations = typeLocations;
        }
        /// <summary>
        /// Adds the given file path.  File path can be absolute, or relative to the package location.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <exception cref="System.ArgumentException">Thrown if path is empty.</exception>
        public void AddFile(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
                throw new ArgumentException("Path not be empty.");

            path = path.Replace('/', '\\');
            string relativePath = path;
            // Validate that the file exists:
            if (System.IO.Path.IsPathRooted(path))
            {
                System.IO.FileInfo info = new FileInfo(path);
                path = info.FullName;
                if (path.StartsWith(Location))
                {
                    relativePath = ".\\" + path.Remove(0, Location.Length + 1);
                }
                else
                {
                    throw new ArgumentException("An path must be within the Package's location.");
                }
            }

            if (!System.IO.File.Exists(System.IO.Path.Combine(Location, relativePath)))
            {
                throw new ArgumentException("File must exist.");
            }

            var file = new PackageFile(this, relativePath);
            m_files.Add(file);
        }
Beispiel #9
0
        /// <summary>
        /// Adds the given file path.  File path can be absolute, or relative to the package location.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <exception cref="System.ArgumentException">Thrown if path is empty.</exception>
        public void AddFile(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
                throw new ArgumentException("Path not be empty.");

            // HERZUM SPRINT 3.1 TLAB-179
            if (TraceLabSDK.RuntimeInfo.OperatingSystem == RuntimeInfo.OS.Windows)
            // END // HERZUM SPRINT 3.1 TLAB-179
                path = path.Replace('/', '\\');
            string relativePath = path;
            // Validate that the file exists:
            if (System.IO.Path.IsPathRooted(path))
            {
                System.IO.FileInfo info = new FileInfo(path);
                path = info.FullName;
                if (path.StartsWith(Location))
                {
                    // HERZUM SPRINT 3.1 TLAB-179
                    // relativePath = ".\\" + path.Remove(0, Location.Length + 1);
                    if (TraceLabSDK.RuntimeInfo.OperatingSystem == RuntimeInfo.OS.Windows)
                        relativePath = ".\\" + path.Remove(0, Location.Length + 1);
                    else
                        relativePath = "./" + path.Remove(0, Location.Length + 1);
                    // END HERZUM SPRINT 3.1 TLAB-179
                }
                else
                {
                    throw new ArgumentException("An path must be within the Package's location.");
                }
            }

            if (!System.IO.File.Exists(System.IO.Path.Combine(Location, relativePath)))
            {
                throw new ArgumentException("File must exist.");
            }

            var file = new PackageFile(this, relativePath);
            m_files.Add(file);
        }
        public void PackAndUnpackFileTest()
        {
            // TODO: Pack file, unpack file, verify file is same.
            IPackage ownerPackage = TempPackage;
            string path = TempFileRelative; // TODO: Initialize to an appropriate value
            PackageFile target = new PackageFile(ownerPackage, path);

            target.PackFile();
            Assert.IsTrue(target.IsCompressed);
            Assert.IsNotNull(target.CompressedHash, "Compressed hash should have been computed");
            Assert.IsNotNull(target.Data, "Data should be valid by now.");
            Assert.AreNotEqual(Int64.MinValue, target.CompressedSize, "Compressed size should be valid, since the file has been compressed.");

            System.IO.File.Delete(TempFile + ".bak");
            System.IO.File.Copy(TempFile, TempFile + ".bak");
            try
            {
                System.IO.File.Delete(TempFile);
                Assert.IsFalse(System.IO.File.Exists(TempFile));
                target.Unpack();
                Assert.IsTrue(System.IO.File.Exists(TempFile));
                var backup = System.IO.File.ReadAllBytes(TempFile + ".bak");
                var unpacked = System.IO.File.ReadAllBytes(TempFile);

                Assert.IsTrue(backup.SequenceEqual(unpacked));

                Assert.IsFalse(target.IsCompressed, "File has been unpacked.");
                Assert.IsNotNull(target.CompressedHash, "Compressed hash should have been computed");
                Assert.AreNotEqual(Int64.MinValue, target.CompressedSize, "Compressed size should be valid, since the file has been compressed at least once.");
                Assert.IsNull(target.Data, "Data is no longer valid - file has been dumped to disk.");

            }
            finally
            {
                System.IO.File.Delete(TempFile + ".bak");
            }
        }
        public void PackageFileConstructorTest1()
        {
            Guid id = Guid.NewGuid();
            IPackage ownerPackage = TempPackage;
            string path = TempFileRelative; // TODO: Initialize to an appropriate value
            long uncompSize = 500;
            long compSize = 156;
            string uncomHash = "AAAFC";
            string compHash = "FFCAB";
            string data = "FFgK8sfee";

            PackageFile target = new PackageFile(ownerPackage, path, id, uncompSize, uncomHash, compSize, compHash, data);
            Assert.AreEqual(id.ToString("D"), target.ID, "Created file should have the ID it was created with.");
            Assert.AreEqual(path, target.Path, "Path does not equal what was used to create the file");
            Assert.AreEqual(true, target.IsCompressed, "Created with compressed data, file should be compressed");
            Assert.AreEqual(uncompSize, target.UncompressedSize, "File must have a non-negative size");
            Assert.AreEqual(compSize, target.CompressedSize, "Compressed size was passed in.");
            Assert.AreEqual(uncomHash, target.UncompressedHash, "Uncompressed hash was passed in");
            Assert.AreEqual(compHash, target.CompressedHash, "Compressed hash was passed in");
            Assert.AreEqual(data, target.Data, "Data shouldn't be valid yet.");
        }
 public void PackageFileConstructorTest()
 {
     IPackage ownerPackage = TempPackage;
     string path = TempFileRelative; // TODO: Initialize to an appropriate value
     PackageFile target = new PackageFile(ownerPackage, path);
     Assert.IsFalse(string.IsNullOrWhiteSpace(target.ID), "Created file should have an ID");
     Assert.AreEqual(path, target.Path, "Path does not equal what was used to create the file");
     Assert.IsFalse(target.IsCompressed, "Created file should not be compressed");
     Assert.AreNotEqual(Int64.MinValue, target.UncompressedSize, "File must have a non-negative size");
     Assert.AreEqual(Int64.MinValue, target.CompressedSize, "Compressed size isn't valid, as the file hasn't been compressed yet.");
     Assert.IsNotNull(target.UncompressedHash, "Uncompressed has should have been computed");
     Assert.IsNull(target.CompressedHash, "Compressed hash shouldn't have been computed");
     Assert.IsNull(target.Data, "Data shouldn't be valid yet.");
 }
 public void PackageFileConstructorFileDoesNotExist()
 {
     IPackage ownerPackage = TempPackage; // TODO: Initialize to an appropriate value
     string path = "fdsjhfsadjk.fdf"; // TODO: Initialize to an appropriate value
     PackageFile target = new PackageFile(ownerPackage, path);
     Assert.Fail("A FileNotFound exception should have been thrown");
 }
 public void PackageFileConstructorNullPath()
 {
     IPackage ownerPackage = new MockPackage("someLocation");
     string path = string.Empty;
     PackageFile target = new PackageFile(ownerPackage, path);
     Assert.Fail("A ArgumentNullException exception should have been thrown");
 }
 public void PackageFileConstructorNullPackage()
 {
     IPackage ownerPackage = null;
     string path = "sfjahsd/dsfe.data";
     PackageFile target = new PackageFile(ownerPackage, path);
     Assert.Fail("A ArgumentNullException exception should have been thrown");
 }