private void CreateBasicDirectoryProperty()
        {
            string name = "MyDirectory";

            _property  = new DirectoryProperty(name);
            _testblock = new byte[128];
            int index = 0;

            for (; index < 0x40; index++)
            {
                _testblock[index] = (byte)0;
            }
            int limit = Math.Min(31, name.Length);

            _testblock[index++] = (byte)(2 * (limit + 1));
            _testblock[index++] = (byte)0;
            _testblock[index++] = (byte)1;
            _testblock[index++] = (byte)1;
            for (; index < 0x50; index++)
            {
                _testblock[index] = (byte)0xff;
            }
            for (; index < 0x80; index++)
            {
                _testblock[index] = (byte)0;
            }
            byte[] name_bytes = Encoding.UTF8.GetBytes(name);

            for (index = 0; index < limit; index++)
            {
                _testblock[index * 2] = name_bytes[index];
            }
        }
Example #2
0
        public void TestConstructor()
        {
            DirectoryProperty property1 = new DirectoryProperty("directory");
            RawDataBlock[] rawBlocks = new RawDataBlock[4];
            MemoryStream stream =
                new MemoryStream(new byte[2048]);

            for (int j = 0; j < 4; j++)
            {
                rawBlocks[j] = new RawDataBlock(stream);
            }
            POIFSDocument document = new POIFSDocument("document", rawBlocks,
                                             2000);
            DocumentProperty property2 = document.DocumentProperty;
            DirectoryNode parent = new DirectoryNode(property1, (POIFSFileSystem)null, null);
            DocumentNode node = new DocumentNode(property2, parent);

            // Verify we can retrieve the document
            Assert.AreEqual(property2.Document, node.Document);

            // Verify we can Get the size
            Assert.AreEqual(property2.Size, node.Size);

            // Verify isDocumentEntry returns true
            Assert.IsTrue(node.IsDocumentEntry);

            // Verify isDirectoryEntry returns false
            Assert.IsTrue(!node.IsDirectoryEntry);

            // Verify GetName behaves correctly
            Assert.AreEqual(property2.Name, node.Name);

            // Verify GetParent behaves correctly
            Assert.AreEqual(parent, node.Parent);
        }
Example #3
0
        public void TestNonEmptyConstructor()
        {
            DirectoryProperty property1 = new DirectoryProperty("parent");
            DirectoryProperty property2 = new DirectoryProperty("child1");

            property1.AddChild(property2);
            property1.AddChild(new DocumentProperty("child2", 2000));
            property2.AddChild(new DocumentProperty("child3", 30000));
            DirectoryNode node = new DirectoryNode(property1,
                                                   new POIFSFileSystem(), null);

            // Verify that GetEntries behaves correctly
            int         count = 0;
            IEnumerator iter  = node.Entries;

            while (iter.MoveNext())
            {
                count++;
                //iter.Current;
            }
            Assert.AreEqual(2, count);

            // Verify behavior of IsEmpty
            Assert.IsTrue(!node.IsEmpty);

            // Verify behavior of EntryCount
            Assert.AreEqual(2, node.EntryCount);

            // Verify behavior of Entry
            DirectoryNode child1 = (DirectoryNode)node.GetEntry("child1");

            child1.GetEntry("child3");
            node.GetEntry("child2");
            try
            {
                node.GetEntry("child3");
                Assert.Fail("Should have caught FileNotFoundException");
            }
            catch (FileNotFoundException)
            {
                // as expected
            }

            // Verify behavior of isDirectoryEntry
            Assert.IsTrue(node.IsDirectoryEntry);

            // Verify behavior of GetName
            Assert.AreEqual(property1.Name, node.Name);

            // Verify behavior of isDocumentEntry
            Assert.IsTrue(!node.IsDocumentEntry);

            // Verify behavior of GetParent
            Assert.IsNull(node.Parent);
        }
Example #4
0
        /// <summary>
        /// Create a new DirectoryEntry
        /// </summary>
        /// <param name="name">the name of the new DirectoryEntry</param>
        /// <returns>the name of the new DirectoryEntry</returns>
        public DirectoryEntry CreateDirectory(String name)
        {
            DirectoryProperty property = new DirectoryProperty(name);
            DirectoryNode     rval     = new DirectoryNode(property, _filesystem,
                                                           this);

            (( DirectoryProperty )Property).AddChild(property);
            _filesystem.AddDirectory(property);
            _entries[name] = rval;
            return(rval);
        }
Example #5
0
        public void TestEmptyConstructor()
        {
            POIFSFileSystem   fs        = new POIFSFileSystem();
            DirectoryProperty property1 = new DirectoryProperty("parent");
            DirectoryProperty property2 = new DirectoryProperty("child");
            DirectoryNode     parent    = new DirectoryNode(property1, fs, null);
            DirectoryNode     node      = new DirectoryNode(property2, fs,
                                                            parent);

            Assert.AreEqual(0, parent.Path.Length);
            Assert.AreEqual(1, node.Path.Length);
            Assert.AreEqual("child", node.Path.GetComponent(0));

            // Verify that GetEntries behaves correctly
            int         count = 0;
            IEnumerator iter  = node.Entries;

            while (iter.MoveNext())
            {
                count++;
                //iter.Current;
            }
            Assert.AreEqual(0, count);

            // Verify behavior of IsEmpty
            Assert.IsTrue(node.IsEmpty);

            // Verify behavior of EntryCount
            Assert.AreEqual(0, node.EntryCount);

            // Verify behavior of Entry
            try
            {
                node.GetEntry("foo");
                Assert.Fail("Should have caught FileNotFoundException");
            }
            catch (FileNotFoundException)
            {
                // as expected
            }

            // Verify behavior of isDirectoryEntry
            Assert.IsTrue(node.IsDirectoryEntry);

            // Verify behavior of GetName
            Assert.AreEqual(property2.Name, node.Name);

            // Verify behavior of isDocumentEntry
            Assert.IsTrue(!node.IsDocumentEntry);

            // Verify behavior of GetParent
            Assert.AreEqual(parent, node.Parent);
        }
Example #6
0
        public void TestEmptyConstructor()
        {
            POIFSFileSystem fs = new POIFSFileSystem();
            DirectoryProperty property1 = new DirectoryProperty("parent");
            DirectoryProperty property2 = new DirectoryProperty("child");
            DirectoryNode parent = new DirectoryNode(property1, fs, null);
            DirectoryNode node = new DirectoryNode(property2, fs, parent);

            Assert.AreEqual(0, parent.Path.Length);
            Assert.AreEqual(1, node.Path.Length);
            Assert.AreEqual("child", node.Path.GetComponent(0));

            // Verify that GetEntries behaves correctly
            int count = 0;
            IEnumerator iter = node.Entries;

            while (iter.MoveNext())
            {
                count++;
            }
            Assert.AreEqual(0, count);

            // Verify behavior of IsEmpty
            Assert.IsTrue(node.IsEmpty);

            // Verify behavior of EntryCount
            Assert.AreEqual(0, node.EntryCount);

            // Verify behavior of Entry
            try
            {
                node.GetEntry("foo");
                Assert.Fail("Should have caught FileNotFoundException");
            }
            catch (FileNotFoundException )
            {

                // as expected
            }

            // Verify behavior of isDirectoryEntry
            Assert.IsTrue(node.IsDirectoryEntry);

            // Verify behavior of GetName
            Assert.AreEqual(property2.Name, node.Name);

            // Verify behavior of isDocumentEntry
            Assert.IsTrue(!node.IsDocumentEntry);

            // Verify behavior of GetParent
            Assert.AreEqual(parent, node.Parent);
        }
 private static void CheckPropertyCorrectDefined(
     DirectoryProperty property,
     string name,
     DirectoryPropertySyntax syntax,
     bool multivalued,
     Type notionalType,
     Type directoryType)
 {
     property.Name.Should().Be(name);
     property.Syntax.Should().Be(syntax);
     property.Multivalued.Should().Be(multivalued);
     property.NotionalType.IsEquivalentTo(notionalType).Should().BeTrue();
     property.DirectoryType.IsEquivalentTo(directoryType).Should().BeTrue();
 }
Example #8
0
        protected void PopulatePropertyTree(DirectoryProperty root)
        {
            try
            {
                int index = root.ChildIndex;

                if (!Property.IsValidIndex(index))
                    return;

                Stack<Property> children = new Stack<Property>();

                children.Push(_properties[index]);

                while (children.Count != 0)
                {
                    Property property = children.Pop();
                    if (property == null)
                    {
                        // unknown / unsupported / corrupted property, skip
                        continue;
                    }
                    root.AddChild(property);

                    if (property.IsDirectory)
                    {
                        PopulatePropertyTree((DirectoryProperty)property);
                    }

                    index = property.PreviousChildIndex;
                    if (Property.IsValidIndex(index))
                    {
                        children.Push(_properties[index]);
                    }

                    index = property.NextChildIndex;
                    if (Property.IsValidIndex(index))
                    {
                        children.Push(_properties[index]);
                    }
                }

            }
            catch (IOException ex)
            {
                throw ex;
            }
        }
Example #9
0
        private DirectoryNode(DirectoryProperty property,
                              DirectoryNode parent,
                              POIFSFileSystem oFileSystem,
                              NPOIFSFileSystem nFileSystem)
            : base(property, parent)
        {
            this._oFilesSystem = oFileSystem;
            this._nFilesSystem = nFileSystem;

            if (parent == null)
            {
                _path = new POIFSDocumentPath();
            }
            else
            {
                _path = new POIFSDocumentPath(parent._path, new string[] { property.Name });
            }

            _byname  = new Dictionary <string, Entry>();
            _entries = new List <Entry>();
            IEnumerator <Property> iter = property.Children;

            while (iter.MoveNext())
            {
                Property child     = iter.Current;
                Entry    childNode = null;

                if (child.IsDirectory)
                {
                    DirectoryProperty childDir = (DirectoryProperty)child;
                    if (_oFilesSystem != null)
                    {
                        childNode = new DirectoryNode(childDir, _oFilesSystem, this);
                    }
                    else
                    {
                        childNode = new DirectoryNode(childDir, _nFilesSystem, this);
                    }
                }
                else
                {
                    childNode = new DocumentNode((DocumentProperty)child, this);
                }
                _entries.Add(childNode);
                _byname.Add(childNode.Name, childNode);
            }
        }
Example #10
0
        /**
         * @return array of properties Read from ROOT._VBA_PROJECT_CUR.VBA node
         */
        protected Property[] GetVBAProperties(POIFSFileSystem fs)
        {
            String _VBA_PROJECT_CUR = "_VBA_PROJECT_CUR";
            String VBA = "VBA";

            DirectoryEntry root        = fs.Root;
            DirectoryEntry vba_project = (DirectoryEntry)root.GetEntry(_VBA_PROJECT_CUR);

            DirectoryNode     vba = (DirectoryNode)vba_project.GetEntry(VBA);
            DirectoryProperty p   = (DirectoryProperty)vba.Property;

            ArrayList lst = new ArrayList();

            for (IEnumerator it = p.Children; it.MoveNext();)
            {
                Property ch = (Property)it.Current;
                lst.Add(ch);
            }
            return((Property[])lst.ToArray(typeof(Property)));
        }
Example #11
0
        /// <summary>
        /// Create a new DirectoryEntry
        /// </summary>
        /// <param name="name">the name of the new DirectoryEntry</param>
        /// <returns>the name of the new DirectoryEntry</returns>
        public DirectoryEntry CreateDirectory(String name)
        {
            DirectoryProperty property = new DirectoryProperty(name);
            DirectoryNode     rval;

            if (_oFilesSystem != null)
            {
                rval = new DirectoryNode(property, _oFilesSystem, this);
                _oFilesSystem.AddDirectory(property);
            }
            else
            {
                rval = new DirectoryNode(property, _nFilesSystem, this);
                _nFilesSystem.AddDirectory(property);
            }

            ((DirectoryProperty)Property).AddChild(property);
            _entries.Add(rval);
            _byname[name] = rval;

            return(rval);
        }
        private void VerifyReadingProperty(int index, byte[] input, int offset,
                                           string name)
        {
            DirectoryProperty property = new DirectoryProperty(index, input,
                                                               offset);
            MemoryStream stream = new MemoryStream(128);

            byte[] expected = new byte[128];

            Array.Copy(input, offset, expected, 0, 128);
            property.WriteData(stream);
            byte[] output = stream.ToArray();

            Assert.AreEqual(128, output.Length);
            for (int j = 0; j < 128; j++)
            {
                Assert.AreEqual(expected[j],
                                output[j], "mismatch at offset " + j);
            }
            Assert.AreEqual(index, property.Index);
            Assert.AreEqual(name, property.Name);
            Assert.IsTrue(!property.Children.MoveNext());
        }
Example #13
0
        /// <summary>
        /// Create a DirectoryNode. This method Is not public by design; it
        /// Is intended strictly for the internal use of this package
        /// </summary>
        /// <param name="property">the DirectoryProperty for this DirectoryEntry</param>
        /// <param name="filesystem">the POIFSFileSystem we belong to</param>
        /// <param name="parent">the parent of this entry</param>
        public DirectoryNode(DirectoryProperty property,
                             POIFSFileSystem filesystem,
                             DirectoryNode parent) : base(property, parent)
        {
            if (parent == null)
            {
                _path = new POIFSDocumentPath();
            }
            else
            {
                _path = new POIFSDocumentPath(parent._path, new String[]
                {
                    property.Name
                });
            }
            _filesystem = filesystem;
            _entries    = new Hashtable();
            IEnumerator iter = property.Children;

            while (iter.MoveNext())
            {
                Property child     = ( Property )iter.Current;
                Entry    childNode = null;

                if (child.IsDirectory)
                {
                    childNode = new DirectoryNode(( DirectoryProperty )child,
                                                  _filesystem, this);
                }
                else
                {
                    childNode = new DocumentNode(( DocumentProperty )child,
                                                 this);
                }
                _entries[childNode.Name] = childNode;
            }
        }
Example #14
0
        public void TestConstructor()
        {
            DirectoryProperty property1 = new DirectoryProperty("directory");

            RawDataBlock[] rawBlocks = new RawDataBlock[4];
            MemoryStream   stream    =
                new MemoryStream(new byte[2048]);

            for (int j = 0; j < 4; j++)
            {
                rawBlocks[j] = new RawDataBlock(stream);
            }
            OPOIFSDocument document = new OPOIFSDocument("document", rawBlocks,
                                                         2000);
            DocumentProperty property2 = document.DocumentProperty;
            DirectoryNode    parent    = new DirectoryNode(property1, (POIFSFileSystem)null, null);
            DocumentNode     node      = new DocumentNode(property2, parent);

            // Verify we can retrieve the document
            Assert.AreEqual(property2.Document, node.Document);

            // Verify we can Get the size
            Assert.AreEqual(property2.Size, node.Size);

            // Verify isDocumentEntry returns true
            Assert.IsTrue(node.IsDocumentEntry);

            // Verify isDirectoryEntry returns false
            Assert.IsTrue(!node.IsDirectoryEntry);

            // Verify GetName behaves correctly
            Assert.AreEqual(property2.Name, node.Name);

            // Verify GetParent behaves correctly
            Assert.AreEqual(parent, node.Parent);
        }
        private void VerifyReadingProperty(int index, byte[] input, int offset,
                                           String name)
        {
            DirectoryProperty property = new DirectoryProperty(index, input,
                                                 offset);
            MemoryStream stream = new MemoryStream(128);
            byte[] expected = new byte[128];

            Array.Copy(input, offset, expected, 0, 128);
            property.WriteData(stream);
            byte[] output = stream.ToArray();

            Assert.AreEqual(128, output.Length);
            for (int j = 0; j < 128; j++)
            {
                Assert.AreEqual(expected[j],
                             output[j], "mismatch at offset " + j);
            }
            Assert.AreEqual(index, property.Index);
            Assert.AreEqual(name, property.Name);
            Assert.IsTrue(!property.Children.MoveNext());
        }
        private void CreateBasicDirectoryProperty()
        {
            String name = "MyDirectory";

            _property = new DirectoryProperty(name);
            _testblock = new byte[128];
            int index = 0;

            for (; index < 0x40; index++)
            {
                _testblock[index] = (byte)0;
            }
            int limit = Math.Min(31, name.Length);

            _testblock[index++] = (byte)(2 * (limit + 1));
            _testblock[index++] = (byte)0;
            _testblock[index++] = (byte)1;
            _testblock[index++] = (byte)1;
            for (; index < 0x50; index++)
            {
                _testblock[index] = (byte)0xff;
            }
            for (; index < 0x80; index++)
            {
                _testblock[index] = (byte)0;
            }
            byte[] name_bytes = Encoding.UTF8.GetBytes(name);

            for (index = 0; index < limit; index++)
            {
                _testblock[index * 2] = name_bytes[index];
            }
        }
Example #17
0
        public void TestNonEmptyConstructor()
        {
            DirectoryProperty property1 = new DirectoryProperty("parent");
            DirectoryProperty property2 = new DirectoryProperty("child1");

            property1.AddChild(property2);
            property1.AddChild(new DocumentProperty("child2", 2000));
            property2.AddChild(new DocumentProperty("child3", 30000));
            DirectoryNode node = new DirectoryNode(property1, new POIFSFileSystem(), null);

            // Verify that GetEntries behaves correctly
            int count = 0;
            IEnumerator iter = node.Entries;

            while (iter.MoveNext())
            {
                count++;
                //iter.Current;
            }
            Assert.AreEqual(2, count);

            // Verify behavior of IsEmpty
            Assert.IsTrue(!node.IsEmpty);

            // Verify behavior of EntryCount
            Assert.AreEqual(2, node.EntryCount);

            // Verify behavior of Entry
            DirectoryNode child1 = (DirectoryNode)node.GetEntry("child1");

            child1.GetEntry("child3");
            node.GetEntry("child2");
            try
            {
                node.GetEntry("child3");
                Assert.Fail("Should have caught FileNotFoundException");
            }
            catch (FileNotFoundException)
            {

                // as expected
            }

            // Verify behavior of isDirectoryEntry
            Assert.IsTrue(node.IsDirectoryEntry);

            // Verify behavior of GetName
            Assert.AreEqual(property1.Name, node.Name);

            // Verify behavior of isDocumentEntry
            Assert.IsTrue(!node.IsDocumentEntry);

            // Verify behavior of GetParent
            Assert.IsNull(node.Parent);
        }
Example #18
0
 public DirectoryNode(DirectoryProperty property,
                      POIFSFileSystem fileSystem,
                      DirectoryNode parent)
     : this(property, parent, fileSystem, (NPOIFSFileSystem)null)
 {
 }
Example #19
0
 /// <summary>
 /// Create a DirectoryNode. This method Is not public by design; it
 /// Is intended strictly for the internal use of this package
 /// </summary>
 /// <param name="property">the DirectoryProperty for this DirectoryEntry</param>
 /// <param name="nFileSystem">the POIFSFileSystem we belong to</param>
 /// <param name="parent">the parent of this entry</param>
 public DirectoryNode(DirectoryProperty property,
                      NPOIFSFileSystem nFileSystem,
                      DirectoryNode parent)
     : this(property, parent, (POIFSFileSystem)null, nFileSystem)
 {
 }
Example #20
0
 /**
  * add a new DirectoryProperty to the FileSystem
  *
  * @param directory the DirectoryProperty being Added
  */
 public void AddDirectory(DirectoryProperty directory)
 {
     _property_table.AddProperty(directory);
 }
Example #21
0
 /// <summary>
 /// Add a new DirectoryProperty
 /// </summary>
 /// <param name="directory">The directory.</param>
 public void AddDirectory(DirectoryProperty directory)
 {
     _property_table.AddProperty(directory);
 }
 set => SetValue(DirectoryProperty, value);