Ejemplo n.º 1
0
        internal protected FamosFileComponent(BinaryReader reader, int codePage) : base(reader, codePage)
        {
            FamosFilePackInfo?    packInfo     = null;
            FamosFileBufferInfo?  bufferInfo   = null;
            FamosFilePropertyInfo?propertyInfo = null;

            while (true)
            {
                var nextKeyType = this.DeserializeKeyType();

                if (propertyInfo != null && nextKeyType != FamosFileKeyType.CN)
                {
                    throw new FormatException("A channel info of type '|CN' was expected because a property info of type '|Np' has been defined previously.");
                }

                // end of CC reached
                if (nextKeyType == FamosFileKeyType.CT ||
                    nextKeyType == FamosFileKeyType.CI ||
                    nextKeyType == FamosFileKeyType.CB ||
                    nextKeyType == FamosFileKeyType.CG ||
                    nextKeyType == FamosFileKeyType.CC ||
                    nextKeyType == FamosFileKeyType.CV ||
                    nextKeyType == FamosFileKeyType.CS)
                {
                    // go back to start of key
                    this.Reader.BaseStream.Position -= 4;
                    break;
                }

                else if (nextKeyType == FamosFileKeyType.Unknown)
                {
                    this.SkipKey();
                    continue;
                }

                // CD
                else if (nextKeyType == FamosFileKeyType.CD)
                {
                    this.XAxisScaling = new FamosFileXAxisScaling(this.Reader, this.CodePage);
                }

                // CZ
                else if (nextKeyType == FamosFileKeyType.CZ)
                {
                    this.ZAxisScaling = new FamosFileZAxisScaling(this.Reader, this.CodePage);
                }

                // NT
                else if (nextKeyType == FamosFileKeyType.NT)
                {
                    this.TriggerTime = new FamosFileTriggerTime(this.Reader);
                }

                // CP
                else if (nextKeyType == FamosFileKeyType.CP)
                {
                    packInfo = new FamosFilePackInfo(this.Reader);
                }

                // Cb
                else if (nextKeyType == FamosFileKeyType.Cb)
                {
                    if (bufferInfo == null)
                    {
                        bufferInfo = new FamosFileBufferInfo(this.Reader);
                    }
                    else
                    {
                        throw new FormatException("Although the format specification allows multiple '|Cb' keys, this implementation supports only a single definition per component. Please send a sample file to the project maintainer to overcome this limitation in future.");
                    }
                }

                // CR
                else if (nextKeyType == FamosFileKeyType.CR)
                {
                    this.DeserializeCR();
                }

                // ND
                else if (nextKeyType == FamosFileKeyType.ND)
                {
                    this.DisplayInfo = new FamosFileDisplayInfo(this.Reader);
                }

                // Cv
                else if (nextKeyType == FamosFileKeyType.Cv)
                {
                    throw new NotSupportedException("Events are not supported yet. Please send a sample file to the package author to find a solution.");
                }
                //this.EventReference = new FamosFileEventReference(this.Reader);

                // CN
                else if (nextKeyType == FamosFileKeyType.CN)
                {
                    this.Channels.Add(new FamosFileChannel(this.Reader, this.CodePage));
                    this.Channels.Last().PropertyInfo = propertyInfo;

                    propertyInfo = null;
                }

                // Np
                else if (nextKeyType == FamosFileKeyType.Np)
                {
                    propertyInfo = new FamosFilePropertyInfo(this.Reader, this.CodePage);
                }

                else
                {
                    // should never happen
                    throw new FormatException("An unexpected state has been reached.");
                }
            }

            if (packInfo is null)
            {
                throw new FormatException("No pack information was found in the component.");
            }
            else
            {
                this.PackInfo = packInfo;
            }

            if (bufferInfo is null)
            {
                throw new FormatException("No buffer information was found in the component.");
            }
            else
            {
                this.BufferInfo = bufferInfo;
            }
        }
Ejemplo n.º 2
0
        private void Deserialize()
        {
            // CF
            var keyType = this.DeserializeKeyType();

            if (keyType != FamosFileKeyType.CF)
            {
                throw new FormatException("The file is not a FAMOS file.");
            }

            var keyVersion = this.DeserializeInt32();

            if (keyVersion == 1)
            {
                throw new FormatException($"Only files of format version '2' can be read.");
            }
            else if (keyVersion == SUPPORTED_VERSION)
            {
                this.DeserializeKey(keySize =>
                {
                    var processor = this.DeserializeInt32();
                });
            }
            else
            {
                throw new FormatException($"Expected key version '2', got '{keyVersion}'.");
            }

            // CK
            new FamosFileKeyGroup(this.Reader);

            // Now, all other keys.
            FamosFileBaseProperty?propertyInfoReceiver = null;

            while (true)
            {
                if (this.Reader.BaseStream.Position >= this.Reader.BaseStream.Length)
                {
                    return;
                }

                var nextKeyType = this.DeserializeKeyType();

                // Reset propertyInfoReceiver if next key type is not 'Np'.
                if (nextKeyType != FamosFileKeyType.Np)
                {
                    propertyInfoReceiver = null;
                }

                // Unknown
                if (nextKeyType == FamosFileKeyType.Unknown)
                {
                    this.SkipKey();
                    continue;
                }

                // NO
                else if (nextKeyType == FamosFileKeyType.NO)
                {
                    this.OriginInfo = new FamosFileOriginInfo(this.Reader, this.CodePage);
                }

                // NL
                else if (nextKeyType == FamosFileKeyType.NL)
                {
                    this.LanguageInfo = new FamosFileLanguageInfo(this.Reader);
                    this.CodePage     = this.LanguageInfo.CodePage;
                }

                // NE - only imc internal
                else if (nextKeyType == FamosFileKeyType.NE)
                {
                    this.SkipKey();
                }

                // Ca
                else if (nextKeyType == FamosFileKeyType.Ca)
                {
                    throw new FormatException("The functionality of the 'Ca'-key is not supported. Please submit a sample .dat or .raw file to the package author to find a solution.");
                }

                // NU
                else if (nextKeyType == FamosFileKeyType.NU)
                {
                    this.CustomKeys.Add(new FamosFileCustomKey(this.Reader, this.CodePage));
                }

                // CB
                else if (nextKeyType == FamosFileKeyType.CB)
                {
                    this.Groups.Add(new FamosFileGroup(this.Reader, this.CodePage));
                    propertyInfoReceiver = this.Groups.Last();
                }

                // CG
                else if (nextKeyType == FamosFileKeyType.CG)
                {
                    this.Fields.Add(new FamosFileField(this.Reader, this.CodePage));
                }

                // CT
                else if (nextKeyType == FamosFileKeyType.CT)
                {
                    _texts.Add(new FamosFileText(this.Reader, this.CodePage));
                    propertyInfoReceiver = _texts.Last();
                }

                // CI
                else if (nextKeyType == FamosFileKeyType.CI)
                {
                    _singleValues.Add(new FamosFileSingleValue.Deserializer(this.Reader, this.CodePage).Deserialize());
                    propertyInfoReceiver = _singleValues.Last();
                }

                // CS
                else if (nextKeyType == FamosFileKeyType.CS)
                {
                    this.RawBlocks.Add(new FamosFileRawBlock(this.Reader));
                }

                // Nv - only for data manager
                else if (nextKeyType == FamosFileKeyType.Nv)
                {
                    this.SkipKey();
                }

                // Np
                else if (nextKeyType == FamosFileKeyType.Np)
                {
                    var propertyInfo = new FamosFilePropertyInfo(this.Reader, this.CodePage);

                    if (propertyInfoReceiver != null)
                    {
                        propertyInfoReceiver.PropertyInfo = propertyInfo;
                    }
                    else
                    {
                        throw new FormatException("Found property key in an unexpected location.");
                    }

                    propertyInfoReceiver = null;
                }

                // Cb
                else if (nextKeyType == FamosFileKeyType.Cb)
                {
                    throw new FormatException("Although the format specification allows '|Cb' keys at any level, this implementation supports this key only at component level. Please send a sample file to the project maintainer to overcome this limitation in future.");
                }

                else
                {
                    //throw new FormatException($"Unexpected key '{keyType}'.");
                    this.SkipKey();
                }
            }
        }