Exemplo n.º 1
0
 public void Write(Issue12Header issue12Header)
 {
     _writer.Write(issue12Header.Description);
     _writer.Write(issue12Header.Version);
     _writer.Write(0);
     _writer.Write(issue12Header.Date.ToBinary());
     _writer.Write(issue12Header.Issue);
 }
        public Issue12Header Read()
        {
            var header = new Issue12Header();

            header.Description = _reader.ReadString();
            header.Version     = _reader.ReadSingle();

            var year = _reader.ReadInt32();
            var dateIsYearMonthDate = year > 0;

            if (dateIsYearMonthDate)
            {
                var month = _reader.ReadInt32();
                var day   = _reader.ReadInt32();
                header.Date = new DateTime(year, month, day);
            }
            else
            {
                header.Date = DateTime.FromBinary(_reader.ReadInt64());
            }
            header.Issue = _reader.ReadInt32();
            return(header);
        }
Exemplo n.º 3
0
        public bool Read()
        {
            switch (_state)
            {
                case State.End:
                    return false;

                case State.Start:
                    _issue12Header = new Issue12HeaderReader(_reader).Read();
                    OnIssue12HeaderRead?.Invoke(_issue12Header);
                    _state = State.Archetypes;
                    return true;

                case State.Archetypes:
                    if (_archetypeHeader == null)
                    {
                        _archetypeHeader = new RecordHeaderReader(_reader).Read();
                        OnArchetypeHeaderRead?.Invoke(_archetypeHeader);
                        _archetypeIndex = 0;
                        return true;
                    }

                    if (_archetypeHeader.Count < _archetypeIndex)
                        return false;

                    if (_archetypeReader == null)
                        _archetypeReader = new ArchetypeReader(_reader);

                    var archetype = _archetypeReader.Read();
                    OnArchetypeRead?.Invoke(archetype);
                    _archetypeIndex++;
                    if (_archetypeIndex > _archetypeHeader.Count)
                        _state = State.Powersets;
                    
                    return true;

                case State.Powersets:
                    if (_powersetHeader == null)
                    {
                        _powersetHeader = new RecordHeaderReader(_reader).Read();
                        OnPowerSetHeaderRead?.Invoke(_powersetHeader);
                        _powersetIndex = 0;
                        return true;
                    }

                    if (_powersetHeader.Count < _powersetIndex)
                        return false;

                    if (_powersetReader == null)
                        _powersetReader = new PowerSetReader(_reader);

                    var powerset = _powersetReader.Read();
                    OnPowerSetRead?.Invoke(powerset);
                    _powersetIndex++;
                    if (_powersetIndex > _powersetHeader.Count)
                        _state = State.Powers;

                    return true;

                case State.Powers:
                    if (_powerHeader == null)
                    {
                        _powerHeader = new PowerHeaderReader(_reader).Read();
                        OnPowersHeaderRead?.Invoke(_powerHeader);
                        _powerIndex = 0;
                        return true;
                    }

                    if (_powerHeader.Count < _powerIndex)
                        return false;

                    if (_powerReader == null)                    
                        _powerReader = new PowerReader(_reader);                        
                    

                    var power = _powerReader.Read();
                    OnPowerRead?.Invoke(power);
                    _powerIndex++;
                    if (_powerIndex > _powerHeader.Count)
                    {
                        _state = State.Summons;
                        OnPowersCompleted?.Invoke();
                    }

                    return true;

                case State.Summons:
                    return false;
                
            }
            return false;
        }