private void handleSendException(Exception e, string filePath, string signBody) { if (e.Message.Equals("Not find successful Aperak for document invoice")) { Logger.log("file [" + filePath + "] will be waiting for next sending"); } else if (e.Message.Contains("Not authorized")) { Logger.log("ERROR: " + e.Message + ", file [" + filePath + "] will be waiting for next sending"); } else { Logger.error("ERROR: " + e.Message + ", file [ " + filePath + " ]"); if (DFSHelper.moveDocToError(Path.GetFileName(filePath), File.ReadAllBytes(filePath))) { File.Delete(filePath); } if (DFSHelper.moveDocToError(Path.GetFileName(filePath).Replace(".xml", ".bin"), Utils.StringToBytes(signBody, "UTF-8"))) { File.Delete(filePath.Replace(".xml", ".bin")); } } }
public void processOutbound() { Logger.log("start processing outbound..."); List <string> outbound = new List <string>(); try { outbound.AddRange(Directory.GetFiles(conf.Outbound.DefaultPath).ToList()); } catch (Exception ex) { Logger.log("ERROR: outbound will NOT be procceed . Reason : " + ex.Message); return; } /* * adding all others files from custom folders */ outbound.AddRange(DFSHelper.GetOutFiles(conf.Outbound.Document)); foreach (string name in outbound) { try { string docType = DFSHelper.GetDocType(Path.GetFileName(name)); Document docSettings = conf.GetCustomOutboundSettingsByPath(docType, name); if (docSettings != null) { if (docSettings.NeedToBeSigned) // for signed docs { string thumbPrint = docSettings.Thumpprint != null ? docSettings.Thumpprint : conf.Thumpprint; string body = Utils.Base64Encode(File.ReadAllBytes(name), "windows-1251"); string sign = controller.Sign(thumbPrint, body); if (docSettings.NeedToBeZipped) // trick with non-secure soap and xp (w/o support tls over 1.0) { zipAndProcessDoc(docSettings, name, body, sign); } else if ( (docType.StartsWith("DP_") || docType.StartsWith("ON_SCHFDOPPOK") || docType.StartsWith("ON_KORSCHFDOPPOK")) && name.EndsWith(".xml") ) { if ((controller.sendDoc(Path.GetFileName(name), body)) && (controller.sendDoc(Path.GetFileName(name).Replace(".xml", ".bin"), sign))) { Logger.log(Path.GetFileName(name) + " sent successfully."); if (conf.Outbound.IsArchive) { if ((DFSHelper.moveDocToArc(Path.GetFileName(name), (File.ReadAllBytes(name)), docSettings)) && (DFSHelper.moveDocToArc(Path.GetFileName(name).Replace(".xml", ".bin"), Utils.StringToBytes(sign, "UTF-8"), docSettings))) { File.Delete(name); } } } } else if (docType.Equals("CONDRA", StringComparison.OrdinalIgnoreCase)) { var c = Condra.toObj(name); string condraXmlBody = body; string filePath = Path.GetDirectoryName(name) + Path.DirectorySeparatorChar + c.getFileName(); body = Utils.Base64Encode(File.ReadAllBytes(filePath), "UTF-8"); sign = controller.Sign(thumbPrint, body); string condraName = "condra_" + Guid.NewGuid() + ".zip"; byte[] condra = ZipHelper.createCondraZip(condraXmlBody, c.getFileName(), body, c.getSignName(), sign); if (controller.sendDoc(condraName, Utils.Base64Encode(condra, "UTF-8"))) { Logger.log(Path.GetFileName(condraName) + " sent successfully."); if (conf.Outbound.IsArchive) { if (DFSHelper.moveDocToArc(condraName, condra, docSettings)) { File.Delete(name); File.Delete(filePath); } } } } else { try { controller.sendDocApi(body, sign, docType); Logger.log(Path.GetFileName(name) + " sent successfully."); if (conf.Outbound.IsArchive) { if (DFSHelper.moveDocToArc(Path.GetFileName(name), File.ReadAllBytes(name), docSettings)) { File.Delete(name); } if (DFSHelper.moveDocToArc(Path.GetFileName(name).Replace(".xml", ".bin"), Utils.StringToBytes(sign, "UTF-8"), docSettings)) { File.Delete(name.Replace(".xml", ".bin")); } } /* * when configured -> creating xml status */ DFSHelper.saveStatus(controller, body, docSettings, null); } catch (Exception e) { try { /* * when configured -> creating xml status */ DFSHelper.saveStatus(controller, body, docSettings, e.Message); handleSendException(new Exception(e.Message + " [ " + controller.GetIDFileFromTicket(body) + " ]"), name, sign); } catch (Exception ex) { handleSendException(new Exception("XML document not well formed"), name, sign); } } } } else // for simple docs { string body = Utils.Base64Encode(File.ReadAllBytes(name), "UTF-8"); string remoteName = Path.GetFileName(name); if (docSettings.remoteFileNamePrefix != null) { remoteName = docSettings.remoteFileNamePrefix + remoteName; } if (controller.sendDoc(remoteName, body)) { Logger.log(remoteName + " sent successfully."); if (conf.Outbound.IsArchive) { if (DFSHelper.moveDocToArc(Path.GetFileName(name), (File.ReadAllBytes(name)), docSettings)) { File.Delete(name); } } } else { if (DFSHelper.moveDocToError(Path.GetFileName(name), (File.ReadAllBytes(name)))) { File.Delete(name); } } } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace);//debug only Logger.log(ex.Message); } } }