/// <summary> /// Zápis do logovací tabulky AppLogNew /// </summary> /// <param name="authToken"></param> /// <param name="type"></param> /// <param name="message"></param> /// <param name="xmlDeclaration"></param> /// <param name="xmlMessage"></param> /// <param name="zicyzUserId"></param> /// <param name="sourceName"></param> /// <returns></returns> public static SubmitDataToProcessingResult AppLogWrite(AuthToken authToken, string type, string message, string xmlDeclaration, string xmlMessage, int zicyzUserId, string sourceName) { SubmitDataToProcessingResult result = new SubmitDataToProcessingResult(); try { if (authToken != null) { FenixAppSvcClient appClient = new FenixAppSvcClient(); appClient.AuthToken = new Fenix.WebService.Service_References.FenixAppService.AuthToken() { Value = authToken.Value }; ProcResult procResult = appClient.AppLogWriteNew(type, message, xmlDeclaration, xmlMessage, zicyzUserId, sourceName); appClient.Close(); if (procResult.ReturnValue == (int)BC.OK) { CreateOkResult(ref result); } else { CreateErrorResult(ApplicationLog.GetMethodName(), ref result, "90", procResult.ReturnMessage); } } } catch (Exception ex) { CreateErrorResult(ApplicationLog.GetMethodName(), ref result, "100", ex); } return(result); }
public SubmitDataToProcessingResult SubmitDataToProcessing(string login, string password, string partnerCode, string messageType, byte[] data, string encoding) { SubmitDataToProcessingResult result = new SubmitDataToProcessingResult(); if (!baseValidation(partnerCode, messageType, data, encoding, result)) { return(result); } try { AuthResult authRes; AuthSvcClient authProxy = new AuthSvcClient(); AuthToken authToken = authProxy.Login(login, password, "", out authRes); authProxy.Close(); if (authToken != null) { result = ProcessData(login, password, partnerCode, messageType, data, encoding, result, authToken); } else { ProjectHelper.CreateErrorResult(Fenix.ApplicationLog.GetMethodName(), ref result, "1", "Invalid login"); } } catch (Exception ex) { ProjectHelper.CreateErrorResult(Fenix.ApplicationLog.GetMethodName(), ref result, "100", ex); } return(result); }
/* * * internal static ProcResult CreateErrorResult(string methodName, Exception ex) * { * ProcResult result = new ProcResult(); * * result.ReturnValue = BC.NOT_OK; * result.ReturnMessage = String.Format("{0}{1}{2}", methodName, Environment.NewLine, ex.Message); * * Exception innerExeption = ex.InnerException; * while (innerExeption != null) * { * result.ReturnMessage += result.ReturnMessage + Environment.NewLine + ex.InnerException.Message; * innerExeption = innerExeption.InnerException; * } * * return result; * } * * */ /// <summary> /// Odstraní OK result (pokud existuje) /// </summary> /// <param name="result">odtud se odstraní OK result</param> private static void RemoveOkResult(ref SubmitDataToProcessingResult result) { if (result.MessageNumber == BC.OK && result.Errors.Count >= 1) { result.Errors.Clear(); } }
/// <summary> /// Vytvoří result pro OK /// </summary> /// <param name="result"></param> public static void CreateOkResult(ref SubmitDataToProcessingResult result) { result.MessageNumber = BC.OK; result.MessageDescription = "OK"; result.Errors.Add(new Errors { ErrorCode = "0", ErrorMessage = "Success" }); }
/// <summary> /// Vytvoří chybový result /// </summary> /// <param name="methodName"></param> /// <param name="result"></param> /// <param name="errorCode">kód chyby</param> /// <param name="errorMessage">text chyby</param> public static void CreateErrorResult(string methodName, ref SubmitDataToProcessingResult result, string errorCode, string errorMessage) { RemoveOkResult(ref result); result.MessageNumber = BC.NOT_OK; result.MessageDescription = $"ERROR in {methodName}"; result.Errors.Add(new Errors { ErrorCode = errorCode, ErrorMessage = errorMessage }); }
/// <summary> /// Vytvoří chybový result /// </summary> /// <param name="methodName"></param> /// <param name="result"></param> /// <param name="errorCode">kód chyby</param> /// <param name="ex">vyjímka</param> public static void CreateErrorResult(string methodName, ref SubmitDataToProcessingResult result, string errorCode, Exception ex) { RemoveOkResult(ref result); result.MessageNumber = BC.NOT_OK; result.MessageDescription = $"ERROR in {methodName}"; result.Errors.Add(new Errors { ErrorCode = errorCode, ErrorMessage = ex.Message }); Exception innerExeption = ex.InnerException; while (innerExeption != null) { result.Errors.Add(new Errors { ErrorCode = errorCode, ErrorMessage = ex.InnerException.Message }); innerExeption = innerExeption.InnerException; } }
/// <summary> /// Základní validace (vyplnění parametrů) /// </summary> /// <param name="partnerCode"></param> /// <param name="messageType"></param> /// <param name="encoding"></param> /// <param name="result"></param> /// <param name="data"></param> /// <returns></returns> private bool baseValidation(string partnerCode, string messageType, byte[] data, string encoding, SubmitDataToProcessingResult result) { if (String.IsNullOrEmpty(partnerCode) || String.IsNullOrEmpty(messageType) || data == null || String.IsNullOrEmpty(encoding)) { ProjectHelper.CreateErrorResult(Fenix.ApplicationLog.GetMethodName(), ref result, "10", "Invalid input parameter"); return(false); } return(true); }
/// <summary> /// Vlastní zpracování přijaté zprávy dle jejího typu /// </summary> /// <param name="login"></param> /// <param name="password"></param> /// <param name="partnerCode"></param> /// <param name="messageType"></param> /// <param name="data"></param> /// <param name="encoding"></param> /// <param name="result"></param> /// <param name="authToken"></param> /// <returns></returns> private static SubmitDataToProcessingResult ProcessData(string login, string password, string partnerCode, string messageType, byte[] data, string encoding, SubmitDataToProcessingResult result, AuthToken authToken) { string messageTypeNormalized = messageType.ToUpper().Trim(); if (messageTypeNormalized.Contains("TEST")) { messageTypeNormalized = "TEST"; } switch (messageTypeNormalized) { case "TEST": result = TestProcessing.Process(authToken, login, password, partnerCode, messageType, data, encoding); break; case "GETSERVICESSTATUSES": result = ServicesStatusesProcessing.Process(authToken, login, password, partnerCode, messageType); break; case "RECEPTIONCONFIRMATION": case "KITTINGCONFIRMATION": case "SHIPMENTCONFIRMATION": case "RETURNED": case "RETURNEDEQUIPMENT": case "RETURNEDITEM": case "RETURNEDSHIPMENT": case "REFURBISHEDCONFIRMATION": case "DELETEMESSAGECONFIRMATION": case "CRMORDERCONFIRMATION": case "CRMORDERAPPROVAL": result = MessageProcessing.Process(authToken, login, password, partnerCode, messageType, data, encoding); break; default: ProjectHelper.CreateErrorResult(Fenix.ApplicationLog.GetMethodName(), ref result, "100", String.Format("Unknown messageType = [{0}]", messageType)); break; } return(result); }
public SubmitDataToProcessingResult SubmitRepaseData(string login, string password, string messageType, byte[] data, string encoding, int customerId = 0, string customerDescription = null, DateTime?dateOfDelivery = null) { SubmitDataToProcessingResult result = new SubmitDataToProcessingResult(); // basic validations if (String.IsNullOrEmpty(messageType)) { result.Errors.Add(new Errors { ErrorCode = "-100", ErrorMessage = "Parameter messageType is required!" }); } if (data == null) { result.Errors.Add(new Errors { ErrorCode = "-101", ErrorMessage = "Parameter data is required!" }); } if (String.IsNullOrEmpty(encoding)) { result.Errors.Add(new Errors { ErrorCode = "-102", ErrorMessage = "Parameter encoding is required!" }); } if (messageType.Contains("TR") || messageType.Contains("TS")) { if (customerId == 0) { result.Errors.Add(new Errors { ErrorCode = "-103", ErrorMessage = "If using TR/TS MSG types, customerId is required!" }); } if (String.IsNullOrEmpty(customerDescription)) { result.Errors.Add(new Errors { ErrorCode = "-104", ErrorMessage = "If using TR/TS MSG types, customerDescription is required!" }); } if (dateOfDelivery == null) { result.Errors.Add(new Errors { ErrorCode = "-105", ErrorMessage = "If using TR/TS MSG types, dateOfDelivery is required!" }); } } // authentication AuthResult authRes; AuthSvcClient authProxy = new AuthSvcClient(); AuthToken authToken = authProxy.Login(login, password, "", out authRes); authProxy.Close(); if (authToken != null && result.Errors.Count == 0) { // test processing result = TestProcessing.Process(authToken, login, password, "", messageType, data, encoding); } else { ProjectHelper.CreateErrorResult(Fenix.ApplicationLog.GetMethodName(), ref result, "1", "Invalid login"); } return(result); }
public SimpleResult TSubmitDataToProcessing(string login, string password) { SimpleResult result = new SimpleResult(); try { if (ProjectHelper.Os.IsWindowsServer() || System.Web.Configuration.WebConfigurationManager.AppSettings["DebugMode"] != "1") { throw new Exception("TSubmitDataToProcessing Exception"); } // {TEST; ReceptionConfirmation; KittingConfirmation; ShipmentConfirmation; RefurbishedConfirmation; // ReturnedEquipment; ReturnedItem; ReturnedShipment; GetServicesStatuses} //string type = "Test"; //string inputString = TestManually.GetTest(); //string type = "ReceptionConfirmation"; //string inputString = ReceptionConfirmationManually.GetReceptionConfirmation(10); //string type = "KittingConfirmation"; //string inputString = KittingConfirmationManually.GetKittingConfirmation(4); //string type = "ShipmentConfirmation"; //string inputString = ShipmentOrderManually.GetShipmentConfirmation(42); //string type = "ReturnedEquipment"; //string inputString = ReturnedEquipmentManually.GetReturnedEquipment(3); //string type = "ReturnedItem"; //string inputString = ReturnedItemManually.GetReturnedItem(3); //string type = "ReturnedShipment"; //string inputString = ReturnedShipmentManually.GetReturnedShipment(2); //string type = "RefurbishedConfirmation"; //string inputString = RefurbishedConfirmationManually.GetRefurbishedConfirmation(3); //string type = "GetServicesStatuses"; //string inputString = "V tomto případě se nepoužívá - existuje jen pro zachování signatury metody SubmitDataToProcessing"; //string type = "CrmOrderConfirmation"; //string inputString = CrmOrderConfirmationManually.GetCrmOrderConfirmation(1); string type = "CrmOrderApproval"; string inputString = CrmOrderApprovalManually.GetCrmOrderApproval(2); byte[] byteU8 = Encoding.UTF8.GetBytes(inputString); SubmitDataToProcessingResult processingResult = SubmitDataToProcessing(login, password, Environment.MachineName, type, byteU8, "UTF-8"); result.Number = (int)processingResult.MessageNumber; result.Message = result.Number == (int)BC.OK ? "OK" : processingResult.Errors[0].ErrorMessage; } catch (Exception ex) { result.Number = 1; result.Message = ex.Message; } return(result); }