Пример #1
0
        private static RecordingAttribute getAttribute(StringBuilder name, StreamBufferAttrDataType attributeType, byte[] attributeValue)
        {
            string attributeName = name.ToString().TrimEnd('\0');
            string type          = attributeType.ToString();

            switch (attributeType)
            {
            case StreamBufferAttrDataType.Binary:
                RecordingAttribute binaryAttribute = new RecordingAttribute(attributeName, type, attributeValue);
                return(binaryAttribute);

            case StreamBufferAttrDataType.Bool:
                RecordingAttribute boolAttribute = new RecordingAttribute(attributeName, type, attributeValue[0] == 0);
                return(boolAttribute);

            case StreamBufferAttrDataType.DWord:
                int intValue = attributeValue[0] << 24 | attributeValue[1] << 16 | attributeValue[2] << 8 | attributeValue[3];
                RecordingAttribute intAttribute = new RecordingAttribute(attributeName, type, intValue);
                return(intAttribute);

            case StreamBufferAttrDataType.Guid:
                RecordingAttribute guidAttribute = new RecordingAttribute(attributeName, type, new Guid(attributeValue));
                return(guidAttribute);

            case StreamBufferAttrDataType.QWord:
                long longValue = attributeValue[0] << 56 | attributeValue[1] << 48 | attributeValue[2] << 40
                                 | attributeValue[3] << 32 | attributeValue[4] << 24 | attributeValue[5] << 16
                                 | attributeValue[6] << 8 | attributeValue[7];
                RecordingAttribute longAttribute = new RecordingAttribute(attributeName, type, longValue);
                return(longAttribute);

            case StreamBufferAttrDataType.String:
                Encoding sourceEncoding = Encoding.GetEncoding("utf-16");
                if (sourceEncoding == null)
                {
                    return(null);
                }
                string             encodedString   = sourceEncoding.GetString(attributeValue, 0, attributeValue.Length);
                RecordingAttribute stringAttribute = new RecordingAttribute(attributeName, type, encodedString);
                return(stringAttribute);

            case StreamBufferAttrDataType.Word:
                int shortValue = attributeValue[0] << 8 | attributeValue[1];
                RecordingAttribute shortAttribute = new RecordingAttribute(attributeName, type, shortValue);
                return(shortAttribute);

            default:
                return(null);
            }
        }
Пример #2
0
        private static RecordingAttribute getAttribute(StringBuilder name, StreamBufferAttrDataType attributeType, byte[] attributeValue)
        {
            string attributeName = name.ToString().TrimEnd('\0');
            string type = attributeType.ToString();

            switch (attributeType)
            {
                case StreamBufferAttrDataType.Binary:
                    RecordingAttribute binaryAttribute = new RecordingAttribute(attributeName, type, attributeValue);
                    return (binaryAttribute);
                case StreamBufferAttrDataType.Bool:
                    RecordingAttribute boolAttribute = new RecordingAttribute(attributeName, type, attributeValue[0] == 0);
                    return (boolAttribute);
                case StreamBufferAttrDataType.DWord:
                    int intValue = attributeValue[0] << 24 | attributeValue[1] << 16 | attributeValue[2] << 8 | attributeValue[3];
                    RecordingAttribute intAttribute = new RecordingAttribute(attributeName, type, intValue);
                    return (intAttribute);
                case StreamBufferAttrDataType.Guid:
                    RecordingAttribute guidAttribute = new RecordingAttribute(attributeName, type, new Guid(attributeValue));
                    return (guidAttribute);
                case StreamBufferAttrDataType.QWord:
                    long longValue = attributeValue[0] << 56 | attributeValue[1] << 48 | attributeValue[2] << 40
                        | attributeValue[3] << 32 | attributeValue[4] << 24 | attributeValue[5] << 16
                        | attributeValue[6] << 8 | attributeValue[7];
                    RecordingAttribute longAttribute = new RecordingAttribute(attributeName, type, longValue);
                    return (longAttribute);
                case StreamBufferAttrDataType.String:
                    Encoding sourceEncoding = Encoding.GetEncoding("utf-16");
                    if (sourceEncoding == null)
                        return (null);
                    string encodedString = sourceEncoding.GetString(attributeValue,  0, attributeValue.Length);
                    RecordingAttribute stringAttribute = new RecordingAttribute(attributeName, type, encodedString);
                    return (stringAttribute);
                case StreamBufferAttrDataType.Word:
                    int shortValue = attributeValue[0] << 8 | attributeValue[1];
                    RecordingAttribute shortAttribute = new RecordingAttribute(attributeName, type, shortValue);
                    return (shortAttribute);
                default:
                    return (null);
            }
        }
Пример #3
0
        /// <summary>
        /// Load the attribute collection from a recording file (dvr-ms or wtv).
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns>An error message or null if the load succeeds.</returns>
        public static string Load(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return("The recording file ' " + fileName + "' does not exist");
            }

            StreamBufferRecordingAttributes recordingAttributes = new StreamBufferRecordingAttributes();

            int reply = ((IFileSourceFilter)recordingAttributes).Load(fileName, null);

            if (reply != 0)
            {
                return("The attributes cannot be loaded");
            }

            int   reserved = 0;
            short attributeCount;

            reply = ((IStreamBufferRecordingAttribute)recordingAttributes).GetAttributeCount(reserved, out attributeCount);

            attributes = new Collection <RecordingAttribute>();

            for (short index = 0; index < attributeCount; index++)
            {
                StreamBufferAttrDataType attributeType;
                StringBuilder            name = null;
                byte[] attributeValue         = null;
                short  nameLength             = 0;
                short  valueLength            = 0;

                reply = ((IStreamBufferRecordingAttribute)recordingAttributes).GetAttributeByIndex(index,
                                                                                                   ref reserved,
                                                                                                   name,
                                                                                                   ref nameLength,
                                                                                                   out attributeType,
                                                                                                   attributeValue,
                                                                                                   ref valueLength);

                name           = new StringBuilder(nameLength);
                attributeValue = new byte[valueLength];

                reply = ((IStreamBufferRecordingAttribute)recordingAttributes).GetAttributeByIndex(index,
                                                                                                   ref reserved,
                                                                                                   name,
                                                                                                   ref nameLength,
                                                                                                   out attributeType,
                                                                                                   attributeValue,
                                                                                                   ref valueLength);

                if (name != null && name.Length != 0)
                {
                    RecordingAttribute attribute = getAttribute(name, attributeType, attributeValue);
                    if (attribute != null)
                    {
                        attributes.Add(attribute);
                    }
                }
            }

            return(null);
        }