예제 #1
0
        /// <summary>
        /// based of the "type" of datadict attribute, choose the appropriate
        /// data template defined in the mainwindow XAML
        /// </summary>
        /// <param name="item"> the bound datadict_Attribute</param>
        /// <param name="container"></param>
        /// <returns></returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;

            DataDict_Attribute attr = item as DataDict_Attribute;

            //if the bound object can't be mapped to a datadict_attribute return null
            if (attr == null)
            {
                return(null);
            }
            else if (attr.Type == 1 || attr.Type == 9)
            {
                //if the attribute is of type 1 or 9 use the four byte attribute data template
                return(element.FindResource("HexFourbyteAttribute") as DataTemplate);
            }
            else if (attr.Type == 6 || attr.Type == 10)
            {
                //if the attribute is of type 6 or 10 use the eight byte attribute data template
                return(element.FindResource("HexEightbyteAttribute") as DataTemplate);
            }
            else if (attr.Type == 12)
            {
                //if the attribute is of type 12 use the sixteen byte attribute data template
                return(element.FindResource("HexSixteenbyteAttribute") as DataTemplate);
            }
            //else the attribute must have a value that is a string
            //use the string attribute data template
            return(element.FindResource("StringAttribute") as DataTemplate);
        }
예제 #2
0
        /// <summary>
        /// Populate an observable collection of DataDict_Objects
        /// from the bytes in the currently opened files any time the currently
        /// opened file changes
        /// </summary>
        private void OnOpenFileBytesChanged()
        {
            //Clear all objects from the observable collection
            DDObjects.Clear();
            //reset the hexidecimal display boolean
            IsHexadecimalDisplayed = false;

            //Declare the number of objects
            //derived by bytes 4-8 of OpenFileBytes array
            int numobjects = BitConverter.ToInt32(OpenFileBytes.Skip(4).Take(4).ToArray(), 0);
            //declare the datablock length from bytes 12-16
            int datablocklength = BitConverter.ToInt32(OpenFileBytes.Skip(12).Take(4).ToArray(), 0);
            //declare the attribute description block length by taking bytes 8-12 as an integer and multiplying by 8
            //because each attribute description is 8 bytes long
            int attributedescriptionblocklength = BitConverter.ToInt32(OpenFileBytes.Skip(8).Take(4).ToArray(), 0) * 8;

            //define the block of data defining the number of attributes per object
            byte[] objectattributeblock = OpenFileBytes.Skip(16).Take(numobjects * 8).ToArray();
            //define the lock of data defining the details of each object attribute
            byte[] attributedescriptionblock = OpenFileBytes.Skip(16 + objectattributeblock.Length).Take(attributedescriptionblocklength).ToArray();
            //define the block of data where all of the attribute values are held
            byte[] datablock = OpenFileBytes.Skip(OpenFileBytes.Length - datablocklength).Take(datablocklength).ToArray();

            //create a loop that repeats for every object in the file
            for (int i = 0; i < numobjects; i++)
            {
                //Get the 8 bits that define the current object and the number of attributes it has
                byte[] currentobject = objectattributeblock.Skip(i * 8).Take(8).ToArray();
                //take the last 4 bits of the current object byte array to define the number of attributes the object has
                int numattributes = BitConverter.ToInt32(currentobject.Skip(4).Take(4).ToArray(), 0);
                //define where in the attribute description block this object's attributes start
                int attrstartOFfset = (BitConverter.ToInt32(currentobject.Skip(0).Take(4).ToArray(), 0) * 8);

                //create a new datadict_object to represent the file object
                //populate the number of attributes and give it an object ID
                DataDict_Object ddobject = new DataDict_Object()
                {
                    NumOfAttributes = numattributes,
                    ObjectID        = i + 1
                };


                //Loop through the attributes and populate the attributes into to DataDict_Object
                for (int a = 0; a < numattributes; a++)
                {
                    //locate and define the current attribute description object (8 bytes)
                    byte[] currentattribute = attributedescriptionblock.Skip((a * 8) + attrstartOFfset).Take(8).ToArray();

                    //create a new datadict_attribute object and populate the description, offset and type
                    DataDict_Attribute ddattribute = new DataDict_Attribute()
                    {
                        Description = currentattribute.Skip(0).Take(4).ToArray(),
                        Offset      = ReturnOffset(currentattribute.Skip(4).Take(3).ToArray()),
                        Type        = currentattribute[7]
                    };
                    //use the get value method to return the value for this attribute based on its type and offset
                    ddattribute.Value = GetValue(ddattribute.Offset, ddattribute.Type, datablock);
                    //add the current attribute to the object's observable collection of attributes
                    ddobject.DataDictObjects.Add(ddattribute);
                }


                //Add the current object to the bound observablecollection of datadict objects
                DDObjects.Add(ddobject);
            }
        }