Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="coDoc"></param>
        /// <returns></returns>
        public async Task <CoDoc> DoCOUpdateAsync(CoDoc coDoc)
        {
            String content = "";

            try {
                String     urlApi = Properties.Settings.Default.Host + "/print/co/update";
                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", this.sessionId);
                String json = JsonConvert.SerializeObject(coDoc);
                Console.WriteLine("json: " + json);
                HttpContent         postContent = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage response    = await client.PostAsync(urlApi, postContent);

                if (response.IsSuccessStatusCode)
                {
                    content = await response.Content.ReadAsStringAsync();
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.StackTrace.ToString());
            }
            Console.WriteLine("content: " + content);
            coDoc = JsonConvert.DeserializeObject <CoDoc>(content);
            Console.WriteLine(coDoc.ToString());
            return(coDoc);
        }
Пример #2
0
        /// <summary>
        /// Pink form test print handler
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/></param>
        /// <param name="e">The e<see cref="EventArgs"/></param>
        private async void bntPink_Click(object sender, EventArgs e)
        {
            try {
                if (null == this.printerConfiguration)
                {
                    return;
                }

                int value = 0;
                if (!int.TryParse(this.txtWithoutLogoOffset.Text, out value))
                {
                    Alert("Please enter a numeric integer for offset");
                    this.txtWithoutLogoOffset.Focus();
                    return;
                }
                CoDoc coDoc = await restProxy.DoCOTestAsync(WebPrintRestProxy.FormType.PINK_FORM, this.txtWithoutLogoOffset.Text);

                if (null != coDoc)
                {
                    Console.WriteLine(coDoc.ToString());
                    if (!coDoc.errCode.Equals("0"))
                    {
                        throw new Exception("CO Retrieve Error " + coDoc.errCode);
                    }

                    this.UpdateControls(ConfigState.TEST_PRINT_PINK);
                    TestPrintCO(WebPrintRestProxy.FormType.PINK_FORM, coDoc);
                }
            } catch (Exception ex) {
                LogException(ex);
            }
        }
Пример #3
0
        /// <summary>
        /// White form test print handler
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/></param>
        /// <param name="e">The e<see cref="EventArgs"/></param>
        private async void bntWhite_Click(object sender, EventArgs e)
        {
            try {
                if (null == this.printerConfiguration)
                {
                    return;
                }

                CoDoc coDoc = await restProxy.DoCOTestAsync(WebPrintRestProxy.FormType.WHITE_FORM, "0");

                if (null != coDoc)
                {
                    Console.WriteLine(coDoc.ToString());
                    if (!coDoc.errCode.Equals("0"))
                    {
                        throw new Exception("CO Retrieve Error " + coDoc.errCode);
                    }

                    this.UpdateControls(ConfigState.TEST_PRINT_WHITE);
                    TestPrintCO(WebPrintRestProxy.FormType.WHITE_FORM, coDoc);
                }
            } catch (Exception ex) {
                LogException(ex);
            }
        }
Пример #4
0
        /// <summary>
        /// Test Print CO
        /// </summary>
        /// <param name="formType"></param>
        /// <returns></returns>
        public async Task <CoDoc> DoCOTestAsync(FormType formType, String offset)
        {
            CoDoc  coDoc   = new CoDoc();
            String content = "";

            try {
                String     urlApi = Properties.Settings.Default.Host + "/print/co/test/" + formType.ToString() + "/" + offset;
                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", this.sessionId);
                HttpResponseMessage response = await client.GetAsync(urlApi);

                if (response.IsSuccessStatusCode)
                {
                    content = await response.Content.ReadAsStringAsync();

                    Console.WriteLine("content: " + content);
                }
                coDoc = JsonConvert.DeserializeObject <CoDoc>(content);
            } catch (Exception ex) {
                Console.WriteLine(ex.StackTrace.ToString());
            }
            Console.WriteLine("cDoc: " + coDoc.ToString());
            return(coDoc);
        }
Пример #5
0
        /**
         * <summary>
         *      Calls webservice API {context}/co/print/{coDocNo}.
         * </summary>
         * <param name="coDocNo"> CO doc no.</param>
         * <returns>CoDoc details </returns>
         */
        public async Task <CoDoc> getCoDetailsAsync(String coDocNo)
        {
            CoDoc  coDoc   = new CoDoc();
            String content = "";

            try {
                String     urlApi = Properties.Settings.Default.Host + "/print/co/details/" + coDocNo;
                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", this.sessionId);
                HttpResponseMessage response = await client.GetAsync(urlApi);

                if (response.IsSuccessStatusCode)
                {
                    content = await response.Content.ReadAsStringAsync();
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.StackTrace.ToString());
            }

            Console.WriteLine("Awaited task has completed... printing content...");
            Console.WriteLine("content: " + content);

            try
            {
                coDoc = JsonConvert.DeserializeObject <CoDoc>(content);
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION IN DESERLIAZING.... ");
                e.StackTrace.ToString();
            }


            Console.WriteLine("Afer deserializing... " + coDoc.ToString());
            return(coDoc);
        }
Пример #6
0
        /**
         * <summary>
         *      Executes the actual currCoPrinting.
         * </summary>
         * <param name="printType">Can be ORIGINAL or COPY</param>
         * <param name="coDoc">Contains all related details of the CO</param>
         */
        private void SendCOToPrinter(PrintType printType, CoDoc coDoc)
        {
            try {
                //If no printerConfiguration object is found.
                if (null == this.printerConfiguration)
                {
                    return;
                }

                //TestPrintJob_Succeeded();
                String tempFile   = Path.GetTempFileName();
                byte[] pdfContent = null;
                switch (printType)
                {
                case PrintType.ORIGINAL:
                    pdfContent = System.Convert.FromBase64String(coDoc.orignal);
                    break;

                case PrintType.COPY:
                    pdfContent = System.Convert.FromBase64String(coDoc.copy);
                    break;
                }

                File.WriteAllBytes(tempFile, pdfContent);
                PrintJob printJob = new PrintJob(this.printerConfiguration.Name, tempFile);
                printJob.DocumentName = "Letter Portrait";

                //If printer is colored
                if (printJob.Printer.Color)
                {
                    printJob.PrintOptions.Color = true;
                }

                printJob.PrintOptions.Copies = 1;
                //?
                PaperSize paperSize = printJob.Printer.PaperSizes.A4;
                if (paperSize != null)
                {
                    printJob.PrintOptions.PaperSize = paperSize;
                }

                printJob.PrintOptions.HorizontalAlign  = HorizontalAlign.Center;
                printJob.PrintOptions.Orientation.Type = OrientationType.Portrait;
                AutoPageScaling scaling = new AutoPageScaling(ScaleTo.PagePrintableArea, true, true);
                printJob.PrintOptions.Scaling = PageScaling.ActualSize;
                printJob.PrintOptions.Scaling = scaling;
                switch (coDoc.coMediaType)
                {
                case "PrePrinted":
                    if (0 != this.printerConfiguration.PinkTray)
                    {
                        printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.PinkTray];
                    }
                    break;

                case "A4":
                    if (0 != this.printerConfiguration.WhiteTray)
                    {
                        printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.WhiteTray];
                    }
                    break;

                case "PrePrintedWithLogo":
                    if (0 != this.printerConfiguration.PPWithLogoTray)
                    {
                        printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.PPWithLogoTray];
                    }
                    break;
                }
                printJob.PrintOptions.PrintAnnotations = false;
                printJob.PrintOptions.Resolution       = printJob.Printer.Resolutions[this.printerConfiguration.Resolution];
                printJob.PrintOptions.VerticalAlign    = VerticalAlign.Top;
                printJob.Succeeded += PrintJob_Succeeded;
                printJob.Failed    += PrintJob_Failed;
                printJob.Updated   += PrintJob_Updated;

                //code to counter the non select print media type. to stop them currCoPrinting from random tray
                if (printJob.PrintOptions.PaperSource.Name == "Automatically Select")
                {
                    throw new Exception("Please select printer tray for media type" + coDoc.coMediaType);
                }

                //TestPrintJob_Succeeded();
                printJob.Print();
            } catch (Exception ex) {
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
        }
Пример #7
0
        /**
         * <summary>
         *      Performs the currCoPrinting of specific coDocNo by calling DocCoPrint method that calls to webservice.<br></br>
         *      It splits the coDocNo passed by colon.
         * </summary>
         *
         * <param name="coDocNo">CO docNo and cert no. concatenated by colon (:)</param>
         */
        private async void ExecutePrintAsync(String coDocNo)
        {
            try {
                char[] sep = { ':' };
                if (null != coDocNo && coDocNo.Length > 0)
                {
                    String[] arrcoDocNo   = coDocNo.Split(sep);
                    String   coDocNoSplit = arrcoDocNo[0];

                    Console.WriteLine("ExecutePrintAsync called for " + coDocNoSplit);

                    //set the bProcess to true for what?
                    isPrintInitiated = true;

                    //Calls the getCoDetailsAsync from server
                    CoDoc coDoc = await restProxy.getCoDetailsAsync(coDocNoSplit);

                    if (null != coDoc)
                    {
                        Console.WriteLine("CODoc found: " + coDoc.ToString());
                        PrintType printType = PrintType.COPY;

                        //if errCode is 0, no issue?
                        if (coDoc.errCode.Equals("0"))
                        {
                            // isPrintSuccess = false;
                            //if nothing has been printed yet and coOriginal is greater than 0 or = 1, set the printType to ORIGINAL
                            if ((coDoc.coDBPrintedCopies == 0 && coDoc.coOriginal > 0) || coDoc.docReqtype.Equals("CO_TESTPRINT"))
                            {
                                printType = PrintType.ORIGINAL;
                            }

                            //Do the actual currCoPrinting
                            SendCOToPrinter(printType, coDoc);
                            CoDoc responseCO = null;

                            //Waits for the current task to finish
                            waitHandle.WaitOne();

                            if (isPrintSuccess)
                            {
                                Console.WriteLine("Printed successfully....");
                                coDoc.coPrintedCopies = coDoc.coDBPrintedCopies + 1;
                                Console.WriteLine("coDoc.coDBPrintedCopies  " + coDoc.coDBPrintedCopies);
                                responseCO = await restProxy.DoCOUpdateAsync(coDoc);

                                if (responseCO.errCode != "0")
                                {
                                    Console.WriteLine("coDoc.errCode: " + responseCO.errCode);
                                    Alert("Error occured while updating CO record. Error Code " + responseCO.errCode);
                                    //stop timing and notify User to call Support and inform the error received

                                    //need to check if we can do this or not
                                    //LogException(new Exception("Non Zero Error code received from the Server. Error COde + "+ responseCO.errCode));
                                }

                                //only move the to completed listing if values below are equal
                                if ((coDoc.coPrintedCopies == (coDoc.coOriginal + coDoc.coCopies)) || (coDoc.docReqtype.Equals("CO_TESTPRINT") || coDoc.docReqtype.Equals("CO_CHAMBER_COPY")))
                                {
                                    //move to the other side
                                    printCompletedCo.Add(coDocNo);
                                    PopulateDataGridCompletedCO(printCompletedCo);
                                    currCoPrinting = null;
                                }
                            }
                            else
                            {
                                //just making sure it's really set to false
                                isPrintSuccess = false;

                                Console.WriteLine("Printed fail....");
                            }
                        }
                        else
                        {
                            Console.WriteLine("coDoc.errCode: " + coDoc.errCode);
                        }
                    }
                }
            } catch (Exception ex) {
                LogException(ex);
            }

            isPrintInitiated = false;
        }
Пример #8
0
        /// <summary>
        /// Test print the CO
        /// </summary>
        /// <param name="formType"></param>
        /// <param name="coDoc"></param>
        private void TestPrintCO(WebPrintRestProxy.FormType formType, CoDoc coDoc)
        {
            try {
                if (null == this.printerConfiguration)
                {
                    Alert(SmarteCOPrintControl.Properties.Resources.ERR_CONFIG_INVALID_CONFIG);
                    return;
                }
                if (this.cbPPWithLogo.Checked == true || this.cbPink.Checked == true)
                {
                    offsetText_check();
                }
                String tempFile = Path.GetTempFileName();
                Console.WriteLine("tempFile: " + tempFile);
                byte[] originPDF = System.Convert.FromBase64String(coDoc.orignal);
                File.WriteAllBytes(tempFile, originPDF);
                PrintJob printJob = new PrintJob(this.printerConfiguration.Name, tempFile);
                printJob.DocumentName = "Letter Portrait";
                if (printJob.Printer.Color)
                {
                    printJob.PrintOptions.Color = true;
                }

                printJob.PrintOptions.Copies = 1;
                //settin paper size to A4 #Saurabh
                PaperSize paperSize = printJob.Printer.PaperSizes.A4;
                if (paperSize != null)
                {
                    printJob.PrintOptions.PaperSize = paperSize;
                }

                printJob.PrintOptions.HorizontalAlign  = HorizontalAlign.Center;
                printJob.PrintOptions.Orientation.Type = OrientationType.Portrait;

                AutoPageScaling scaling = new AutoPageScaling(ScaleTo.PagePrintableArea, true, true);
                printJob.PrintOptions.Scaling = PageScaling.ActualSize;
                printJob.PrintOptions.Scaling = scaling;
                switch (formType)
                {
                case WebPrintRestProxy.FormType.PINK_FORM:
                    if (-1 != this.printerConfiguration.PinkTray)
                    {
                        printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.PinkTray];
                    }
                    break;

                case WebPrintRestProxy.FormType.WHITE_FORM:
                    if (-1 != this.printerConfiguration.WhiteTray)
                    {
                        printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.WhiteTray];
                    }
                    break;
                }
                printJob.PrintOptions.PrintAnnotations = false;
                printJob.PrintOptions.Resolution       = printJob.Printer.Resolutions[this.printerConfiguration.Resolution];
                printJob.PrintOptions.VerticalAlign    = VerticalAlign.Top;
                printJob.Starting  += PrintJob_Starting;
                printJob.Succeeded += PrintJob_Succeeded;
                printJob.Failed    += PrintJob_Failed;
                printJob.Updated   += PrintJob_Updated;
                printJob.Print();
            } catch (Exception ex) {
                LogException(ex);
            }
        }