private static void ConfigurePrintUriRequest(SimpleMapper mapper) { mapper.CreateMap <PrintUriRequest, IppRequestMessage>((src, map) => { var dst = new IppRequestMessage { IppOperation = IppOperation.PrintUri }; mapper.Map <IIppPrinterRequest, IppRequestMessage>(src, dst); var operation = dst.OperationAttributes; operation.Add(new IppAttribute(Tag.Uri, "document-uri", src.DocumentUri.ToString())); if (src.NewJobAttributes != null) { map.Map(src.NewJobAttributes, dst); } if (src.DocumentAttributes != null) { map.Map(src.DocumentAttributes, dst); } return(dst); }); mapper.CreateMap <IppResponseMessage, PrintUriResponse>((src, map) => { var dst = new PrintUriResponse(); map.Map <IppResponseMessage, IIppJobResponse>(src, dst); return(dst); }); }
private static void ConfigurePrintJobRequest(SimpleMapper mapper) { mapper.CreateMap <PrintJobRequest, IppRequestMessage>((src, map) => { var dst = new IppRequestMessage { IppOperation = IppOperation.PrintJob, Document = src.Document }; mapper.Map <IIppPrinterRequest, IppRequestMessage>(src, dst); if (src.NewJobAttributes != null) { map.Map(src.NewJobAttributes, dst); } if (src.DocumentAttributes != null) { map.Map(src.DocumentAttributes, dst); } return(dst); }); mapper.CreateMap <IppResponseMessage, PrintJobResponse>((src, map) => { var dst = new PrintJobResponse(); map.Map <IppResponseMessage, IIppJobResponse>(src, dst); return(dst); }); }
public void Write(IppRequestMessage requestMessage, BinaryWriter writer) { writer.WriteBigEndian((short)requestMessage.Version); writer.WriteBigEndian((short)requestMessage.IppOperation); writer.WriteBigEndian(requestMessage.RequestId); //operation-attributes-tag https://tools.ietf.org/html/rfc8010#section-3.5.1 var attributes = requestMessage.OperationAttributes.Select(x => (SectionTag.OperationAttributesTag, x)) .Concat(requestMessage.JobAttributes.Select(x => (SectionTag.JobAttributesTag, x))) .ToArray(); if (!attributes.Any()) { return; } IppAttribute?prevAttribute = null; SectionTag? prevTag = null; foreach (var(ippTag, ippAttribute) in attributes) { if (prevTag == null || ippTag != prevTag) { writer.Write((byte)ippTag); } var isSet = prevAttribute != null && ippAttribute.Name == prevAttribute.Name; Write(writer, ippAttribute, isSet); prevAttribute = ippAttribute; prevTag = ippTag; } //end-of-attributes-tag https://tools.ietf.org/html/rfc8010#section-3.5.1 writer.Write((byte)SectionTag.EndOfAttributesTag); }
private static void ConfigureSendDocumentRequest(SimpleMapper mapper) { mapper.CreateMap <SendDocumentRequest, IppRequestMessage>((src, map) => { var dst = new IppRequestMessage { IppOperation = IppOperation.SendDocument, Document = src.LastDocument ? null : src.Document }; mapper.Map <IIppJobRequest, IppRequestMessage>(src, dst); var operation = dst.OperationAttributes; operation.Add(new IppAttribute(Tag.Boolean, "last-document", src.LastDocument)); if (src.DocumentAttributes != null) { map.Map(src.DocumentAttributes, dst); } return(dst); }); mapper.CreateMap <IppResponseMessage, SendDocumentResponse>((src, map) => { var dst = new SendDocumentResponse(); map.Map <IppResponseMessage, IIppJobResponse>(src, dst); return(dst); }); }
private static void ConfigureGetJobsResponse(SimpleMapper mapper) { mapper.CreateMap <GetJobsRequest, IppRequestMessage>((src, map) => { var dst = new IppRequestMessage { IppOperation = IppOperation.GetJobs }; mapper.Map <IIppPrinterRequest, IppRequestMessage>(src, dst); var operation = dst.OperationAttributes; if (src.Limit != null) { operation.Add(new IppAttribute(Tag.Integer, "requesting-user-name", src.Limit.Value)); } if (src.WhichJobs != null) { operation.Add(new IppAttribute(Tag.Keyword, "which-jobs", Mapper.Map <string>(src.WhichJobs.Value))); } if (src.MyJobs != null) { operation.Add(new IppAttribute(Tag.Boolean, "my-jobs", Mapper.Map <string>(src.MyJobs.Value))); } if (src.RequestedAttributes != null) { operation.AddRange(src.RequestedAttributes.Select(requestedAttribute => new IppAttribute(Tag.Keyword, "requested-attributes", requestedAttribute))); } dst.OperationAttributes.Populate(src.AdditionalOperationAttributes); dst.JobAttributes.Populate(src.AdditionalJobAttributes); return(dst); }); mapper.CreateMap <IppResponseMessage, GetJobsResponse>((src, map) => { var dst = new GetJobsResponse { Jobs = map.Map <List <IppSection>, JobAttributes[]>(src.Sections) }; map.Map <IppResponseMessage, IIppResponseMessage>(src, dst); return(dst); }); //https://tools.ietf.org/html/rfc2911#section-4.4 mapper.CreateMap <List <IppSection>, JobAttributes[]>((src, map) => src.Where(x => x.Tag == SectionTag.JobAttributesTag) .Select(x => map.Map <JobAttributes>(x.AllAttributes())) .ToArray()); }
private static void ConfigureRestartJobRequest(SimpleMapper mapper) { mapper.CreateMap <RestartJobRequest, IppRequestMessage>((src, map) => { var dst = new IppRequestMessage { IppOperation = IppOperation.RestartJob }; mapper.Map <IIppJobRequest, IppRequestMessage>(src, dst); return(dst); }); mapper.CreateMap <IppResponseMessage, RestartJobResponse>((src, map) => { var dst = new RestartJobResponse(); map.Map <IppResponseMessage, IIppResponseMessage>(src, dst); return(dst); }); }
public void Write(IppRequestMessage ippRequestMessage, Stream stream) { if (ippRequestMessage == null) { throw new ArgumentException($"{nameof(ippRequestMessage)}"); } if (stream == null) { throw new ArgumentException($"{nameof(stream)}"); } using var writer = new BinaryWriter(stream, Encoding.ASCII, true); Write(ippRequestMessage, writer); if (ippRequestMessage.Document != null) { ippRequestMessage.Document.CopyTo(stream); } }
private static void ConfigurePurgeJobsRequest(SimpleMapper mapper) { mapper.CreateMap <PurgeJobsRequest, IppRequestMessage>((src, map) => { var dst = new IppRequestMessage { IppOperation = IppOperation.PurgeJobs }; mapper.Map <IIppPrinterRequest, IppRequestMessage>(src, dst); return(dst); }); mapper.CreateMap <IppResponseMessage, PurgeJobsResponse>((src, map) => { var dst = new PurgeJobsResponse(); map.Map <IppResponseMessage, IIppResponseMessage>(src, dst); return(dst); }); }
/// <summary> /// Custom Operation, not defined in the standard /// </summary> /// <param name="printerUri">printer uri</param> /// <param name="request">custom made request</param> /// <returns></returns> public async Task <IppResponseMessage> CustomOperationAsync(Uri printerUri, IppRequestMessage request) { return(await SendAsync(printerUri, () => request, ippResponse => ippResponse)); }
private static void ConfigureGetPrinterAttributesResponse(SimpleMapper mapper) { mapper.CreateMap <GetPrinterAttributesRequest, IppRequestMessage>((src, map) => { var dst = new IppRequestMessage { IppOperation = IppOperation.GetPrinterAttributes }; mapper.Map <IIppPrinterRequest, IppRequestMessage>(src, dst); var operation = dst.OperationAttributes; if (src.RequestedAttributes != null) { operation.AddRange(src.RequestedAttributes.Select(requestedAttribute => new IppAttribute(Tag.Keyword, "requested-attributes", requestedAttribute))); } dst.OperationAttributes.Populate(src.AdditionalOperationAttributes); dst.JobAttributes.Populate(src.AdditionalJobAttributes); return(dst); }); mapper.CreateMap <IppResponseMessage, GetPrinterAttributesResponse>((src, map) => { var dst = map.Map <GetPrinterAttributesResponse>(src.AllAttributes()); map.Map <IppResponseMessage, IIppResponseMessage>(src, dst); return(dst); }); //https://tools.ietf.org/html/rfc2911#section-4.4 mapper.CreateMap <IDictionary <string, IppAttribute[]>, GetPrinterAttributesResponse>((src, map) => new GetPrinterAttributesResponse { CharsetConfigured = map.MapFromDic <string?>(src, PrinterAttribute.CharsetConfigured), CharsetSupported = map.MapFromDicSetNull <string[]?>(src, PrinterAttribute.CharsetSupported), ColorSupported = map.MapFromDic <bool?>(src, PrinterAttribute.ColorSupported), CompressionSupported = map.MapFromDicSetNull <Compression[]?>(src, PrinterAttribute.CompressionSupported), DocumentFormatDefault = map.MapFromDic <string?>(src, PrinterAttribute.DocumentFormatDefault), DocumentFormatSupported = map.MapFromDicSetNull <string[]?>(src, PrinterAttribute.DocumentFormatSupported), GeneratedNaturalLanguageSupported = map.MapFromDicSetNull <string[]?>(src, PrinterAttribute.GeneratedNaturalLanguageSupported), IppVersionsSupported = map.MapFromDicSetNull <string[]?>(src, PrinterAttribute.IppVersionsSupported), JobImpressionsSupported = map.MapFromDic <Range?>(src, PrinterAttribute.JobImpressionsSupported), JobKOctetsSupported = map.MapFromDic <Range?>(src, PrinterAttribute.JobKOctetsSupported), JobMediaSheetsSupported = map.MapFromDic <Range?>(src, PrinterAttribute.JobMediaSheetsSupported), MultipleDocumentJobsSupported = map.MapFromDic <bool?>(src, PrinterAttribute.MultipleDocumentJobsSupported), MultipleOperationTimeOut = map.MapFromDic <int?>(src, PrinterAttribute.MultipleOperationTimeOut), NaturalLanguageConfigured = map.MapFromDic <string?>(src, PrinterAttribute.NaturalLanguageConfigured), OperationsSupported = map.MapFromDicSetNull <IppOperation[]?>(src, PrinterAttribute.OperationsSupported), PagesPerMinute = map.MapFromDic <int?>(src, PrinterAttribute.PagesPerMinute), PdlOverrideSupported = map.MapFromDic <string?>(src, PrinterAttribute.PdlOverrideSupported), PagesPerMinuteColor = map.MapFromDic <int?>(src, PrinterAttribute.PagesPerMinuteColor), PrinterCurrentTime = map.MapFromDic <DateTimeOffset?>(src, PrinterAttribute.PrinterCurrentTime), PrinterDriverInstaller = map.MapFromDic <string?>(src, PrinterAttribute.PrinterDriverInstaller), PrinterInfo = map.MapFromDic <string?>(src, PrinterAttribute.PrinterInfo), PrinterIsAcceptingJobs = map.MapFromDic <bool?>(src, PrinterAttribute.PrinterIsAcceptingJobs), PrinterLocation = map.MapFromDic <string?>(src, PrinterAttribute.PrinterLocation), PrinterMakeAndModel = map.MapFromDic <string?>(src, PrinterAttribute.PrinterMakeAndModel), PrinterMessageFromOperator = map.MapFromDic <string?>(src, PrinterAttribute.PrinterMessageFromOperator), PrinterMoreInfo = map.MapFromDic <string?>(src, PrinterAttribute.PrinterMoreInfo), PrinterMoreInfoManufacturer = map.MapFromDic <string?>(src, PrinterAttribute.PrinterMoreInfoManufacturer), PrinterName = map.MapFromDic <string?>(src, PrinterAttribute.PrinterName), PrinterState = map.MapFromDic <PrinterState?>(src, PrinterAttribute.PrinterState), PrinterStateMessage = map.MapFromDic <string?>(src, PrinterAttribute.PrinterStateMessage), PrinterStateReasons = map.MapFromDicSetNull <string[]?>(src, PrinterAttribute.PrinterStateReasons), PrinterUpTime = map.MapFromDic <int?>(src, PrinterAttribute.PrinterUpTime), PrinterUriSupported = map.MapFromDicSetNull <string[]?>(src, PrinterAttribute.PrinterUriSupported), PrintScalingDefault = map.MapFromDic <PrintScaling?>(src, PrinterAttribute.PrintScalingDefault), PrintScalingSupported = map.MapFromDicSetNull <PrintScaling[]?>(src, PrinterAttribute.PrintScalingSupported), QueuedJobCount = map.MapFromDic <int?>(src, PrinterAttribute.QueuedJobCount), ReferenceUriSchemesSupported = map.MapFromDicSetNull <string[]?>(src, PrinterAttribute.ReferenceUriSchemesSupported), UriAuthenticationSupported = map.MapFromDicSetNull <string[]?>(src, PrinterAttribute.UriAuthenticationSupported), UriSecuritySupported = map.MapFromDicSetNull <string[]?>(src, PrinterAttribute.UriSecuritySupported) }); }
private static void ConfigureGetJobAttributesResponse(SimpleMapper mapper) { mapper.CreateMap <GetJobAttributesRequest, IppRequestMessage>((src, map) => { var dst = new IppRequestMessage { IppOperation = IppOperation.GetJobAttributes }; mapper.Map <IIppJobRequest, IppRequestMessage>(src, dst); var operation = dst.OperationAttributes; if (src.RequestedAttributes != null) { operation.AddRange(src.RequestedAttributes.Select(requestedAttribute => new IppAttribute(Tag.Keyword, "requested-attributes", requestedAttribute))); } dst.OperationAttributes.Populate(src.AdditionalOperationAttributes); dst.JobAttributes.Populate(src.AdditionalJobAttributes); return(dst); }); //https://tools.ietf.org/html/rfc2911#section-4.4 mapper.CreateMap <IppResponseMessage, GetJobAttributesResponse>((src, map) => { var dst = new GetJobAttributesResponse { JobAttributes = map.Map <JobAttributes>(src.AllAttributes()) }; map.Map <IppResponseMessage, IIppResponseMessage>(src, dst); return(dst); }); mapper.CreateMap <IDictionary <string, IppAttribute[]>, JobAttributes>((src, map) => new JobAttributes { Compression = map.MapFromDic <Compression?>(src, JobAttribute.Compression), Copies = map.MapFromDic <int?>(src, JobAttribute.Copies), DateTimeAtCompleted = map.MapFromDic <DateTimeOffset?>(src, JobAttribute.DateTimeAtCompleted), DateTimeAtCreation = map.MapFromDic <DateTimeOffset?>(src, JobAttribute.DateTimeAtCreation), DateTimeAtProcessing = map.MapFromDic <DateTimeOffset?>(src, JobAttribute.DateTimeAtProcessing), DocumentFormat = map.MapFromDic <string?>(src, JobAttribute.DocumentFormat), DocumentName = map.MapFromDic <string?>(src, JobAttribute.DocumentName), Finishings = map.MapFromDic <Finishings?>(src, JobAttribute.Finishings), IppAttributeFidelity = map.MapFromDic <bool?>(src, JobAttribute.IppAttributeFidelity), JobId = map.MapFromDic <int?>(src, JobAttribute.JobId), JobUri = map.MapFromDic <string?>(src, JobAttribute.JobUri), JobImpressions = map.MapFromDic <int?>(src, JobAttribute.JobImpressions), JobImpressionsCompleted = map.MapFromDic <int?>(src, JobAttribute.JobImpressionsCompleted), JobKOctetsProcessed = map.MapFromDic <int?>(src, JobAttribute.JobKOctetsProcessed), JobMediaSheets = map.MapFromDic <int?>(src, JobAttribute.JobMediaSheets), JobMediaSheetsCompleted = map.MapFromDic <int?>(src, JobAttribute.JobMediaSheetsCompleted), JobName = map.MapFromDic <string?>(src, JobAttribute.JobName), JobOriginatingUserName = map.MapFromDic <string?>(src, JobAttribute.JobOriginatingUserName), JobOriginatingUserNameLanguage = map.MapFromDicLanguage(src, JobAttribute.JobOriginatingUserNameLanguage), JobPrinterUpTime = map.MapFromDic <DateTime?>(src, JobAttribute.JobPrinterUpTime), JobPrinterUri = map.MapFromDic <string?>(src, JobAttribute.JobPrinterUri), JobSheets = map.MapFromDic <JobSheets?>(src, JobAttribute.JobSheets), JobState = map.MapFromDic <JobState?>(src, JobAttribute.JobState), JobStateMessage = map.MapFromDic <string?>(src, JobAttribute.JobStateMessage), JobStateReasons = map.MapFromDicSetNull <string[]?>(src, JobAttribute.JobStateReasons), Media = map.MapFromDic <string?>(src, JobAttribute.Media), MultipleDocumentHandling = map.MapFromDic <MultipleDocumentHandling?>(src, JobAttribute.MultipleDocumentHandling), NumberUp = map.MapFromDic <int?>(src, JobAttribute.NumberUp), OrientationRequested = map.MapFromDic <Orientation?>(src, JobAttribute.OrientationRequested), PrinterResolution = map.MapFromDic <Resolution?>(src, JobAttribute.PrinterResolution), PrintQuality = map.MapFromDic <PrintQuality?>(src, JobAttribute.PrintQuality), Sides = map.MapFromDic <Sides?>(src, JobAttribute.Sides), TimeAtCompleted = map.MapFromDic <DateTime?>(src, JobAttribute.TimeAtCompleted), TimeAtCreation = map.MapFromDic <DateTime?>(src, JobAttribute.TimeAtCreation), TimeAtProcessing = map.MapFromDic <DateTime?>(src, JobAttribute.TimeAtProcessing) }); }