Esempio n. 1
0
        internal bool InsertEvent(Mail mail, MailEvent mailEvent)
        {
            bool res = false;

            try
            {
                _query.Parameters.Clear();

                _query.Parameters.Add(new SqlParameter("@MailId", mail.Id));
                _query.Parameters.Add(new SqlParameter("@UserId", mailEvent.EventUser.Id));
                _query.Parameters.Add(new SqlParameter("@EventTypeId", mailEvent.EventType.Id));
                _query.Parameters.Add(new SqlParameter("@EventTime", Utils.GetDbTime(mailEvent.EventTime)));

                int id;
                res          = _query.ExecuteInsertProc("MailEventsAdd", out id);
                mailEvent.Id = id;
            }
            catch (Exception ex)
            {
                try
                {
                    DomainModel.Application.Status.Update(
                        StatusController.Abstract.StatusTypes.Error,
                        "",
                        ex.Message);
                }
                catch { }
            }

            return(res);
        }
Esempio n. 2
0
    private void OnMailNumUpdate(EventBase e)
    {
        MailEvent evt = (MailEvent)e;

        if (evt.number > 0)
        {
            if (!NGUITools.GetActive(mEmailBtn.gameObject))
            {
                NGUITools.SetActive(mEmailBtn.gameObject, true);
            }
        }
    }
Esempio n. 3
0
    private void OnUnReadMailNumUpdate(EventBase e)
    {
        MailEvent evt = (MailEvent)e;

        if (evt.unreadnumber > 0)
        {
            NGUITools.SetActive(mMailAnimation.gameObject, true);
            mUnReadNum.text = (evt.unreadnumber).ToString();
        }
        else if (evt.unreadnumber == 0)
        {
            NGUITools.SetActive(mMailAnimation.gameObject, false);
            mUnReadNum.text = "";
        }
    }
        private void WriteOnConsole(MailEvent message, string description, ConsoleColor foregroundColor)
        {
            Console.ForegroundColor = foregroundColor;
            try
            {
                Console.WriteLine();
                Console.WriteLine($"Email {description} on {message.DateTime}");
                Console.WriteLine($"    From: {message.From} to {message.To}");
                Console.WriteLine($"    Subject: {message.Subject}");
                Console.WriteLine($"    Message: {message.Message}");
                Console.WriteLine();

                //if (message is MailUnsentEvent)
                //    throw new SendMailException($"Email from {message.From} to {message.To} { description }");
            }
            finally
            {
                Console.ForegroundColor = ConsoleColor.Black;
            }
        }
Esempio n. 5
0
        public IActionResult EventCallback([FromBody] MailEvent mailEvent)
        {
            _logger.LogInformation($"Recieved Event { mailEvent.EventType }");

            if (mailEvent.EventType == MailEventType.sent)
            {
                return(SentEventCallback(mailEvent));
            }

            if (mailEvent.EventType == MailEventType.open)
            {
                return(OpenEventCallback(mailEvent));
            }

            if (mailEvent.EventType == MailEventType.click)
            {
                return(ClickEventCallback(mailEvent));
            }

            if (mailEvent.EventType == MailEventType.bounce)
            {
                return(BounceEventCallback(mailEvent));
            }

            if (mailEvent.EventType == MailEventType.blocked)
            {
                return(BlockedEventCallback(mailEvent));
            }

            if (mailEvent.EventType == MailEventType.spam)
            {
                return(SpamEventCallback(mailEvent));
            }

            if (mailEvent.EventType == MailEventType.unsub)
            {
                return(UnsubscribeEventCallback(mailEvent));
            }

            return(BadRequest("Something goes wrong 0_o"));
        }
Esempio n. 6
0
 public MailEventResponse()
 {
     ResponseStatus = new ResponseStatus();
     MailEvent      = new MailEvent();
 }
Esempio n. 7
0
        public static DefaultProcess CreateSampleProcess()
        {
            // Create new process
            DefaultProcess process = WorkflowFactory.CreateProcess <DefaultProcess>("Sample Approval Process", WizardNames.DefaultProcess);

            // Add some data fields with default values
            DataField fromEmailDataField = new DataField("From Email", "*****@*****.**");
            DataField toEmailDataField   = new DataField("To Email", "*****@*****.**");

            process.DataFields.Add(fromEmailDataField);
            process.DataFields.Add(toEmailDataField);

            // Create 3 activities and add them to the process
            DefaultActivity awaitApprovalActivity = WorkflowFactory.CreateActivity <DefaultActivity>("Await approval", WizardNames.DefaultActivity);
            DefaultActivity approvedActivity      = WorkflowFactory.CreateActivity <DefaultActivity>("Approved", WizardNames.DefaultActivity);
            DefaultActivity declinedActivity      = WorkflowFactory.CreateActivity <DefaultActivity>("Declined", WizardNames.DefaultActivity);

            process.Activities.Add(awaitApprovalActivity);
            process.Activities.Add(approvedActivity);
            process.Activities.Add(declinedActivity);

            // Create a client event
            ClientEvent approvalClientEvent = WorkflowFactory.CreateEvent <ClientEvent>("Get client approval", WizardNames.DefaultClientEvent);

            SourceCode.Workflow.Design.DefaultClientWizardDefinition a = new DefaultClientWizardDefinition();


            // Configure the client event
            approvalClientEvent.EventItem.InternetPlatform = "ASP";
            approvalClientEvent.EventItem.SendToInternet   = true;
            approvalClientEvent.EventItem.InternetUrl      = K2FieldFactory.CreateK2Field(
                typeof(string),
                new ValueTypePart("http://webserver/page.aspx?"),
                new SerialNoFieldPart());

            // Add event to the activity so that the helper methods for generating
            // the default outcomes will work correctly
            awaitApprovalActivity.Events.Add(approvalClientEvent);

            // Add two actions for the client event
            EventAction approveAction = WorkflowFactory.CreateK2Object <EventAction>("Approve");

            approveAction.ActionItem = new DefaultOutcomeAction();
            EventAction declineAction = WorkflowFactory.CreateK2Object <EventAction>("Decline");

            declineAction.ActionItem = new DefaultOutcomeAction();
            approvalClientEvent.Actions.Add(approveAction);
            approvalClientEvent.Actions.Add(declineAction);

            // Set the activity succeeding rule to the outcome succeeding rule
            awaitApprovalActivity.SucceedingRule = new DefaultOutcomeSucceedingRule();

            // Find the default succeeding rule property wizard definition,
            // and replace it with the default outcome succeeding rule
            PropertyWizardDefinition propWizDefSimple  = WorkflowHelpers.FindOfType <SimpleSucceedingRulePropertyWizardDefinition>(awaitApprovalActivity.WizardDefinition.PropertyWizardDefinitions);
            PropertyWizardDefinition propWizDefOutcome = WorkflowHelpers.FindOfType <OutcomeSucceedingRulePropertyWizardDefinition>(awaitApprovalActivity.WizardDefinition.PropertyWizardDefinitions);

            if (propWizDefSimple != null && propWizDefOutcome == null)
            {
                awaitApprovalActivity.WizardDefinition.PropertyWizardDefinitions.Remove(propWizDefSimple);
                awaitApprovalActivity.WizardDefinition.PropertyWizardDefinitions.Add(
                    WorkflowFactory.CreatePropertyWizardDefinition(PropertyWizardNames.OutcomeSucceedingRule));
            }
            SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultOutcomesForActions(approvalClientEvent);
            SourceCode.Workflow.Design.Outcome.Common.GenerateDefaultLinesForOutcomes(awaitApprovalActivity.SucceedingRule as DefaultOutcomeSucceedingRule);

            // Add some destination users
            SimpleDestinationRule destinationRule       = new SimpleDestinationRule();
            DestinationSet        defaultDestinationSet = new DestinationSet();
            Destination           destination1          = new Destination();

            destination1.Type  = DestinationTypes.User;
            destination1.Value = K2FieldFactory.CreateK2Field("K2:Domain\\User1");
            Destination destination2 = new Destination();

            destination2.Type  = DestinationTypes.User;
            destination2.Value = K2FieldFactory.CreateK2Field("K2:Domain\\User2");

            defaultDestinationSet.Destinations.Add(destination1);
            defaultDestinationSet.Destinations.Add(destination2);

            destinationRule.DestinationSets.Add(defaultDestinationSet);


            // Set the destination rule of the activity
            awaitApprovalActivity.DestinationRule = destinationRule;

            // Create the approved email event
            MailEvent approvedMail = WorkflowFactory.CreateEvent <MailEvent>("Send approved email", WizardNames.MailEvent);

            // Use string values for the email addresses
            approvedMail.EventItem.To      = K2FieldFactory.CreateK2Field("*****@*****.**");
            approvedMail.EventItem.From    = K2FieldFactory.CreateK2Field("*****@*****.**");
            approvedMail.EventItem.Subject = K2FieldFactory.CreateK2Field("Leave Approved");
            approvedMail.EventItem.Body    = K2FieldFactory.CreateK2Field("Your leave has been approved.");

            // Create the declined email event
            MailEvent declinedMail = WorkflowFactory.CreateEvent <MailEvent>("Send declined email", WizardNames.MailEvent);

            // Use process data fields for the email addresses
            declinedMail.EventItem.To      = K2FieldFactory.CreateK2Field(toEmailDataField);
            declinedMail.EventItem.From    = K2FieldFactory.CreateK2Field(fromEmailDataField);
            declinedMail.EventItem.Subject = K2FieldFactory.CreateK2Field("Leave Declined");
            declinedMail.EventItem.Body    = K2FieldFactory.CreateK2Field("Your leave has been declined.");

            // Add the events to the activities
            approvedActivity.Events.Add(approvedMail);
            declinedActivity.Events.Add(declinedMail);

            // Link the lines created by the "GenerateDefaultLinesForOutcomes" method to the approved and declined activities
            process.Lines["Approve"].FinishActivity = approvedActivity;
            process.Lines["Decline"].FinishActivity = declinedActivity;

            // Link the start activity with the await approval activity
            Line startLine = WorkflowFactory.CreateLine("StartLine");

            startLine.StartActivity  = process.StartActivity;
            startLine.FinishActivity = awaitApprovalActivity;
            process.Lines.Add(startLine);

            // Position the activities and lines
            WorkflowHelpers.PositionActivity(process.StartActivity, 208, 16);
            WorkflowHelpers.PositionActivity(awaitApprovalActivity, 208, 112);
            WorkflowHelpers.PositionActivity(approvedActivity, 32, 224);
            WorkflowHelpers.PositionActivity(declinedActivity, 368, 224);

            // FinishLines are the lines that flows out from the activity
            // when the activity has finished
            WorkflowHelpers.AutoPositionLines(awaitApprovalActivity.FinishLines);

            return(process);
        }
Esempio n. 8
0
 // ------------------------ constructor ------------------------------
 public MailEventArgs(MailEvent InEvent)
 {
     mEvent = InEvent;
 }
Esempio n. 9
0
 public IActionResult OpenEventCallback([FromBody] MailEvent mailOpenEvent)
 {
     _logger.LogInformation($"Recieved Open Event for: { mailOpenEvent.MessageGuid }");
     return(SendMessageToBrocker(mailOpenEvent));
 }
Esempio n. 10
0
        public static bool Send(Mail mail, UserCollection recipients)
        {
            bool res;

            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    // Insert mail
                    res = _mailsRepo.InsertMail(mail);

                    // Insert Send event
                    if (res)
                    {
                        var me = new MailEvent
                        {
                            EventTime = DateTime.Now,
                            EventUser = DomainModel.Application.User,
                            EventType = MailEventTypes.GetById(21) // Send
                        };

                        res = _mailsRepo.InsertEvent(mail, me);
                        if (res)
                        {
                            mail.EventLog.Add(me);
                        }
                    }

                    // Insert Receieve events
                    foreach (User user in recipients)
                    {
                        var me = new MailEvent
                        {
                            EventTime = DateTime.Now,
                            EventUser = user,
                            EventType = MailEventTypes.GetById(22) // Receive
                        };

                        if (!(res = _mailsRepo.InsertEvent(mail, me)))
                        {
                            break;
                        }

                        mail.EventLog.Add(me);
                    }

                    if (res)
                    {
                        ts.Complete();
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                res = false;

                try
                {
                    DomainModel.Application.Status.Update(
                        StatusController.Abstract.StatusTypes.Error,
                        "",
                        ex.Message);
                }
                catch (Exception)
                { }
            }

            return(res);
        }
Esempio n. 11
0
        private void OnMailTimer(object state)
        {
            try
            {
                var time      = DateTime.Now;
                var sendEicar = _timeTable.SendEicarFile && new Random().NextDouble() <= EicarProbability;

                var from     = GetFrom();
                var to       = GetRecipients();
                var fromMail = new MailAddress(from);
                var toMail   = to.Select(r => new MailAddress(r)).ToArray();
                var content  = CreateContent(fromMail, toMail, sendEicar);

                var sendableMail = new SendableMail(fromMail, toMail, content.ToString(), null)
                {
                    ResultHandler = success =>
                    {
                        var evt = new MailEvent
                        {
                            Eicar   = sendEicar,
                            Success = success,
                            Time    = time
                        };

                        lock (_events)
                        {
                            _events.Add(evt);
                        }

                        if (success)
                        {
                            _timeTables.IncreaseSuccessMailCount(_timeTable.Id);
                        }
                        else
                        {
                            _timeTables.IncreaseErrorMailCount(_timeTable.Id);
                        }
                    }
                };

                if (_timeTable.ProtocolLevel > ProtocolLevel.Off)
                {
                    Logger.InfoFormat("Timetable '{0}' enqueued a mail.", _timeTable.Name);

                    if (_timeTable.ProtocolLevel == ProtocolLevel.Verbose)
                    {
                        Logger.InfoFormat("From: {0}, To: {1}", from, string.Join(", ", to));
                    }
                }

                _queue.Enqueue(sendableMail, TimeSpan.Zero);
            }
            catch (Exception e)
            {
                Logger.Error(
                    string.Format("Timetable '{0}': An exception occured while sending a mail.", _timeTable.Name), e);
            }
            finally
            {
                _timer.Change(GetWaitTime(), TimeSpan.Zero);
            }
        }