public ActionResult Calendar() { DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar(); // Create the event, and add it to the iCalendar Event evt = iCal.Create <Event>(); // Set information about the event evt.Start = iCalDateTime.Today.AddHours(8); evt.End = evt.Start.AddHours(18); // This also sets the duration evt.Description = "The event description"; evt.Location = "Event location"; evt.Summary = "18 hour event summary"; // Set information about the second event evt = iCal.Create <Event>(); evt.Start = iCalDateTime.Today.AddDays(5); evt.End = evt.Start.AddDays(1); evt.IsAllDay = true; evt.Summary = "All-day event"; // Create a serialization context and serializer factory. // These will be used to build the serializer for our object. ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); // Get a serializer for our object IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var contentType = "text/calendar"; var bytes = Encoding.UTF8.GetBytes(output); return(File(bytes, contentType, "calendar.ics")); }
public ActionResult ICalendar(string shortcut, Guid hallID, string accessToken) { var iCal = new iCalendar(); var studio = _context.Photostudios.Single(x => x.Shortcut == shortcut); var hall = studio.Halls.Single(x => x.ID == hallID); foreach (var @event in hall.Calendar.Events) { var evt = iCal.Create <DDay.iCal.Event>(); // Set information about the event evt.Start = new iCalDateTime(@event.Start); evt.End = new iCalDateTime(@event.End); // This also sets the duration evt.Description = @event.Description; evt.Location = hall.Photostudio.Adress; evt.Summary = "18 hour event summary"; evt.UID = @event.ID.ToString(); } // Create a serialization context and serializer factory. // These will be used to build the serializer for our object. ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); // Get a serializer for our object IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var contentType = "text/calendar"; var bytes = Encoding.UTF8.GetBytes(output); return(File(bytes, contentType, hallID + ".ics")); }
public void ExportSolution() { DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar(); var t = new DBManager(); t.initInputData(); t.initOutputData(); foreach(ScheduledTimeSlot[] solution in (t.solutions)) { for (int i = 0; i < solution.Length; i++) { Event evt = iCal.Create<Event>(); evt.Start = iCalDateTime.Today.AddHours((int)solution[i].timeSlot.StartHour).AddDays((int)(solution[i].timeSlot.Day)); evt.End = iCalDateTime.Today.AddHours((int)solution[i].timeSlot.EndHour).AddDays((int)(solution[i].timeSlot.Day)); evt.Summary = string.Join(", ", solution[i].groups.Select(g => g.name)); evt.Location = solution[i].room.nameOrNumber; } break; } ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); // Get a serializer for our object IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var bytes = Encoding.UTF8.GetBytes(output); File.WriteAllBytes("solution.ics", bytes); }
private System.IO.MemoryStream Generacion(string Titulo, String nombreCalendario, DateTime fechayHoraInicio, Int32 duracionEnMinutos, string ubicacion) { DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar(); // Create the event, and add it to the iCalendar Event evt = iCal.Create <Event>(); // Set information about the event evt.Start = new iCalDateTime(fechayHoraInicio); evt.End = evt.Start.AddMinutes(duracionEnMinutos); // This also sets the duration evt.Description = String.Format("Agenda del día {0} a las {1}", fechayHoraInicio.ToString("dd 'de' MMM 'de' yyyy"), fechayHoraInicio.ToString("HH:MM") ); evt.Location = ubicacion; evt.Summary = Titulo; ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); // Get a serializer for our object IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var bytes = Encoding.UTF8.GetBytes(output); //return File(bytes, contentType, DownloadFileName); System.IO.MemoryStream data = new System.IO.MemoryStream(bytes); return(data); }
// GET: Calendar public ActionResult Index() { foreach (var r in Request.Params.AllKeys) { System.Diagnostics.Debug.WriteLine(r + " = " + Request.Params[r]); } var iCal = new iCalendar(); Event evt = iCal.Create<Event>(); evt.Start = iCalDateTime.Today.AddHours(8); evt.End = evt.Start.AddHours(18); // This also sets the duration evt.Description = "The event description"; evt.Location = "Event location"; evt.Summary = "18 hour event summary"; evt = iCal.Create<Event>(); evt.Start = iCalDateTime.Today.AddDays(5); evt.End = evt.Start.AddDays(1); evt.IsAllDay = true; evt.Summary = "All-day event"; ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var bytes = System.Text.Encoding.UTF8.GetBytes(output); return File(bytes, "text/calendar"); }
private Response GetCalendarFeed() { var pastDays = 7; var futureDays = 28; var start = DateTime.Today.AddDays(-pastDays); var end = DateTime.Today.AddDays(futureDays); // TODO: Remove start/end parameters in v3, they don't work well for iCal var queryStart = Request.Query.Start; var queryEnd = Request.Query.End; var queryPastDays = Request.Query.PastDays; var queryFutureDays = Request.Query.FutureDays; if (queryStart.HasValue) start = DateTime.Parse(queryStart.Value); if (queryEnd.HasValue) end = DateTime.Parse(queryEnd.Value); if (queryPastDays.HasValue) { pastDays = int.Parse(queryPastDays.Value); start = DateTime.Today.AddDays(-pastDays); } if (queryFutureDays.HasValue) { futureDays = int.Parse(queryFutureDays.Value); end = DateTime.Today.AddDays(futureDays); } var episodes = _episodeService.EpisodesBetweenDates(start, end, false); var icalCalendar = new iCalendar(); foreach (var episode in episodes.OrderBy(v => v.AirDateUtc.Value)) { var occurrence = icalCalendar.Create<Event>(); occurrence.UID = "NzbDrone_episode_" + episode.Id.ToString(); occurrence.Status = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative; occurrence.Start = new iCalDateTime(episode.AirDateUtc.Value) { HasTime = true }; occurrence.End = new iCalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)) { HasTime = true }; occurrence.Description = episode.Overview; occurrence.Categories = new List<string>() { episode.Series.Network }; switch (episode.Series.SeriesType) { case SeriesTypes.Daily: occurrence.Summary = string.Format("{0} - {1}", episode.Series.Title, episode.Title); break; default: occurrence.Summary = string.Format("{0} - {1}x{2:00} - {3}", episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber, episode.Title); break; } } var serializer = new DDay.iCal.Serialization.iCalendar.SerializerFactory().Build(icalCalendar.GetType(), new DDay.iCal.Serialization.SerializationContext()) as DDay.iCal.Serialization.IStringSerializer; var icalendar = serializer.SerializeToString(icalCalendar); return new TextResponse(icalendar, "text/calendar"); }
private Response GetCalendarFeed() { var start = DateTime.Today.AddDays(-7); var end = DateTime.Today.AddDays(28); var queryStart = Request.Query.Start; var queryEnd = Request.Query.End; if (queryStart.HasValue) { start = DateTime.Parse(queryStart.Value); } if (queryEnd.HasValue) { end = DateTime.Parse(queryEnd.Value); } var episodes = _episodeService.EpisodesBetweenDates(start, end); var icalCalendar = new iCalendar(); foreach (var episode in episodes.OrderBy(v => v.AirDateUtc.Value)) { var occurrence = icalCalendar.Create <Event>(); occurrence.UID = "NzbDrone_episode_" + episode.Id.ToString(); occurrence.Status = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative; occurrence.Start = new iCalDateTime(episode.AirDateUtc.Value) { HasTime = true }; occurrence.End = new iCalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)) { HasTime = true }; occurrence.Description = episode.Overview; occurrence.Categories = new List <string>() { episode.Series.Network }; switch (episode.Series.SeriesType) { case SeriesTypes.Daily: occurrence.Summary = string.Format("{0} - {1}", episode.Series.Title, episode.Title); break; default: occurrence.Summary = string.Format("{0} - {1}x{2:00} - {3}", episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber, episode.Title); break; } } var serializer = new DDay.iCal.Serialization.iCalendar.SerializerFactory().Build(icalCalendar.GetType(), new DDay.iCal.Serialization.SerializationContext()) as DDay.iCal.Serialization.IStringSerializer; var icalendar = serializer.SerializeToString(icalCalendar); return(new TextResponse(icalendar, "text/calendar")); }
public static string SerializeCalendar(IICalendar calendar) { try { var context = new DDay.iCal.Serialization.SerializationContext(); var factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); var serializer = factory.Build(calendar.GetType(), context) as DDay.iCal.Serialization.IStringSerializer; return(serializer != null?serializer.SerializeToString(calendar) : null); } catch (Exception) { return(null); } }
public static string SerializeCalendar(DDay.iCal.IICalendar calendar) { try { var context = new DDay.iCal.Serialization.SerializationContext(); var factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); var serializer = factory.Build(calendar.GetType(), context) as DDay.iCal.Serialization.IStringSerializer; return(serializer != null?serializer.SerializeToString(calendar) : null); } catch (Exception ex) { log4net.LogManager.GetLogger("ASC.Calendar").Error(ex); return(null); } }
public ActionResult ExportSolution() { var userDetail = SessionHelper.GetUserDetailFromSession(); if (userDetail == null) { return(RedirectToAction("Index", "Login", new { ReturnUrl = "/BookRoom" })); } int UserId = Convert.ToInt32(userDetail.user.id); var calendarevents = db.BookRooms.Where(x => x.UserId == UserId && x.IsSyncIcal == false && x.IsActive == true).ToList(); // var calendarevents = CM.calendardetailtomodel(); var FileTime = DateTime.Now.ToFileTime(); var ext = ".ics"; DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar(); foreach (var demoEvent in calendarevents) { Event evt = iCal.Create <Event>(); evt.Start = new iCalDateTime(demoEvent.StartDate); evt.End = new iCalDateTime(demoEvent.EndDate); evt.Description = demoEvent.Description; evt.Summary = demoEvent.Description; var datas = db.BookRooms.Where(x => x.BookRoomId == demoEvent.BookRoomId).FirstOrDefault(); if (datas != null) { datas.IsSyncIcal = true; db.SaveChanges();//update //TempData["StatusMsg"] = "Success"; } } ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); // Get a serializer for our object IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var contentType = "text/calendar"; var bytes = Encoding.UTF8.GetBytes(output); return(File(bytes, contentType, FileTime + ext)); }
public ActionResult EmailMySchedule(int id) { List<ClassHour> UserClassHours = new List<ClassHour>(); string role = (string)Session["selectedRoles"]; if (role.Equals("instructor")) { var InstructorClasses = repository.GetInstructorRoster(id).ToList(); foreach (var c in InstructorClasses) { var classHours = repository.GetClassHoursList(c.ClassID).ToList(); foreach (var h in classHours) { UserClassHours.Add(h); } } } else if (role.Equals("student")) { var StudentClasses = repository.GetEnrolledClasses(id).ToList(); foreach (var c in StudentClasses) { var classHours = repository.GetClassHoursList(c.ClassID).ToList(); foreach (var h in classHours) { UserClassHours.Add(h); } } } DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar(); // Create the event, and add it to the iCalendar foreach (var h in UserClassHours) { StringBuilder des = new StringBuilder(); // Set information about the event Event evt = iCal.Create<Event>(); //evt.Start.Add(h.startTime); // IRecurrencePattern pattern = new RecurrencePattern(); pattern.Frequency = FrequencyType.Weekly; // Weekly pattern.Interval = 1; // Every 1 pattern.ByDay.Add(new WeekDay(h.day)); // pattern.Until = h.Class.EndDate; iCalDateTime Date = new iCalDateTime(h.Class.StartDate); evt.RecurrenceRules.Add(pattern); evt.Start = Date.AddHours(h.startTime.Hours); evt.End = Date.AddHours(h.endTime.Hours); des.Append(" -Session ID: " + h.id); des.Append(" -Istructor: " + h.Class.Instructor); des.Append(" -Course Name: " + h.Class.Course.Title); evt.Description = des.ToString(); evt.Location = h.location; evt.Summary = "Class Event"; } // Create a serialization context and serializer factory. // These will be used to build the serializer for our object. ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); // Get a serializer for our object IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var contentType = "text/calendar"; var bytes = Encoding.UTF8.GetBytes(output); MemoryStream stream = new MemoryStream(bytes); var MySmtp = repository.Smtp.First(); var user = repository.Users.FirstOrDefault(u => u.userName == User.Identity.Name); // send notification email through gmail // email address "*****@*****.**" // password "P@ttersonetsemail" (Patterson employee training system email) System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage(); email.To.Add(user.email); email.Subject = "Your schedule from P.E.T.S"; var fromAddress = new MailAddress(MySmtp.user); email.From = fromAddress; email.Body = "This is the schedule for " + user.name + " that has been requested, Thank you."; System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(stream, "MySchedule.ics", contentType); email.Attachments.Add(attachment); System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(MySmtp.server); smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential(fromAddress.Address, MySmtp.password); smtp.EnableSsl = true; smtp.Port = MySmtp.port; smtp.Send(email); TempData["message"] = string.Format("Your schedule has been sent to {0} .", user.email); return RedirectToAction("Index", "Home"); }
public ActionResult GiveMySchedule(int id) { List<ClassHour> UserClassHours = new List<ClassHour>(); string role = (string)Session["selectedRoles"]; if (role.Equals("instructor")) { var InstructorClasses = repository.GetInstructorRoster(id).ToList(); foreach (var c in InstructorClasses) { var classHours = repository.GetClassHoursList(c.ClassID).ToList(); foreach (var h in classHours) { UserClassHours.Add(h); } } } else if (role.Equals("student")) { var StudentClasses = repository.GetEnrolledClasses(id).ToList(); foreach (var c in StudentClasses) { var classHours = repository.GetClassHoursList(c.ClassID).ToList(); foreach (var h in classHours) { UserClassHours.Add(h); } } } DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar(); // Create the event, and add it to the iCalendar foreach(var h in UserClassHours) { StringBuilder des = new StringBuilder(); // Set information about the event Event evt = iCal.Create<Event>(); //evt.Start.Add(h.startTime); // IRecurrencePattern pattern = new RecurrencePattern(); pattern.Frequency = FrequencyType.Weekly; // Weekly pattern.Interval = 1; // Every 1 pattern.ByDay.Add(new WeekDay(h.day)); // pattern.Until = h.Class.EndDate; iCalDateTime Date = new iCalDateTime(h.Class.StartDate); evt.RecurrenceRules.Add(pattern); evt.Start = Date.AddHours(h.startTime.Hours); evt.End = Date.AddHours(h.endTime.Hours); des.Append(" -Session ID: " + h.id); des.Append(" -Istructor: " + h.Class.Instructor); des.Append(" -Course Name: " + h.Class.Course.Title); evt.Description = des.ToString(); evt.Location = h.location; evt.Summary = "Class Event"; } // Create a serialization context and serializer factory. // These will be used to build the serializer for our object. ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); // Get a serializer for our object IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var contentType = "text/calendar"; var bytes = Encoding.UTF8.GetBytes(output); return File(bytes, contentType, "MySchedule.ics"); }
public ActionResult GetIcsForCalendar(int id) { DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar(); var lctrl = new LocationApiController(); var calctrl = new CalendarApiController(); var cal = calctrl.GetById(id); EventLocation l = null; iCal.Properties.Add(new CalendarProperty("X-WR-CALNAME", cal.Calendarname)); //Get normal events for calendar var nectrl = new EventApiController(); foreach (var e in nectrl.GetAll().Where(x => x.calendarId == id)) { // Create the event, and add it to the iCalendar DDay.iCal.Event evt = iCal.Create <DDay.iCal.Event>(); var start = (DateTime)e.start; evt.Start = new iCalDateTime(start.ToUniversalTime()); if (e.end != null) { var end = (DateTime)e.end; evt.End = new iCalDateTime(end.ToUniversalTime()); } evt.Description = this.GetDescription(e, CultureInfo.CurrentCulture.ToString()); evt.Summary = e.title; evt.IsAllDay = e.allDay; evt.Categories.AddRange(e.categories.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList()); //If it has a location fetch it if (e.locationId != 0) { l = lctrl.GetById(e.locationId); evt.Location = l.LocationName + "," + l.Street + "," + l.ZipCode + " " + l.City + "," + l.Country; //evt.GeographicLocation = new GeographicLocation(Convert.ToDouble(l.lat,CultureInfo.InvariantCulture), Convert.ToDouble(l.lon, CultureInfo.InvariantCulture)); } var attendes = new List <IAttendee>(); if (e.Organisator != null && e.Organisator != 0) { var ms = Services.MemberService; var member = ms.GetById(e.Organisator); string attendee = "MAILTO:" + member.Email; IAttendee reqattendee = new DDay.iCal.Attendee(attendee) { CommonName = member.Name, Role = "REQ-PARTICIPANT" }; attendes.Add(reqattendee); } if (attendes != null && attendes.Count > 0) { evt.Attendees = attendes; } } //Get recurring events var rectrl = new REventApiController(); foreach (var e in rectrl.GetAll().Where(x => x.calendarId == id)) { // Create the event, and add it to the iCalendar DDay.iCal.Event evt = iCal.Create <DDay.iCal.Event>(); evt.Description = this.GetDescription(e, CultureInfo.CurrentCulture.ToString()); evt.Summary = e.title; evt.IsAllDay = e.allDay; evt.Categories.AddRange(e.categories.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList()); //If it has a location fetch it if (e.locationId != 0) { l = lctrl.GetById(e.locationId); evt.Location = l.LocationName + "," + l.Street + "," + l.ZipCode + " " + l.City + "," + l.Country; //evt.GeographicLocation = new GeographicLocation(Convert.ToDouble(l.lat, CultureInfo.InvariantCulture), Convert.ToDouble(l.lon, CultureInfo.InvariantCulture)); } RecurrencePattern rp = null; var frequency = (FrequencyTypeEnum)e.frequency; switch (frequency) { case FrequencyTypeEnum.Daily: { rp = new RecurrencePattern(FrequencyType.Daily); break; } case FrequencyTypeEnum.Monthly: { rp = new RecurrencePattern(FrequencyType.Monthly); break; } case FrequencyTypeEnum.Weekly: { rp = new RecurrencePattern(FrequencyType.Weekly); break; } case FrequencyTypeEnum.Yearly: { rp = new RecurrencePattern(FrequencyType.Yearly); break; } default: { rp = new RecurrencePattern(FrequencyType.Monthly); break; } } switch (e.day) { case (int)DayOfWeekEnum.Mon: { rp.ByDay.Add(new WeekDay(DayOfWeek.Monday)); break; } case (int)DayOfWeekEnum.Tue: { rp.ByDay.Add(new WeekDay(DayOfWeek.Tuesday)); break; } case (int)DayOfWeekEnum.Wed: { rp.ByDay.Add(new WeekDay(DayOfWeek.Wednesday)); break; } case (int)DayOfWeekEnum.Thu: { rp.ByDay.Add(new WeekDay(DayOfWeek.Thursday)); break; } case (int)DayOfWeekEnum.Fri: { rp.ByDay.Add(new WeekDay(DayOfWeek.Friday)); break; } case (int)DayOfWeekEnum.Sat: { rp.ByDay.Add(new WeekDay(DayOfWeek.Saturday)); break; } case (int)DayOfWeekEnum.Sun: { rp.ByDay.Add(new WeekDay(DayOfWeek.Sunday)); break; } } evt.RecurrenceRules.Add(rp); Schedule schedule = new Schedule(new ScheduleWidget.ScheduledEvents.Event() { Title = e.title, DaysOfWeekOptions = (DayOfWeekEnum)e.day, FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency, MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval }); var occurence = Convert.ToDateTime(schedule.NextOccurrence(DateTime.Now)); evt.Start = new iCalDateTime(new DateTime(occurence.Year, occurence.Month, occurence.Day, e.start.Hour, e.start.Minute, 0)); var attendes = new List <IAttendee>(); if (e.Organisator != null && e.Organisator != 0) { var ms = Services.MemberService; var member = ms.GetById(e.Organisator); string attendee = "MAILTO:" + member.Email; IAttendee reqattendee = new DDay.iCal.Attendee(attendee) { CommonName = member.Name, Role = "REQ-PARTICIPANT" }; attendes.Add(reqattendee); } if (attendes != null && attendes.Count > 0) { evt.Attendees = attendes; } } // Create a serialization context and serializer factory. // These will be used to build the serializer for our object. ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); // Get a serializer for our object IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var contentType = "text/calendar"; var bytes = Encoding.UTF8.GetBytes(output); return(File(bytes, contentType, cal.Calendarname + ".ics")); }
public ActionResult GetIcsForCalendar(int id) { DDay.iCal.iCalendar iCal = new DDay.iCal.iCalendar(); var lctrl = new LocationApiController(); var calctrl = new CalendarApiController(); var cal = calctrl.GetById(id); EventLocation l = null; iCal.Properties.Add(new CalendarProperty("X-WR-CALNAME", cal.Calendarname)); //Get normal events for calendar var nectrl = new EventApiController(); foreach (var e in nectrl.GetAll().Where(x => x.calendarId == id)) { // Create the event, and add it to the iCalendar DDay.iCal.Event evt = iCal.Create<DDay.iCal.Event>(); var start = (DateTime)e.start; evt.Start = new iCalDateTime(start.ToUniversalTime()); if (e.end != null) { var end = (DateTime)e.end; evt.End = new iCalDateTime(end.ToUniversalTime()); } evt.Description = this.GetDescription(e, CultureInfo.CurrentCulture.ToString()); evt.Summary = e.title; evt.IsAllDay = e.allDay; evt.Categories.AddRange(e.categories.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList()); //If it has a location fetch it if (e.locationId != 0) { l = lctrl.GetById(e.locationId); evt.Location = l.LocationName + "," + l.Street + "," + l.ZipCode + " " + l.City + "," + l.Country; //evt.GeographicLocation = new GeographicLocation(Convert.ToDouble(l.lat,CultureInfo.InvariantCulture), Convert.ToDouble(l.lon, CultureInfo.InvariantCulture)); } var attendes = new List<IAttendee>(); if (e.Organisator != null && e.Organisator != 0) { var ms = Services.MemberService; var member = ms.GetById(e.Organisator); string attendee = "MAILTO:" + member.Email; IAttendee reqattendee = new DDay.iCal.Attendee(attendee) { CommonName = member.Name, Role = "REQ-PARTICIPANT" }; attendes.Add(reqattendee); } if (attendes != null && attendes.Count > 0) { evt.Attendees = attendes; } } //Get recurring events var rectrl = new REventApiController(); foreach(var e in rectrl.GetAll().Where(x => x.calendarId == id)) { // Create the event, and add it to the iCalendar DDay.iCal.Event evt = iCal.Create<DDay.iCal.Event>(); evt.Description = this.GetDescription(e, CultureInfo.CurrentCulture.ToString()); evt.Summary = e.title; evt.IsAllDay = e.allDay; evt.Categories.AddRange(e.categories.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList()); //If it has a location fetch it if (e.locationId != 0) { l = lctrl.GetById(e.locationId); evt.Location = l.LocationName + "," + l.Street + "," + l.ZipCode + " " + l.City + "," + l.Country; //evt.GeographicLocation = new GeographicLocation(Convert.ToDouble(l.lat, CultureInfo.InvariantCulture), Convert.ToDouble(l.lon, CultureInfo.InvariantCulture)); } RecurrencePattern rp = null; var frequency = (FrequencyTypeEnum)e.frequency; switch (frequency) { case FrequencyTypeEnum.Daily: { rp = new RecurrencePattern(FrequencyType.Daily); break; } case FrequencyTypeEnum.Monthly: { rp = new RecurrencePattern(FrequencyType.Monthly); break; } case FrequencyTypeEnum.Weekly: { rp = new RecurrencePattern(FrequencyType.Weekly); break; } case FrequencyTypeEnum.Yearly: { rp = new RecurrencePattern(FrequencyType.Yearly); break; } default: { rp = new RecurrencePattern(FrequencyType.Monthly); break; } } switch (e.day) { case (int)DayOfWeekEnum.Mon: { rp.ByDay.Add(new WeekDay(DayOfWeek.Monday)); break; } case (int)DayOfWeekEnum.Tue: { rp.ByDay.Add(new WeekDay(DayOfWeek.Tuesday)); break; } case (int)DayOfWeekEnum.Wed: { rp.ByDay.Add(new WeekDay(DayOfWeek.Wednesday)); break; } case (int)DayOfWeekEnum.Thu: { rp.ByDay.Add(new WeekDay(DayOfWeek.Thursday)); break; } case (int)DayOfWeekEnum.Fri: { rp.ByDay.Add(new WeekDay(DayOfWeek.Friday)); break; } case (int)DayOfWeekEnum.Sat: { rp.ByDay.Add(new WeekDay(DayOfWeek.Saturday)); break; } case (int)DayOfWeekEnum.Sun: { rp.ByDay.Add(new WeekDay(DayOfWeek.Sunday)); break; } } evt.RecurrenceRules.Add(rp); Schedule schedule = new Schedule(new ScheduleWidget.ScheduledEvents.Event() { Title = e.title, DaysOfWeekOptions = (DayOfWeekEnum)e.day, FrequencyTypeOptions = (FrequencyTypeEnum)e.frequency, MonthlyIntervalOptions = (MonthlyIntervalEnum)e.monthly_interval }); var occurence = Convert.ToDateTime(schedule.NextOccurrence(DateTime.Now)); evt.Start = new iCalDateTime(new DateTime(occurence.Year, occurence.Month, occurence.Day, e.start.Hour, e.start.Minute, 0)); var attendes = new List<IAttendee>(); if (e.Organisator != null && e.Organisator != 0) { var ms = Services.MemberService; var member = ms.GetById(e.Organisator); string attendee = "MAILTO:" + member.Email; IAttendee reqattendee = new DDay.iCal.Attendee(attendee) { CommonName = member.Name, Role = "REQ-PARTICIPANT" }; attendes.Add(reqattendee); } if (attendes != null && attendes.Count > 0) { evt.Attendees = attendes; } } // Create a serialization context and serializer factory. // These will be used to build the serializer for our object. ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new DDay.iCal.Serialization.iCalendar.SerializerFactory(); // Get a serializer for our object IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(iCal); var contentType = "text/calendar"; var bytes = Encoding.UTF8.GetBytes(output); return File(bytes, contentType, cal.Calendarname + ".ics"); }
private Response GetCalendarFeed() { var pastDays = 7; var futureDays = 28; var start = DateTime.Today.AddDays(-pastDays); var end = DateTime.Today.AddDays(futureDays); var unmonitored = false; var premiersOnly = false; var tags = new List <int>(); // TODO: Remove start/end parameters in v3, they don't work well for iCal var queryStart = Request.Query.Start; var queryEnd = Request.Query.End; var queryPastDays = Request.Query.PastDays; var queryFutureDays = Request.Query.FutureDays; var queryUnmonitored = Request.Query.Unmonitored; var queryPremiersOnly = Request.Query.PremiersOnly; var queryTags = Request.Query.Tags; if (queryStart.HasValue) { start = DateTime.Parse(queryStart.Value); } if (queryEnd.HasValue) { end = DateTime.Parse(queryEnd.Value); } if (queryPastDays.HasValue) { pastDays = int.Parse(queryPastDays.Value); start = DateTime.Today.AddDays(-pastDays); } if (queryFutureDays.HasValue) { futureDays = int.Parse(queryFutureDays.Value); end = DateTime.Today.AddDays(futureDays); } if (queryUnmonitored.HasValue) { unmonitored = bool.Parse(queryUnmonitored.Value); } if (queryPremiersOnly.HasValue) { premiersOnly = bool.Parse(queryPremiersOnly.Value); } if (queryTags.HasValue) { var tagInput = (string)queryTags.Value.ToString(); tags.AddRange(tagInput.Split(',').Select(_tagService.GetTag).Select(t => t.Id)); } var episodes = _episodeService.EpisodesBetweenDates(start, end, unmonitored); var icalCalendar = new iCalendar(); foreach (var episode in episodes.OrderBy(v => v.AirDateUtc.Value)) { if (premiersOnly && (episode.SeasonNumber == 0 || episode.EpisodeNumber != 1)) { continue; } if (tags.Any() && tags.None(episode.Series.Tags.Contains)) { continue; } var occurrence = icalCalendar.Create <Event>(); occurrence.UID = "NzbDrone_episode_" + episode.Id.ToString(); occurrence.Status = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative; occurrence.Start = new iCalDateTime(episode.AirDateUtc.Value) { HasTime = true }; occurrence.End = new iCalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)) { HasTime = true }; occurrence.Description = episode.Overview; occurrence.Categories = new List <string>() { episode.Series.Network }; switch (episode.Series.SeriesType) { case SeriesTypes.Daily: occurrence.Summary = string.Format("{0} - {1}", episode.Series.Title, episode.Title); break; default: occurrence.Summary = string.Format("{0} - {1}x{2:00} - {3}", episode.Series.Title, episode.SeasonNumber, episode.EpisodeNumber, episode.Title); break; } } var serializer = new DDay.iCal.Serialization.iCalendar.SerializerFactory().Build(icalCalendar.GetType(), new DDay.iCal.Serialization.SerializationContext()) as DDay.iCal.Serialization.IStringSerializer; var icalendar = serializer.SerializeToString(icalCalendar); return(new TextResponse(icalendar, "text/calendar")); }