//public ViewDataDictionary ViewData = new ViewDataDictionary();
        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);
            this.ProcessId         = this.MyRequest.QueryString["processId"]?.ToGuidObjNull() ?? this.MyRequest.Form["processId"]?.ToGuidObjNull();
            this.ApplicationPageId = this.MyRequest.QueryString["ApplicationPageId"]?.ToGuidObjNull() ?? this.MyRequest.Form["ApplicationPageId"]?.ToGuidObjNull();
            //Because json data is not put in request.Form
            var data = controllerContext.Request.Content.ReadAsStringAsync().Result;

            if (data != null &&
                (DomainUtility.GetRegularValue("\"ApplicationPageId\":\"", "\"", data).Any() ||
                 DomainUtility.GetRegularValue("\"ProcessId\":\"", "\"", data).Any()))
            {
                this.ProcessId         = DomainUtility.GetRegularValue("\"ProcessId\":\"", "\"", data).FirstOrDefault().ToGuidObjNull();
                this.ApplicationPageId = DomainUtility.GetRegularValue("\"ApplicationPageId\":\"", "\"", data).FirstOrDefault().ToGuidObjNull();
            }
        }
Exemplo n.º 2
0
        public ResultOperation SendEmail(sysBpmsEvent _event)
        {
            ResultOperation        resultOperation  = new ResultOperation();
            SubTypeEmailEventModel email            = _event.SubTypeMessageEventModel.Email;
            sysBpmsEmailAccount    fromEmailAccount = new sysBpmsEmailAccount();
            DataManageEngine       dataManageEngine = new DataManageEngine(base.EngineSharedModel, base.UnitOfWork);

            List <string> toEmailList = new List <string>();

            switch (email.From.ToIntObj())
            {
            case (int)SubTypeEmailEventModel.e_FromType.CurrentUser:
                sysBpmsUser user = new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentUserName);
                if (user != null)
                {
                    fromEmailAccount = new EmailAccountService(base.UnitOfWork).GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.User, user.ID, null).LastOrDefault();
                }
                break;

            case (int)SubTypeEmailEventModel.e_FromType.CurrentThreadUser:
                user = base.EngineSharedModel.CurrentThread != null && base.EngineSharedModel.CurrentThread.UserID.HasValue ? new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentThread.UserID.Value) : null;
                if (user != null)
                {
                    fromEmailAccount = new EmailAccountService(base.UnitOfWork).GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.User, user.ID, null).LastOrDefault();
                }
                break;

            default:
                fromEmailAccount = new EmailAccountService(base.UnitOfWork).GetInfo(email.From.ToGuidObj());
                break;
            }

            switch ((SubTypeEmailEventModel.e_ToType)email.ToType)
            {
            case SubTypeEmailEventModel.e_ToType.Static:
                toEmailList = email.To.Split(',').Where(c => !string.IsNullOrWhiteSpace(c)).ToList();
                break;

            case SubTypeEmailEventModel.e_ToType.Systemic:
                switch ((SubTypeEmailEventModel.e_ToSystemicType)email.To.ToIntObj())
                {
                case SubTypeEmailEventModel.e_ToSystemicType.CurrentUser:
                    sysBpmsUser user = new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentUserName);
                    if (user != null)
                    {
                        toEmailList.Add(user.Email);
                    }
                    break;

                case SubTypeEmailEventModel.e_ToSystemicType.CurrentThreadUser:
                    user = base.EngineSharedModel.CurrentThread != null && base.EngineSharedModel.CurrentThread.UserID.HasValue ? new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentThread.UserID.Value) : null;
                    if (user != null)
                    {
                        toEmailList.Add(user.Email);
                    }
                    break;
                }
                break;

            case SubTypeEmailEventModel.e_ToType.Variable:
                toEmailList = dataManageEngine.GetValueByBinding(email.To).ToStringObj().Split(',').Where(c => !string.IsNullOrWhiteSpace(c)).ToList();
                break;
            }

            string subject = email.Subject;
            string content = email.Content;

            if (!string.IsNullOrWhiteSpace(subject))
            {
                foreach (string item in DomainUtility.GetRegularValue("[", "]", subject).Distinct())
                {
                    subject = subject.Replace("[" + item + "]", dataManageEngine.GetValueByBinding(item.Trim()).ToStringObj());
                }
            }

            if (!string.IsNullOrWhiteSpace(content))
            {
                foreach (string item in DomainUtility.GetRegularValue("[", "]", content).Distinct())
                {
                    content = content.Replace("[" + item + "]", dataManageEngine.GetValueByBinding(item.Trim()).ToStringObj());
                }
            }

            new EmailService().SendEmailAsync(fromEmailAccount.Email, fromEmailAccount.MailPassword, fromEmailAccount.SMTP, fromEmailAccount.Port.ToIntObj(), toEmailList, "", "", subject, content);
            return(resultOperation);
        }