Example #1
0
        /// <summary>
        /// Saves the supplied calendar object as an iCalendar file at the supplied path.
        /// </summary>
        /// <param name="calendar">The calendar object to save.</param>
        /// <param name="path">The path to save the iCalendar file at.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if a calendar is not provided, or a path was not provided.</exception>
        /// <returns>Always returns true. (The iCalendar serializer does not report whether it was successful.)</returns>
        public void SaveCalendar(Calendar calendar, string path)
        {
            // Check if a calendar and path was provided.
            if (calendar != null && !string.IsNullOrWhiteSpace(path))
            {
                // A calendar and path was provided.

                // Create a serializer to save the iCalendar calendar file.
                DDay.iCal.Serialization.iCalendar.iCalendarSerializer serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer();

                // Serialize the iCalendar calendar file to the path supplied.
                serializer.Serialize(ToIICalendar(calendar), path);
            }
            else
            {
                // A calendar or path not provided.
                if (calendar == null)
                {
                    throw new ArgumentNullException("calendar");
                }
                else
                {
                    throw new ArgumentNullException("path");
                }
            }
        }
Example #2
0
        public static Schedule SyncSchedule(
            ESpace.Occurrence eSpaceOccurrence,
            EventItemOccurrence rockOccurrence,
            out bool changed
            )
        {
            changed = false;

            if (rockOccurrence.Schedule == null)
            {
                rockOccurrence.Schedule = new Schedule
                {
                    ForeignKey = ForeignKey_eSpaceOccurrenceId,
                    ForeignId  = eSpaceOccurrence.OccurrenceId.Value
                };
                changed = true;
            }

            var schedule = rockOccurrence.Schedule;


            if (schedule.EffectiveStartDate != eSpaceOccurrence.EventStart)
            {
                schedule.EffectiveStartDate = eSpaceOccurrence.EventStart;
                changed = true;
            }

            if (schedule.EffectiveEndDate != eSpaceOccurrence.EventEnd)
            {
                schedule.EffectiveEndDate = eSpaceOccurrence.EventEnd;
                changed = true;
            }

            var scheduleName = "";

            if (schedule.Name != scheduleName)
            {
                schedule.Name = scheduleName;
                changed       = true;
            }

            var iCalEvent = SyncICalEvent(eSpaceOccurrence, schedule, out var iCalChanged);

            if (iCalChanged)
            {
                // Serialize the event
                var calendar = new DDay.iCal.iCalendar();
                calendar.Events.Add(iCalEvent);
                var serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer(calendar);
                schedule.iCalendarContent = serializer.SerializeToString(calendar);
                changed = true;
            }

            return(schedule);
        }
Example #3
0
        /// <summary>
        /// Returns the text of the iCalendar feed associated with the calendar object supplied.
        /// </summary>
        /// <param name="calendar">The object to get the iCalendar feed text of.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if a calendar is not provided.</exception>
        /// <returns>The text of the iCalendar feed associated with the calendar supplied.</returns>
        public string GetCalendarText(Calendar calendar)
        {
            // Check if a calendar was provided.
            if (calendar != null)
            {
                // A calendar was provided.

                // Create a serializer to save the iCalendar calendar feed.
                DDay.iCal.Serialization.iCalendar.iCalendarSerializer serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer();

                // Serialize the iCalendar calendar feed to a string.
                return(serializer.SerializeToString(ToIICalendar(calendar)));
            }
            else
            {
                // A calendar was not provided.
                throw new ArgumentNullException("calendar");
            }
        }
Example #4
0
		public static void MergeIcs(Calinfo calinfo)
		{
			var id = calinfo.id;
			GenUtils.LogMsg("status", "MergeIcs: " + id, null);
			List<string> suffixes = new List<string>() { "ical" };
			if (calinfo.hub_enum == HubType.where)
				foreach (NonIcalType type in Enum.GetValues(typeof(CalendarAggregator.NonIcalType)))
				{
					if (Utils.UseNonIcalService(type, settings, calinfo) == true)
						suffixes.Add(type.ToString());
				}
			try
			{
				var all_ical = new iCalendar();
				Collector.AddTimezoneToDDayICal(all_ical, calinfo.tzinfo);

				foreach (var suffix in suffixes)  // todo: skip if disabled in settings
				{
					var url = MakeIcsUrl(id, suffix);
					try
					{
						var feedtext = HttpUtils.FetchUrl(url).DataAsString();
						var sr = new StringReader(feedtext);
						var ical = iCalendar.LoadFromStream(sr).First().Calendar;
						all_ical.MergeWith(ical);
					}
					catch (Exception e)
					{
						GenUtils.LogMsg("warning", "MergeICS: " + url, e.Message);
					}
				}

				var serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer(all_ical);
				var icsbytes = Encoding.UTF8.GetBytes(serializer.SerializeToString(all_ical));
				bs.PutBlob(id, id + ".ics", new Hashtable(), icsbytes, "text/calendar");
			}
			catch (Exception e)
			{
				GenUtils.LogMsg("exception", "MergeIcs: " + id, e.Message + e.StackTrace);
			}
		}
Example #5
0
        /// <summary>
        /// Send mail ICalendar
        /// </summary>
        /// <param name="mailMeetingEntity">MailMeetingEntity</param>
        /// <param name="actionBeforeSendMeeting">Action<MailMessage></param>
        public string SendMeeting(MailMeetingEntity mailMeetingEntity, Action <MailMessage> actionBeforeSendMeeting)
        {
            SmtpClient m_SmtpClient = new SmtpClient();

            if (this.MailConfig != null)
            {
                m_SmtpClient.UseDefaultCredentials = MailConfig.UseDefaultCredentials;
                if (!MailConfig.UseDefaultCredentials) //tạo mới Smtp Credentials
                {
                    m_SmtpClient.Credentials = new NetworkCredential(MailConfig.Username, MailConfig.Password, MailConfig.Domain);
                }
                m_SmtpClient.Port      = MailConfig.Port;
                m_SmtpClient.Host      = MailConfig.Host;
                m_SmtpClient.EnableSsl = MailConfig.EnableSsl;
            }

            MailMessage m_MailMessage = new MailMessage()
            {
                From       = new MailAddress(mailMeetingEntity.From),
                Body       = mailMeetingEntity.Body,
                Subject    = mailMeetingEntity.Subject,
                IsBodyHtml = true,
            };

            //Parse MailMeetingEntity -> ICalendar Entity

            // Create a new iCalendar
            iCalendar m_iCalendar = new iCalendar()
            {
                Method    = MailServiceICal.ICalendarMethod_Request, //PUBLISH THÌ KO ADD VÀO TRONG CALENDAR
                Version   = MailServiceICal.ICalendar_Version,
                ProductID = MailServiceICal.ICalendar_ProductID,
            };

            // Create the event, and add it to the iCalendar
            Event m_Event = m_iCalendar.Create <Event>();

            // Set information about the event
            m_Event.UID         = mailMeetingEntity.UID;
            m_Event.DTStamp     = new iCalDateTime(mailMeetingEntity.Stamp);
            m_Event.Start       = new iCalDateTime(mailMeetingEntity.Start);
            m_Event.End         = new iCalDateTime(mailMeetingEntity.End);
            m_Event.Description = mailMeetingEntity.Description;
            m_Event.Location    = mailMeetingEntity.Location;
            m_Event.Summary     = mailMeetingEntity.Description;
            //m_event.Transparency = TransparencyType.Opaque;

            //CONFIG ALARM
            foreach (var m_AlarmEntity in mailMeetingEntity.Alarms)
            {
                AlarmAction m_AlarmAction = new AlarmAction();
                if (m_AlarmEntity.Trigger.Equals(MailServiceICal.Action_Audio))
                {
                    m_AlarmAction = AlarmAction.Audio;
                }
                else if (m_AlarmEntity.Trigger.Equals(MailServiceICal.Action_Display))
                {
                    m_AlarmAction = AlarmAction.Display;
                }
                else if (m_AlarmEntity.Trigger.Equals(MailServiceICal.Action_Email))
                {
                    m_AlarmAction = AlarmAction.Email;
                }
                else if (m_AlarmEntity.Trigger.Equals(MailServiceICal.Action_Procedure))
                {
                    m_AlarmAction = AlarmAction.Procedure;
                }
                m_Event.Alarms.Add(new Alarm
                {
                    Duration    = m_AlarmEntity.Duration,
                    Trigger     = new Trigger(m_AlarmEntity.Trigger),
                    Description = m_AlarmEntity.Description,
                    Repeat      = m_AlarmEntity.RepeatTime,
                    Action      = m_AlarmAction,
                });
            }

            //Add Attendees
            var m_Attendes = new List <IAttendee>();

            foreach (var m_AttendeesEntity in mailMeetingEntity.Attendees)
            {
                m_MailMessage.To.Add(new MailAddress(m_AttendeesEntity.Email));
                IAttendee m_Attendee = new DDay.iCal.Attendee(MailServiceICal.Attendee_MailTo + m_AttendeesEntity.Email);
                if (m_AttendeesEntity.IsOptional)
                {
                    m_Attendee.Role = MailServiceICal.Role_Optional;
                }
                else
                {
                    m_Attendee.Role = MailServiceICal.Role_Request;
                }
                m_Attendes.Add(m_Attendee);
            }

            if (m_Attendes != null && m_Attendes.Count > 0)
            {
                m_Event.Attendees = m_Attendes;
            }

            //Check before send meeting
            if (actionBeforeSendMeeting != null)
            {
                actionBeforeSendMeeting(m_MailMessage);
            }

            DDay.iCal.Serialization.iCalendar.iCalendarSerializer m_Serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer();
            //Convert iCal to string
            string m_iCalendarData = m_Serializer.SerializeToString(m_iCalendar);

            System.Net.Mime.ContentType m_Contype = new System.Net.Mime.ContentType(MailServiceICal.ICalendar_ContentType);
            m_Contype.Parameters.Add(MailServiceICal.ICalendar_Method, MailServiceICal.ICalendarMethod_Request);
            m_Contype.Parameters.Add(MailServiceICal.ICalendar_Name, MailServiceICal.ICalendar_FileName);
            AlternateView m_AlternateView = AlternateView.CreateAlternateViewFromString(m_iCalendarData, m_Contype);

            m_MailMessage.AlternateViews.Add(m_AlternateView);

            m_SmtpClient.Send(m_MailMessage);
            return(m_iCalendarData);
        }
 // in support of add-to-calendar
 public static string RenderEventAsIcs(string elmcity_id, string summary, string start, string end, string description, string location, string url)
 {
     try
     {
         var calinfo = Utils.AcquireCalinfo(elmcity_id);
         var tzname = calinfo.tzname;
         var tzid = calinfo.tzinfo.Id;
         var ical = new DDay.iCal.iCalendar();
         Collector.AddTimezoneToDDayICal(ical, Utils.TzinfoFromName(tzname));
         var evt = new DDay.iCal.Event();
         evt.Summary = summary;
         evt.Description = Utils.MakeAddToCalDescription(description, url, location);
         evt.Location = location;
         evt.Url = new Uri(url);
         var dtstart = DateTime.Parse(start);
         evt.Start = new DDay.iCal.iCalDateTime(dtstart, tzname);
         evt.Start.TZID = tzid;
         if (evt.End != null)
         {
             var dtend = DateTime.Parse(end);
             evt.End = new DDay.iCal.iCalDateTime(dtend, tzname);
             evt.End.TZID = tzid;
         }
         ical.Events.Add(evt);
         var serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer();
         return serializer.SerializeToString(ical);
     }
     catch (Exception e)
     {
         GenUtils.PriorityLogMsg("exception", "RenderEventAsIcs", e.Message);
         return "exception: " + e.Message;
     }
 }
Example #7
0
 public ActionResult TestIcal()
 {
     DDay.iCal.iCalendar calendario = new DDay.iCal.iCalendar();
     DDay.iCal.Event evento = calendario.Create<DDay.iCal.Event>();
     evento.Start = new DDay.iCal.iCalDateTime(System.DateTime.Now);
      evento.Summary = "Presentacion Demo";
     evento.End = new DDay.iCal.iCalDateTime(System.DateTime.Now).AddHours(2);
     evento.GeographicLocation = new DDay.iCal.GeographicLocation(-33.372909, -70.581080);
      DDay.iCal.Serialization.iCalendar.iCalendarSerializer serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer(calendario);
     String ruta = Server.MapPath("..\\Content\\Eventos\\");
     serializer.Serialize(ruta+"filename.ics");
     return View();
 }
Example #8
0
        /// <summary>
        /// Saves the supplied calendar object as an iCalendar file at the supplied path.
        /// </summary>
        /// <param name="calendar">The calendar object to save.</param>
        /// <param name="path">The path to save the iCalendar file at.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if a calendar is not provided, or a path was not provided.</exception>
        /// <returns>Always returns true. (The iCalendar serializer does not report whether it was successful.)</returns>
        public void SaveCalendar(Calendar calendar, string path)
        {
            // Check if a calendar and path was provided.
            if (calendar != null && !string.IsNullOrWhiteSpace(path))
            {
                // A calendar and path was provided.

                // Create a serializer to save the iCalendar calendar file.
                DDay.iCal.Serialization.iCalendar.iCalendarSerializer serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer();

                // Serialize the iCalendar calendar file to the path supplied.
                serializer.Serialize(ToIICalendar(calendar), path);
            }
            else
            {
                // A calendar or path not provided.
                if (calendar == null)
                {
                    throw new ArgumentNullException("calendar");
                }
                else
                {
                    throw new ArgumentNullException("path");
                }
            }
        }
Example #9
0
        /// <summary>
        /// Returns the text of the iCalendar feed associated with the calendar object supplied.
        /// </summary>
        /// <param name="calendar">The object to get the iCalendar feed text of.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if a calendar is not provided.</exception>
        /// <returns>The text of the iCalendar feed associated with the calendar supplied.</returns>
        public string GetCalendarText(Calendar calendar)
        {
            // Check if a calendar was provided.
            if (calendar != null)
            {
                // A calendar was provided.

                // Create a serializer to save the iCalendar calendar feed.
                DDay.iCal.Serialization.iCalendar.iCalendarSerializer serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer();

                // Serialize the iCalendar calendar feed to a string.
                return serializer.SerializeToString(ToIICalendar(calendar));
            }
            else
            {
                // A calendar was not provided.
                throw new ArgumentNullException("calendar");
            }
        }