public static void UpdateCreatedProductStatus(int temp_id, int option_id, AxBaseException ex) { int status = 2; if (ex != null && ex.error != null && ex.error.innererror != null) { status = -1; LogError(ex.error.innererror.message, ex.error.innererror.stacktrace, "create_product", -99); } var connectionString = ConfigurationManager.ConnectionStrings["prod_connection"].ConnectionString; using (var connection = new SqlConnection(connectionString)) { using (var cmd = new SqlCommand("bm.products_created_update_status")) { connection.Open(); cmd.Connection = connection; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@temp_id", temp_id); cmd.Parameters.AddWithValue("@option_id", option_id); cmd.Parameters.AddWithValue("@status", status); cmd.ExecuteNonQuery(); } } }
public int GetSingleTable(ErpTaskStep step, int actionId, DateTime date) { AxBaseException result = null; try { if (date == DateTime.MaxValue) { DataWriter.TruncateSingleTable(step.DbTable); } result = TaskExecute.ExecuteTask(actionId, step, date); } catch (Exception e) { result = new AxBaseException { ApplicationException = e }; } finally { OnTaskCompleted(null, new ErpTaskCompletedArgs { Exception = result, ActionId = actionId, Status = result == null ? 2 : 3 }); } return(actionId); }
//public string GetDBScript(string entity) //{ // return ScriptGeneratorModule.GenerateScript(entity); //} public int TaskList(int actionId, ErpTask erpTasks, DateTime date, int?no_of_paralle_processes) { AxBaseException result = null; try { //DataWriter.TruncateTables(erpTasks.truncate_items, erpTasks.truncate_sales_trans_dump, erpTasks.truncate_sales_trans_refresh, erpTasks.truncate_locations_and_vendors, // erpTasks.truncate_lookup_info, erpTasks.truncate_bom, erpTasks.truncate_po_to, erpTasks.truncate_price, erpTasks.truncate_attribute_refresh); TaskExecute exec = new TaskExecute(erpTasks.Steps, no_of_paralle_processes.HasValue ? no_of_paralle_processes.Value : 1, actionId, date); exec.Execute(); //foreach (var erpStep in erpTasks.Steps) //{ // ExecuteTask(actionId, erpStep, date); // possible to do some parallel processing. //} } catch (Exception e) { result = new AxBaseException { ApplicationException = e }; } finally { OnTaskCompleted(null, new ErpTaskCompletedArgs { Exception = result, ActionId = actionId, Status = result == null ? 2 : 3 }); } return(actionId); }
public static AxBaseException ExecTask(ErpTaskStep taskStep) { Process pr = new Process(); AxBaseException result = null; try { pr.StartInfo.FileName = taskStep.ExternalProcess; pr.StartInfo.Arguments = taskStep.ExternalProcessArgument ?? ""; pr.StartInfo.UseShellExecute = false; pr.StartInfo.RedirectStandardError = true; pr.StartInfo.RedirectStandardOutput = true; //pr.StartInfo.Verb = "runas"; bool success = pr.Start(); pr.WaitForExit(); string standardError = pr.StandardError.ReadToEnd(); if (!string.IsNullOrEmpty(standardError)) { result = new AxBaseException { ApplicationException = new ApplicationException(standardError) }; } return(result); } catch (Exception e) { return(new AxBaseException { ApplicationException = e }); } }
public static void UpdateActionStatus(int id, int status, Task a, AxBaseException e) { string errorMessage = null; string errorStackTrace = null; if (a != null && a.IsFaulted) { status = 3; if (a.Exception != null) { if (!string.IsNullOrEmpty(a.Exception.StackTrace)) { errorMessage = a.Exception.Message; errorStackTrace = a.Exception.StackTrace; } else if (a.Exception.GetBaseException() == null) { errorMessage = a.Exception.GetBaseException().Message; errorStackTrace = a.Exception.GetBaseException().StackTrace; } } } else if (e != null && e.ApplicationException != null) { status = 3; errorMessage = e.ApplicationException.Message; errorStackTrace = e.ApplicationException.StackTrace; } else if (e != null && e.error != null && e.error.innererror != null) { status = 3; errorMessage = e.error.innererror.message; errorStackTrace = e.error.innererror.stacktrace; } var connectionString = ConfigurationManager.ConnectionStrings["stg_connection"].ConnectionString; using (var connection = new SqlConnection(connectionString)) { using (var cmd = new SqlCommand("erp.update_transfer_status")) { connection.Open(); cmd.Connection = connection; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@action_id", id); cmd.Parameters.AddWithValue("@status", status); cmd.Parameters.AddWithValue("@error_message", errorMessage); cmd.Parameters.AddWithValue("@error_stack_trace", errorStackTrace); cmd.ExecuteNonQuery(); } } }
public override int CreatePoTo(List <POTOCreate> po_to_create, int actionId) { try { DateTime start = DateTime.Now; var SapComanyCode = "1000";// DataWriter.GetSetting("SapCompanyCode"); if (po_to_create.Any()) { AxBaseException result = null; var first = po_to_create.First(x => x.unit_qty_chg > 0); if (first.order_id > 0) { try { //DataWriter.LogError("Processing order nr " + oRow.id, this.ToString(), SapToStgWriter.ERROR_CODE.PROD_TO_SAP, // "", ""); if (first.vendor_location_type.ToLower() != "vendor") { var res = CreateTO(po_to_create, SapComanyCode); if (res.Exception == null && !string.IsNullOrEmpty(res.SimpleResult)) { SAPDbHandler.SetAGR5OrderAsTransfered(first.order_id, res.SimpleResult, "Res"); } else { result = res.Exception; } } else { var req = CreatePO(po_to_create, SapComanyCode); if (req != null && req.Exception == null && !string.IsNullOrEmpty(req.SimpleResult)) { SAPDbHandler.SetAGR5OrderAsTransfered(first.order_id, req.SimpleResult, "Req"); } else { result = req.Exception; } } if (result == null) { DataWriter.LogErpActionStep(actionId, "Create PO or TO orderid = " + first.order_id, start, true, null, null, -1); DataWriter.UpdateOrderStatus(first.order_id); } else { DataWriter.LogErpActionStep(actionId, "Create PO or TO orderid = " + first.order_id, start, false, result.ErrorMessage, result.StackTrace, -1); } } catch (Exception e) { DataWriter.LogError("Error on transfer", e.StackTrace, this, e.HResult); } //SapToStgWriter.SetOrderAsTransfered(orderId); } else { DataWriter.LogErpActionStep(actionId, "No items to transfer for order_id = " + first.order_id, start, false, null, null, -1); } } } catch (Exception e) { DataWriter.LogError("Error in Prod to Sap Transfer", e.StackTrace, this, e.HResult); } return(actionId); }
public static AxBaseException ExecuteTask(int actionId, ErpTaskStep erpStep, DateTime date) { if (!string.IsNullOrEmpty(erpStep.ExternalProcess)) { DateTime start = DateTime.Now; var baseEx = ExternalTaskExec.ExecTask(erpStep); DataWriter.LogErpActionStep(actionId, erpStep.StepName, start, baseEx == null, baseEx == null ? null : baseEx.ApplicationException.InnerException.Message, baseEx == null ? null : baseEx.ApplicationException.InnerException.StackTrace, erpStep.Id); return(baseEx); } else { AxBaseException result = null; if (erpStep.TaskType == ErpTaskStep.ErpTaskType.ODATA_ENDPOINT) { if (erpStep.MaxPageSize.HasValue) { MethodInfo method = typeof(ServiceConnector).GetMethod("CallOdataEndpointWithPageSize"); MethodInfo generic = method.MakeGenericMethod(erpStep.ReturnType); Object[] parameters = new Object[3]; parameters = new object[] { erpStep, actionId, Authenticator.GetAuthData(erpStep.AuthenitcationType) }; result = ((Task <AxBaseException>)generic.Invoke(null, parameters)).Result; } else { Type genericType = erpStep.GenericObjectType.MakeGenericType(erpStep.ReturnType); MethodInfo method = typeof(ServiceConnector).GetMethod("CallOdataEndpoint"); MethodInfo generic = method.MakeGenericMethod(genericType, erpStep.ReturnType); Object[] parameters = new Object[3]; parameters = new object[] { erpStep, actionId, Authenticator.GetAuthData(erpStep.AuthenitcationType) }; result = ((Task <AxBaseException>)generic.Invoke(null, parameters)).Result; } } else if (erpStep.TaskType == ErpTaskStep.ErpTaskType.CUSTOM_SERVICE) { MethodInfo method = typeof(ServiceConnector).GetMethod("CallService"); MethodInfo generic = method.MakeGenericMethod(erpStep.ReturnType); result = ((Task <AxBaseException>)generic.Invoke(null, new Object[3] { actionId, erpStep, Authenticator.GetAuthData(erpStep.AuthenitcationType) })).Result; } else if (erpStep.TaskType == ErpTaskStep.ErpTaskType.CUSTOM_SERVICE_BY_DATE) { MethodInfo method = typeof(ServiceConnector).GetMethod("CallServiceByDate"); MethodInfo generic = method.MakeGenericMethod(erpStep.ReturnType); Func <DateTime, DateTime> action = null; switch (erpStep.PeriodIncrement) { case ErpTaskStep.PeriodIncrementType.HOURS: { action = delegate(DateTime d) { return(d.AddHours(1)); }; break; } case ErpTaskStep.PeriodIncrementType.DAYS: { action = delegate(DateTime d) { return(d.AddDays(1)); }; break; } case ErpTaskStep.PeriodIncrementType.MONTHS: { action = delegate(DateTime d) { return(d.AddMonths(1)); }; break; } default: { action = null; break; } } Object[] parameters = new Object[5] { date, actionId, erpStep, Authenticator.GetAuthData(erpStep.AuthenitcationType), action }; result = ((Task <AxBaseException>)generic.Invoke(null, parameters)).Result; } else if (erpStep.TaskType == ErpTaskStep.ErpTaskType.ITERATIVE_ENDPOINT) { var list = DataWriter.GetIdsFromEntities(erpStep.BaseTypeProcedure); var endPointTemplate = erpStep.EndPoint; foreach (var id in list) { erpStep.EndPoint = endPointTemplate.Replace("{key}", id); Type genericType = erpStep.GenericObjectType.MakeGenericType(erpStep.ReturnType); MethodInfo method = typeof(ServiceConnector).GetMethod("CallOdataEndpoint"); MethodInfo generic = method.MakeGenericMethod(genericType, erpStep.ReturnType); Object[] parameters = new Object[3]; var authData = Authenticator.GetAuthData(erpStep.AuthenitcationType); authData.InjectionPropertyName = erpStep.InjectionPropertyName; authData.InjectionPropertyValue = id; parameters = new object[] { erpStep, actionId, authData }; result = ((Task <AxBaseException>)generic.Invoke(null, parameters)).Result; } } else if (erpStep.TaskType == ErpTaskStep.ErpTaskType.COMPLEX_RETURN_TYPE) { Type genericType = erpStep.GenericObjectType.MakeGenericType(erpStep.ReturnType); MethodInfo method = typeof(ServiceConnector).GetMethod("CallOdataEndpointComplex"); MethodInfo generic = method.MakeGenericMethod(genericType, erpStep.ReturnType); Object[] parameters = new Object[3]; parameters = new object[] { erpStep, actionId, Authenticator.GetAuthData(erpStep.AuthenitcationType) }; result = ((Task <AxBaseException>)generic.Invoke(null, parameters)).Result; } else if (erpStep.TaskType == ErpTaskStep.ErpTaskType.COMPLEX_RETURN_TYPE_BY_DATE) { //Hard code start date to be 2019-01-01 if (date == DateTime.MaxValue) { date = new DateTime(2019, 1, 1); } Type genericType = erpStep.GenericObjectType.MakeGenericType(erpStep.ReturnType); MethodInfo method = typeof(ServiceConnector).GetMethod("CallOdataEndpointComplexByDate"); MethodInfo generic = method.MakeGenericMethod(genericType, erpStep.ReturnType); Object[] parameters = new Object[7]; parameters = new object[] { erpStep.EndPoint, erpStep.EndpointFilter, erpStep.Details, actionId, Authenticator.GetAuthData(erpStep.AuthenitcationType), erpStep.StepName, date }; result = ((Task <AxBaseException>)generic.Invoke(null, parameters)).Result; } return(null); } }
public static AxBaseException ExecuteTask(int actionId, ErpTaskStep erpStep, DateTime date) { AxBaseException result = null; if (erpStep.TaskType == ErpTaskStep.ErpTaskType.ODATA_ENDPOINT) { if (erpStep.MaxPageSize.HasValue) { MethodInfo method = typeof(ServiceConnector).GetMethod("CallOdataEndpointWithPageSize"); MethodInfo generic = method.MakeGenericMethod(erpStep.ReturnType); Object[] parameters = new Object[4]; parameters = new object[] { erpStep.EndPoint, erpStep.MaxPageSize.Value, erpStep.DbTable, actionId }; result = ((Task <AxBaseException>)generic.Invoke(null, parameters)).Result; } else { MethodInfo method = typeof(ServiceConnector).GetMethod("CallOdataEndpoint"); MethodInfo generic = method.MakeGenericMethod(erpStep.ReturnType); Object[] parameters = new Object[4]; parameters = new object[] { erpStep.EndPoint, erpStep.EndpointFilter, erpStep.DbTable, actionId }; result = ((Task <AxBaseException>)generic.Invoke(null, parameters)).Result; } } else if (erpStep.TaskType == ErpTaskStep.ErpTaskType.CUSTOM_SERVICE) { MethodInfo method = typeof(ServiceConnector).GetMethod("CallService"); MethodInfo generic = method.MakeGenericMethod(erpStep.ReturnType); result = ((Task <AxBaseException>)generic.Invoke(null, new Object[5] { actionId, erpStep.ServiceMethod, erpStep.ServiceName, erpStep.DbTable, erpStep.MaxPageSize })).Result; } else if (erpStep.TaskType == ErpTaskStep.ErpTaskType.CUSTOM_SERVICE_BY_DATE) { MethodInfo method = typeof(ServiceConnector).GetMethod("CallServiceByDate"); MethodInfo generic = method.MakeGenericMethod(erpStep.ReturnType); Func <DateTime, DateTime> action = null; switch (erpStep.PeriodIncrement) { case ErpTaskStep.PeriodIncrementType.HOURS: { action = delegate(DateTime d) { return(d.AddHours(1)); }; break; } case ErpTaskStep.PeriodIncrementType.DAYS: { action = delegate(DateTime d) { return(d.AddDays(1)); }; break; } case ErpTaskStep.PeriodIncrementType.MONTHS: { action = delegate(DateTime d) { return(d.AddMonths(1)); }; break; } default: { action = null; break; } } Object[] parameters = new Object[6] { date, actionId, erpStep.ServiceMethod, erpStep.ServiceName, erpStep.DbTable, action }; result = ((Task <AxBaseException>)generic.Invoke(null, parameters)).Result; } return(result); }