public void SetPrintingDevice(PrintingDevice printingDevice) { ProcedureCall storePrintingDevice = new ProcedureCall("pr_storePrintingDevice", sqlConnection); storePrintingDevice.parameters.Add(new ProcedureParam("@tenantId", SqlDbType.Int, 4, printingDevice.tenantId)); storePrintingDevice.parameters.Add(new ProcedureParam("@ipAddress", SqlDbType.VarChar, 100, printingDevice.ipAddress)); storePrintingDevice.parameters.Add(new ProcedureParam("@description", SqlDbType.VarChar, 100, printingDevice.description)); storePrintingDevice.parameters.Add(new ProcedureParam("@serialNumber", SqlDbType.VarChar, 100, printingDevice.serialNumber)); storePrintingDevice.parameters.Add(new ProcedureParam("@counter", SqlDbType.Int, 4, printingDevice.counter)); storePrintingDevice.Execute(true); int?deviceId = storePrintingDevice.ExtractFromResultset(); if (deviceId != null) { List <Object> counterHistory = GetCounterHistory(deviceId.Value); if (counterHistory.Count > 0) { // Verifica se o contador é repetido, considera uma diferença de 50 páginas ao comparar DateTime today = DateTime.Now; PageCounter lastCounter = (PageCounter)counterHistory[0]; Decimal diff = Math.Abs(printingDevice.counter - lastCounter.counter); if ((lastCounter.date.Day != today.Day) || (diff > 50)) { SetPageCounter(deviceId.Value, printingDevice.counter); } } else { // Nenhum contador prévio, insere primeira ocorrência SetPageCounter(deviceId.Value, printingDevice.counter); } } }
public void Print(Job job) { var gsVersion = _ghostscriptDiscovery.GetGhostscriptInstance(); if (gsVersion == null) { _logger.Error("No valid Ghostscript version found."); throw new InvalidOperationException("No valid Ghostscript version found."); } _logger.Debug("Ghostscript Version: " + gsVersion.Version + " loaded from " + gsVersion.ExePath); var ghostscript = new GhostScript(gsVersion); OutputDevice printingDevice = new PrintingDevice(job); ghostscript.Run(printingDevice, job.JobTempFolder); }
private void button2_Click(object sender, EventArgs e) { // Registra os dispositivos SNMP com número de série e contador PrintingDevice printingDevice1 = new PrintingDevice(); printingDevice1.tenantId = 5; printingDevice1.ipAddress = "192.168.0.101"; printingDevice1.description = "Brother MFC-8890DW"; printingDevice1.serialNumber = "E0J405989"; printingDevice1.counter = 11111; printingDevice1.lastUpdated = DateTime.Now; PrintingDevice printingDevice2 = new PrintingDevice(); printingDevice2.tenantId = 5; printingDevice2.ipAddress = "192.168.0.136"; printingDevice2.description = "Lexmark X466de 35P620G LR.BS.P649"; printingDevice2.serialNumber = "35P620G"; printingDevice2.counter = 22222; printingDevice2.lastUpdated = DateTime.Now; List <PrintingDevice> deviceList = new List <PrintingDevice>(); deviceList.Add(printingDevice1); deviceList.Add(printingDevice2); /************************************************************************************/ Byte[] serializedObject = ObjectSerializer.SerializeObjectToArray(deviceList); String encodedData = HttpUtility.UrlEncode(Convert.ToBase64String(serializedObject)); Byte[] postData = Encoding.UTF8.GetBytes("txtPostData=" + encodedData); String serviceUrl = "http://localhost:2086/JobRoutingService.aspx"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceUrl + "?" + "action=RegisterDevices"); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(postData, 0, postData.Length); requestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); MessageBox.Show(response.StatusCode + Environment.NewLine); }
public void SetUp() { _printerStub = MockRepository.GenerateStub <PrinterWrapper>(); // TODO Use NSubstitute and Interface var jobStub = ParametersTestHelper.GenerateJobStub(OutputFormat.Txt); jobStub.OutputFiles = new List <string>(); jobStub.OutputFiles.Add(TestFileDummie); var fileStub = MockRepository.GenerateStub <IFile>(); var osHelperStub = MockRepository.GenerateStub <IOsHelper>(); osHelperStub.Stub(x => x.WindowsFontsFolder).Return(ParametersTestHelper.WindowsFontsFolderDummie); var commandLineUtilStub = MockRepository.GenerateStub <ICommandLineUtil>(); _printingDevice = new PrintingDevice(jobStub, _printerStub, fileStub, osHelperStub, commandLineUtilStub); _printingDevice.Job.OutputFiles.Add(TestFileDummie); _ghostscriptVersion = ParametersTestHelper.GhostscriptVersionDummie; }
/// <summary> /// Prints the input files to the configured printer /// </summary> /// <param name="job">The job to process</param> /// <returns>An ActionResult to determine the success and a list of errors</returns> public ActionResult ProcessJob(IJob job) { Logger.Debug("Launched Printing-Action"); try { OutputDevice printingDevice = new PrintingDevice(job); _ghostscript.Run(printingDevice, job.JobTempFolder); return(new ActionResult()); } catch (Exception ex) { try { var errorCode = Convert.ToInt32(ex.Message); return(new ActionResult(ActionId, errorCode)); } catch { Logger.Error("Error while printing"); return(new ActionResult(ActionId, 999)); } } }