2226 lines
118 KiB
C#
2226 lines
118 KiB
C#
using EnVisage.Code.BLL;
|
|
using EnVisage.Models;
|
|
using OptimaJet.Workflow.Core.Model;
|
|
using OptimaJet.Workflow.Core.Runtime;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Mvc;
|
|
using NLog;
|
|
using System.Data.Entity.Validation;
|
|
using Newtonsoft.Json;
|
|
using System.IO;
|
|
using System.Xml.Serialization;
|
|
using System.Xml;
|
|
|
|
namespace EnVisage.Code
|
|
{
|
|
public class WorkflowActions : IWorkflowActionProvider
|
|
{
|
|
|
|
protected static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
#region Action/Condition Dictionarys
|
|
private static Dictionary<string, Action<ProcessInstance, string>> _actions = new Dictionary
|
|
<string, Action<ProcessInstance, string>>
|
|
{
|
|
{"Clear Approvals",ClearApprovals },
|
|
{"Reset Approvals",ResetApprovals },
|
|
{"Prevu Project Contact Notification",SendProjectContactNotification },
|
|
{"Approve",Approve} ,
|
|
{"Fill Approver list",FillApproversForStep },
|
|
{"Setup Team ADHOC Approval", SetupADHOCApprovalForTeam },
|
|
{"Send Project Contact Email",SendProjectContactEmail },
|
|
{"Send Notification To Team Roles", SendTeamGroupEmail },
|
|
{"Send Notification To Project Roles", SendProjectGroupEmail },
|
|
{"Send Notification To Workflow Roles",SendWorkFlowRoleEmail },
|
|
{"Send Notification To Team Roles By Costcenter",SendTeamGroupByCostCenterEmail },
|
|
{"Send Notification To Team BY EC",SendTeamGroupByEC },
|
|
{"Prevu Notification To Team Roles By Costcenter",inAppNotificationTeamGroupByCostCenter },
|
|
{"Prevu Notification Not Approved yet",inAppPendingApprovalNotification },
|
|
{"Prevu Team Notification", inAppNotificationTeams },
|
|
{"Prevu ADHOC Approver Notification",inAppAdhocApproverGroupNotification },
|
|
{"Prevu Notification", inAppNotificationProject },
|
|
{"Send ADHOC Approval Email",SendAdhocApproverGroupEmail },
|
|
{"UpdateProjectStatus",UpdateProjectStatus },
|
|
{"SetScenarioInActive",SetScenarioInActive },
|
|
{"UpdateProbability",UpdateProbability },
|
|
{"SetScenarioActive",SetScenarioActive }
|
|
|
|
|
|
// {"Clear Approved Notifications",ClearApprovedNotifications }
|
|
};
|
|
private static Dictionary<string, Func<ProcessInstance, string, bool>> _conditions = new Dictionary<string, Func<ProcessInstance, string, bool>>
|
|
{
|
|
{"Project Start Date <=", LessEqProjectStartDate },
|
|
{"Project End Date <=", LessEqProjectEndDate },
|
|
{"Project Start Date >=",GreatEqProjectStartDate },
|
|
{"Project End Date >=",GreatEqProjectEndDate },
|
|
{"Approval complete",IsApproveComplete },
|
|
{"Approval not complete",NotApproveComplete },
|
|
};
|
|
#endregion
|
|
#region Approval Processing
|
|
static Approvers FillApprovers(ProcessInstance processInstance,string step, string parameter, string WorkflowRole)
|
|
{
|
|
|
|
return ApproversProvider.GetApprovers(processInstance, parameter, step, WorkflowRole);
|
|
}
|
|
static void FillApproversForStep(ProcessInstance processInstance, string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.ApprovalState == null)
|
|
throw new Exception("ApprovalState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.ApprovelType == null)
|
|
throw new Exception("ApprovelType Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string ApprovalState = parms.ApprovalState.Value;
|
|
string ApprovelType = parms.ApprovelType.Value;
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
|
|
var approvers = FillApprovers(processInstance, ApprovalState, ApprovelType, WorkflowRole);
|
|
|
|
}
|
|
catch (Exception appvEx)
|
|
{
|
|
LogException(appvEx);
|
|
}
|
|
}
|
|
static void SetupADHOCApprovalForTeam(ProcessInstance processInstance, string actionParameter)
|
|
{
|
|
try {
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.ApprovalState == null)
|
|
throw new Exception("ApprovalState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
string ApprovalState = parms.ApprovalState.Value;
|
|
var parm = processInstance.GetParameter<List<Guid>>("TeamIds");
|
|
if (parm == null)
|
|
return;
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var pr = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(pr.ConnectionString, true))
|
|
{
|
|
foreach (var p in parm)
|
|
{
|
|
var teamApvs = context.vw_User2Team2WorkflowRoleContactInfo.Where(x => x.TeamId == p && x.RoleName == WorkflowRole).ToList();
|
|
foreach (var user in teamApvs) {
|
|
var userId = Guid.Parse(user.Id);
|
|
if (!context.WorkFlowParallelApprovals.Any(x => x.UserId == userId && x.StepName == ApprovalState && x.ProcessId == processInstance.ProcessId && x.IsActive == true))
|
|
{
|
|
context.WorkFlowParallelApprovals.Add(new WorkFlowParallelApproval()
|
|
{
|
|
Approved = false,
|
|
Id = Guid.NewGuid(),
|
|
IsActive = true,
|
|
ProcessId = processInstance.ProcessId,
|
|
StepName = ApprovalState,
|
|
GroupId = user.TeamId,
|
|
UserId = userId
|
|
});
|
|
}
|
|
}
|
|
}
|
|
context.SaveChanges();
|
|
}
|
|
}catch(Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
|
|
}
|
|
static void Approve(ProcessInstance processInstance, string actionParameter)
|
|
{
|
|
try {
|
|
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.ApprovalState == null)
|
|
throw new Exception("ApprovalState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.ApprovelType == null)
|
|
throw new Exception("ApprovelType Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string ApprovalState = parms.ApprovalState.Value;
|
|
string ApprovelType = parms.ApprovelType.Value;
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
if (string.IsNullOrEmpty(processInstance.CurrentCommand) ||
|
|
processInstance.CurrentCommand.Equals("start", StringComparison.InvariantCultureIgnoreCase))
|
|
return;
|
|
var approvers = FillApprovers(processInstance, ApprovalState, ApprovelType, WorkflowRole);
|
|
|
|
if (processInstance.IdentityId != null && approvers != null)
|
|
approvers.Approve(Guid.Parse(processInstance.IdentityId), true, processInstance.ProcessId, parms.ApprovalState.Value);
|
|
else
|
|
{
|
|
LogDebugMessage("Workflow message: Approve no users loaded to do approval!!: Approval State" + ApprovalState+", ApprovalType:"+ApprovelType+", WorkflowRole:"+WorkflowRole);
|
|
|
|
}
|
|
}
|
|
catch(Exception appvEx)
|
|
{
|
|
LogException(appvEx);
|
|
}
|
|
}
|
|
public void ClearApprovalNotifications(ProcessInstance processInstance, string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var userid = Guid.Parse(processInstance.IdentityId);
|
|
var teams = context.WorkFlowParallelApprovals.Where(x => x.UserId == userid && x.ProcessId == processInstance.ProcessId).Select(x => x.GroupId).ToList();
|
|
|
|
foreach (var team in teams)
|
|
{
|
|
|
|
var users = context.WorkFlowParallelApprovals.Where(x => x.GroupId == team && x.ProcessId == processInstance.ProcessId).Select(x => x.UserId).ToList();
|
|
var notifications = context.Notifications.Where(x => users.Contains(x.ParentId.Value) && x.IdinLink == processInstance.ProcessId).ToList();
|
|
foreach (var n in notifications)
|
|
{
|
|
n.NotificationViewed = true;
|
|
context.Entry(n).State = System.Data.Entity.EntityState.Modified;
|
|
}
|
|
}
|
|
context.SaveChanges();
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception dd) { }
|
|
}
|
|
static bool IsApproveComplete(ProcessInstance processInstance,string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.ApprovalState == null)
|
|
throw new Exception("ApprovalState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.ApprovelType == null)
|
|
throw new Exception("ApprovelType Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string ApprovalState = parms.ApprovalState.Value;
|
|
string ApprovelType = parms.ApprovelType.Value;
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
if (string.IsNullOrEmpty(processInstance.PreviousState) || string.IsNullOrEmpty(processInstance.CurrentCommand) ||
|
|
processInstance.CurrentCommand.Equals("start", StringComparison.InvariantCultureIgnoreCase) ||
|
|
processInstance.PreviousState.Equals("start", StringComparison.InvariantCultureIgnoreCase))
|
|
return true;
|
|
|
|
var approvers = FillApprovers(processInstance, ApprovalState, ApprovelType, WorkflowRole);
|
|
|
|
if (approvers != null)
|
|
return approvers.IsApproved;
|
|
return true;
|
|
}
|
|
catch (Exception isAppvEx)
|
|
{
|
|
LogException(isAppvEx);
|
|
}
|
|
return false;
|
|
}
|
|
static void ResetApprovals(ProcessInstance processInstance, string parameter)
|
|
{
|
|
try
|
|
{
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var approvals = context.WorkFlowParallelApprovals.Where(x => x.ProcessId == processInstance.ProcessId
|
|
&& x.StepName == parameter).ToList();
|
|
foreach (var a in approvals)
|
|
{
|
|
a.IsActive = false;
|
|
context.Entry(a).State = System.Data.Entity.EntityState.Modified;
|
|
}
|
|
context.SaveChanges();
|
|
}
|
|
|
|
}
|
|
catch (Exception dd) {
|
|
LogException(dd);
|
|
}
|
|
}
|
|
static void ClearApprovals(ProcessInstance processInstance, string parameter)
|
|
{
|
|
try
|
|
{
|
|
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
|
|
var approvals = context.WorkFlowParallelApprovals.Where(x => x.ProcessId == processInstance.ProcessId
|
|
&& x.StepName == parameter ).ToList();
|
|
foreach (var a in approvals)
|
|
{
|
|
context.WorkFlowParallelApprovals.Remove(a);
|
|
context.Entry(a).State = System.Data.Entity.EntityState.Deleted;
|
|
}
|
|
context.SaveChanges();
|
|
}
|
|
|
|
}
|
|
catch (Exception dd)
|
|
{
|
|
LogException(dd);
|
|
}
|
|
}
|
|
static bool NotApproveComplete(ProcessInstance processInstance, string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.ApprovalState == null)
|
|
throw new Exception("ApprovalState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.ApprovelType == null)
|
|
throw new Exception("ApprovelType Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string ApprovalState = parms.ApprovalState.Value;
|
|
string ApprovelType = parms.ApprovelType.Value;
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
if (string.IsNullOrEmpty(processInstance.PreviousState) || string.IsNullOrEmpty(processInstance.CurrentCommand) ||
|
|
processInstance.CurrentCommand.Equals("start", StringComparison.InvariantCultureIgnoreCase) ||
|
|
processInstance.PreviousState.Equals("start", StringComparison.InvariantCultureIgnoreCase))
|
|
return true;
|
|
var approvers = FillApprovers(processInstance, ApprovalState, ApprovelType, WorkflowRole);
|
|
if (approvers != null)
|
|
return approvers.NotApproved;
|
|
|
|
}
|
|
catch (Exception dd)
|
|
{
|
|
LogException(dd);
|
|
}
|
|
return true;
|
|
}
|
|
static bool Approver(ProcessInstance processInstance, string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.ApprovalState == null)
|
|
throw new Exception("ApprovalState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.ApprovelType == null)
|
|
throw new Exception("ApprovelType Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string ApprovalState = parms.ApprovalState.Value;
|
|
string ApprovelType = parms.ApprovelType.Value;
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
string step = processInstance.CurrentCommand;
|
|
if (string.IsNullOrEmpty(step))
|
|
step = "Approvers";
|
|
|
|
var approvers = FillApprovers(processInstance, ApprovalState, ApprovelType, WorkflowRole);
|
|
|
|
if (approvers != null)
|
|
{
|
|
var apvs = approvers.GetAvailiableApprovers();
|
|
return apvs.Any(x => x == Guid.Parse(processInstance.IdentityId));
|
|
}
|
|
}
|
|
catch (Exception dd)
|
|
{
|
|
LogException(dd);
|
|
}
|
|
return false;
|
|
}
|
|
//static void ClearApprovedNotifications(ProcessInstance processInstance, string actionParameter)
|
|
//{
|
|
// try
|
|
// {
|
|
// var _runtime = WorkFlowEngine.Runtime(null);
|
|
// var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
// using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
// {
|
|
// var userid = Guid.Parse(processInstance.IdentityId);
|
|
// var teams = context.WorkFlowParallelApprovals.Where(x => x.UserId == userid && x.ProcessId == processInstance.ProcessId).Select(x => x.GroupId).ToList();
|
|
|
|
// foreach (var team in teams)
|
|
// {
|
|
|
|
// var users = context.WorkFlowParallelApprovals.Where(x => x.GroupId == team && x.ProcessId == processInstance.ProcessId).Select(x => x.UserId).ToList();
|
|
// var processId = processInstance.ProcessId;
|
|
// var processIdStr = processInstance.ProcessId.ToString();
|
|
// var notifications = context.Notifications.Where(x => users.Contains(x.ParentId.Value) && (x.IdinLink == processInstance.ProcessId || x.Link.Contains(processIdStr)) && x.WorkFlowState != null).ToList();
|
|
// foreach (var n in notifications)
|
|
// {
|
|
// if (n.ParentId != userid)
|
|
// {
|
|
// context.Notifications.Remove(n); //.State = System.Data.Entity.EntityState.Modified;
|
|
// context.Entry(n).State = System.Data.Entity.EntityState.Deleted;
|
|
// context.SaveChanges();
|
|
// }
|
|
// }
|
|
// }
|
|
// // context.SaveChanges();
|
|
// }
|
|
// }
|
|
// catch (Exception dd) { }
|
|
//}
|
|
#endregion
|
|
#region Email Notifications
|
|
private static EmailTemplate GetEmailTemplate(ProcessInstance processInstance, EmailTemplateType _type, string state, EnVisageEntities context)
|
|
{
|
|
var template = context.EmailTemplates.Where(x => x.isActive == true && x.isDefault == true && x.ProcessType == (int) _type && x.TemplateId == state).FirstOrDefault();
|
|
if (template == null)
|
|
{
|
|
template = context.EmailTemplates.Where(x => x.isActive == true && x.isDefault == true && x.ProcessType == (int) _type ).FirstOrDefault();
|
|
if (template == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail No default email template defined for process ID:" + processInstance.ProcessId.ToString());
|
|
return null;
|
|
}
|
|
}
|
|
return template;
|
|
}
|
|
static void SendProjectContactEmail(ProcessInstance processInstance,string actionParameter)
|
|
{
|
|
|
|
try
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.TemplateState == null)
|
|
throw new Exception("TemplateState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string contactRole=parms.WorkflowRole.Value;
|
|
string state= parms.TemplateState.Value;
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl= parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var template = GetEmailTemplate(processInstance, EmailTemplateType.WorkFlowProjectNotification, state, context);
|
|
if (template == null)
|
|
return;
|
|
var wfMan = new WorkFlowManager(context);
|
|
|
|
var contacts = project.Contact2Project.Where(x => x.Contact.Type == (int) ContactType.CompanyContact).Select(x=>x.Contact).ToList();
|
|
|
|
|
|
|
|
if (contacts.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString());
|
|
return;
|
|
}
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
var SentEmails = new List<string>();
|
|
string url = "";
|
|
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
bool okToSave = false;
|
|
foreach (var contact in contacts)
|
|
{
|
|
var u = context.AspNetUsers.Where(x => x.Email == contact.Email).FirstOrDefault();
|
|
if (u == null)
|
|
continue;
|
|
if (!SentEmails.Contains(u.Email))
|
|
{
|
|
SentEmails.Add(u.Email);
|
|
string t = template.Template;
|
|
t = t.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy).Replace("[%MESSAGE%]", Message).
|
|
Replace("[%DATE%]", DateTime.Now.ToString("MM/dd/yyyy")).Replace("[%URL%]", url);
|
|
MailManager.SendMessageHtml("Workflow notification from Prevu®", u.Email, t, "support@prevuplan.com");
|
|
okToSave = true;
|
|
}
|
|
}
|
|
if (SentEmails.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString() + " that belong to any of the provided groups:" + contactRole);
|
|
|
|
return;
|
|
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void SendProjectGroupEmail(ProcessInstance processInstance, string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.TemplateState == null)
|
|
throw new Exception("TemplateState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string workflowRole = parms.WorkflowRole.Value;
|
|
string state = parms.TemplateState.Value;
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
bool filterByRole = false;
|
|
if (string.IsNullOrEmpty(workflowRole))
|
|
{
|
|
workflowRole = "";
|
|
filterByRole = false;
|
|
}
|
|
else
|
|
{
|
|
filterByRole = true;
|
|
}
|
|
char[] splPrm = { ';' };
|
|
string[] groups = { workflowRole };
|
|
if (workflowRole.IndexOf(';') > 0)
|
|
{
|
|
groups = workflowRole.Split(splPrm);
|
|
|
|
}
|
|
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var template = GetEmailTemplate(processInstance, EmailTemplateType.WorkFlowProjectNotification, state, context);
|
|
if (template == null)
|
|
return;
|
|
var wfMan = new WorkFlowManager(context);
|
|
var who = wfMan.GetContactProjectDetails(processInstance.ProcessId);
|
|
var who2 = wfMan.GetContactProjectDetails(project.Id);
|
|
|
|
who.AddRange(who2);
|
|
if (who.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString());
|
|
return;
|
|
}
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
var SentEmails = new List<string>();
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
bool okToSave = false;
|
|
foreach (var u in who)
|
|
{
|
|
if (filterByRole)
|
|
if (!wfMan.UserInAnyRole(u.EmailAddress, groups.ToList()))
|
|
continue;
|
|
if (!SentEmails.Contains(u.EmailAddress))
|
|
{
|
|
SentEmails.Add(u.EmailAddress);
|
|
string t = template.Template;
|
|
t = t.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy).Replace("[%MESSAGE%]", Message).
|
|
Replace("[%DATE%]", DateTime.Now.ToString("MM/dd/yyyy")).Replace("[%URL%]", url);
|
|
MailManager.SendMessageHtml("Workflow notification from Prevu®", u.EmailAddress, t, "support@prevuplan.com");
|
|
okToSave = true;
|
|
}
|
|
}
|
|
if (SentEmails.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString() + " that belong to any of the provided groups:" + workflowRole);
|
|
|
|
return;
|
|
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void SendTeamGroupEmail(ProcessInstance processInstance,string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.TemplateState == null)
|
|
throw new Exception("TemplateState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
|
|
string workflowRole = parms.WorkflowRole.Value;
|
|
string state = parms.TemplateState.Value;
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
|
|
bool filterByRole = false;
|
|
if (string.IsNullOrEmpty(workflowRole))
|
|
{
|
|
workflowRole = "";
|
|
filterByRole = false;
|
|
}
|
|
else
|
|
{
|
|
filterByRole = true;
|
|
}
|
|
char[] splPrm = { ';' };
|
|
string[] groups = { workflowRole };
|
|
if (workflowRole.IndexOf(';') > 0)
|
|
{
|
|
groups = workflowRole.Split(splPrm);
|
|
|
|
}
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupEmail get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupEmail get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var template = GetEmailTemplate(processInstance, EmailTemplateType.WorkFlowTeamNotification, state, context);
|
|
if (template == null)
|
|
return;
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
var mailManager = new MailManager();
|
|
var teams = context.Team2Project.Where(x => x.ProjectId == scenario.ParentId).ToList();
|
|
var SentEmails = new List<string>();
|
|
var wfMan = new WorkFlowManager(context);
|
|
bool okToSave = false;
|
|
foreach (var team in teams)
|
|
{
|
|
|
|
var who = wfMan.GetContactTeamDetails(team.TeamId, WorkFlowContactNotificationType.None,null);
|
|
foreach (var u in who)
|
|
{
|
|
if (filterByRole)
|
|
if (!wfMan.UserInAnyRole(u.EmailAddress, groups.ToList()))
|
|
continue;
|
|
if (!SentEmails.Contains(u.EmailAddress))
|
|
{
|
|
SentEmails.Add(u.EmailAddress);
|
|
string t = template.Template;
|
|
t = t.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).Replace("[%TEAM_NAME%]", team.Team.Name).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy).Replace("[%MESSAGE%]", Message).
|
|
Replace("[%DATE%]", DateTime.Now.ToString("MM/dd/yyyy")).Replace("[%URL%]", url);
|
|
MailManager.SendMessageHtml("Workflow notification from Prevu®", u.EmailAddress, t, "workflow@prevuplan.com");
|
|
okToSave = true;
|
|
}
|
|
}
|
|
}
|
|
if (SentEmails.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString() + " that belong to any of the provided groups:" + workflowRole);
|
|
return;
|
|
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void SendTeamGroupByCostCenterEmail(ProcessInstance processInstance,string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.TemplateState == null)
|
|
throw new Exception("TemplateState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string workflowRole = parms.WorkflowRole.Value;
|
|
string state = parms.TemplateState.Value;
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
|
|
bool filterByRole = false;
|
|
if (string.IsNullOrEmpty(workflowRole))
|
|
{
|
|
workflowRole = "";
|
|
filterByRole = false;
|
|
}
|
|
else
|
|
{
|
|
filterByRole = true;
|
|
}
|
|
char[] splPrm = { ';' };
|
|
string[] groups = { workflowRole };
|
|
if (workflowRole.IndexOf(';') > 0)
|
|
{
|
|
groups = workflowRole.Split(splPrm);
|
|
|
|
}
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByCostCenterEmail get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByCostCenterEmail get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var CostCenters = context.ScenarioDetail.Where(x => x.ParentID == scenario.Id).Select(x => x.ExpenditureCategory.CreditId).Distinct().ToList();
|
|
if (CostCenters == null || CostCenters.Count ==0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByCostCenterEmail get costcenters returned null or is empty for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var template = GetEmailTemplate(processInstance, EmailTemplateType.WorkFlowTeamNotification, state, context);
|
|
if (template == null)
|
|
return;
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
var mailManager = new MailManager();
|
|
var teams = context.Teams.Where(x => CostCenters.Contains((x.CostCenterId.HasValue ? x.CostCenterId.Value : Guid.Empty))).ToList();
|
|
var SentEmails = new List<string>();
|
|
var wfMan = new WorkFlowManager(context);
|
|
bool okToSave = false;
|
|
foreach (var team in teams)
|
|
{
|
|
|
|
var who = wfMan.GetContactTeamDetails(team.Id, WorkFlowContactNotificationType.None, null);
|
|
foreach (var u in who)
|
|
{
|
|
if (filterByRole)
|
|
if (!wfMan.UserInAnyRole(u.EmailAddress, groups.ToList()))
|
|
continue;
|
|
if (!SentEmails.Contains(u.EmailAddress))
|
|
{
|
|
SentEmails.Add(u.EmailAddress);
|
|
string t = template.Template;
|
|
t = t.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).Replace("[%TEAM_NAME%]", team.Name).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy).Replace("[%MESSAGE%]", Message).
|
|
Replace("[%DATE%]", DateTime.Now.ToString("MM/dd/yyyy")).Replace("[%URL%]", url);
|
|
MailManager.SendMessageHtml("Workflow notification from Prevu®", u.EmailAddress, t, "workflow@prevuplan.com");
|
|
okToSave = true;
|
|
}
|
|
}
|
|
}
|
|
if (SentEmails.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByCostCenterEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString() + " that belong to any of the provided groups:" + workflowRole);
|
|
return;
|
|
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void SendTeamGroupByEC(ProcessInstance processInstance, string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.TemplateState == null)
|
|
throw new Exception("TemplateState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string workflowRole = parms.WorkflowRole.Value;
|
|
string state = parms.TemplateState.Value;
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
|
|
bool filterByRole = false;
|
|
if (string.IsNullOrEmpty(workflowRole))
|
|
{
|
|
workflowRole = "";
|
|
filterByRole = false;
|
|
}
|
|
else
|
|
{
|
|
filterByRole = true;
|
|
}
|
|
char[] splPrm = { ';' };
|
|
string[] groups = { workflowRole };
|
|
if (workflowRole.IndexOf(';') > 0)
|
|
{
|
|
groups = workflowRole.Split(splPrm);
|
|
|
|
}
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByECEmail get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByECEmail get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var CostCenters = context.ScenarioDetail.Where(x => x.ParentID == scenario.Id).Select(x => x.ExpenditureCategory.CreditId).Distinct().ToList();
|
|
if (CostCenters == null || CostCenters.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByECEmail get costcenters returned null or is empty for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var template = GetEmailTemplate(processInstance, EmailTemplateType.WorkFlowTeamNotification, state, context);
|
|
if (template == null)
|
|
return;
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
var mailManager = new MailManager();
|
|
var ECLists = context.ScenarioDetail.Where(x => x.ParentID == scenario.Id).Select(x => x.ExpenditureCategoryId).Distinct().ToList();
|
|
|
|
var teamids = context.VW_TeamResource.Where(x => ECLists.Contains(x.ExpenditureCategoryId)).Select(x => x.TeamId).Distinct().ToList();
|
|
var teams = context.Teams.Where(x => teamids.Contains(x.Id)).Distinct().ToList();
|
|
|
|
|
|
//var teams = context.Teams.Where(x => CostCenters.Contains((x.CostCenterId.HasValue ? x.CostCenterId.Value : Guid.Empty))).ToList();
|
|
var SentEmails = new List<string>();
|
|
var wfMan = new WorkFlowManager(context);
|
|
bool okToSave = false;
|
|
foreach (var team in teams)
|
|
{
|
|
|
|
var who = wfMan.GetContactTeamDetails(team.Id, WorkFlowContactNotificationType.None, null);
|
|
foreach (var u in who)
|
|
{
|
|
if (filterByRole)
|
|
if (!wfMan.UserInAnyRole(u.EmailAddress, groups.ToList()))
|
|
continue;
|
|
if (!SentEmails.Contains(u.EmailAddress))
|
|
{
|
|
SentEmails.Add(u.EmailAddress);
|
|
string t = template.Template;
|
|
t = t.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).Replace("[%TEAM_NAME%]", team.Name).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy).Replace("[%MESSAGE%]", Message).
|
|
Replace("[%DATE%]", DateTime.Now.ToString("MM/dd/yyyy")).Replace("[%URL%]", url);
|
|
MailManager.SendMessageHtml("Workflow notification from Prevu®", u.EmailAddress, t, "workflow@prevuplan.com");
|
|
okToSave = true;
|
|
}
|
|
}
|
|
}
|
|
if (SentEmails.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByCostCenterEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString() + " that belong to any of the provided groups:" + workflowRole);
|
|
return;
|
|
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void SendAdhocApproverGroupEmail(ProcessInstance processInstance,string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.TemplateState == null)
|
|
throw new Exception("TemplateState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.ApprovelType == null)
|
|
throw new Exception("ApprovelType Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
string ApprovelType = parms.ApprovelType.Value;
|
|
string ApprovalState = parms.TemplateState.Value;
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendAdhoApproverGroupEmail get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendAdhoApproverGroupEmail get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var template = GetEmailTemplate(processInstance, EmailTemplateType.WorkFlowTeamNotification, ApprovalState, context);
|
|
if (template == null)
|
|
return;
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
var mailManager = new MailManager();
|
|
var SentEmails = new List<string>();
|
|
var approvers = FillApprovers(processInstance, ApprovalState, ApprovelType, WorkflowRole);
|
|
|
|
bool okToSave = false;
|
|
foreach (var a in approvers.GetAvailiableApprovers())
|
|
{
|
|
string teamName = "N/A";
|
|
var approvalRec = context.WorkFlowParallelApprovals.Where(x => x.UserId == a && x.ProcessId == processInstance.ProcessId && x.IsActive == true && x.Approved == false && x.StepName == ApprovalState).FirstOrDefault();
|
|
if (approvalRec != null)
|
|
{
|
|
var team = context.Teams.Where(x => x.Id == approvalRec.GroupId).FirstOrDefault();
|
|
if (team != null)
|
|
teamName = team.Name;
|
|
}
|
|
var userid = a.ToString();
|
|
var u = context.AspNetUsers.Where(x => x.Id == userid).FirstOrDefault();
|
|
if (u == null)
|
|
continue;
|
|
if (!SentEmails.Contains(u.Email))
|
|
{
|
|
SentEmails.Add(u.Email);
|
|
string t = template.Template;
|
|
t = t.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).Replace("[%TEAM_NAME%]", teamName).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy).Replace("[%MESSAGE%]", Message).
|
|
Replace("[%DATE%]", DateTime.Now.ToString("MM/dd/yyyy")).Replace("[%URL%]", url);
|
|
MailManager.SendMessageHtml("Workflow notification from Prevu®", u.Email, t, "workflow@prevuplan.com");
|
|
okToSave = true;
|
|
}
|
|
}
|
|
if (SentEmails.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendAdhoApproverGroupEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString() + " that belong to the adhoc approval step");
|
|
|
|
return;
|
|
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void SendWorkFlowRoleEmail(ProcessInstance processInstance,string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.TemplateState == null)
|
|
throw new Exception("TemplateState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
|
|
|
|
string workflowRole = parms.WorkflowRole.Value;
|
|
|
|
string state = parms.TemplateState.Value;
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
if (string.IsNullOrEmpty(workflowRole))
|
|
return;
|
|
char[] splPrm = { ';' };
|
|
string[] groups = { workflowRole };
|
|
if (workflowRole.IndexOf(';') > 0)
|
|
{
|
|
groups = workflowRole.Split(splPrm);
|
|
}
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendWorkFlowRoleEmail get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendWorkFlowRoleEmail get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var template = GetEmailTemplate(processInstance, EmailTemplateType.WorkFlowRoleNotification, state, context);
|
|
if (template == null)
|
|
return;
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
bool okToSave = false;
|
|
var SentEmails = new List<string>();
|
|
foreach (var group in groups)
|
|
{
|
|
|
|
var who = (new WorkFlowManager(context)).GetContactDetails(group);
|
|
foreach (var u in who)
|
|
{
|
|
if (!SentEmails.Contains(u.EmailAddress))
|
|
{
|
|
SentEmails.Add(u.EmailAddress);
|
|
string t = template.Template;
|
|
t = t.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy).Replace("[%MESSAGE%]", Message).
|
|
Replace("[%DATE%]", DateTime.Now.ToString("MM/dd/yyyy")).Replace("[%URL%]", url);
|
|
MailManager.SendMessageHtml("Workflow notification from Prevu®", u.EmailAddress, t, "workflow@prevuplan.com");
|
|
okToSave = true;
|
|
}
|
|
}
|
|
}
|
|
if (SentEmails.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendWorkFlowRoleEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString() + " that belong to any of the provided groups:" + workflowRole);
|
|
return;
|
|
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
#endregion
|
|
#region InApp notifications
|
|
static void inAppAdhocApproverGroupNotification(ProcessInstance processInstance, string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.TemplateState == null)
|
|
throw new Exception("TemplateState Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.ApprovelType == null)
|
|
throw new Exception("ApprovelType Parameter not set for processId:" + processInstance.ProcessId);
|
|
bool DeleteOnView = false;
|
|
if (parms.DeleteOnView != null)
|
|
DeleteOnView = parms.DeleteOnView.Value == null ? false : parms.DeleteOnView.Value.ToLower() == "true";
|
|
|
|
int ExpiresOnDays = 0;
|
|
if (parms.ExpiresOnDays != null)
|
|
ExpiresOnDays = parms.ExpiresOnDays.Value == null ? 0 : Int32.Parse(parms.ExpiresOnDays.Value);
|
|
DateTime? ExpiresOnDate = null;
|
|
if (ExpiresOnDays > 0)
|
|
ExpiresOnDate = DateTime.Now.AddDays(ExpiresOnDays);
|
|
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
string ApprovelType = parms.ApprovelType.Value;
|
|
string ApprovalState = parms.TemplateState.Value;
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendAdhoApproverGroupEmail get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendAdhoApproverGroupEmail get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var template = GetEmailTemplate(processInstance, EmailTemplateType.WorkFlowTeamNotification, ApprovalState, context);
|
|
if (template == null)
|
|
return;
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
var mailManager = new MailManager();
|
|
var SentEmails = new List<string>();
|
|
var approvers = FillApprovers(processInstance, ApprovalState, ApprovelType, WorkflowRole);
|
|
|
|
bool okToSave = false;
|
|
foreach (var a in approvers.GetAvailiableApprovers())
|
|
{
|
|
string teamName = "N/A";
|
|
var approvalRec = context.WorkFlowParallelApprovals.Where(x => x.UserId == a && x.ProcessId == processInstance.ProcessId && x.IsActive == true && x.Approved == false && x.StepName == ApprovalState).FirstOrDefault();
|
|
if (approvalRec != null)
|
|
{
|
|
var team = context.Teams.Where(x => x.Id == approvalRec.GroupId).FirstOrDefault();
|
|
if (team != null)
|
|
teamName = team.Name;
|
|
}
|
|
var userid = a.ToString();
|
|
var u = context.AspNetUsers.Where(x => x.Id == userid).FirstOrDefault();
|
|
if (u == null)
|
|
continue;
|
|
if (!SentEmails.Contains(u.Email))
|
|
{
|
|
var msg = Message.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy);
|
|
|
|
NotificationModel m = new NotificationModel();
|
|
var username = u.FirstName + " " + u.LastName;
|
|
m.title = project.Name + " requires your attention";
|
|
m.description = msg;
|
|
m.link = new Uri(url);
|
|
m.WorkFlowEntityName = "project";
|
|
m.IdinLink = scenario.ParentId;
|
|
m.DeleteOnPageView = DeleteOnView;
|
|
m.ExpiresOnDate = ExpiresOnDate;
|
|
m.WorkFlowState = processInstance.ExecutedActivityState;
|
|
m.WorkFlowLinkName = project.Name;
|
|
m.NotificationGroup = NotificationGroupType.Project;
|
|
m.ParentId =Guid.Parse(u.Id);
|
|
m.Id = Guid.NewGuid();
|
|
m.NotificationViewed = false;
|
|
m.NotificationDate = DateTime.Now;
|
|
m.type = NotificationType.Workflow;
|
|
(new NotificationManager(context)).Save(m);
|
|
okToSave = true;
|
|
SentEmails.Add(u.Email);
|
|
}
|
|
}
|
|
if (SentEmails.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendAdhoApproverGroupEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString() + " that belong to the adhoc approval step");
|
|
return;
|
|
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void inAppNotificationTeamGroupByCostCenter(ProcessInstance processInstance, string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string workflowRole = parms.WorkflowRole.Value;
|
|
bool DeleteOnView = false;
|
|
if (parms.DeleteOnView != null)
|
|
DeleteOnView = parms.DeleteOnView.Value == null ? false : parms.DeleteOnView.Value.ToLower() == "true";
|
|
|
|
int ExpiresOnDays = 0;
|
|
if (parms.ExpiresOnDays != null)
|
|
ExpiresOnDays = parms.ExpiresOnDays.Value == null ? 0 : Int32.Parse(parms.ExpiresOnDays.Value);
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
DateTime? ExpiresOnDate = null;
|
|
if (ExpiresOnDays > 0)
|
|
ExpiresOnDate = DateTime.Now.AddDays(ExpiresOnDays);
|
|
bool filterByRole = false;
|
|
if (string.IsNullOrEmpty(workflowRole))
|
|
{
|
|
workflowRole = "";
|
|
filterByRole = false;
|
|
}
|
|
else
|
|
{
|
|
filterByRole = true;
|
|
}
|
|
char[] splPrm = { ';' };
|
|
string[] groups = { workflowRole };
|
|
if (workflowRole.IndexOf(';') > 0)
|
|
{
|
|
groups = workflowRole.Split(splPrm);
|
|
|
|
}
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByCostCenterEmail get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByCostCenterEmail get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var CostCenters = context.ScenarioDetail.Where(x => x.ParentID == scenario.Id).Select(x => x.ExpenditureCategory.CreditId).Distinct().ToList();
|
|
if (CostCenters == null || CostCenters.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByCostCenterEmail get costcenters returned null or is empty for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
var mailManager = new MailManager();
|
|
var teams = context.Teams.Where(x => CostCenters.Contains((x.CostCenterId.HasValue ? x.CostCenterId.Value : Guid.Empty))).ToList();
|
|
var SentEmails = new List<string>();
|
|
var wfMan = new WorkFlowManager(context);
|
|
bool okToSave = false;
|
|
foreach (var team in teams)
|
|
{
|
|
|
|
var who = wfMan.GetContactTeamDetails(team.Id, WorkFlowContactNotificationType.None, null);
|
|
foreach (var u in who)
|
|
{
|
|
if (filterByRole)
|
|
if (!wfMan.UserInAnyRole(u.EmailAddress, groups.ToList()))
|
|
continue;
|
|
if (!SentEmails.Contains(u.EmailAddress))
|
|
{
|
|
var msg = Message.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy);
|
|
|
|
NotificationModel m = new NotificationModel();
|
|
var username = u.FirstName + " " + u.LastName;
|
|
m.title = project.Name + " requires your attention";
|
|
m.description = msg;
|
|
m.link = new Uri(url);
|
|
m.WorkFlowEntityName = "project";
|
|
m.IdinLink = scenario.ParentId;
|
|
m.DeleteOnPageView = DeleteOnView;
|
|
m.ExpiresOnDate = ExpiresOnDate;
|
|
m.WorkFlowState = processInstance.ExecutedActivityState;
|
|
m.WorkFlowLinkName = project.Name;
|
|
m.NotificationGroup = NotificationGroupType.Project;
|
|
m.ParentId = u.UserId;
|
|
m.Id = Guid.NewGuid();
|
|
m.NotificationViewed = false;
|
|
m.NotificationDate = DateTime.Now;
|
|
m.type = NotificationType.Workflow;
|
|
(new NotificationManager(context)).Save(m);
|
|
okToSave = true;
|
|
SentEmails.Add(u.EmailAddress);
|
|
|
|
}
|
|
}
|
|
}
|
|
if (SentEmails.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendTeamGroupByCostCenterEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString() + " that belong to any of the provided groups:" + workflowRole);
|
|
return;
|
|
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void SendProjectContactNotification(ProcessInstance processInstance,string actionParameter)
|
|
{
|
|
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
|
|
string contactRole = parms.WorkflowRole.Value;
|
|
bool DeleteOnView = false;
|
|
if (parms.DeleteOnView != null)
|
|
DeleteOnView = parms.DeleteOnView.Value == null ? false : parms.DeleteOnView.Value.ToLower() == "true";
|
|
|
|
int ExpiresOnDays = 0;
|
|
if (parms.ExpiresOnDays != null)
|
|
ExpiresOnDays = parms.ExpiresOnDays.Value == null ? 0 : Int32.Parse(parms.ExpiresOnDays.Value);
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
|
|
|
|
DateTime? ExpiresOnDate = null;
|
|
if (ExpiresOnDays > 0)
|
|
ExpiresOnDate = DateTime.Now.AddDays(ExpiresOnDays);
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
|
|
var wfMan = new WorkFlowManager(context);
|
|
|
|
var contacts = project.Contact2Project.Where(x => x.Contact.Type == (int) ContactType.CompanyContact).Select(x => x.Contact).ToList();
|
|
|
|
|
|
|
|
if (contacts.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString());
|
|
return;
|
|
}
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
var SentEmails = new List<string>();
|
|
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
bool okToSave = false;
|
|
foreach (var contact in contacts)
|
|
{
|
|
var u = context.AspNetUsers.Where(x => x.Email == contact.Email).FirstOrDefault();
|
|
if (u == null)
|
|
continue;
|
|
if (!SentEmails.Contains(u.Email))
|
|
{
|
|
var msg = Message.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy);
|
|
|
|
NotificationModel m = new NotificationModel();
|
|
var username = u.FirstName + " " + u.LastName;
|
|
m.title = project.Name + " requires your attention";
|
|
m.description = msg;
|
|
m.link = new Uri(url);
|
|
m.WorkFlowEntityName = "project";
|
|
m.IdinLink = scenario.ParentId;
|
|
m.DeleteOnPageView = DeleteOnView;
|
|
m.ExpiresOnDate = ExpiresOnDate;
|
|
m.WorkFlowState = processInstance.ExecutedActivityState;
|
|
m.WorkFlowLinkName = project.Name;
|
|
m.NotificationGroup = NotificationGroupType.Project;
|
|
m.ParentId = Guid.Parse(u.Id);
|
|
m.Id = Guid.NewGuid();
|
|
m.NotificationViewed = false;
|
|
m.NotificationDate = DateTime.Now;
|
|
m.type = NotificationType.Workflow;
|
|
(new NotificationManager(context)).Save(m);
|
|
okToSave = true;
|
|
SentEmails.Add(u.Email);
|
|
}
|
|
}
|
|
if (SentEmails.Count == 0)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail No Project contacts defined for project:" + project.Name + " ID:" + project.Id.ToString() + " that belong to any of the provided groups:" + contactRole);
|
|
|
|
return;
|
|
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void inAppNotificationProject(ProcessInstance processInstance,string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
|
|
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
bool DeleteOnView = false;
|
|
if (parms.DeleteOnView != null)
|
|
DeleteOnView = parms.DeleteOnView.Value == null ? false : parms.DeleteOnView.Value.ToLower() == "true";
|
|
|
|
int ExpiresOnDays = 0;
|
|
if (parms.ExpiresOnDays != null)
|
|
ExpiresOnDays = parms.ExpiresOnDays.Value == null ? 0 : Int32.Parse(parms.ExpiresOnDays.Value);
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
|
|
|
|
|
|
if (Message == null)
|
|
Message = "";
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: inAppNotification get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: inAppNotification get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
|
|
if (processInstance.CurrentState == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail Current process instance state is NULL for process ID:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
var notifyMan = new NotificationManager(context);
|
|
|
|
|
|
bool okToSave = false;
|
|
var SentEmails = new List<string>();
|
|
if (string.IsNullOrEmpty(Message))
|
|
Message = "Missing message for command/State:" + processInstance.CurrentCommand + "/" + processInstance.CurrentState;
|
|
|
|
var who = (new WorkFlowManager(context)).GetContactDetails(WorkflowRole, project.Id, WorkFlowApprovalType.Project);
|
|
foreach (var u in who)
|
|
{
|
|
if (!SentEmails.Contains(u.EmailAddress))
|
|
{
|
|
SentEmails.Add(u.EmailAddress);
|
|
var msg = Message.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy);
|
|
NotificationModel m = new NotificationModel();
|
|
var username = u.FirstName + " " + u.LastName;
|
|
m.title = project.Name + " requires your attention";
|
|
m.description = msg;
|
|
m.link = new Uri(url);
|
|
m.WorkFlowEntityName = "project";
|
|
m.IdinLink = scenario.ParentId;
|
|
m.DeleteOnPageView = DeleteOnView;
|
|
m.WorkFlowState = processInstance.ExecutedActivityState;
|
|
m.WorkFlowLinkName = project.Name;
|
|
m.NotificationGroup = NotificationGroupType.Project;
|
|
m.ParentId = u.UserId;
|
|
m.Id = Guid.NewGuid();
|
|
m.NotificationViewed = false;
|
|
m.NotificationDate = DateTime.Now;
|
|
m.type = NotificationType.Workflow;
|
|
(new NotificationManager(context)).Save(m);
|
|
okToSave = true;
|
|
}
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void inAppNotificationTeams(ProcessInstance processInstance,string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
|
|
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
bool DeleteOnView = false;
|
|
if (parms.DeleteOnView != null)
|
|
DeleteOnView = parms.DeleteOnView.Value == null ? false : parms.DeleteOnView.Value.ToLower() == "true";
|
|
|
|
int ExpiresOnDays = 0;
|
|
if (parms.ExpiresOnDays != null)
|
|
ExpiresOnDays = parms.ExpiresOnDays.Value == null ? 0 : Int32.Parse(parms.ExpiresOnDays.Value);
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
|
|
|
|
|
|
if (Message == null)
|
|
Message = "";
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: inAppNotification get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: inAppNotification get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
|
|
if (processInstance.CurrentState == null)
|
|
{
|
|
LogDebugMessage("Workflow message: SendProjectGroupEmail Current process instance state is NULL for process ID:" + processInstance.ProcessId.ToString());
|
|
return;
|
|
}
|
|
var userWhoUpdated = context.AspNetUsers.Where(x => x.Id == processInstance.IdentityId).FirstOrDefault();
|
|
var updatedBy = "Sysetem Event";
|
|
if (userWhoUpdated != null)
|
|
{
|
|
|
|
updatedBy = userWhoUpdated.FirstName + " " + userWhoUpdated.LastName;
|
|
}
|
|
string url = "";
|
|
// url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id);
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
var notifyMan = new NotificationManager(context);
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
if (string.IsNullOrEmpty(Message))
|
|
Message = "Missing message for command/State:" + processInstance.CurrentCommand+"/"+ processInstance.CurrentState;
|
|
bool okToSave = false;
|
|
var SentEmails = new List<string>();
|
|
//var teams = scenario.TeamAllocations.ToList();
|
|
var teams = project.Team2Project.ToList();
|
|
foreach (var team in teams)
|
|
{
|
|
var who = (new WorkFlowManager(context)).GetContactDetails(WorkflowRole, team.TeamId, WorkFlowApprovalType.Team);
|
|
foreach (var u in who)
|
|
{
|
|
|
|
if (!SentEmails.Contains(u.EmailAddress))
|
|
{
|
|
SentEmails.Add(u.EmailAddress);
|
|
var msg = Message.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy);
|
|
NotificationModel m = new NotificationModel();
|
|
var username = u.FirstName + " " + u.LastName;
|
|
m.title = project.Name + " requires your attention";
|
|
m.description = msg;
|
|
m.WorkFlowEntityName = "scenario";
|
|
m.link = new Uri(url);
|
|
m.IdinLink = scenario.Id;
|
|
m.DeleteOnPageView = DeleteOnView;
|
|
m.WorkFlowState = processInstance.ExecutedActivityState;
|
|
m.WorkFlowLinkName = project.Name;
|
|
m.NotificationGroup = NotificationGroupType.Project;
|
|
m.ParentId = u.UserId;
|
|
m.Id = Guid.NewGuid();
|
|
m.NotificationViewed = false;
|
|
m.NotificationDate = DateTime.Now;
|
|
m.type = NotificationType.Workflow;
|
|
(new NotificationManager(context)).Save(m);
|
|
okToSave = true;
|
|
}
|
|
}
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
static void inAppPendingApprovalNotification(ProcessInstance processInstance,string actionParameter)
|
|
{
|
|
try
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(actionParameter))
|
|
throw new Exception("Action Parameters not set for processId:" + processInstance.ProcessId);
|
|
dynamic parms = JsonConvert.DeserializeObject(actionParameter);
|
|
|
|
if (parms.Message == null)
|
|
throw new Exception("Message Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.WorkflowRole == null)
|
|
throw new Exception("WorkflowRole Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.ApprovelType == null)
|
|
throw new Exception("ApprovelType Parameter not set for processId:" + processInstance.ProcessId);
|
|
if (parms.ApprovalState == null)
|
|
throw new Exception("ApprovalState Parameter not set for processId:" + processInstance.ProcessId);
|
|
|
|
string WorkflowRole = parms.WorkflowRole.Value;
|
|
bool DeleteOnView = false;
|
|
if (parms.DeleteOnView != null)
|
|
DeleteOnView = parms.DeleteOnView.Value == null ? false : parms.DeleteOnView.Value.ToLower() == "true";
|
|
string ApprovelType= parms.ApprovelType.Value;
|
|
int ExpiresOnDays = 0;
|
|
if (parms.ExpiresOnDays != null)
|
|
ExpiresOnDays = parms.ExpiresOnDays.Value == null ? 0 : Int32.Parse(parms.ExpiresOnDays.Value);
|
|
string Message = parms.Message.Value;
|
|
bool UseScenarioUrl = false;
|
|
if (parms.UseScenarioUrl != null)
|
|
UseScenarioUrl = parms.UseScenarioUrl.Value == null ? false : parms.UseScenarioUrl.Value.ToLower() == "true";
|
|
|
|
if (string.IsNullOrEmpty(WorkflowRole))
|
|
return;
|
|
|
|
if (Message == null)
|
|
Message = "";
|
|
if (string.IsNullOrEmpty(processInstance.PreviousState) || string.IsNullOrEmpty(processInstance.CurrentCommand) ||
|
|
processInstance.CurrentCommand.Equals("start", StringComparison.InvariantCultureIgnoreCase) ||
|
|
processInstance.PreviousState.Equals("start", StringComparison.InvariantCultureIgnoreCase))
|
|
return;
|
|
string step = parms.ApprovalState.Value;
|
|
|
|
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
|
|
var approvers = new List<WorkFlowParallelApproval>();
|
|
var approvedAlready=context.WorkFlowParallelApprovals.Where(x => x.ProcessId == processInstance.ProcessId && x.StepName == step && x.Approved == true && x.IsActive ==true).ToList();
|
|
var approversList = context.WorkFlowParallelApprovals.Where(x => x.ProcessId == processInstance.ProcessId && x.StepName == step && x.IsActive == true).ToList();
|
|
foreach( var a in approversList)
|
|
{
|
|
|
|
if (a.GroupId != null)
|
|
if (approvedAlready.Any(x => x.GroupId == a.GroupId))
|
|
continue;
|
|
if (a.GroupId == null)
|
|
if (approvedAlready.Any(x => x.UserId == a.UserId))
|
|
continue;
|
|
if (a.Approved == false)
|
|
approvers.Add(a);
|
|
}
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
{
|
|
LogDebugMessage("Workflow message: inAppNotification get scenario returned null for processId:" + processInstance.ProcessId.ToString());
|
|
|
|
return;
|
|
}
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
{
|
|
LogDebugMessage("Workflow message: inAppNotification get project returned null for processId:" + processInstance.ProcessId.ToString() + " Scenaio parentid:" + scenario.ParentId.ToString());
|
|
return;
|
|
}
|
|
|
|
var updatedBy = "Sysetem Event";
|
|
string url = "";
|
|
if (UseScenarioUrl)
|
|
url = Session.AbsoluteUrl.EditScenarioUrl(scenario.Id, context);
|
|
else
|
|
url = Session.AbsoluteUrl.EditProjectUrl(scenario.ParentId, context);
|
|
var notifyMan = new NotificationManager(context);
|
|
if (url != null)
|
|
url += "?ptab=Details";
|
|
|
|
if (string.IsNullOrEmpty(Message))
|
|
Message = "Missing message for command/State:" + processInstance.CurrentCommand + "/" + processInstance.CurrentState;
|
|
|
|
|
|
bool okToSave = false;
|
|
var SentEmails = new List<string>();
|
|
var userids = approvers.Select(x => x.UserId).ToList();
|
|
foreach (var user in userids)
|
|
{
|
|
|
|
string userStr = user.ToString();
|
|
var u = context.AspNetUsers.Where(x => x.Id == userStr).FirstOrDefault();
|
|
if (u != null)
|
|
{
|
|
if (!SentEmails.Contains(u.Email))
|
|
{
|
|
SentEmails.Add(u.Email);
|
|
var msg = Message.Replace("[%FIRST_NAME%]", u.FirstName).Replace("[%LAST_NAME%]", u.LastName).
|
|
Replace("[%PROJECT_NAME%]", project.Name).Replace("[%UPDATED_BY%]", updatedBy);
|
|
NotificationModel m = new NotificationModel();
|
|
var username = u.FirstName + " " + u.LastName;
|
|
m.title = project.Name + " requires your attention";
|
|
m.description = msg;
|
|
m.WorkFlowEntityName = "project";
|
|
m.link = new Uri(url);
|
|
m.IdinLink = scenario.Id;
|
|
m.DeleteOnPageView = DeleteOnView;
|
|
m.WorkFlowState = processInstance.ExecutedActivityState;
|
|
m.WorkFlowLinkName = project.Name;
|
|
m.NotificationGroup = NotificationGroupType.Project;
|
|
m.ParentId = Guid.Parse(u.Id);
|
|
m.Id = Guid.NewGuid();
|
|
m.NotificationViewed = false;
|
|
m.NotificationDate = DateTime.Now;
|
|
m.type = NotificationType.Workflow;
|
|
(new NotificationManager(context)).Save(m);
|
|
okToSave = true;
|
|
}
|
|
}
|
|
}
|
|
if (okToSave)
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
catch (Exception dds)
|
|
{
|
|
LogException(dds);
|
|
}
|
|
}
|
|
#endregion
|
|
#region Condition Checks for Scenario Dates
|
|
static bool LessEqProjectStartDate(ProcessInstance processInstance, string parameter)
|
|
{
|
|
if (string.IsNullOrEmpty(parameter))
|
|
return false;
|
|
int nbrDays = Int32.Parse(parameter);
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
return false;
|
|
TimeSpan difference = scenario.StartDate.Value - DateTime.Now;
|
|
double totalDays = difference.TotalDays;
|
|
//if (totalDays < 0)
|
|
// totalDays = totalDays * -1;
|
|
if (totalDays <= nbrDays)
|
|
return true;
|
|
return false;
|
|
}
|
|
}
|
|
static bool LessEqProjectEndDate(ProcessInstance processInstance, string parameter)
|
|
{
|
|
if (string.IsNullOrEmpty(parameter))
|
|
return false;
|
|
int nbrDays = Int32.Parse(parameter);
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
return false;
|
|
TimeSpan difference = scenario.EndDate.Value -DateTime.Now ;
|
|
double totalDays = difference.TotalDays;
|
|
//if (totalDays < 0)
|
|
// totalDays = totalDays * -1;
|
|
if (totalDays <= nbrDays)
|
|
return true;
|
|
return false;
|
|
}
|
|
}
|
|
static bool GreatEqProjectStartDate(ProcessInstance processInstance, string parameter)
|
|
{
|
|
if (string.IsNullOrEmpty(parameter))
|
|
return false;
|
|
int nbrDays = Int32.Parse(parameter);
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
return false;
|
|
TimeSpan difference = DateTime.Now - scenario.StartDate.Value;
|
|
double totalDays = difference.TotalDays;
|
|
if (totalDays < 0)
|
|
totalDays = totalDays * -1;
|
|
if (totalDays >= nbrDays)
|
|
return true;
|
|
return false;
|
|
}
|
|
}
|
|
static bool GreatEqProjectEndDate(ProcessInstance processInstance, string parameter)
|
|
{
|
|
if (string.IsNullOrEmpty(parameter))
|
|
return false;
|
|
int nbrDays = Int32.Parse(parameter);
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
return false;
|
|
TimeSpan difference = scenario.EndDate.Value - DateTime.Now;
|
|
if (difference.TotalDays >= nbrDays)
|
|
return true;
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
#region util calls
|
|
static void SetScenarioActive(ProcessInstance processInstance, string parameter)
|
|
{
|
|
try
|
|
{
|
|
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
return;
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
return;
|
|
var scenarios = context.Scenarios.Where(x => x.ParentId == project.Id && x.Id != scenario.Id);
|
|
foreach (var s in scenarios)
|
|
{
|
|
s.Status = (int) ScenarioStatus.Inactive;
|
|
context.Entry(s).State = System.Data.Entity.EntityState.Modified;
|
|
|
|
}
|
|
scenario.Status = (int) ScenarioStatus.Active;
|
|
context.Entry(scenario).State = System.Data.Entity.EntityState.Modified;
|
|
context.SaveChanges();
|
|
}
|
|
|
|
}
|
|
catch (Exception dd) { }
|
|
}
|
|
static void UpdateProbability(ProcessInstance processInstance, string parameter)
|
|
{
|
|
if (string.IsNullOrEmpty(parameter))
|
|
return;
|
|
var pInt = decimal.Parse(parameter);
|
|
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
return;
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
return;
|
|
project.Probability = pInt;
|
|
context.Entry(project).State = System.Data.Entity.EntityState.Modified;
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
static void SetScenarioInActive(ProcessInstance processInstance, string parameter)
|
|
{
|
|
try
|
|
{
|
|
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
return;
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
return;
|
|
if (scenario.Status == (int) ScenarioStatus.Inactive)
|
|
return;
|
|
scenario.Status = (int) ScenarioStatus.Inactive;
|
|
context.Entry(scenario).State = System.Data.Entity.EntityState.Modified;
|
|
context.SaveChanges();
|
|
}
|
|
|
|
}
|
|
catch (Exception dd) { }
|
|
}
|
|
static void UpdateProjectStatus(ProcessInstance processInstance, string parameter)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(parameter))
|
|
return;
|
|
var _runtime = WorkFlowEngine.Runtime(null);
|
|
var p = (OptimaJet.Workflow.DbPersistence.MSSQLProvider) _runtime.PersistenceProvider;
|
|
using (var context = EnVisageEntities.PrevuEntity(p.ConnectionString, true))
|
|
{
|
|
var scenario = context.Scenarios.Where(x => x.Id == processInstance.ProcessId).FirstOrDefault();
|
|
if (scenario == null)
|
|
return;
|
|
var project = context.Projects.Where(x => x.Id == scenario.ParentId).FirstOrDefault();
|
|
if (project == null)
|
|
return;
|
|
var status = context.Status.Where(x => x.Name == parameter).FirstOrDefault();
|
|
if (status == null)
|
|
return;
|
|
project.StatusId = status.Id;
|
|
context.Entry(project).State = System.Data.Entity.EntityState.Modified;
|
|
context.SaveChanges();
|
|
if (!string.IsNullOrEmpty(status.WorkFlowState))
|
|
{
|
|
var state = _runtime.GetCurrentState(scenario.Id);
|
|
|
|
var states = _runtime.GetAvailableStateToSet(processInstance.SchemeCode);
|
|
if ((state == null || state.Name != status.WorkFlowState) && states.Any(x => x.Name == status.WorkFlowState))
|
|
_runtime.SetState(scenario.Id, processInstance.IdentityId, processInstance.IdentityId, status.WorkFlowState, null);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception dd) { }
|
|
}
|
|
#endregion
|
|
|
|
public void ExecuteAction(string name, ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter)
|
|
{
|
|
if (_actions.ContainsKey(name))
|
|
{
|
|
|
|
_actions[name].Invoke(processInstance, actionParameter);
|
|
return;
|
|
}
|
|
|
|
throw new NotImplementedException(string.Format("Action with name {0} not implemented", name));
|
|
}
|
|
|
|
public bool ExecuteCondition(string name, ProcessInstance processInstance, WorkflowRuntime runtime, string actionParameter)
|
|
{
|
|
if (_conditions.ContainsKey(name))
|
|
{
|
|
return _conditions[name].Invoke(processInstance, actionParameter);
|
|
}
|
|
|
|
throw new NotImplementedException(string.Format("Action condition with name {0} not implemented", name));
|
|
}
|
|
|
|
public List<string> GetActions()
|
|
{
|
|
var list=_actions.Keys.Concat(_conditions.Keys).ToList();
|
|
list.Sort();
|
|
return list;
|
|
}
|
|
#region Error/Debug Logging
|
|
private static void LogDebugMessage(string message)
|
|
{
|
|
Logger.Debug(message);
|
|
}
|
|
private static void LogException(Exception ex)
|
|
{
|
|
var sb = new StringBuilder();
|
|
sb.AppendLine(string.Format("{0}: {1}", ex.GetType(), ex.Message));
|
|
sb.AppendLine(ex.StackTrace);
|
|
|
|
var innerCount = 0;
|
|
var innerEx = ex;
|
|
while (innerEx.InnerException != null && innerCount++ < Constants.MAX_INNER_EXCEPTION_LOG_LEVEL)
|
|
{
|
|
if (innerEx.Message != innerEx.InnerException.Message)
|
|
sb.AppendLine("Inner Exception Message: " + innerEx.InnerException.Message);
|
|
innerEx = innerEx.InnerException;
|
|
}
|
|
var dbEntityValidationException = ex as DbEntityValidationException;
|
|
if (dbEntityValidationException != null)
|
|
{
|
|
foreach (var validationErrors in dbEntityValidationException.EntityValidationErrors)
|
|
{
|
|
foreach (var validationError in validationErrors.ValidationErrors)
|
|
{
|
|
sb.AppendFormat("Property: {0} Error: {1}", validationError.PropertyName,
|
|
validationError.ErrorMessage);
|
|
|
|
}
|
|
}
|
|
sb.AppendLine(dbEntityValidationException.StackTrace);
|
|
}
|
|
if (System.Web.HttpContext.Current != null)
|
|
{
|
|
sb.AppendLine();
|
|
sb.AppendLine(string.Format("URL: {0}", System.Web.HttpContext.Current.Request.Url));
|
|
sb.AppendLine(string.Format("Referrer: {0}", System.Web.HttpContext.Current.Request.UrlReferrer));
|
|
sb.AppendLine(string.Format("QueryString: {0}", System.Web.HttpContext.Current.Request.QueryString));
|
|
sb.AppendLine(string.Format("UserHostAddress: {0}", System.Web.HttpContext.Current.Request.UserHostAddress));
|
|
sb.AppendLine(string.Format("UserAgent: {0}", System.Web.HttpContext.Current.Request.UserAgent));
|
|
if (System.Web.HttpContext.Current.Request.Form.Count > 0)
|
|
{
|
|
sb.AppendLine();
|
|
sb.AppendLine("Form:");
|
|
foreach (string key in System.Web.HttpContext.Current.Request.Form.Keys)
|
|
{
|
|
sb.AppendLine(string.Format("{0}: {1}", key, System.Web.HttpContext.Current.Request.Form[key]));
|
|
}
|
|
}
|
|
}
|
|
|
|
// log error using NLog
|
|
Logger.Fatal(sb.ToString());
|
|
}
|
|
#endregion
|
|
}
|
|
}
|