示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Property"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 /// <param name="owner">The owner.</param>
 internal Property( string name, object value, PropertyStorage owner )
 {
     _id = Marshal.StringToCoTaskMemUni( name );
     _name = name;
     _propValue = value;
     _owner = owner;
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Property"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="name">The name.</param>
 /// <param name="value">The value.</param>
 /// <param name="owner">The owner.</param>
 internal Property( IntPtr id, string name, object value, PropertyStorage owner )
 {
     _id = id;
     _name = name;
     _propValue = value;
     _owner = owner;
 }
        /**
         * Writes outStream the property sets
         *
         * @exception IOException
         */
        private void writePropertySets()
        {
            byte[] propertySetStorage = new byte[BIG_BLOCK_SIZE * numRootEntryBlocks];

            int pos = 0;
            int[] mappings = null;

            // Build up the mappings array
            if (additionalPropertySets != null)
                {
                mappings = new int[numPropertySets];

                // Map the standard ones to the first four
                for (int i = 0; i < STANDARD_PROPERTY_SETS.Length; i++)
                    {
                    if (!standardPropertySets.ContainsKey(STANDARD_PROPERTY_SETS[i]))
                        {
                        //logger.warn("Standard property set " + STANDARD_PROPERTY_SETS[i] +
                        //            " not present in source file");
                        }
                    else
                        {
                        ReadPropertyStorage rps = standardPropertySets[STANDARD_PROPERTY_SETS[i]];

                        mappings[rps.number] = i;
                        }
                    }

                // Now go through the original ones
                int newMapping = STANDARD_PROPERTY_SETS.Length;
                foreach (ReadPropertyStorage rps in additionalPropertySets)
                    {
                    mappings[rps.number] = newMapping;
                    newMapping++;
                    }
                }

            int child = 0;
            int previous = 0;
            int next = 0;

            // Compute the size of the root property set
            int size = 0;

            if (additionalPropertySets != null)
                {
                // Workbook
                size += getBigBlocksRequired(requiredSize) * BIG_BLOCK_SIZE;

                // The two information blocks
                size += getBigBlocksRequired(SMALL_BLOCK_THRESHOLD) * BIG_BLOCK_SIZE;
                size += getBigBlocksRequired(SMALL_BLOCK_THRESHOLD) * BIG_BLOCK_SIZE;

                // Additional property sets
                foreach (ReadPropertyStorage rps in additionalPropertySets)
                    {
                    if (rps.propertyStorage.type != 1)
                        {
                        if (rps.propertyStorage.size >= SMALL_BLOCK_THRESHOLD)
                            size += getBigBlocksRequired(rps.propertyStorage.size) * BIG_BLOCK_SIZE;
                        else
                            size += getSmallBlocksRequired(rps.propertyStorage.size) * SMALL_BLOCK_SIZE;
                        }
                    }
                }

            // Set the root entry property set
            PropertyStorage ps = new PropertyStorage(ROOT_ENTRY_NAME);
            ps.setType(5);
            ps.setStartBlock(sbdStartBlock);
            ps.setSize(size);
            ps.setPrevious(-1);
            ps.setNext(-1);
            ps.setColour(0);

            child = 1;
            if (additionalPropertySets != null)
                {
                ReadPropertyStorage rps = standardPropertySets[ROOT_ENTRY_NAME];
                child = mappings[rps.propertyStorage.child];
                }
            ps.setChild(child);

            System.Array.Copy(ps.data, 0,
                             propertySetStorage, pos,
                             PROPERTY_STORAGE_BLOCK_SIZE);
            pos += PROPERTY_STORAGE_BLOCK_SIZE;

            // Set the workbook property set
            ps = new PropertyStorage(WORKBOOK_NAME);
            ps.setType(2);
            ps.setStartBlock(excelDataStartBlock);
            // start the excel data after immediately after this block
            ps.setSize(requiredSize);
            // always use a big block stream - none of that messing around
            // with small blocks

            previous = 3;
            next = -1;

            if (additionalPropertySets != null)
                {
                ReadPropertyStorage rps = standardPropertySets[WORKBOOK_NAME];
                previous = rps.propertyStorage.previous != -1 ? mappings[rps.propertyStorage.previous] : -1;
                next = rps.propertyStorage.next != -1 ? mappings[rps.propertyStorage.next] : -1;
                }

            ps.setPrevious(previous);
            ps.setNext(next);
            ps.setChild(-1);

            System.Array.Copy(ps.data, 0,
                             propertySetStorage, pos,
                             PROPERTY_STORAGE_BLOCK_SIZE);
            pos += PROPERTY_STORAGE_BLOCK_SIZE;

            // Set the summary information
            ps = new PropertyStorage(SUMMARY_INFORMATION_NAME);
            ps.setType(2);
            ps.setStartBlock(excelDataStartBlock + excelDataBlocks);
            ps.setSize(SMALL_BLOCK_THRESHOLD);

            previous = 1;
            next = 3;

            if (additionalPropertySets != null)
                {
                if (standardPropertySets.ContainsKey(SUMMARY_INFORMATION_NAME))
                    {
                    ReadPropertyStorage rps = standardPropertySets[SUMMARY_INFORMATION_NAME];
                    previous = rps.propertyStorage.previous != -1 ? mappings[rps.propertyStorage.previous] : -1;
                    next = rps.propertyStorage.next != -1 ? mappings[rps.propertyStorage.next] : -1;
                    }
                }

            ps.setPrevious(previous);
            ps.setNext(next);
            ps.setChild(-1);

            System.Array.Copy(ps.data, 0,
                             propertySetStorage, pos,
                             PROPERTY_STORAGE_BLOCK_SIZE);
            pos += PROPERTY_STORAGE_BLOCK_SIZE;

            // Set the document summary information
            ps = new PropertyStorage(DOCUMENT_SUMMARY_INFORMATION_NAME);
            ps.setType(2);
            ps.setStartBlock(excelDataStartBlock + excelDataBlocks + 8);
            ps.setSize(SMALL_BLOCK_THRESHOLD);
            ps.setPrevious(-1);
            ps.setNext(-1);
            ps.setChild(-1);

            System.Array.Copy(ps.data, 0,
                             propertySetStorage, pos,
                             PROPERTY_STORAGE_BLOCK_SIZE);
            pos += PROPERTY_STORAGE_BLOCK_SIZE;

            // Write outStream the additional property sets
            if (additionalPropertySets == null)
                {
                outStream.Write(propertySetStorage,0,propertySetStorage.Length);
                return;
                }

            int bigBlock = excelDataStartBlock + excelDataBlocks + 16;
            int smallBlock = 0;

            foreach (ReadPropertyStorage rps in additionalPropertySets)
                {
                int block = rps.data.Length > SMALL_BLOCK_THRESHOLD ? bigBlock : smallBlock;

                ps = new PropertyStorage(rps.propertyStorage.name);
                ps.setType(rps.propertyStorage.type);
                ps.setStartBlock(block);
                ps.setSize(rps.propertyStorage.size);
                //      ps.setColour(rps.propertyStorage.colour);

                previous = rps.propertyStorage.previous != -1 ? mappings[rps.propertyStorage.previous] : -1;
                next = rps.propertyStorage.next != -1 ? mappings[rps.propertyStorage.next] : -1;
                child = rps.propertyStorage.child != -1 ? mappings[rps.propertyStorage.child] : -1;

                ps.setPrevious(previous);
                ps.setNext(next);
                ps.setChild(child);

                System.Array.Copy(ps.data, 0,
                                 propertySetStorage, pos,
                                 PROPERTY_STORAGE_BLOCK_SIZE);
                pos += PROPERTY_STORAGE_BLOCK_SIZE;

                if (rps.data.Length > SMALL_BLOCK_THRESHOLD)
                    bigBlock += getBigBlocksRequired(rps.data.Length);
                else
                    smallBlock += getSmallBlocksRequired(rps.data.Length);
                }

            outStream.Write(propertySetStorage,0,propertySetStorage.Length);
        }
 public ReadPropertyStorage(PropertyStorage ps, byte[] d, int n)
 {
     propertyStorage = ps;
     data = d;
     number = n;
 }
示例#5
0
        public void Dispose()
        {
            Events.Fire("OnDispose");

            Dependencies = null;
            Filename = null;
            Icons = null;
            Info = null;
            ItemTemplates = null;
            ProjectTemplates = null;
            Properties = null;
            _engine = null;
        }
示例#6
0
文件: Plugin.cs 项目: MyvarHD/OpenIDE
 public void Dispose()
 {
     Dependencies = null;
     Filename = null;
     Highlightings = null;
     Icons = null;
     Info = null;
     ItemTemplates = null;
     Language = null;
     ProjectTemplates = null;
     Properties = null;
     _engine = null;
 }
        /**
         * Build up the resultant stream using the small blocks
         * @param ps the property storage
         * @return  the data
         * @exception BiffException
         */
        private byte[] getSmallBlockStream(PropertyStorage ps)
        {
            byte[] rootdata = readData(rootEntryPropertyStorage.startBlock);
            byte[] sbdata = new byte[0];

            int block = ps.startBlock;
            int pos = 0;

            int blockCount = 0;
            for (; blockCount <= smallBlockChain.Length && block != -2; blockCount++)
                {
                // grow the array
                byte[] olddata = sbdata;
                sbdata = new byte[olddata.Length + SMALL_BLOCK_SIZE];
                System.Array.Copy(olddata,0,sbdata,0,olddata.Length);

                // Copy in the new data
                pos = block * SMALL_BLOCK_SIZE;
                System.Array.Copy(rootdata,pos,sbdata,
                                 olddata.Length,SMALL_BLOCK_SIZE);
                block = smallBlockChain[block];

                if (block == -1)
                    {
                    //logger.warn("Incorrect terminator for small block stream " + ps.name);
                    block = -2; // kludge to force the loop termination
                    }
                }

            if (blockCount > smallBlockChain.Length)
                {
                // Attempted to read more blocks than the block chain contains entries
                // for. This indicates a loop in the chain
                throw new BiffException(BiffException.corruptFileFormat);
                }

            return sbdata;
        }
        /**
         * Reads all the property sets
         */
        private void readPropertySets()
        {
            int offset = 0;
            byte[] d = null;

            while (offset < rootEntry.Length)
                {
                d = new byte[PROPERTY_STORAGE_BLOCK_SIZE];
                System.Array.Copy(rootEntry,offset,d,0,d.Length);
                PropertyStorage ps = new PropertyStorage(d);

                // sometimes the MAC Operating system leaves some property storage
                // names blank.  Contributed by Jacky
                if (ps.name == null || ps.name.Length == 0)
                    {
                    if (ps.type == ROOT_ENTRY_PS_TYPE)
                        {
                        ps.name = ROOT_ENTRY_NAME;
                        //logger.warn("Property storage name for " + ps.type +
                        //            " is empty - setting to " + ROOT_ENTRY_NAME);
                        }
                    else
                        {
                        if (ps.size != 0)
                            {
                            //logger.warn("Property storage type " + ps.type +
                            //            " is non-empty and has no associated name");
                            }
                        }
                    }
                propertySets.Add(ps);
                if (System.String.Compare(ps.name,ROOT_ENTRY_NAME,true) == 0)
                    rootEntryPropertyStorage = ps;
                offset += PROPERTY_STORAGE_BLOCK_SIZE;
                }

            if (rootEntryPropertyStorage == null)
                rootEntryPropertyStorage = (PropertyStorage)propertySets[0];
        }
        /**
         * Build up the resultant stream using the big blocks
         *
         * @param ps the property storage
         * @return the big block stream
         */
        private byte[] getBigBlockStream(PropertyStorage ps)
        {
            int numBlocks = ps.size / BIG_BLOCK_SIZE;
            if (ps.size % BIG_BLOCK_SIZE != 0)
                {
                numBlocks++;
                }

            byte[] streamData = new byte[numBlocks * BIG_BLOCK_SIZE];

            int block = ps.startBlock;

            int count = 0;
            int pos = 0;
            while (block != -2 && count < numBlocks)
                {
                pos = (block + 1) * BIG_BLOCK_SIZE;
                System.Array.Copy(data,pos,streamData,
                                 count * BIG_BLOCK_SIZE,BIG_BLOCK_SIZE);
                count++;
                block = bigBlockChain[block];
                }

            if (block != -2 && count == numBlocks)
                {
                //logger.warn("Property storage size inconsistent with block chain.");
                }

            return streamData;
        }
        /**
         * Recursively searches the property storages in hierarchy order
         * for the appropriate name.
         */
        private PropertyStorage findPropertyStorage(string name,
            PropertyStorage ps)
        {
            if (ps.child == -1)
                {
                return null;
                }

            // Get the child
            PropertyStorage child = getPropertyStorage(ps.child);
            if (System.String.Compare(child.name,name) == 0)
                return child;

            // Find the previous property storages on the same level
            PropertyStorage prev = child;
            while (prev.previous != -1)
                {
                prev = getPropertyStorage(prev.previous);
                if (System.String.Compare(prev.name,name) == 0)
                    return prev;
                }

            // Find the next property storages on the same level
            PropertyStorage next = child;
            while (next.next != -1)
                {
                next = getPropertyStorage(next.next);
                if (System.String.Compare(next.name,name) == 0)
                    return next;
                }

            return findPropertyStorage(name,child);
        }
示例#11
0
        /// <summary>
        /// Creates a <see cref="RouteValueDictionary"/> initialized with the specified <paramref name="values"/>.
        /// </summary>
        /// <param name="values">An object to initialize the dictionary. The value can be of type
        /// <see cref="IDictionary{TKey, TValue}"/> or <see cref="IReadOnlyDictionary{TKey, TValue}"/>
        /// or an object with public properties as key-value pairs.
        /// </param>
        /// <remarks>
        /// If the value is a dictionary or other <see cref="IEnumerable{T}"/> of <see cref="KeyValuePair{String, Object}"/>,
        /// then its entries are copied. Otherwise the object is interpreted as a set of key-value pairs where the
        /// property names are keys, and property values are the values, and copied into the dictionary.
        /// Only public instance non-index properties are considered.
        /// </remarks>
        public RouteValueDictionary(object values)
        {
            if (values is RouteValueDictionary dictionary)
            {
                if (dictionary._propertyStorage != null)
                {
                    // PropertyStorage is immutable so we can just copy it.
                    _propertyStorage = dictionary._propertyStorage;
                    _count           = dictionary._count;
                    return;
                }

                var count = dictionary._count;
                if (count > 0)
                {
                    var other   = dictionary._arrayStorage;
                    var storage = new KeyValuePair <string, object> [count];
                    Array.Copy(other, 0, storage, 0, count);
                    _arrayStorage = storage;
                    _count        = count;
                }
                else
                {
                    _arrayStorage = Array.Empty <KeyValuePair <string, object> >();
                }

                return;
            }

            if (values is IEnumerable <KeyValuePair <string, object> > keyValueEnumerable)
            {
                _arrayStorage = Array.Empty <KeyValuePair <string, object> >();

                foreach (var kvp in keyValueEnumerable)
                {
                    Add(kvp.Key, kvp.Value);
                }

                return;
            }

            if (values is IEnumerable <KeyValuePair <string, string> > stringValueEnumerable)
            {
                _arrayStorage = Array.Empty <KeyValuePair <string, object> >();

                foreach (var kvp in stringValueEnumerable)
                {
                    Add(kvp.Key, kvp.Value);
                }

                return;
            }

            if (values != null)
            {
                var storage = new PropertyStorage(values);
                _propertyStorage = storage;
                _count           = storage.Properties.Length;
            }
            else
            {
                _arrayStorage = Array.Empty <KeyValuePair <string, object> >();
            }
        }
示例#12
0
 public PropertyStorage(PropertyStorage propertyStorage)
 {
     _value      = propertyStorage._value;
     _properties = propertyStorage._properties;
 }
示例#13
0
 set => SetProperty(ref PropertyStorage, value);