public static void SyncEvents(Event pattern, IEnumerable<Event> events, EventList list, EventListManager manager)
 {
     Message message = Message.Parse(pattern, "event:sync");
      var deleteContext = new SyncEventContext(pattern, events, list,
                                           manager);
      Dispatcher.Dispatch(message, deleteContext);
 }
 public static void CreateRecurrence(Event ev, Schedule schedule, Options options)
 {
     Message message = Message.Parse(ev,
                                  "recurrence:" +
                                  schedule.Recurrence.ToString().ToLower());
      var context = new EventCommandContext(ev, schedule, options);
      Dispatcher.Dispatch(message, context);
 }
 public static void UpdateEvent(Event evnt, Schedule schedule, Options options,
                              bool updateSeries)
 {
     if (RemoteSettings.Service != null)
      {
     RemoteSettings.Service.SaveEventInfo(evnt.ToXml(), schedule == null ? string.Empty : schedule.ToXml(), options.ToXml(),
                                          updateSeries, RemoteSettings.ServiceCredentials);
     CacheManager.ClearAllCaches();
      }
      else
      {
     CalendarActions.UpdateEvent(evnt, schedule, options, updateSeries);
      }
 }
        public static void CreateEvent(Event ev, Schedule schedule, Options options)
        {
            if (RemoteSettings.Service != null)
             {
            RemoteSettings.Service.CreateEvent(ev.ToXml(),
                                               schedule == null ? string.Empty : schedule.ToXml(),
                                               options.ToXml(), RemoteSettings.ServiceCredentials);

            CacheManager.ClearAllCaches();
             }
             else
             {
            CalendarActions.CreateEvent(ev, schedule, options);
             }
        }
        private static void CreateEndUserTrainingEvents(EventListManager eventManager)
        {
            DateTime start = FindNextDayOfWeek(DateTime.Today, DeveloperDay);

             var evt = new Event
                      {
                         Description = string.Empty, StartDate = Utilities.NormalizeDate(start),
                         EndDate = Utilities.NormalizeDate(start.AddMonths(2)), StartTime = "09:00",
                         EndTime = "17:00", Location = EndUserLocationDefault,
                         Title = EndUserDefaultTitle
                      };

             var scheduler = new Schedule
                            {
                               DaysOfWeek = (Utils.DaysOfWeek.Monday | Utils.DaysOfWeek.Friday),
                               StartDate = Utilities.NormalizeDate(start),
                               EndDate = Utilities.NormalizeDate(start.AddMonths(2)),
                               Recurrence = Recurrence.Weekly,
                               Frequency = 1
                            };

             var options = new Options
                          {
                             CalendarID = EndUserTrainingList,
                             ControlSettingsPath = DeveloperViewSettings,
                             SiteSettingsPath = DefaultModuleSettings
                          };

             CalendarActions.CreateEvent(evt, scheduler, options);
        }
        protected virtual void RenderEventSection(HtmlTextWriter writer, Event ev, EventList evList, DateTime date,
                                                string eventAttributes, string dotAttributes, string cssClassReadOnly,
                                                string cssClassCanWrite, bool isUseBackgroundColor)
        {
            string title = (ev.Title == string.Empty) ? ev.Name : ev.Title;
             string cssStyle = ((!ReadOnly && !ev.ReadOnly) || isUseBackgroundColor)
                              ? buildRuntimeStyle(evList.TextColor, evList.BackgroundColor) : "";

             writer.Write(
            string.Format(
               "<div id='{0}' {1} eventID='{0}' align='left' startTime='{2}' endTime='{3}' readonly='{4}' link='{5}' {6} class='{7}' startHour='{8}' isrecur='{9}'>",
               ev.ID, cssStyle, ev.StartTime, ev.EndTime, ReadOnly ? true : ev.ReadOnly,
               (LinkBehaviour == LinkBehaviour.Redirect) ? ev.Path : String.Empty, eventAttributes,
               (ReadOnly || ev.ReadOnly) ? cssClassReadOnly : cssClassCanWrite, date.Hour, ev.IsRecurrentEvent ? "1" : "0"));

             RenderDataBeforeEvent(writer, ev);
             RenderEvent(writer, dotAttributes, ev, title, evList.EventEditIcon);
             RenderDataAfterEvent(writer, ev);

             writer.Write("</div>");
        }
 protected abstract void RenderDataBeforeEvent(HtmlTextWriter writer, Event ev);
 protected override void RenderDataAfterEvent(HtmlTextWriter writer, Event ev)
 {
     if (ShowEventTime)
      {
     writer.Write(string.Format("<br/><span>{0}-{1}</span>",
        Utilities.GetTime(ev.StartTime).ToString(Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern),
        Utilities.GetTime(ev.EndTime).ToString(Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern)));
      }
 }
        private static void addDaily(DateTime start, Event eventItem, Schedule schedule, EventList calendar)
        {
            if (eventItem == null || schedule == null || start > Utilities.StringToDate(schedule.EndDate) ||
             schedule.Frequency == 0 || calendar == null)
             {
            return;
             }

             eventItem.StartDate = Utilities.NormalizeDate(start);
             eventItem.EndDate = Utilities.NormalizeDate(start);

             eventItem.ScheduleID = schedule.ID;

             calendar.AddEvent(eventItem, StaticSettings.EventBranch);

             addDaily(start.AddDays(schedule.Frequency), eventItem, schedule, calendar);
        }
        private static void addByDayOfWeek(DateTime start, Event eventItem, Schedule schedule, EventList calendar)
        {
            if ((schedule.DaysOfWeek & DaysCollection.Monday) == DaysCollection.Monday)
             {
            addEvent(eventItem, start, calendar, schedule);
             }

             if ((schedule.DaysOfWeek & DaysCollection.Tuesday) == DaysCollection.Tuesday)
             {
            addEvent(eventItem, start.AddDays(1), calendar, schedule);
             }

             if ((schedule.DaysOfWeek & DaysCollection.Wednesday) == DaysCollection.Wednesday)
             {
            addEvent(eventItem, start.AddDays(2), calendar, schedule);
             }

             if ((schedule.DaysOfWeek & DaysCollection.Thursday) == DaysCollection.Thursday)
             {
            addEvent(eventItem, start.AddDays(3), calendar, schedule);
             }

             if ((schedule.DaysOfWeek & DaysCollection.Friday) == DaysCollection.Friday)
             {
            addEvent(eventItem, start.AddDays(4), calendar, schedule);
             }

             if ((schedule.DaysOfWeek & DaysCollection.Saturday) == DaysCollection.Saturday)
             {
            addEvent(eventItem, start.AddDays(5), calendar, schedule);
             }

             if ((schedule.DaysOfWeek & DaysCollection.Sunday) == DaysCollection.Sunday)
             {
            addEvent(eventItem, start.AddDays(6), calendar, schedule);
             }
        }
        public void UpdateEvent(Event evnt, Schedule schedule, string calendarID, bool updateSeries, BranchItem branchID)
        {
            if (evnt == null)
             {
            return;
             }

             EventList newCal = EventLists[calendarID];
             EventList currentCal = GetCalendar(evnt);

             if (updateSeries == false)
             {
            evnt.ScheduleID = string.Empty;
            evnt.Save();
            PublishUtil.Publishing(evnt.GetTargetItem(), true, false);

            if (newCal != null && currentCal != null && currentCal.ID != newCal.ID)
            {
               currentCal.DeleteEvent(evnt);

               newCal.AddEvent(evnt, branchID);
            }

            return;
             }

             if (schedule == null || schedule.IsNew || schedule.IsChanged)
             {
            DeleteEvent(evnt.ID, true, true);
            CreateEvent(evnt, schedule, newCal, branchID);

            return;
             }

             if (newCal != null && currentCal != null)
             {
            DeleteEvent(evnt.ID, true, true);

            evnt.StartDate = schedule.StartDate;
            evnt.EndDate = schedule.EndDate;

            CreateEvent(evnt, schedule, newCal, branchID);
             }

             if (evnt.IsChanged != true)
             {
            return;
             }

             ItemLink[] links = Globals.LinkDatabase.GetReferences(schedule.GetTargetItem());
             foreach (ItemLink link in links)
             {
            evnt.SaveToItem(link.GetSourceItem(), true);
             }
        }
        public void MoveEvent(Event ev)
        {
            if (ev != null)
             {
            EventList currentCal = GetCalendar(ev);

            if (currentCal != null)
            {
               currentCal.MoveEvent(ev);
            }
             }
        }
 public EventList GetCalendar(Event ev)
 {
     return GetCalendar(StaticSettings.EventSourceDatabase.GetItem(ev.ID));
 }
        public void CreateEvent(Event eventItem, Schedule schedule, EventList calendar, BranchItem branch)
        {
            if (eventItem == null || calendar == null)
             {
            return;
             }

             calendar.AddEvent(eventItem, branch);

             if (schedule != null)
             {
            if (schedule.IsNew)
            {
               schedule.StartDate = eventItem.StartDate;
               schedule.EndDate = eventItem.EndDate;

               CreateSchedule(schedule);
            }

            switch (schedule.Recurrence)
            {
               case Recurrence.Daily:

                  addDaily(Utilities.StringToDate(schedule.StartDate), eventItem, schedule, calendar);

                  break;
               case Recurrence.Weekly:

                  addWeekly(Utilities.FirstCalendarDay(Utilities.StringToDate(schedule.StartDate)), eventItem, schedule,
                            calendar);

                  break;
               case Recurrence.Monthly:

                  addMonthly(Utilities.FirstMonthDay(Utilities.StringToDate(schedule.StartDate)), eventItem, schedule,
                             calendar);

                  break;
               case Recurrence.Yearly:

                  addYearly(Utilities.FirstMonthDay(Utilities.StringToDate(schedule.StartDate)), eventItem, schedule,
                            calendar);
                  break;
               default:
                  break;
            }
             }
        }
 public void MoveEvent(Event ev)
 {
     CalendarActions.MoveEvent(ev.ID, ev.StartDate);
 }
 public static void CreateEvent(Event ev, Schedule schedule, Options options)
 {
     CreateEvent(ev, schedule, options, null);
 }
 public static void CreateEvent(Event ev, Schedule schedule, Options options, BranchItem branch)
 {
     Message message = Message.Parse(ev, "event:create");
      var calendarContext = new EventCommandContext(ev, schedule, options, branch);
      Dispatcher.Dispatch(message, calendarContext);
 }
        private static void addEvent(Event eventItem, DateTime date, EventList calendar, Schedule schedule)
        {
            if (date > Utilities.StringToDate(schedule.EndDate))
             {
            return;
             }

             eventItem.StartDate = Utilities.NormalizeDate(date);
             eventItem.EndDate = Utilities.NormalizeDate(date);
             eventItem.ScheduleID = schedule.ID;
             calendar.AddEvent(eventItem, StaticSettings.EventBranch);
        }
 public static void CreateSchedule(Event ev, Schedule schedule, Options options)
 {
     Message message = Message.Parse(ev, "schedule:create");
      var context = new EventCommandContext(ev, schedule, options);
      Dispatcher.Dispatch(message, context);
 }
        private static void addMonthly(DateTime start, Event eventItem, Schedule schedule, EventList calendar)
        {
            if (eventItem == null || schedule == null || start > Utilities.StringToDate(schedule.EndDate) ||
             schedule.Frequency == 0 || calendar == null)
             {
            return;
             }

             switch (schedule.Sequence)
             {
            case Sequence.First:
            case Sequence.Second:
            case Sequence.Third:
            case Sequence.Fourth:
               addSequence(start, eventItem, schedule, calendar);
               break;

            case Sequence.Last:

               DateTime tmp = start.AddMonths(1);
               tmp = tmp.Subtract(TimeSpan.FromDays(1));

               while (true)
               {
                  if (string.Compare(tmp.DayOfWeek.ToString(), schedule.DaysOfWeek.ToString(), true) == 0)
                  {
                     addEvent(eventItem, tmp, calendar, schedule);
                     break;
                  }
                  else
                  {
                     tmp = tmp.Subtract(TimeSpan.FromDays(1));
                  }
               }

               break;
            default:
               break;
             }

             addMonthly(start.AddMonths(schedule.Frequency), eventItem, schedule, calendar);
        }
 public static void UpdateEvent(Event evnt, Schedule schedule, Options options, bool updateSeries)
 {
     var context = new UpdateCommandContext(evnt, schedule, options, updateSeries);
      Message message = Message.Parse(evnt, "event:update");
      Dispatcher.Dispatch(message, context);
 }
        private static void addSequence(DateTime start, Event eventItem, Schedule schedule, EventList calendar)
        {
            DateTime tmp = start;

             while (true)
             {
            if (string.Compare(tmp.DayOfWeek.ToString(), schedule.DaysOfWeek.ToString(), true) == 0)
            {
               if (schedule.Sequence != Sequence.None && schedule.Sequence != Sequence.First)
               {
                  tmp = tmp.AddDays(((int) schedule.Sequence)*7);
               }

               if (tmp >= Utilities.StringToDate(schedule.StartDate))
               {
                  addEvent(eventItem, tmp, calendar, schedule);
               }

               break;
            }
            else
            {
               tmp = tmp.AddDays(1);
            }
             }
        }
 protected override void RenderDataBeforeEvent(HtmlTextWriter writer, Event ev)
 {
 }
        private static void addWeekly(DateTime start, Event eventItem, Schedule schedule, EventList calendar)
        {
            if (eventItem == null || schedule == null || start > Utilities.StringToDate(schedule.EndDate) ||
             schedule.Frequency == 0 || calendar == null)
             {
            return;
             }

             addByDayOfWeek(start, eventItem, schedule, calendar);

             start = start.AddDays(schedule.Frequency*7);

             addWeekly(start, eventItem, schedule, calendar);
        }
 protected virtual void RenderEvent(HtmlTextWriter writer, string onclientclick, Event ev, string title,
                                  string dotImage)
 {
     if (ev.ReadOnly || ReadOnly)
      {
     RenderRecurrentEventPrefix(writer, ev);
     writer.Write(
        string.Format("<a class='textEvent' eventID='{0}' link='' {1}>{2}</a>", ev.ID,
                      ev.Path != string.Empty ? string.Format("href='{0}'", ev.Path) : onclientclick, title));
      }
      else
      {
     writer.Write(
        string.Format(
           "<img class='eventImage' src='{0}' style='background-color:inherit' readonly='true' eventID='{1}' {2} align='absmiddle' title='Click to edit' border='0' alt='' width='16px' height='16px' />",
           dotImage, ev.ID, onclientclick));
     RenderRecurrentEventPrefix(writer, ev);
     writer.Write(title);
      }
      RenderRecurrentEventSuffix(writer, ev);
 }
        private static void addYearly(DateTime start, Event eventItem, Schedule schedule, EventList calendar)
        {
            if (eventItem == null || schedule == null || start > Utilities.StringToDate(schedule.EndDate) ||
             schedule.Frequency == 0 || calendar == null)
             {
            return;
             }

             DateTime tmp = new DateTime(start.Year, (int) schedule.Month, schedule.Frequency);

             if (tmp >= Utilities.StringToDate(schedule.StartDate) && tmp <= Utilities.StringToDate(schedule.EndDate))
             {
            addEvent(eventItem, tmp, calendar, schedule);
             }

             addYearly(start.AddYears(1), eventItem, schedule, calendar);
        }
 protected virtual void RenderRecurrentEventSuffix(HtmlTextWriter writer, Event ev)
 {
     if (ev.IsRecurrentEvent)
      {
     writer.Write(string.Format("<span class='recurrent'>{0}</span>", RecurrentEventSuffix));
      }
 }
 public void CreateEvent(Event ev, Schedule schedule, Options options)
 {
     RemoteActionWrapper.CreateEvent(ev, schedule, options);
 }
        private static void NewEvent(EventDetails details, bool useOrdinalInformation, int pos)
        {
            var evt = new Event();

             if (pos == -1)
             {
            pos = Math.Min(Math.Min(details.TitleCount, details.LocationCount),
                           details.DescriptionCount);
             }

             evt.Name = GetResourceString(details.Title,
                                      useOrdinalInformation ? pos : details.TitleCount,
                                      details.DefaultTitle, !useOrdinalInformation);
             evt.Title = evt.Name;

             evt.Location = GetResourceString(details.Location,
                                          useOrdinalInformation ? pos : details.LocationCount,
                                          details.DefaultLocation, !useOrdinalInformation);
             evt.Description = GetResourceString(details.Description,
                                             useOrdinalInformation ? pos : details.DescriptionCount,
                                             details.DefaultDescription, !useOrdinalInformation);

             evt.StartDate = Utilities.NormalizeDate(details.Date);
             evt.EndDate = Utilities.NormalizeDate(details.Date);

             evt.StartTime = details.StartTime;
             evt.EndTime = details.EndTime;

             details.List.CreateEvent(evt, details.Branch);
        }
 public void SaveEventInfo(Event evnt, Schedule schedule, bool updateSeries, Options options)
 {
     RemoteActionWrapper.UpdateEvent(evnt, schedule, options, updateSeries);
 }