Пример #1
0
        private void WriteParameters(Byte firstParameterBlockIndex, C3DParameterDictionary dictionary)
        {
            Int32 startPosition = (firstParameterBlockIndex - 1) * C3DConstants.FILE_SECTION_SIZE;

            this._writer.Seek(startPosition, SeekOrigin.Begin);
            this._writer.Write(C3DConstants.FILEPARAMETER_FIRST_PARAM_BLOCK);
            this._writer.Write(C3DConstants.FILEPARAMETER_SIGNATURE);
            this._writer.Write((Byte)0);
            this._writer.Write((Byte)C3DConstants.FILE_DEFAULT_PROCESSOR_TYPE);

            foreach (C3DParameterGroup group in dictionary)
            {
                if (group.ID < 0)
                {
                    this.WriteParameter(null, group, false);

                    foreach (C3DParameter param in group)
                    {
                        this.WriteParameter(group, param, false);
                    }
                }
            }

            C3DParameterGroup lastGroup = new C3DParameterGroup(0, "", "");

            this.WriteParameter(null, lastGroup, true);

            this._newDataStartBlockIndex = (UInt16)((this._writer.BaseStream.Position + C3DConstants.FILE_SECTION_SIZE) / C3DConstants.FILE_SECTION_SIZE + 1);
            this._writer.Write(new Byte[(this._newDataStartBlockIndex - 1) * C3DConstants.FILE_SECTION_SIZE - this._writer.BaseStream.Position]);

            this._writer.Seek(startPosition + 2, SeekOrigin.Begin);
            this._writer.Write((Byte)(this._newDataStartBlockIndex - 2));
        }
Пример #2
0
        public C3DParameterDictionary ReadParameters()
        {
            Dictionary <Int32, C3DParameterGroup>    groups     = new Dictionary <Int32, C3DParameterGroup>();
            Dictionary <Int32, List <C3DParameter> > parameters = new Dictionary <Int32, List <C3DParameter> >();

            Int32 startPosition = (this._firstParameterBlockIndex - 1) * C3DConstants.FILE_SECTION_SIZE;

            this._reader.BaseStream.Seek(startPosition + 2, SeekOrigin.Begin);

            Byte paramsBlocksCount = this._reader.ReadByte();
            Byte processorType     = this._reader.ReadByte();

            Int64 endPosition  = startPosition + paramsBlocksCount * C3DConstants.FILE_SECTION_SIZE;
            Int16 nextPosition = 0;

            do
            {
                SByte   nameLength = this._reader.ReadSByte();//Byte 1
                Boolean isLocked   = nameLength < 0;
                nameLength = Math.Abs(nameLength);

                SByte  id   = this._reader.ReadSByte();           //Byte 2
                Byte[] name = this._reader.ReadBytes(nameLength); //Byte 3

                nextPosition = this._reader.ReadInt16();          //Byte 3 + n
                Byte[] lastData = (nextPosition > 0 ? this._reader.ReadBytes(nextPosition - 2) : null);

                if (id > 0)//C3DParameter
                {
                    C3DParameter parameter = new C3DParameter(this._processorType, id, name, isLocked, lastData);

                    List <C3DParameter> list = null;
                    if (!parameters.TryGetValue(parameter.ID, out list))
                    {
                        list = new List <C3DParameter>();
                    }

                    list.Add(parameter);
                    parameters[parameter.ID] = list;
                }
                else//C3DParameterGroup
                {
                    C3DParameterGroup group = new C3DParameterGroup(id, name, isLocked, lastData);
                    groups[-group.ID] = group;
                }
            }while (nextPosition > 0 && this._reader.BaseStream.Position < endPosition);

            return(C3DParameterDictionary.CreateParameterDictionaryFromParameterList(groups, parameters));
        }
Пример #3
0
        private void WriteParameter(C3DParameterGroup parent, AbstractC3DParameter param, Boolean isLast)
        {
            this._writer.Write((SByte)(param.IsLocked ? -param.Name.Length : param.Name.Length));
            this._writer.Write(param.ID);
            this._writer.Write(param.GetNameByteArray());

            Byte[] lastData = (param.ID > 0 ? param.GetLastDataArrayWithoutDescrption() : null);

            Int16 nextPosition = (Int16)(isLast ? 0 :
                                         (2 + (lastData == null ? 0 : lastData.Length) +
                                          1 + (String.IsNullOrEmpty(param.Description) ? 0 : param.Description.Length)));

            this._writer.Write(nextPosition);

            if (parent != null && String.Equals(parent.Name, "POINT", StringComparison.OrdinalIgnoreCase))
            {
                if (String.Equals(param.Name, "DATA_START", StringComparison.OrdinalIgnoreCase))
                {
                    this._dataStartOffset = this._writer.BaseStream.Position;
                }
            }

            if (lastData != null)
            {
                this._writer.Write(lastData);
            }

            if (param.Description == null)
            {
                this._writer.Write((Byte)0);
            }
            else
            {
                this._writer.Write((Byte)param.Description.Length);
                this._writer.Write(param.GetDescriptionByteArray());
            }
        }