private static void SaveToFile(string icsFilename, iCalendar ical) { var ctx = new SerializationContext(); var factory = new SerializerFactory(); var serializer = factory.Build(ical.GetType(), ctx) as IStringSerializer; var content = serializer.SerializeToString(ical); File.WriteAllText(icsFilename, content); }
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")); }
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"); }
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 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"); }
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)); }
private byte[] WrapResource(IUniqueComponent resource) { var iCal = new iCalendar(); iCal.UniqueComponents.Add(resource); ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new SerializerFactory(); IStringSerializer serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; return Encoding.UTF8.GetBytes(serializer.SerializeToString(iCal)); }
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 GetIcsForEvent(int id, int type = 0) { var iCal = new iCalendar(); var evt = iCal.Create<Event>(); var cs = ApplicationContext.Current.Services.ContentService; var content = cs.GetById(id); var seminarStart = Convert.ToDateTime(content.GetValue("start").ToString()); var start = Convert.ToDateTime(content.GetValue("start").ToString()); var end = Convert.ToDateTime(content.GetValue("end").ToString()); evt.Start = new iCalDateTime(start.ToUniversalTime()); evt.End = new iCalDateTime(end.ToUniversalTime()); var eventName = evt.Name= content.Name.ToCleanString(CleanStringType.FileName); var f =VirtualPathUtility.ToAbsolute(Umbraco.Media(content.GetValue("seminarPoster").ToString()).umbracoFile); Attachment poster = new Attachment(f); evt.Attachments.Add(poster); var gmapLocation = content.GetValue<GMapsLocation>("location"); var lat = gmapLocation.Lat; var lng = gmapLocation.Lng; evt.GeographicLocation = new GeographicLocation(Convert.ToDouble(lat), Convert.ToDouble(lng)); ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new SerializerFactory(); // Get a serializer for our object var serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; var output = serializer.SerializeToString(iCal); var contentType = "text/calendar"; var bytes = Encoding.UTF8.GetBytes(output); return File(bytes, contentType, eventName + ".ics"); //if (type == 0) //{ // //Fetch Event // var ectrl = new EventApiController(); // var e = ectrl.GetById(id); // if (e.End != null) // { // var end = (DateTime)e.End; // } // evt.IsAllDay = e.AllDay; // //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; // } // var attendes = new List<IAttendee>(); // if (e.Organiser != null && e.Organiser != 0) // { // var ms = Services.MemberService; // var member = ms.GetById(e.Organiser); // 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; // } //} //else if (type == 1) //{ // var ectrl = new REventApiController(); // var e = ectrl.GetById(id); // evt.Summary = e.Title; // evt.IsAllDay = e.AllDay; // //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; // } // RecurrencePattern rp = null; // rp = new RecurrencePattern(); // 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; // } // } // rp.ByDay.AddRange(e.Days.Select(x => new WeekDay(x.ToString()))); // evt.RecurrenceRules.Add(rp); // var tmp_event = new ScheduleWidget.ScheduledEvents.Event() // { // Title = e.Title, // FrequencyTypeOptions = (FrequencyTypeEnum)e.Frequency // }; // foreach (var day in e.Days) // { // tmp_event.DaysOfWeekOptions = tmp_event.DaysOfWeekOptions | (DayOfWeekEnum)day; // } // foreach (var i in e.MonthlyIntervals) // { // tmp_event.MonthlyIntervalOptions = tmp_event.MonthlyIntervalOptions | (MonthlyIntervalEnum)i; // } // Schedule schedule = new Schedule(tmp_event); // 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.Organiser != null && e.Organiser != 0) // { // var ms = Services.MemberService; // var member = ms.GetById(e.Organiser); // 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. }
public ActionResult GetIcsdddForCalendar(int id) { var iCal = new iCalendar(); //c.Url = "/" + content.GetValue("umbracoUrlAlias").ToString(); //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; // } // var attendes = new List<IAttendee>(); // if (e.Organiser != null && e.Organiser != 0) // { // var ms = Services.MemberService; // var member = ms.GetById(e.Organiser); // 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; // } // 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; // } // } // rp.ByDay.AddRange(e.Days.Select(x => new WeekDay(x.ToString()))); // evt.RecurrenceRules.Add(rp); // var tmp_event = new ScheduleWidget.ScheduledEvents.Event() // { // Title = e.Title, // FrequencyTypeOptions = (FrequencyTypeEnum)e.Frequency // }; // foreach (var day in e.Days) // { // tmp_event.DaysOfWeekOptions = tmp_event.DaysOfWeekOptions | (DayOfWeekEnum)day; // } // foreach (var i in e.MonthlyIntervals) // { // tmp_event.MonthlyIntervalOptions = tmp_event.MonthlyIntervalOptions | (MonthlyIntervalEnum)i; // } // Schedule schedule = new Schedule(tmp_event); // 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.Organiser != null && e.Organiser != 0) // { // var ms = Services.MemberService; // var member = ms.GetById(e.Organiser); // 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 SerializerFactory(); // Get a serializer for our object var serializer = factory.Build(iCal.GetType(), ctx) as IStringSerializer; var output = serializer.SerializeToString(iCal); var contentType = "text/calendar"; var bytes = Encoding.UTF8.GetBytes(output); return File(bytes, contentType, "name" + ".ics"); }
public ActionResult TeamFeed(int seasonId, int teamId, string desc) { var seasonName = _context.Seasons.Where(x => x.SeasonId == seasonId).Single().SeasonName; var teamName = _context.Teams.Where(x => x.TeamId == teamId).Single().TeamNameLong; List<GameTeam> gameTeams = _context.GameTeams .IncludeAll() .Where(x => x.SeasonId == seasonId && x.TeamId == teamId) .ToList(); iCalendar ical = new iCalendar(); ical.Properties.Set("X-WR-CALNAME", "LO30Schedule-" + teamName.Replace(" ", "") + "-" + seasonName.Replace(" ", "")); foreach (var gameTeam in gameTeams) { Event icalEvent = ical.Create<Event>(); var summary = gameTeam.OpponentTeam.TeamNameShort + " vs " + gameTeam.Team.TeamNameShort; if (gameTeam.HomeTeam) { summary = gameTeam.Team.TeamNameShort + " vs " + gameTeam.OpponentTeam.TeamNameShort; } icalEvent.Summary = summary; icalEvent.Description = summary + " " + gameTeam.Game.Location; var year = gameTeam.Game.GameDateTime.Year; var mon = gameTeam.Game.GameDateTime.Month; var day = gameTeam.Game.GameDateTime.Day; var hr = gameTeam.Game.GameDateTime.Hour; var min = gameTeam.Game.GameDateTime.Minute; var sec = gameTeam.Game.GameDateTime.Second; icalEvent.Start = new iCalDateTime(gameTeam.Game.GameDateTime); icalEvent.Duration = TimeSpan.FromHours(1.25); //icalEvent.Location = "Eddie Edgar " + gameTeam.Game.Location; // TODO set the Rink location icalEvent.Location = "Eddie Edgar"; } ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new SerializerFactory(); IStringSerializer serializer = factory.Build(ical.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(ical); var contentType = "text/calendar"; return Content(output, contentType); }
public IActionResult TeamFeed(int seasonId, int teamId, string desc) { var seasonName = _context.Seasons.Where(x => x.SeasonId == seasonId).Single().SeasonName; var teamName = _context.Teams.Where(x => x.TeamId == teamId).Single().TeamNameLong; List<GameTeam> gameTeams = _context.GameTeams .Include(x => x.Season) .Include(x => x.Team) .Include(x => x.OpponentTeam) .Include(x => x.Game).ThenInclude(y => y.GameOutcomes) .Include(x => x.Game).ThenInclude(y => y.GameScores) .Where(x => x.SeasonId == seasonId && x.TeamId == teamId) .ToList(); // HACK, for some reason, the team was not getting "included" gameTeams = gameTeams.Join(_context.Teams, a => a.TeamId, b => b.TeamId, (a, b) => new { a, b }) .Select(m => new GameTeam { Game = m.a.Game, GameId = m.a.GameId, HomeTeam = m.a.HomeTeam, OpponentTeam = m.a.OpponentTeam, OpponentTeamId = m.a.OpponentTeamId, Season = m.a.Season, SeasonId = m.a.SeasonId, Team = m.b, TeamId = m.a.TeamId }) .ToList(); iCalendar ical = new iCalendar(); ical.Properties.Set("X-WR-CALNAME", "LO30Schedule-" + teamName.Replace(" ", "") + "-" + seasonName.Replace(" ","")); foreach (var gameTeam in gameTeams) { Event icalEvent = ical.Create<Event>(); var summary = gameTeam.OpponentTeam.TeamNameShort + " vs " + gameTeam.Team.TeamNameShort; if (gameTeam.HomeTeam) { summary = gameTeam.Team.TeamNameShort + " vs " + gameTeam.OpponentTeam.TeamNameShort; } icalEvent.Summary = summary; icalEvent.Description = summary + " " + gameTeam.Game.Location; var year = gameTeam.Game.GameDateTime.Year; var mon = gameTeam.Game.GameDateTime.Month; var day = gameTeam.Game.GameDateTime.Day; var hr = gameTeam.Game.GameDateTime.Hour; var min = gameTeam.Game.GameDateTime.Minute; var sec = gameTeam.Game.GameDateTime.Second; icalEvent.Start = new iCalDateTime(gameTeam.Game.GameDateTime); icalEvent.Duration = TimeSpan.FromHours(1.25); icalEvent.Location = "Eddie Edgar " + gameTeam.Game.Location; } ISerializationContext ctx = new SerializationContext(); ISerializerFactory factory = new SerializerFactory(); IStringSerializer serializer = factory.Build(ical.GetType(), ctx) as IStringSerializer; string output = serializer.SerializeToString(ical); var contentType = "text/calendar"; return Content(output, contentType); }
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"); }