/// <summary> /// /// </summary> /// <param name="siteId"></param> /// <param name="guid"></param> /// <param name="title">Approve Post Comment</param> /// <param name="description"></param> /// <param name="deleteAfterComplete"></param> /// <param name="completedMessage">Comment has been approved</param> /// <param name="namespaceAndClass">AWAPI_BusinessLibrary.library.BlogLibrary</param> /// <param name="methodName">UpdateBlogPostCommentStatus</param> /// <param name="methodParameters">int64:5635821884568557888|int:1</param> /// <param name="resultRedirectUrl">http://awapi.com/registerationconfirm.aspx. The page will be resurect to /// resultRedirectUrl + "?status=ok/error&description={description}"</param> public void Add(long siteId, long automatedTaskGroupId, Guid guid, string title, string description, bool deleteAfterComplete, string completedMessage, string namespaceAndClass, string methodName, string methodParameters, string resultRedirectUrl) { awAutomatedTask task = new awAutomatedTask(); task.automatedTaskId = AWAPI_Common.library.MiscLibrary.CreateUniqueId(); task.siteId = siteId; task.automatedTaskGroupId = automatedTaskGroupId; task.guidToRun = guid; task.title = title; task.description = description; task.deleteAfterComplete = deleteAfterComplete; task.completedMessage = completedMessage; task.namespaceAndClass = namespaceAndClass; task.methodName = methodName; task.methodParameters = methodParameters; task.resultRedirectUrl = resultRedirectUrl; task.lastBuildDate = DateTime.Now; task.createDate = DateTime.Now; _context.awAutomatedTasks.InsertOnSubmit(task); _context.SubmitChanges(); }
public bool RunTask(awAutomatedTask task) { try { Assembly asm = Assembly.GetExecutingAssembly(); Type type = asm.GetType(task.namespaceAndClass); object obj = Activator.CreateInstance(type); MethodInfo method = type.GetMethod(task.methodName); if (String.IsNullOrEmpty(task.methodParameters)) { method.Invoke(obj, null); } else { string[] prms = task.methodParameters.Split('|'); object[] objParams = new object[prms.Length]; int n = 0; foreach (string prm in prms) { if (prm.ToLower().IndexOf("int:") == 0) { objParams[n] = Convert.ToInt32(prm.Replace("int:", "")); } else if (prm.ToLower().IndexOf("int64:") == 0) { objParams[n] = Convert.ToInt64(prm.Replace("int64:", "")); } if (prm.ToLower().IndexOf("string:") == 0) { objParams[n] = prm.Replace("string:", ""); } if (prm.ToLower().IndexOf("bool:") == 0) { objParams[n] = Convert.ToBoolean(prm.Replace("bool:", "")); } if (prm.ToLower().IndexOf("double:") == 0) { objParams[n] = Convert.ToDouble(prm.Replace("double:", "")); } n++; } method.Invoke(obj, objParams); CompleteTask(task.automatedTaskGroupId); } } catch (Exception ex) { string error = ex.Message + ex.InnerException == null ? "" : "\n" + ex.InnerException.Message; UpdateErrorMessage(task.guidToRun, error); return(false); } return(true); }
public void UpdateErrorMessage(Guid guid, string errorMessage) { awAutomatedTask task = (from l in _context.awAutomatedTasks where l.guidToRun.Equals(guid) select l).FirstOrDefault(); if (task == null) { return; } task.errorMessage = errorMessage; task.lastBuildDate = DateTime.Now; _context.SubmitChanges(); }
public bool RunTask(Guid guid) { awAutomatedTask task = Get(guid); return(RunTask(task)); }
public bool RunTask(long taskId) { awAutomatedTask task = Get(taskId); return(RunTask(task)); }