Пример #1
0
        public static DataTable GetVariablesForTemplateEditor(AlertTemplateTypes type, string templateName)
        {
            DataTable table = new DataTable();

            table.Columns.Add(new DataColumn("Name", typeof(string)));
            table.Columns.Add(new DataColumn("Description", typeof(string)));
            table.Columns.Add(new DataColumn("Value", typeof(string)));

            AlertVariable[] vars = null;
            switch (type)
            {
            case AlertTemplateTypes.Notification:
                string[] parts = templateName.Split('|');
                vars = AlertVariable.GetVariables((SystemEventTypes)Enum.Parse(typeof(SystemEventTypes), parts[0]));
                break;

            case AlertTemplateTypes.Reminder:
                vars = Reminder.GetVariables((DateTypes)Enum.Parse(typeof(DateTypes), templateName));
                break;

            case AlertTemplateTypes.Special:
                vars = SpecialMessage.GetVariables((SpecialMessageType)Enum.Parse(typeof(SpecialMessageType), templateName));
                break;
            }

            if (vars != null)
            {
                foreach (AlertVariable var in vars)
                {
                    DataRow row = table.NewRow();

                    row["Name"]        = var.Name;
                    row["Description"] = string.Empty;

                    string value = "[=" + var.Name + "=]";
                    if (var.isLink)
                    {
                        value += "[=/" + var.Name + "=]";
                    }
                    row["Value"] = value;

                    table.Rows.Add(row);
                }
            }

            return(table);
        }
Пример #2
0
        private static void SendReminder(DateTypes dateType, ObjectTypes objecType, int?objectId, Guid?objectUid, List <int> users)
        {
            // TODO: Step 0. Check Security (Not implemented yet)

            // Step 1. Calculate variables
            foreach (int userId in users)
            {
                int reminderType = 0;

                using (IDataReader reader = User.GetUserPreferences(userId))
                {
                    if (reader.Read())
                    {
                        reminderType = (int)reader["ReminderType"];
                    }
                }

                if (reminderType != 0)
                {
                    // Step 2. Get Message Template
                    ReminderTemplate tmpl = Reminder.GetMessageTemplate(dateType, User.GetUserLanguage(userId));

                    // Step 2.1. Calculate Variables
                    ArrayList vars = new ArrayList();

                    Alerts2.GetObjectVariables(objecType, objectId, objectUid, false, Reminder.GetVariables(dateType), vars);

                    // Step 3. Replace variables and GetMessage
                    Alerts2.Message msg = Reminder.GetMessage(tmpl, objectId, objectUid, objecType, userId, (VariableInfo[])vars.ToArray(typeof(VariableInfo)));

                    // Step 4. Save to log
                    using (DbTransaction tran = DbTransaction.Begin())
                    {
                        int logId = DbAlert2.MessageLogAdd(msg.Subject, msg.Body);
                        DBSystemEvents.RecipientUpdateSend(userId, (reminderType & 1) != 0, PortalConfig.UseIM && (reminderType & 2) != 0, logId);                         // IsNotifiedByEmail, IsNotifiedByIBN

                        tran.Commit();
                    }

                    #region -- Send via Email --
                    // Step 5. Send via Email
                    try
                    {
                        if ((reminderType & 1) != 0)                        //IsNotifiedByEmail
                        {
                            string body = "<html><head><meta http-equiv=Content-Type content=\"text/html; charset=utf-8\" /></head><body>" + msg.Body + "</body></html>";

                            using (DbTransaction tran = DbTransaction.Begin())
                            {
                                Alerts2.SendMessage(DeliveryType.Email, Reminder.GetAddress(DeliveryType.Email, userId), body, msg.Subject);

                                DBSystemEvents.RecipientUpdateSent(userId, (int)DeliveryType.Email, true);

                                tran.Commit();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError(ex.ToString());
                    }
                    #endregion

                    #region -- Send via IM --
                    // Step 6. Send via IM
                    try
                    {
                        if ((reminderType & 2) != 0)                        //uInfo != null && uInfo.IsNotifiedByIBN)
                        {
                            using (DbTransaction tran = DbTransaction.Begin())
                            {
                                Alerts2.SendMessage(DeliveryType.IBN, Reminder.GetAddress(DeliveryType.IBN, userId), msg.Body, msg.Subject);

                                DBSystemEvents.RecipientUpdateSent(userId, (int)DeliveryType.IBN, true);

                                tran.Commit();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError(ex.ToString());
                    }
                    #endregion
                }
            }
        }