Ejemplo n.º 1
0
        /// <summary>
        /// Gets an iCalendar version of the appointment
        /// </summary>
        /// <param name="Canceled">If true, it returns a cancellation version.
        /// If false, it returns a request version.</param>
        /// <returns>An iCalendar version of the appointment</returns>
        private string GetCalendar(bool Canceled)
        {
            string DateFormatUsing = "yyyyMMddTHHmmssZ";
            string Method;

            if (!Canceled)
            {
                Method = "REQUEST";
            }
            else
            {
                Method = "CANCEL";
            }
            string bodyCalendar = "BEGIN:VCALENDAR\r\nMETHOD:{10}\r\nPRODID:Microsoft CDO for Microsoft Exchange\r\nVERSION:2.0\r\nBEGIN:VTIMEZONE\r\nTZID:(GMT-06.00) Central Time (US & Canada)\r\nX-MICROSOFT-CDO-TZID:11\r\nBEGIN:STANDARD\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0500\r\nTZOFFSETTO:-0600\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU\r\nEND:STANDARD\r\nBEGIN:DAYLIGHT\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0600\r\nTZOFFSETTO:-0500\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU\r\nEND:DAYLIGHT\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTAMP:{8}\r\nDTSTART:{0}\r\nSUMMARY:{7}\r\nUID:{5}\r\nATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=\"{9}\":MAILTO:{9}\r\nACTION;RSVP=TRUE;CN=\"{4}\":MAILTO:{4}\r\nORGANIZER;CN=\"{3}\":mailto:{4}\r\nLOCATION:{2}\r\nDTEND:{1}\r\nDESCRIPTION:{7}\\N\r\nSEQUENCE:1\r\nPRIORITY:5\r\nCLASS:\r\nCREATED:{8}\r\nLAST-MODIFIED:{8}\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nX-MICROSOFT-CDO-BUSYSTATUS:{11}\r\nX-MICROSOFT-CDO-INSTTYPE:0\r\nX-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\nX-MICROSOFT-CDO-ALLDAYEVENT:FALSE\r\nX-MICROSOFT-CDO-IMPORTANCE:1\r\nX-MICROSOFT-CDO-OWNERAPPTID:-1\r\nX-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:{8}\r\nX-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:{8}\r\nBEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:REMINDER\r\nTRIGGER;RELATED=START:-PT00H15M00S\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";

            bodyCalendar = string.Format(bodyCalendar,
                                         StartDate.ToUniversalTime().ToString(DateFormatUsing),
                                         EndDate.ToUniversalTime().ToString(DateFormatUsing),
                                         Location,
                                         OrganizerName,
                                         OrganizerEmail,
                                         MeetingGUID.ToString("B"),
                                         Summary,
                                         Subject,
                                         DateTime.Now.ToUniversalTime().ToString(DateFormatUsing),
                                         AttendeeList.ToString(),
                                         Method,
                                         Status);
            return(bodyCalendar);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds an appointment to a user's calendar
        /// </summary>
        public virtual void AddAppointment()
        {
            string XMLNSInfo = "xmlns:g=\"DAV:\" "
                               + "xmlns:e=\"http://schemas.microsoft.com/exchange/\" "
                               + "xmlns:mapi=\"http://schemas.microsoft.com/mapi/\" "
                               + "xmlns:mapit=\"http://schemas.microsoft.com/mapi/proptag/\" "
                               + "xmlns:x=\"xml:\" xmlns:cal=\"urn:schemas:calendar:\" "
                               + "xmlns:dt=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\" "
                               + "xmlns:header=\"urn:schemas:mailheader:\" "
                               + "xmlns:mail=\"urn:schemas:httpmail:\"";

            string CalendarInfo = "<cal:location>" + Location + "</cal:location>"                                                                               // + Location + "</cal:location>"
                                  + "<cal:dtstart dt:dt=\"dateTime.tz\">" + StartDate.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.000Z") + "</cal:dtstart>" // + StartDate.ToUniversalTime().ToString("yyyyMMddTHHmmssZ") + "</cal:dtstart>"
                                  + "<cal:dtend dt:dt=\"dateTime.tz\">" + EndDate.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.000Z") + "</cal:dtend>"       // + EndDate.ToUniversalTime().ToString("yyyyMMddTHHmmssZ") + "</cal:dtend>"
                                  + "<cal:instancetype dt:dt=\"int\">0</cal:instancetype>"
                                  + "<cal:busystatus>" + Status + "</cal:busystatus>"
                                  + "<cal:meetingstatus>CONFIRMED</cal:meetingstatus>"
                                  + "<cal:alldayevent dt:dt=\"boolean\">0</cal:alldayevent>"
                                  + "<cal:responserequested dt:dt=\"boolean\">1</cal:responserequested>"
                                  + "<cal:reminderoffset dt:dt=\"int\">900</cal:reminderoffset>"
                                  + "<cal:uid>" + MeetingGUID.ToString("B") + "</cal:uid>";

            string HeaderInfo = "<header:to>" + AttendeeList.ToString() + "</header:to>";

            string MailInfo = "<mail:subject>" + Subject + "</mail:subject>"
                              + "<mail:htmldescription>" + Summary + "</mail:htmldescription>";

            string AppointmentRequest = "<?xml version=\"1.0\"?>"
                                        + "<g:propertyupdate " + XMLNSInfo + ">"
                                        + "<g:set><g:prop>"
                                        + "<g:contentclass>urn:content-classes:appointment</g:contentclass>"
                                        + "<e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>"
                                        + MailInfo
                                        + CalendarInfo
                                        + HeaderInfo
                                        + "<mapi:finvited dt:dt=\"boolean\">1</mapi:finvited>"
                                        + "</g:prop></g:set>"
                                        + "</g:propertyupdate>";

            System.Net.HttpWebRequest PROPPATCHRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(ServerName + "/exchange/" + Directory + "/Calendar/" + MeetingGUID.ToString() + ".eml");

            System.Net.CredentialCache MyCredentialCache = new System.Net.CredentialCache();
            if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
            {
                MyCredentialCache.Add(new System.Uri(ServerName + "/exchange/" + Directory + "/Calendar/" + MeetingGUID.ToString() + ".eml"),
                                      "NTLM",
                                      new System.Net.NetworkCredential(UserName, Password));
            }
            else
            {
                MyCredentialCache.Add(new System.Uri(ServerName + "/exchange/" + Directory + "/Calendar/" + MeetingGUID.ToString() + ".eml"),
                                      "Negotiate",
                                      (System.Net.NetworkCredential)CredentialCache.DefaultCredentials);
            }

            PROPPATCHRequest.Credentials = MyCredentialCache;
            PROPPATCHRequest.Method      = "PROPPATCH";
            byte[] bytes = Encoding.UTF8.GetBytes((string)AppointmentRequest);
            PROPPATCHRequest.ContentLength = bytes.Length;
            using (System.IO.Stream PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream())
            {
                PROPPATCHRequestStream.Write(bytes, 0, bytes.Length);
                PROPPATCHRequestStream.Close();
                PROPPATCHRequest.ContentType = "text/xml";
                System.Net.WebResponse PROPPATCHResponse = (System.Net.HttpWebResponse)PROPPATCHRequest.GetResponse();
                PROPPATCHResponse.Close();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Cancels an appointment on someone's calendar
        /// </summary>
        public virtual void CancelAppointment()
        {
            System.Net.HttpWebRequest PROPPATCHRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(ServerName + "/exchange/" + Directory + "/Calendar/" + MeetingGUID.ToString() + ".eml");

            System.Net.CredentialCache MyCredentialCache = new System.Net.CredentialCache();
            if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
            {
                MyCredentialCache.Add(new System.Uri(ServerName + "/exchange/" + Directory + "/Calendar/" + MeetingGUID.ToString() + ".eml"),
                                      "NTLM",
                                      new System.Net.NetworkCredential(UserName, Password));
            }
            else
            {
                MyCredentialCache.Add(new System.Uri(ServerName + "/exchange/" + Directory + "/Calendar/" + MeetingGUID.ToString() + ".eml"),
                                      "Negotiate",
                                      (System.Net.NetworkCredential)CredentialCache.DefaultCredentials);
            }

            PROPPATCHRequest.Credentials = MyCredentialCache;
            PROPPATCHRequest.Method      = "DELETE";
            System.Net.WebResponse PROPPATCHResponse = (System.Net.HttpWebResponse)PROPPATCHRequest.GetResponse();
            PROPPATCHResponse.Close();
        }