private void ExecuteReceivedEvent(AlertEventType eventType, SPItemEventProperties properties)
        {
            LogManager.write("Entered in to ExecuteReceivedEvent with event type" + eventType);
            try
            {
                using (SPWeb web = properties.OpenWeb())
                {
                    //TODO we have to check is feature activated for this site or not
                    AlertManager        alertManager        = new AlertManager(web.Site.Url);
                    MailTemplateManager mailTemplateManager = new MailTemplateManager(web.Site.Url);
                    IList <Alert>       alerts        = alertManager.GetAlertForList(properties.ListItem, eventType, mailTemplateManager);
                    Notifications       notifications = new Notifications();
                    foreach (Alert alert in alerts)
                    {
                        if (eventType != AlertEventType.DateColumn)
                        {
                            if (alert.IsValid(properties.ListItem, eventType, properties))
                            {
                                try
                                {
                                    if (alert.SendType == SendType.ImmediateAlways)
                                    {
                                        notifications.SendMail(alert, eventType, properties.ListItem, FinalBody);
                                    }
                                    else if (alert.SendType == SendType.ImmediateBusinessDays)
                                    {
                                        if (alert.ImmediateBusinessDays.Contains((WeekDays)DateTime.UtcNow.DayOfWeek))
                                        {
                                            if (alert.BusinessStartHour <= Convert.ToInt32(DateTime.UtcNow.Hour) && alert.BusinessendtHour >= Convert.ToInt32(DateTime.UtcNow.Hour))
                                            {
                                                notifications.SendMail(alert, eventType, properties.ListItem, FinalBody);
                                            }
                                            else
                                            {
                                                return;
                                            }
                                        }
                                    }

                                    else
                                    {
                                        CreateDelayedAlert(alert, eventType, properties, alertManager);
                                    }
                                }
                                catch { }
                            }
                        }
                    }
                }
            }
            catch (System.Exception Ex)
            {
                LogManager.write("Error occured white excuting event receiver" + Ex.Message);
            }
        }
        private void ExecuteTimerAlert(SPWeb web, SPList list, Alert alert)
        {
            try
            {
                if (web != null && list != null)
                {
                    DateTime startTime = web.RegionalSettings.TimeZone.UTCToLocalTime(DateTime.UtcNow).AddMinutes(-30.0);
                    DateTime endTime   = web.RegionalSettings.TimeZone.UTCToLocalTime(DateTime.UtcNow);
                    TimerJobHelper.CaliculateExecutionTime(ref startTime, alert, false);
                    TimerJobHelper.CaliculateExecutionTime(ref endTime, alert, false);

                    int num  = !alert.Repeat ? 1 : (alert.RepeatCount + 1);
                    int num2 = 1;
                    while (num2 <= num)
                    {
                        //We need to get all alerts which are fall
                        SPQuery query = new SPQuery();
                        query.Query = string.Format("<Where>" +
                                                    "<And>" +
                                                    "<Gt>" +
                                                    "<FieldRef Name=\"{0}\" />" +
                                                    "<Value Type=\"DateTime\" IncludeTimeValue=\"TRUE\">{1}</Value>" +
                                                    "</Gt>" +
                                                    "<Leq>" +
                                                    "<FieldRef Name=\"{0}\" />" +
                                                    "<Value Type=\"DateTime\" IncludeTimeValue=\"TRUE\">{2}</Value>" +
                                                    "</Leq>" +
                                                    "</And>" +
                                                    "</Where>",
                                                    new object[] { alert.DateColumnName, SPUtility.CreateISO8601DateTimeFromSystemDateTime(startTime), SPUtility.CreateISO8601DateTimeFromSystemDateTime(endTime) });
                        SPListItemCollection items = list.GetItems(query);
                        if (items.Count > 0)
                        {
                            foreach (SPListItem item in items)
                            {
                                if (alert.IsValid(item, AlertEventType.DateColumn, null))
                                {
                                    Notifications mailSender = new Notifications();
                                    //mailSender.SendAlert(alert, ChangeTypes.DateColumn, item2, null);
                                    mailSender.SendMail(alert, AlertEventType.DateColumn, item);
                                }
                                else
                                {
                                    //Some conditions are not passthrough
                                }
                            }
                        }
                        else
                        { //No items returned as part of Query
                        }
                        if (num2 < num)
                        {
                            TimerJobHelper.CaliculateExecutionTime(ref startTime, alert, true);
                            TimerJobHelper.CaliculateExecutionTime(ref endTime, alert, true);
                        }
                        num2++;
                    }
                }
            }
            catch
            {
                //Error occured while executing timer alerts
            }
        }
Esempio n. 3
0
        private void ExecuteTimerAlert(SPWeb web, SPList list, Alert alert)
        {
            try
            {
                if (web != null && list != null)
                {


                    DateTime startTime = web.RegionalSettings.TimeZone.UTCToLocalTime(DateTime.UtcNow).AddMinutes(-30.0);
                    DateTime endTime = web.RegionalSettings.TimeZone.UTCToLocalTime(DateTime.UtcNow);
                    TimerJobHelper.CaliculateExecutionTime(ref startTime, alert, false);
                    TimerJobHelper.CaliculateExecutionTime(ref endTime, alert, false);

                    int num = !alert.Repeat ? 1 : (alert.RepeatCount + 1);
                    int num2 = 1;
                    while (num2 <= num)
                    {

                        //We need to get all alerts which are fall
                        SPQuery query = new SPQuery();
                        query.Query = string.Format("<Where>" +
                                                      "<And>" +
                                                       "<Gt>" +
                                                        "<FieldRef Name=\"{0}\" />" +
                                                          "<Value Type=\"DateTime\" IncludeTimeValue=\"TRUE\">{1}</Value>" +
                                                        "</Gt>" +
                                                        "<Leq>" +
                                                          "<FieldRef Name=\"{0}\" />" +
                                                          "<Value Type=\"DateTime\" IncludeTimeValue=\"TRUE\">{2}</Value>" +
                                                        "</Leq>" +
                                                       "</And>" +
                                                       "</Where>",
                                                        new object[] { alert.DateColumnName, SPUtility.CreateISO8601DateTimeFromSystemDateTime(startTime), SPUtility.CreateISO8601DateTimeFromSystemDateTime(endTime) });
                        SPListItemCollection items = list.GetItems(query);
                        if (items.Count > 0)
                        {
                            foreach (SPListItem item in items)
                            {
                                if (alert.IsValid(item, AlertEventType.DateColumn, null))
                                {
                                    Notifications mailSender = new Notifications();
                                    //mailSender.SendAlert(alert, ChangeTypes.DateColumn, item2, null);
                                    mailSender.SendMail(alert, AlertEventType.DateColumn, item);

                                }
                                else
                                {
                                    //Some conditions are not passthrough
                                }
                            }
                        }
                        else
                        { //No items returned as part of Query
                        }
                        if (num2 < num)
                        {
                            TimerJobHelper.CaliculateExecutionTime(ref startTime, alert, true);
                            TimerJobHelper.CaliculateExecutionTime(ref endTime, alert, true);
                        }
                        num2++;
                    }
                }
            }
            catch
            {
                //Error occured while executing timer alerts
            }
        }
       private void ExecuteReceivedEvent(AlertEventType eventType, SPItemEventProperties properties)
       {
           LogManager.write("Entered in to ExecuteReceivedEvent with event type" + eventType);
           try
           { 
               using (SPWeb web = properties.OpenWeb())
               {
                   //TODO we have to check is feature activated for this site or not
                   AlertManager alertManager = new AlertManager(web.Site.Url);
                   MailTemplateManager mailTemplateManager = new MailTemplateManager(web.Site.Url);
                   IList<Alert> alerts = alertManager.GetAlertForList(properties.ListItem ,eventType, mailTemplateManager);
                   Notifications notifications = new Notifications();
                   foreach (Alert alert in alerts)
                   {
                       if (eventType != AlertEventType.DateColumn)
                       {

                           if (alert.IsValid(properties.ListItem, eventType, properties))
                           {
                               try
                               {
                                   if (alert.SendType == SendType.ImmediateAlways)
                                   {

                                       notifications.SendMail(alert, eventType, properties.ListItem, FinalBody);
                                   }
                                   else if (alert.SendType == SendType.ImmediateBusinessDays)
                                   {
                                       if (alert.ImmediateBusinessDays.Contains((WeekDays)DateTime.UtcNow.DayOfWeek))
                                       {
                                           if (alert.BusinessStartHour <= Convert.ToInt32(DateTime.UtcNow.Hour) && alert.BusinessendtHour >= Convert.ToInt32(DateTime.UtcNow.Hour))
                                           {
                                               notifications.SendMail(alert, eventType, properties.ListItem, FinalBody);
                                           }
                                           else
                                           {
                                               return;
                                           }

                                       }
                                   }

                                   else
                                   {
                                       CreateDelayedAlert(alert, eventType, properties, alertManager);
                                   }
                               }
                               catch { }
                           }
                       }
                   }
               }
           }
           catch (System.Exception Ex)
           {
               LogManager.write("Error occured white excuting event receiver" + Ex.Message);
           }

       }