예제 #1
0
        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);
            });
        }
예제 #2
0
        private bool _handlePost(HttpListenerRequest req, HttpListenerResponse resp, string accesslog)
        {
            if (req.HasEntityBody)
            {
                PrintJobResponse printjobresp = new PrintJobResponse();
                try
                {
                    using (Stream body = req.InputStream)
                    {
                        Encoding encoding = req.ContentEncoding;
                        using (StreamReader reader = new StreamReader(body, encoding))
                        {
                            string           json     = reader.ReadToEnd();
                            PrintJobPostBody printjob = ServerConfig.fromJSON <PrintJobPostBody>(json);
                            body.Close();
                            reader.Close();

                            byte[] bindata = printjob.DataToByteArray();

                            bool success = false;
                            if (server.config.testingMode == 1)
                            {
                                success = WritePrintJobFile(printjob.id, bindata);
                            }
                            else if (server.config.testingMode == 0)
                            {
                                success = RawPrintingHelper.SendBytesToPrinter(printjob.printer, bindata, printjob.id);
                            }
                            else
                            {
                                success = RawPrintingHelper.SendBytesToPrinter(printjob.printer, bindata, printjob.id) && WritePrintJobFile(printjob.id, bindata);
                            }

                            accesslog += "\tsuccess\t" + printjob.id;
                            ServerConfig.appendLog(accesslog);
                            printjobresp.success = true;
                            printjobresp.data    = printjob.id;
                        }
                    }
                }
                catch (Exception e)
                {
                    printjobresp.success = false;
                    printjobresp.data    = e.Message;
                    accesslog           += "\tfailed";
                    ServerConfig.appendLog(accesslog);
                }
                byte[] data = Encoding.UTF8.GetBytes(ServerConfig.toJSON(printjobresp));
                resp.ContentType     = "application/json";
                resp.ContentEncoding = Encoding.UTF8;
                resp.ContentLength64 = data.LongLength;
                resp.OutputStream.Write(data, 0, data.Length);
                resp.Close();
            }
            else
            {
                return(true);
            }
            return(false);
        }
예제 #3
0
        private ResponseCode _handlePost(HttpListenerRequest req, HttpListenerResponse resp, string accesslog)
        {
            if (!req.HasEntityBody)
            {
                return(ResponseCode.NotFound);
            }

            PrintJobResponse printjobresp = new PrintJobResponse();

            try
            {
                using (Stream body = req.InputStream)
                {
                    Encoding encoding = req.ContentEncoding;
                    using (StreamReader reader = new StreamReader(body, encoding))
                    {
                        string           json     = reader.ReadToEnd();
                        PrintJobPostBody printjob = ServerConfig.fromJSON <PrintJobPostBody>(json);
                        body.Close();
                        reader.Close();

                        byte[] bindata = printjob.DataToByteArray();

                        bool success = false;
                        if (server.config.testingMode == 1)
                        {
                            success = WritePrintJobFile(printjob.id, bindata);
                        }
                        else if (server.config.testingMode == 0)
                        {
                            success = RawPrintingHelper.SendBytesToPrinter(printjob.printer, bindata, printjob.id);
                        }
                        else
                        {
                            success = RawPrintingHelper.SendBytesToPrinter(printjob.printer, bindata, printjob.id) && WritePrintJobFile(printjob.id, bindata);
                        }

                        accesslog += "\tsuccess\t" + printjob.id + "\t" + printjob.printer;
                        ServerConfig.appendLog(accesslog);
                        printjobresp.success = true;
                        printjobresp.data    = printjob.id;
                    }
                }
            }
            catch (Exception e)
            {
                ServerConfig.appendLog("Error: " + e.Message + "\n" + e.StackTrace);
                printjobresp.success = false;
                printjobresp.data    = "";
                accesslog           += "\tfailed";
                ServerConfig.appendLog(accesslog);
            }
            server.responseJSON(resp, printjobresp);

            return(ResponseCode.OK);
        }