コード例 #1
0
        public IppResponseMessage ReadIppResponse(Stream stream)
        {
            var res = new IppResponseMessage();

            try
            {
                using var reader = new BinaryReader(stream, Encoding.ASCII, true);
                res.Version      = (IppVersion)reader.ReadInt16BigEndian();
                res.StatusCode   = (IppStatusCode)reader.ReadInt16BigEndian();
                res.RequestId    = reader.ReadInt32BigEndian();
                ReadSection(reader, res);
                return(res);
            }
            catch (Exception ex)
            {
                throw new IppResponseException(
                          $"Failed to parse ipp response. Current response parsing ended on: \n{res}", ex, res);
            }
        }
コード例 #2
0
        private void ReadSection(BinaryReader reader, IppResponseMessage res)
        {
            IppAttribute?       prevAttribute = null;
            List <IppAttribute>?attributes    = null;

            do
            {
                var data       = reader.ReadByte();
                var sectionTag = (SectionTag)data;
                switch (sectionTag)
                {
                //https://tools.ietf.org/html/rfc8010#section-3.5.1
                case SectionTag.EndOfAttributesTag: return;

                case SectionTag.Reserved:
                case SectionTag.OperationAttributesTag:
                case SectionTag.JobAttributesTag:
                case SectionTag.PrinterAttributesTag:
                case SectionTag.UnsupportedAttributesTag:
                    var section = new IppSection {
                        Tag = sectionTag
                    };
                    res.Sections.Add(section);
                    attributes = section.Attributes;
                    break;

                default:
                    var attribute = ReadAttribute((Tag)data, reader, prevAttribute);
                    prevAttribute = attribute;
                    if (attributes == null)
                    {
                        throw new ArgumentException(
                                  $"Section start tag not found in stream. Expected < 0x06. Actual: {data}");
                    }

                    attributes.Add(attribute);

                    break;
                }
            } while (true);
        }
コード例 #3
0
 public static IDictionary <string, IppAttribute[]> AllAttributes(this IppResponseMessage ippResponseMessage) =>
 ippResponseMessage.Sections.SelectMany(x => x.Attributes)
 .GroupBy(x => x.Name)
 .ToDictionary(g => g.Key, g => g.ToArray());
コード例 #4
0
 public IppResponseException(IppResponseMessage responseMessage)
 {
     ResponseMessage = responseMessage;
 }
コード例 #5
0
 public IppResponseException(string message, Exception innerException, IppResponseMessage responseMessage) :
     base(message, innerException)
 {
     ResponseMessage = responseMessage;
 }
コード例 #6
0
 public IppResponseException(string message, IppResponseMessage responseMessage) : base(message)
 {
     ResponseMessage = responseMessage;
 }
コード例 #7
0
 protected IppResponseException(SerializationInfo info, StreamingContext context,
                                IppResponseMessage responseMessage) : base(info, context)
 {
     ResponseMessage = responseMessage;
 }