/// <summary>
        /// Removes a specific event or a series of events
        /// </summary>
        /// <param name="objItems">Contains all the event items in a specific calendar/folder</param>
        /// <param name="subject">Subject of the event to delete</param>
        /// <param name="eventDate">If specified, this specific event is deleted instead of all events with subject</param>
        internal static void RemoveEvent(Outlook.Items objItems, string subject, string eventDate)
        {
            string methodTag = "RemoveEvent";

            LogWriter.WriteInfo(TAG, methodTag, "Starting: " + methodTag + " in " + TAG);

            Outlook.AppointmentItem agendaMeeting = null;

            if (eventDate == null)
            {
                objItems.Sort("[Subject]");
                objItems.IncludeRecurrences = true;

                LogWriter.WriteInfo(TAG, methodTag, "Attempting to find event with subject: " + subject);
                agendaMeeting = objItems.Find("[Subject]=" + subject);

                if (agendaMeeting == null)
                {
                    LogWriter.WriteWarning(TAG, methodTag, "No event found with subject: " + subject);
                }
                else
                {
                    LogWriter.WriteInfo(TAG, methodTag, "Removing all events with subject: " + subject);
                    do
                    {
                        agendaMeeting.Delete();

                        agendaMeeting = objItems.FindNext();

                        LogWriter.WriteInfo(TAG, methodTag, "Event found and deleted, finding next");
                    } while (agendaMeeting != null);

                    LogWriter.WriteInfo(TAG, methodTag, "All events with subject: " + subject + " found and deleted");
                }
            }
            else
            {
                LogWriter.WriteInfo(TAG, methodTag, "Finding event with subject" + subject + " and date: " + eventDate);
                agendaMeeting = objItems.Find("[Subject]=" + subject);

                if (agendaMeeting == null)
                {
                    LogWriter.WriteWarning(TAG, methodTag, "No event found with subject: " + subject);
                }
                else
                {
                    Outlook.RecurrencePattern recurrPatt = agendaMeeting.GetRecurrencePattern();
                    agendaMeeting = recurrPatt.GetOccurrence(DateTime.Parse(eventDate));

                    agendaMeeting.Delete();

                    LogWriter.WriteInfo(TAG, methodTag, "Event found and deleted");
                }
            }
        }
        // <Snippet1>
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Outlook.MAPIFolder calendar =
                Application.Session.GetDefaultFolder(
                    Outlook.OlDefaultFolders.olFolderCalendar);

            Outlook.Items calendarItems = calendar.Items;

            Outlook.AppointmentItem item =
                calendarItems["Test Appointment"] as Outlook.AppointmentItem;

            Outlook.RecurrencePattern pattern =
                item.GetRecurrencePattern();
            Outlook.AppointmentItem itemDelete = pattern.
                                                 GetOccurrence(new DateTime(2006, 6, 28, 8, 0, 0));

            if (itemDelete != null)
            {
                itemDelete.Delete();
            }
        }
Exemple #3
0
        /// <summary>
        /// Sets recurrence exceptions in direction Outlook -> Google
        /// </summary>
        /// <param name="outlookItem">Source Outlook event</param>
        /// <param name="googleItem">Target Google event</param>
        private void SetRecurrenceExceptions(Outlook.AppointmentItem outlookItem, Event googleItem)
        {
            if (!outlookItem.IsRecurring)
            {
                return;
            }
            Outlook.RecurrencePattern outlookRecurrence = outlookItem.GetRecurrencePattern();
            var instancesRequest = this.CalendarService.Events.Instances(this._googleCalendar.Id, googleItem.Id);

            instancesRequest.ShowDeleted = true;
            var instances  = instancesRequest.Execute().Items;
            var exceptions = instances.Where(i => i.Status == "cancelled" || i.OriginalStartTime.DateTime != i.Start.DateTime);

            try
            {
                foreach (Outlook.Exception outlookException in outlookRecurrence.Exceptions)
                {
                    try {
                        /// If the exception is already in Google event this one is omited
                        if (RecurrenceExceptionComparer.Contains(exceptions, outlookException))
                        {
                            continue;
                        }
                        //googleItem.RecurrenceException = new Google.GData.Extensions.RecurrenceException();
                        Event googleException;
                        if (outlookException.Deleted)
                        {
                            googleException = instances.First(e =>
                                                              (e.OriginalStartTime.DateTime ?? DateTime.Parse(e.OriginalStartTime.Date)).Date == outlookException.OriginalDate);
                            googleException.Status = "cancelled";
                        }
                        else
                        {
                            googleException = instances.First(e =>
                                                              (e.OriginalStartTime.DateTime ?? DateTime.Parse(e.OriginalStartTime.Date)) == outlookException.OriginalDate);
                            googleException.Status = "confirmed";
                            this.SetSubject(googleException, outlookException.AppointmentItem, Target.Google);
                            this.SetDescription(googleException, outlookException.AppointmentItem, Target.Google);
                            this.SetLocation(googleException, outlookException.AppointmentItem, Target.Google);
                            this.SetTime(googleException, outlookException.AppointmentItem, Target.Google);
                        }
                        /// Add exception to update batch
                        this._googleBatchRequest.Queue <Event>(this.CalendarService.Events.Update(
                                                                   googleException, this._googleCalendar.Id, googleException.Id), BatchCallback);
                    } catch (COMException exc) {
                        if (exc.HResult == -1802485755)
                        {
                            Logger.Log(string.Format(
                                           "The exception of '{0}' with original start time {1} couldn't be read. Ignoring this exception",
                                           outlookItem.Subject, outlookException.OriginalDate), EventType.Warning);
                        }
                    } finally {
                        Marshal.ReleaseComObject(outlookException);
                    }
                }
            }
            finally
            {
                Marshal.ReleaseComObject(outlookRecurrence);
            }
        }
Exemple #4
0
        /// <summary>
        /// Matches outlook and Google appointment by a) id b) properties.
        /// </summary>
        /// <param name="sync">Syncronizer instance</param>
        /// <returns>Returns a list of match pairs (outlook appointment + Google appointment) for all appointment. Those that weren't matche will have it's peer set to null</returns>
        public static List <AppointmentMatch> MatchAppointments(AppointmentsSynchronizer sync)
        {
            Logger.Log("Matching Outlook and Google appointments...", EventType.Information);
            var result = new List <AppointmentMatch>();

            var googleAppointmentExceptions = new List <Event>();

            //for each outlook appointment try to get Google appointment id from user properties
            //if no match - try to match by properties
            //if no match - create a new match pair without Google appointment.
            //foreach (Outlook._AppointmentItem olc in outlookAppointments)
            var OutlookAppointmentsWithoutSyncId = new Collection <Outlook.AppointmentItem>();

            #region Match first all outlookAppointments by sync id
            for (int i = 1; i <= sync.OutlookAppointments.Count; i++)
            {
                Outlook.AppointmentItem ola = null;

                try
                {
                    ola = sync.OutlookAppointments[i] as Outlook.AppointmentItem;

                    if (ola == null || string.IsNullOrEmpty(ola.Subject) && ola.Start == AppointmentSync.outlookDateMin)
                    {
                        Logger.Log("Empty Outlook appointment found. Skipping", EventType.Warning);
                        sync.SkippedCount++;
                        sync.SkippedCountNotMatches++;
                        continue;
                    }
                    else if (ola.MeetingStatus == Outlook.OlMeetingStatus.olMeetingCanceled || ola.MeetingStatus == Outlook.OlMeetingStatus.olMeetingReceivedAndCanceled)
                    {
                        Logger.Log("Skipping Outlook appointment found because it is cancelled: " + ola.Subject + " - " + ola.Start, EventType.Debug);
                        //sync.SkippedCount++;
                        //sync.SkippedCountNotMatches++;
                        continue;
                    }
                    else if (AppointmentsSynchronizer.TimeMin != null &&
                             (ola.IsRecurring && ola.GetRecurrencePattern().PatternEndDate < AppointmentsSynchronizer.TimeMin ||
                              !ola.IsRecurring && ola.End < AppointmentsSynchronizer.TimeMin) ||
                             AppointmentsSynchronizer.TimeMax != null &&
                             (ola.IsRecurring && ola.GetRecurrencePattern().PatternStartDate > AppointmentsSynchronizer.TimeMax ||
                              !ola.IsRecurring && ola.Start > AppointmentsSynchronizer.TimeMax))
                    {
                        Logger.Log("Skipping Outlook appointment because it is out of months range to sync:" + ola.Subject + " - " + ola.Start, EventType.Debug);
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    //this is needed because some appointments throw exceptions
                    if (ola != null && !string.IsNullOrEmpty(ola.Subject))
                    {
                        Logger.Log("Accessing Outlook appointment: " + ola.Subject + " threw and exception. Skipping: " + ex.Message, EventType.Warning);
                    }
                    else
                    {
                        Logger.Log("Accessing Outlook appointment threw and exception. Skipping: " + ex.Message, EventType.Warning);
                    }
                    sync.SkippedCount++;
                    sync.SkippedCountNotMatches++;
                    continue;
                }

                NotificationReceived?.Invoke(string.Format("Matching appointment {0} of {1} by id: {2} ...", i, sync.OutlookAppointments.Count, ola.Subject));

                // Create our own info object to go into collections/lists, so we can free the Outlook objects and not run out of resources / exceed policy limits.
                //OutlookAppointmentInfo olci = new OutlookAppointmentInfo(ola, sync);

                //try to match this appointment to one of Google appointments

                var gid = AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, ola);

                if (gid != null)
                {
                    var e     = sync.GetGoogleAppointmentById(gid);
                    var match = new AppointmentMatch(ola, null);

                    if (e != null && !e.Status.Equals("cancelled"))
                    {
                        //we found a match by google id, that is not deleted or cancelled yet
                        match.AddGoogleAppointment(e);
                        result.Add(match);
                        sync.GoogleAppointments.Remove(e);
                    }
                    else
                    {
                        OutlookAppointmentsWithoutSyncId.Add(ola);
                    }
                }
                else
                {
                    OutlookAppointmentsWithoutSyncId.Add(ola);
                }
            }
            #endregion
            #region Match the remaining appointments by properties

            for (int i = 0; i < OutlookAppointmentsWithoutSyncId.Count; i++)
            {
                var ola = OutlookAppointmentsWithoutSyncId[i];

                NotificationReceived?.Invoke(string.Format("Matching appointment {0} of {1} by unique properties: {2} ...", i + 1, OutlookAppointmentsWithoutSyncId.Count, ola.Subject));

                //no match found by id => match by subject/title
                //create a default match pair with just outlook appointment.
                var match = new AppointmentMatch(ola, null);

                //foreach Google appointment try to match and create a match pair if found some match(es)
                for (int j = sync.GoogleAppointments.Count - 1; j >= 0; j--)
                {
                    var e = sync.GoogleAppointments[j];
                    // only match if there is a appointment targetBody, else
                    // a matching Google appointment will be created at each sync
                    if (!e.Status.Equals("cancelled") && ola.Subject == e.Summary && e.Start.DateTime != null && ola.Start == e.Start.DateTime)
                    {
                        match.AddGoogleAppointment(e);
                        sync.GoogleAppointments.Remove(e);
                    }
                }

                if (match.GoogleAppointment == null)
                {
                    Logger.Log(string.Format("No match found for outlook appointment ({0}) => {1}", match.OutlookAppointment.Subject + " - " + match.OutlookAppointment.Start, (AppointmentPropertiesUtils.GetOutlookGoogleAppointmentId(sync, match.OutlookAppointment) != null ? "Delete from Outlook" : "Add to Google")), EventType.Information);
                }

                result.Add(match);
            }
            #endregion


            //for each Google appointment that's left (they will be nonmatched) create a new match pair without outlook appointment.
            for (int i = 0; i < sync.GoogleAppointments.Count; i++)
            {
                var googleAppointment = sync.GoogleAppointments[i];

                NotificationReceived?.Invoke(string.Format("Adding new Google appointment {0} of {1} by unique properties: {2} ...", i + 1, sync.GoogleAppointments.Count, googleAppointment.Summary));

                if (googleAppointment.RecurringEventId != null)
                {
                    sync.SkippedCountNotMatches++;
                    googleAppointmentExceptions.Add(googleAppointment);
                }
                else if (googleAppointment.Status.Equals("cancelled"))
                {
                    Logger.Log("Skipping Google appointment found because it is cancelled: " + googleAppointment.Summary + " - " + AppointmentsSynchronizer.GetTime(googleAppointment), EventType.Debug);
                    //sync.SkippedCount++;
                    //sync.SkippedCountNotMatches++;
                }
                else if (string.IsNullOrEmpty(googleAppointment.Summary) && (googleAppointment.Start == null || googleAppointment.Start.DateTime == null && googleAppointment.Start.Date == null))
                {
                    // no title or time
                    sync.SkippedCount++;
                    sync.SkippedCountNotMatches++;
                    Logger.Log("Skipped GoogleAppointment because no unique property found (Subject or StartDate):" + googleAppointment.Summary + " - " + AppointmentsSynchronizer.GetTime(googleAppointment), EventType.Warning);
                }
                else
                {
                    Logger.Log(string.Format("No match found for Google appointment ({0}) => {1}", googleAppointment.Summary + " - " + AppointmentsSynchronizer.GetTime(googleAppointment), (!string.IsNullOrEmpty(AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(sync.SyncProfile, googleAppointment)) ? "Delete from Google" : "Add to Outlook")), EventType.Information);
                    var match = new AppointmentMatch(null, googleAppointment);
                    result.Add(match);
                }
            }

            //for each Google appointment exception, assign to proper match
            for (int i = 0; i < googleAppointmentExceptions.Count; i++)
            {
                var e = googleAppointmentExceptions[i];
                NotificationReceived?.Invoke(string.Format("Adding Google appointment exception {0} of {1} : {2} ...", i + 1, googleAppointmentExceptions.Count, e.Summary + " - " + AppointmentsSynchronizer.GetTime(e)));

                //Search for original recurrent event in matches
                bool found = false;
                foreach (var m in result)
                {
                    if (m.GoogleAppointment != null && e.RecurringEventId.Equals(m.GoogleAppointment.Id))
                    {
                        m.GoogleAppointmentExceptions.Add(e);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    Logger.Log(string.Format("No match found for Google appointment exception: {0}", e.Summary + " - " + AppointmentsSynchronizer.GetTime(e)), EventType.Debug);
                }
            }

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// 会议修改失败,会议属性回滚 2014/11/6
        /// </summary>
        /// <param name="ai"></param>
        /// <param name="bak_appointment"></param>
        private void ValueBackAppointMent(ref AppointmentItem ai, BackUpAppointment bak_appointment)
        {
            try
            {
                ai.Subject = bak_appointment.bak_subject;
                ai.RequiredAttendees = bak_appointment.bak_attdences;
                ai.Resources = "";
                ai.Resources = bak_appointment.bak_resources;
                ai.Location = "";
                ai.Location = bak_appointment.bak_location;
                try
                {
                    UserProperty up = ai.UserProperties.Find(ThisAddIn.PROPERTY_CONFERENCE_PASSWORD, Type.Missing);
                    up.Value = bak_appointment.bak_confPwd;

                    up = ai.UserProperties.Find(ThisAddIn.PROPERTY_VIDEO_SITES_COUNT, Type.Missing);
                    up.Value = bak_appointment.bak_videoCount;

                    up = ai.UserProperties.Find(ThisAddIn.PROPERTY_VOICE_SITES_COUNT, Type.Missing);
                    up.Value = bak_appointment.bak_voiceCount;

                    //is recording
                    up = ai.UserProperties.Find(ThisAddIn.PROPERTY_IS_RECORDING, Type.Missing);
                    up.Value = bak_appointment.bak_record;

                    //is living
                    up = ai.UserProperties.Find(ThisAddIn.PROPERTY_IS_LIVING, Type.Missing);
                    up.Value = bak_appointment.bak_liveBoradcast;

                    //site rate
                    up = ai.UserProperties.Find(ThisAddIn.PROPERTY_SITE_RATE, Type.Missing);
                    up.Value = bak_appointment.bak_siteRate;

                    up = ai.UserProperties.Find(ThisAddIn.PROPERTY_SECURITY_LEVEL, Type.Missing);
                    up.Value = bak_appointment.bak_securityLevel;

                    up = ai.UserProperties.Find(ThisAddIn.PROPERTY_BILL_CODE, Type.Missing);
                    up.Value = bak_appointment.bak_billCode;

                    up = ai.UserProperties.Find(ThisAddIn.PROPERTY_CPRESOURCE, Type.Missing);
                    up.Value = bak_appointment.bak_cpResource;

                    ThisAddIn.g_log.Info(string.Format("Set AppointmentItem properties back end"));
                }
                catch (System.Exception ex)
                {
                    ThisAddIn.g_log.Error(string.Format("Set AppointmentItem properties Exception. because {0}", ex.Message));
                }

                //2014/11/10 测试
                if (ai.RecurrenceState == OlRecurrenceState.olApptMaster)
                {
                    RecurrencePattern rPattern = ai.GetRecurrencePattern();
                    rPattern.StartTime = bak_appointment.bak_recurrencePattern.StartTime;
                    rPattern.EndTime = bak_appointment.bak_recurrencePattern.EndTime;
                    rPattern.Duration = bak_appointment.bak_recurrencePattern.Duration;
                    rPattern.PatternStartDate = bak_appointment.bak_recurrencePattern.PatternStartDate;
                    rPattern.PatternEndDate = bak_appointment.bak_recurrencePattern.PatternEndDate;

                    rPattern.Interval = bak_appointment.bak_recurrencePattern.Interval;
                    rPattern.NoEndDate = bak_appointment.bak_recurrencePattern.NoEndDate;
                    rPattern.Occurrences = bak_appointment.bak_recurrencePattern.Occurrences;
                    rPattern.RecurrenceType = (OlRecurrenceType)bak_appointment.bak_recurrencePattern.RecurrenceType;
                }
                else
                {
                    ai.Start = bak_appointment.bak_start;
                    ai.End = bak_appointment.bak_end;
                }
                ThisAddIn.g_log.Info(string.Format("Set AppointmentItem time back end"));
            }
            catch (System.Exception ex)
            {
                ThisAddIn.g_log.Info(string.Format("Set AppointmentItem back comes Exception {0}", ex.ToString()));
            }
        }
Exemple #6
0
        /// <summary>
        /// 获取周期性会议信息
        /// </summary>
        /// <param name="ConfInfo">周期性会议信息</param>
        private void setRecurrenceConferenceInfo(ref RecurrenceConfInfo recurrenceConfInfo, AppointmentItem ai, bool bSingle)
        {
            //获取智真会议参数
            recurrenceConfInfo.name = ai.Subject;
            recurrenceConfInfo.beginTime = ai.Start.ToUniversalTime();

            TimeSpan span = ai.End - ai.Start;
            string duration = String.Format("P0Y0M{0}DT{1}H{2}M{3}S", span.Days, span.Hours, span.Minutes, span.Seconds);
            recurrenceConfInfo.duration = duration;
            recurrenceConfInfo.mediaEncryptType = ThisAddIn.g_SystemSettings.nMediaEncryptType;
            recurrenceConfInfo.rate = ThisAddIn.g_SystemSettings.strSiteRate;

            recurrenceConfInfo.isLiveBroadcast = ThisAddIn.g_SystemSettings.nLiving;
            recurrenceConfInfo.isRecording = ThisAddIn.g_SystemSettings.nRecording;

            recurrenceConfInfo.timeZone = transSysTimezone2SMC(ai.StartTimeZone);

            recurrenceConfInfo.billCode = ThisAddIn.g_SystemSettings.strBillCode;
            recurrenceConfInfo.password = ThisAddIn.g_SystemSettings.strConfPWD;
            recurrenceConfInfo.chairmanPassword = ThisAddIn.g_SystemSettings.strConfPWD;
            recurrenceConfInfo.cpResouce = ThisAddIn.g_SystemSettings.nCPResource;

            #region
            UserProperty up = ai.UserProperties.Find(PROPERTY_NAME_CONF_INFO, Type.Missing);
            if (up != null)
            {
                recurrenceConfInfo.confId = up.Value;
            }
            else
            {
                UserProperty upConfoID = ai.UserProperties.Add(ThisAddIn.PROPERTY_NAME_CONF_INFO, Outlook.OlUserPropertyType.olText, Type.Missing, Type.Missing);
            }

            up = ai.UserProperties.Find(PROPERTY_CONFERENCE_PASSWORD, Type.Missing);
            if (up != null)
            {
                recurrenceConfInfo.password = up.Value;
                recurrenceConfInfo.chairmanPassword = up.Value;
            }
            else
            {
                UserProperty upConfoPassword = ai.UserProperties.Add(ThisAddIn.PROPERTY_CONFERENCE_PASSWORD, Outlook.OlUserPropertyType.olText, Type.Missing, Type.Missing);
                upConfoPassword.Value = ThisAddIn.g_SystemSettings.strConfPWD;
            }

            up = ai.UserProperties.Find(PROPERTY_IS_RECORDING, Type.Missing);
            if (up != null)
            {
                recurrenceConfInfo.isRecording = Convert.ToInt32(up.Value);
            }
            else
            {
                UserProperty upRecording = ai.UserProperties.Add(ThisAddIn.PROPERTY_IS_RECORDING, Outlook.OlUserPropertyType.olYesNo, Type.Missing, Type.Missing);
                upRecording.Value = Convert.ToBoolean(ThisAddIn.g_SystemSettings.nRecording);
            }

            up = ai.UserProperties.Find(PROPERTY_IS_LIVING, Type.Missing);
            if (up != null)
            {
                recurrenceConfInfo.isLiveBroadcast = Convert.ToInt32(up.Value);
            }
            else
            {
                UserProperty upLiving = ai.UserProperties.Add(ThisAddIn.PROPERTY_IS_LIVING, Outlook.OlUserPropertyType.olYesNo, Type.Missing, Type.Missing);
                upLiving.Value = Convert.ToBoolean(ThisAddIn.g_SystemSettings.nLiving);
            }

            up = ai.UserProperties.Find(PROPERTY_SITE_RATE, Type.Missing);
            if (up != null)
            {
                recurrenceConfInfo.rate = up.Value;
            }
            else
            {
                UserProperty upSiteRate = ai.UserProperties.Add(ThisAddIn.PROPERTY_SITE_RATE, Outlook.OlUserPropertyType.olText, Type.Missing, Type.Missing);
                upSiteRate.Value = ThisAddIn.g_SystemSettings.strSiteRate;
            }

            up = ai.UserProperties.Find(PROPERTY_SECURITY_LEVEL, Type.Missing);
            if (up != null)
            {
                recurrenceConfInfo.mediaEncryptType = up.Value;
            }
            else
            {
                UserProperty upSecurityLevel = ai.UserProperties.Add(ThisAddIn.PROPERTY_SECURITY_LEVEL, Outlook.OlUserPropertyType.olInteger, Type.Missing, Type.Missing);
                upSecurityLevel.Value = ThisAddIn.g_SystemSettings.nMediaEncryptType;
            }

            up = ai.UserProperties.Find(PROPERTY_BILL_CODE, Type.Missing);
            if (up != null)
            {
                recurrenceConfInfo.billCode = up.Value;
            }
            else
            {
                UserProperty upBillCode = ai.UserProperties.Add(ThisAddIn.PROPERTY_BILL_CODE, Outlook.OlUserPropertyType.olText, Type.Missing, Type.Missing);
                upBillCode.Value = ThisAddIn.g_SystemSettings.strBillCode;
            }

            up = ai.UserProperties.Find(PROPERTY_CPRESOURCE, Type.Missing);
            if (up != null)
            {
                if (false == ThisAddIn.g_SystemSettings.bShowCPResource)
                {
                    recurrenceConfInfo.cpResouce = 0;
                }
                else
                {
                    recurrenceConfInfo.cpResouce = up.Value;
                }
            }
            else//非智真会场入口
            {
                UserProperty upCPResource = ai.UserProperties.Add(ThisAddIn.PROPERTY_CPRESOURCE, Outlook.OlUserPropertyType.olInteger, Type.Missing, Type.Missing);

                if (false == ThisAddIn.g_SystemSettings.bShowCPResource)
                {
                    upCPResource.Value = 0;
                    recurrenceConfInfo.cpResouce = 0;
                }
                else
                {
                    upCPResource.Value = ThisAddIn.g_SystemSettings.nCPResource;
                }
            }

            #endregion
            ThisAddIn.g_log.Info(string.Format("recurrence conf id is: {0}", recurrenceConfInfo.confId));
            ThisAddIn.g_log.Info(string.Format("recurrence conf name is: {0}", recurrenceConfInfo.name));
            ThisAddIn.g_log.Info(string.Format("recurrence conf begin at utc: {0}", recurrenceConfInfo.beginTime.ToString()));
            ThisAddIn.g_log.Info(string.Format("appointment item begin at local: {0}", ai.Start.ToString()));

            ThisAddIn.g_log.Info(string.Format("recurrence conf duration: {0}", recurrenceConfInfo.duration));
            ThisAddIn.g_log.Info(string.Format("recurrence conf rate is: {0}", recurrenceConfInfo.rate));
            ThisAddIn.g_log.Info(string.Format("recurrence conf media encrypt type is: {0}", recurrenceConfInfo.mediaEncryptType));
            ThisAddIn.g_log.Info(string.Format("recurrence conf recording is: {0}", recurrenceConfInfo.isRecording));

            ThisAddIn.g_log.Info(string.Format("recurrence conf living is: {0}", recurrenceConfInfo.isLiveBroadcast));
            ThisAddIn.g_log.Info(string.Format("recurrence conf bill code is: {0}", recurrenceConfInfo.billCode));
            ThisAddIn.g_log.Info(string.Format("recurrence conf password is: ******"));
            ThisAddIn.g_log.Info(string.Format("recurrence conf chairman password is: ******"));
            ThisAddIn.g_log.Info(string.Format("recurrence conf CPResource is: {0}", recurrenceConfInfo.cpResouce));
            ThisAddIn.g_log.Info(string.Format("recurrence conf timezone is: {0}", recurrenceConfInfo.timeZone));

            //视频会场
            ArrayList list = new ArrayList();
            SiteInfo tempSite = null;
            int nVideoCount = 0;

            up = ai.UserProperties.Find(PROPERTY_VIDEO_SITES_COUNT, Type.Missing);
            if (up != null)
            {
                nVideoCount = up.Value;
            }
            else
            {
                UserProperty upVideoSiteCounts = ai.UserProperties.Add(ThisAddIn.PROPERTY_VIDEO_SITES_COUNT, Outlook.OlUserPropertyType.olInteger, Type.Missing, Type.Missing);
                upVideoSiteCounts.Value = ThisAddIn.g_SystemSettings.nVideoSitesCount;
                nVideoCount = ThisAddIn.g_SystemSettings.nVideoSitesCount;
            }

            if (nVideoCount > 0)
            {
                for (int i = 0; i < nVideoCount; i++)
                {
                    tempSite = new SiteInfo();
                    tempSite.type = 4;
                    list.Add(tempSite);
                }
            }

            //语音会场
            int nVoiceCount = 0;
            up = ai.UserProperties.Find(PROPERTY_VOICE_SITES_COUNT, Type.Missing);
            if (up != null)
            {
                nVoiceCount = up.Value;
            }
            else
            {
                UserProperty upVoiceSiteCounts = ai.UserProperties.Add(ThisAddIn.PROPERTY_VOICE_SITES_COUNT, Outlook.OlUserPropertyType.olInteger, Type.Missing, Type.Missing);
                upVoiceSiteCounts.Value = ThisAddIn.g_SystemSettings.nVoiceSitesCount;
                nVoiceCount = ThisAddIn.g_SystemSettings.nVoiceSitesCount;
            }

            if (nVoiceCount > 0)
            {
                for (int i = 0; i < nVoiceCount; i++)
                {
                    tempSite = new SiteInfo();
                    tempSite.type = 9;
                    list.Add(tempSite);
                }
            }

            //2015-7-8 w00322557 临时会场
            up = ai.UserProperties.Find(PROPERTY_TEMP_SITES, Type.Missing);
            if (up != null)
            {
                List<SiteInfo> listTempSites = XmlHelper.Desrialize<List<SiteInfo>>(up.Value);
                foreach (SiteInfo site in listTempSites)
                {
                    list.Add(site);
                    ThisAddIn.g_log.Info(string.Format("Temp site name: {0}", site.name));
                    ThisAddIn.g_log.Info(string.Format("Temp site uri: {0}", site.uri));
                    ThisAddIn.g_log.Info(string.Format("Temp site type: {0}", site.type));
                }
            }
            else
            {
                ThisAddIn.g_log.Debug("Temp site is null or empty!");
            }

            //从地址栏获取智真会场
            List<string> listSites = GetTPSitesFromLocation(ai);

            if (listSites != null)
            {
                SiteInfo[] sites = new SiteInfo[listSites.Count];
                for (int i = 0; i < listSites.Count; i++)
                {
                    sites[i] = new SiteInfo();
                    sites[i].uri = listSites[i];
                    sites[i].type = -1;//2015-7-13 w00322557 smc会场类型修改为-1
                    list.Add(sites[i]);

                    ThisAddIn.g_log.Info(string.Format("TP site uri is: {0}", sites[i].uri));
                }
            }

            if (list.Count > 0)
            {
                recurrenceConfInfo.sites = (SiteInfo[])list.ToArray(typeof(SiteInfo));
                ThisAddIn.g_log.Info(string.Format("RecurrenceConfInfo sites length is: {0}", recurrenceConfInfo.sites.Length));
                ThisAddIn.g_log.Info(string.Format("Total TP sites count is: {0}", list.Count));
            }
            else
            {
                ThisAddIn.g_log.Error(string.Format("There is no TP sites!"));
            }

            if (bSingle == false)
            {
                ThisAddIn.g_log.Info("setRecurrenceConferenceInfo recurrence");

                //周期信息
                RecurrencePattern recurrencePattern = ai.GetRecurrencePattern();
                OlDaysOfWeek daysOfWeek = recurrencePattern.DayOfWeekMask;//一周中的天数
                //recurrenceConfInfo.count = recurrencePattern.Occurrences;//周期性会议重复次数
                //recurrencePattern.GetOccurrence()//根据指定日期,返回AppointmentItem

                if (recurrencePattern.NoEndDate == true)
                {
                    recurrencePattern.NoEndDate = false;
                }

                //周期类型(天=0、周=1、月=2)
                if (recurrencePattern.RecurrenceType == OlRecurrenceType.olRecursDaily)//天
                {
                    recurrenceConfInfo.frequency = 0;
                    recurrenceConfInfo.interval = recurrencePattern.Interval;//周期间隔

                    if (true == recurrenceConfInfo.endDateSpecified)
                    {
                        recurrenceConfInfo.endDate = Convert.ToDateTime(recurrencePattern.PatternEndDate.ToShortDateString());//周期性会议结束日期
                    }
                    else
                    {
                        recurrenceConfInfo.count = recurrencePattern.Occurrences;//周期性会议重复次数
                    }
                }
                else if (recurrencePattern.RecurrenceType == OlRecurrenceType.olRecursWeekly)//周
                {
                    recurrenceConfInfo.frequency = 1;
                    //
                    Int32[] weekDays = this.getWeekDays(daysOfWeek);
                    if (weekDays != null)
                    {
                        recurrenceConfInfo.weekDays = weekDays;
                    }

                    if (0 == recurrencePattern.Interval)
                    {
                        recurrenceConfInfo.interval = 1;//周期间隔
                    }
                    else
                    {
                        recurrenceConfInfo.interval = recurrencePattern.Interval;
                    }

                    if (true == recurrenceConfInfo.endDateSpecified)
                    {
                        recurrenceConfInfo.endDate = Convert.ToDateTime(recurrencePattern.PatternEndDate.ToShortDateString());//周期性会议结束日期
                    }
                    else
                    {
                        recurrenceConfInfo.count = recurrencePattern.Occurrences;//周期性会议重复次数
                    }
                }
                else if (recurrencePattern.RecurrenceType == OlRecurrenceType.olRecursMonthly)//月
                {
                    recurrenceConfInfo.frequency = 2;
                    int nDay = recurrencePattern.PatternStartDate.Day;
                    recurrenceConfInfo.monthDay = nDay;

                    recurrenceConfInfo.interval = recurrencePattern.Interval;//周期间隔

                    if (true == recurrenceConfInfo.endDateSpecified)
                    {
                        recurrenceConfInfo.endDate = Convert.ToDateTime(recurrencePattern.PatternEndDate.ToShortDateString());//周期性会议结束日期
                    }
                    else
                    {
                        recurrenceConfInfo.count = recurrencePattern.Occurrences;//周期性会议重复次数
                    }
                }
                else if (recurrencePattern.RecurrenceType == OlRecurrenceType.olRecursMonthNth)
                {
                    recurrenceConfInfo.frequency = 2;
                    recurrenceConfInfo.weekDay = recurrencePattern.Instance;
                    recurrenceConfInfo.weekDays = this.getWeekDays(daysOfWeek);
                    recurrenceConfInfo.interval = recurrencePattern.Interval;//周期间隔

                    if (true == recurrenceConfInfo.endDateSpecified)
                    {
                        recurrenceConfInfo.endDate = Convert.ToDateTime(recurrencePattern.PatternEndDate.ToShortDateString());//周期性会议结束日期
                    }
                    else
                    {
                        recurrenceConfInfo.count = recurrencePattern.Occurrences;//周期性会议重复次数
                    }
                }
                else
                {
                    ThisAddIn.g_log.Error("RecurrenceType is year!");
                }
            }
            else
            {
                //recurrenceConfInfo.timeZone = null;
                recurrenceConfInfo.frequency = null;
                recurrenceConfInfo.interval = null;
                ThisAddIn.g_log.Info("setRecurrenceConferenceInfo single");
            }

            ThisAddIn.g_log.Info("setRecurrenceConferenceInfo success");
        }
Exemple #7
0
        /// <summary>
        /// 预约周期性智真会议
        /// </summary>
        /// <returns>native接口返回值</returns>
        private int scheduleRecurrenceTPConf(ref AppointmentItem ai)
        {
            ThisAddIn.g_log.Info("scheduleRecurrenceTPConf enter");
            Inspector ins = ai.GetInspector;

            RecurrenceConfInfo ConfInfo = new RecurrenceConfInfo();
            setRecurrenceConferenceInfo(ref ConfInfo, ai, false);

            //2015-5-25 w00322557 账号传入“eSDK账号,Outlook邮箱账号”
            //string strAccountName = ThisAddIn.g_AccountInfo.strUserName;
            Outlook.ExchangeUser mainUser = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry.GetExchangeUser();
            string strOutlookAccount = string.Empty;
            if (mainUser != null)
            {
                strOutlookAccount = mainUser.PrimarySmtpAddress;
            }

            string strAccountName = string.Format("{0},{1}", ThisAddIn.g_AccountInfo.strUserName, strOutlookAccount);
            string strAccountPWD = ThisAddIn.g_AccountInfo.strPWD;
            string strServerAddress = ThisAddIn.g_AccountInfo.strServer;

            ThisAddIn.g_log.Debug(string.Format("Account is: {0}", strAccountName));
            ThisAddIn.g_log.Debug("PWD is: ******");
            ThisAddIn.g_log.Debug(string.Format("Server is: {0}", strServerAddress));

            TPOASDKResponse<RecurrenceConfInfo> responseRecurrence = null;
            try
            {
                //密码不存在,返回
                if (string.IsNullOrEmpty(ThisAddIn.g_AccountInfo.strPWD))
                {
                    ThisAddIn.g_log.Info("pwd is null");
                    MessageBox.Show(GlobalResourceClass.getMsg("INPUT_OUTLOOK_PASSWORD"));
                }

                ConferenceMgrService conferenceServiceEx = ConferenceMgrService.Instance(strAccountName, strAccountPWD, strServerAddress);
                responseRecurrence = conferenceServiceEx.scheduleRecurrenceConference(ConfInfo);
            }
            catch (System.Exception ex)
            {
                ThisAddIn.g_log.Error(string.Format("scheduleRecurrenceTPConf exception,because {0}", ex.Message));
                return PARAM_ERROR;
            }

            if (0 == responseRecurrence.resultCode)
            {
                try
                {
                    //预约成功,将返回的confId作为属性保存
                    RecurrenceConfInfo retConfInfo = responseRecurrence.result;

                    //2014/10/14 新增测试
                    List<RecurrenceAppoint> retConfInfoArray = new List<RecurrenceAppoint>();
                    ArrayList tempCon = new ArrayList();
                    if (retConfInfo.siteAccessInfos != null)
                    {
                        RecurrenceAppoint appo = null;
                        for (int i = 0; i < retConfInfo.siteAccessInfos.Length; i++)
                        {
                            DateTime time = retConfInfo.siteAccessInfos[i].beginTime.ToLocalTime();
                            if (!tempCon.Contains(time))//
                            {
                                tempCon.Add(time);

                                appo = new RecurrenceAppoint();
                                appo.AppointDate = time.ToShortDateString();
                                appo.AppointTime = time.ToLongTimeString();
                                appo.AccessCode = retConfInfo.siteAccessInfos[i].confAccessCode;

                                //2015-6-17 w00322557 保存会场
                                appo.AppointSites += retConfInfo.sites[i].name + ",";
                                retConfInfoArray.Add(appo);
                            }
                            else
                            {
                                appo.AppointSites += retConfInfo.sites[i].name + ",";
                            }

                            ThisAddIn.g_log.Info(string.Format("RecurrenceAppoint sites name: {0}", retConfInfo.sites[i].name));
                        }
                    }

                    SaveRecurrenceReturnUserProperties(retConfInfo, ai, retConfInfoArray);

                    DateTime tmpBeginTime = retConfInfo.siteAccessInfos[0].beginTime.ToLocalTime();
                    if (ai.Start != tmpBeginTime)
                    {
                        RecurrencePattern recurrencePattern = ai.GetRecurrencePattern();
                        recurrencePattern.StartTime = DateTime.Parse(tmpBeginTime.ToShortTimeString());
                    }

                    if (string.IsNullOrEmpty(ai.Subject))
                    {
                        ai.Subject = retConfInfo.name;
                        ThisAddIn.g_log.Info(string.Format("outlook subject is empty. return subject is: {0}", retConfInfo.name));
                    }

                    //HTML模板
                    Microsoft.Office.Interop.Word.Document objDoc = ins.WordEditor as Microsoft.Office.Interop.Word.Document;
                    if (null != objDoc)
                    {
                        //获取当前语言通知模板的路径
                        string strFilePath = string.Empty;
                        strFilePath = SetNotificationLanguage(GetNotificationCurrentLanguage(ThisAddIn.g_AccountInfo.strLanguage));

                        if (!File.Exists(strFilePath))
                        {
                            ThisAddIn.g_log.Error("notification file path not exist.");
                            return PARAM_ERROR;
                        }

                        string textTemplate = System.IO.File.ReadAllText(strFilePath, Encoding.GetEncoding("utf-8"));
                        string strNotify = this.replaceContentsInTemplateRecurrence(ai, textTemplate, ref retConfInfo);

                        Clipboard.Clear();
                        VideoConfSettingsForm.CopyHtmlToClipBoard(strNotify);
                        object html = Clipboard.GetData(DataFormats.Html);

                        ThisAddIn.g_log.Info("schedule recurrence paste enter.");

                        object start = 0;
                        Range newRang = objDoc.Range(ref start, ref start);

                        int ioo = objDoc.Sections.Count;
                        Section sec = objDoc.Sections.Add(Type.Missing, Type.Missing);

                        sec.Range.InsertBreak(Type.Missing);//插入换行符

                        //2014/11/13 测试,防止异常,邮件体出现空白
                        for (int i = 0; i < 5; i++)
                        {
                            try
                            {
                                sec.Range.PasteAndFormat(WdRecoveryType.wdPasteDefault);
                                break;
                            }
                            catch (System.Exception ex)
                            {
                                ThisAddIn.g_log.Error(ex.Message);
                                Thread.Sleep(500);
                            }
                        }

                        ThisAddIn.g_log.Info("schedule recurrence paste end");

                        #region 2014/11/3 注销,合并入SendMailNotification()
                        ThisAddIn.g_log.Info("schedule send mail enter.");

                        //MailItem email = this.Application.CreateItem(OlItemType.olMailItem);
                        //string smtpAddress = "";

                        //Outlook.Recipients recipients = ai.Recipients;
                        //foreach (Outlook.Recipient recipient in recipients)
                        //{
                        //    Outlook.ExchangeUser exchangeUser = recipient.AddressEntry.GetExchangeUser();

                        //    if (exchangeUser != null)
                        //    {
                        //        smtpAddress += exchangeUser.PrimarySmtpAddress + ";";//获取账户信息,作为默认第一个收件人
                        //    }
                        //    else
                        //    {
                        //        smtpAddress += recipient.Address + ";";//添加收件人地址
                        //    }
                        //}

                        //email.To = smtpAddress;  //收件人地址
                        //email.Subject = "[Successfully Scheduled]" + ai.Subject;
                        //email.BodyFormat = OlBodyFormat.olFormatHTML;//body格式
                        //email.HTMLBody = strNotify;

                        //((Outlook._MailItem)email).Send();//发送邮件

                        //ThisAddIn.g_log.Info("sendMailNotifications exit");
                        //ThisAddIn.g_log.Info("schedule send mail exit.");
                        #endregion

                        Outlook.Recipients recipients = ai.Recipients;
                        sendMailNotifications(ai, OperatorType.Schedule, recipients);

                        //3's
                        MessageBoxTimeOut mes = new MessageBoxTimeOut();
                        string strFormat = GlobalResourceClass.getMsg("OPERATOR_MESSAGE");
                        string messageBody = string.Format(strFormat, GlobalResourceClass.getMsg("OPERATOR_TYPE_SCHEDULE"));
                        mes.Show(messageBody, GlobalResourceClass.getMsg("OPERATOR_SUCCESS"), 3000);
                    }
                }
                catch (System.Exception ex)
                {
                    ThisAddIn.g_log.Error(string.Format("recurrence email notification error,because {0}.", ex.Message));
                }
            }
            else
            {
                //
                ThisAddIn.g_log.Info(string.Format("scheduleRecurrenceTPConf failed with: {0}", responseRecurrence.resultCode.ToString()));
            }

            ThisAddIn.g_log.Info("scheduleRecurrenceTPConf exit");
            return responseRecurrence.resultCode;
        }
Exemple #8
0
        /// <summary>
        /// 替换通知模板中的内容
        /// </summary>
        /// <param name="textTemplate">通知模板</param>
        /// <param name="confInfo">会议信息</param>  
        /// <returns>新的通知消息</returns>
        private string replaceContentsInTemplateRecurrence(AppointmentItem ai, string textTemplate, ref RecurrenceConfInfo confInfo)
        {
            //begin 替换模板中的数据
            string[] strLanguages = ThisAddIn.g_AccountInfo.strLanguage.Split(';');
            int nLanguage = 1033;
            bool bContain = textTemplate.Contains("{Recurrence_Type}");
            if (true == bContain)
            {
                if (string.Equals(strLanguages[0].ToLower(), "zh_cn"))
                {
                    textTemplate = textTemplate.Replace("{Recurrence_Type}", "重复周期");
                    nLanguage = 2052;
                }
                else if (string.Equals(strLanguages[0].ToLower(), "ru") || string.Equals(strLanguages[0].ToLower(), "ru_ru"))
                {
                    textTemplate = textTemplate.Replace("{Recurrence_Type}", "Интервал повтора");
                    nLanguage = 1049;
                }
                else
                {
                    textTemplate = textTemplate.Replace("{Recurrence_Type}", "Recurrence");
                    nLanguage = 1033;
                }
            }

            bContain = textTemplate.Contains("{Recurrence_Time}");
            if (true == bContain)
            {
                if (string.Equals(strLanguages[0].ToLower(), "zh_cn"))
                {
                    textTemplate = textTemplate.Replace("{Recurrence_Time}", "有效时间");
                }
                else if (string.Equals(strLanguages[0].ToLower(), "ru") || string.Equals(strLanguages[0].ToLower(), "ru_ru"))
                {
                    textTemplate = textTemplate.Replace("{Recurrence_Time}", "Срок действия");
                }
                else
                {
                    textTemplate = textTemplate.Replace("{Recurrence_Time}", "Valid Time");
                }
            }
            //替换模板中的"会议名称"
            bContain = textTemplate.Contains("{Conf_Subject}");
            string strNewString = "";
            if (true == bContain)
            {
                if (string.IsNullOrEmpty(ai.Subject))
                {
                    strNewString = textTemplate.Replace("{Conf_Subject}", confInfo.name);
                }
                else
                {
                    string myEncodedString = HttpUtility.HtmlEncode(ai.Subject);
                    strNewString = textTemplate.Replace("{Conf_Subject}", myEncodedString);
                }
            }

            //替换模板中的"会议密码"
            bContain = strNewString.Contains("{Conf_Password}");
            string strNewString2 = "";
            if (true == bContain)
            {
                UserProperty up = ai.UserProperties.Find(ThisAddIn.PROPERTY_CONFERENCE_PASSWORD, Type.Missing);
                if (up != null)
                {
                    strNewString2 = strNewString.Replace("{Conf_Password}", up.Value);
                }
                else
                {
                    strNewString2 = strNewString.Replace("{Conf_Password}", ThisAddIn.g_SystemSettings.strConfPWD);
                }

            }
            else
            {
                strNewString2 = strNewString;
            }

            //替换模板中的"会议开始时间"
            bContain = strNewString2.Contains("{Conf_Start_Time}");
            string strNewString3 = "";
            if (true == bContain)
            {
                RecurrencePattern rp = ai.GetRecurrencePattern();
                string strTemp = string.Empty;
                DateTime dateTime = rp.PatternStartDate.AddHours(rp.StartTime.Hour);
                dateTime = dateTime.AddMinutes(rp.StartTime.Minute);
                string strFormat = string.Empty;
                if (rp.RecurrenceType == OlRecurrenceType.olRecursDaily)//天
                {
                    if (rp.Interval < 2)
                    {
                        strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_EVERY_DAY", nLanguage));
                    }
                    else
                    {
                        strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_WITH_DAY", nLanguage), rp.Interval);
                    }

                }
                else if (rp.RecurrenceType == OlRecurrenceType.olRecursWeekly)//周
                {
                    string strDayOfWeek = string.Empty;
                    int[] nDayOfWeek = getWeekDays(rp.DayOfWeekMask);
                    for (int i = 0; i < nDayOfWeek.Length; i++)
                    {
                        switch (nDayOfWeek[i])
                        {
                            case 0:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_SUNDAY", nLanguage);
                                break;
                            case 1:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_MONDAY", nLanguage);
                                break;
                            case 2:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_TUESDAY", nLanguage);
                                break;
                            case 3:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_WEDNESDAY", nLanguage);
                                break;
                            case 4:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_THURSDAY", nLanguage);
                                break;
                            case 5:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_FRIDAY", nLanguage);
                                break;
                            case 6:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_SATURDAY", nLanguage);
                                break;
                            default:
                                break;
                        }
                    }

                    if (!string.IsNullOrEmpty(strDayOfWeek) && strDayOfWeek.Length > 0)
                    {
                        strDayOfWeek = strDayOfWeek.Trim();
                        strDayOfWeek = strDayOfWeek.Remove(strDayOfWeek.Length - 1);
                    }

                    if (rp.Interval < 2)
                    {
                        strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_EVERY_WEEK", nLanguage), strDayOfWeek);
                    }
                    else
                    {
                        //2014/10/11修改
                        if (string.Equals(strLanguages[0].ToLower(), "zh_cn"))//中文
                        {
                            strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_WITH_WEEK", nLanguage), rp.Interval, strDayOfWeek);
                        }
                        else//英文
                        {
                            strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_WITH_WEEK", nLanguage), strDayOfWeek, rp.Interval);
                        }

                    }

                }
                else if (rp.RecurrenceType == OlRecurrenceType.olRecursMonthly)//月
                {
                    if (rp.Interval < 2)
                    {
                        strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_EVERY_MONTH", nLanguage), rp.DayOfMonth, (rp.DayOfMonth < 4 ? (MonthDayNum)rp.DayOfMonth : (MonthDayNum)4));
                    }
                    else
                    {
                        if (nLanguage == 1033)//2015-4-22 w00322557英文格式
                        {
                            strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_WITH_MONTH", nLanguage), rp.DayOfMonth, (rp.DayOfMonth < 4 ? (MonthDayNum)rp.DayOfMonth : (MonthDayNum)4), rp.Interval);
                        }
                        else if (nLanguage == 1049)//2015-4-22 w00322557俄文格式
                        {
                            strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_WITH_MONTH", nLanguage), rp.DayOfMonth, rp.Interval);
                        }
                        else
                        {
                            strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_WITH_MONTH", nLanguage), rp.Interval, rp.DayOfMonth);
                        }
                    }
                    ThisAddIn.g_log.Info(string.Format("RECURRENCE_WITH_MONTH : {0}", strTemp));
                }
                else if (rp.RecurrenceType == OlRecurrenceType.olRecursMonthNth)
                {
                    string strDayOfWeek = string.Empty;
                    int[] nDayOfWeek = getWeekDays(rp.DayOfWeekMask);
                    for (int i = 0; i < nDayOfWeek.Length; i++)
                    {
                        switch (nDayOfWeek[i])
                        {
                            case 0:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_SUNDAY", nLanguage);
                                break;
                            case 1:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_MONDAY", nLanguage);
                                break;
                            case 2:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_TUESDAY", nLanguage);
                                break;
                            case 3:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_WEDNESDAY", nLanguage);
                                break;
                            case 4:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_THURSDAY", nLanguage);
                                break;
                            case 5:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_FRIDAY", nLanguage);
                                break;
                            case 6:
                                strDayOfWeek += GlobalResourceClass.getMsg("RECURRENCE_SATURDAY", nLanguage);
                                break;
                            default:
                                break;
                        }
                    }

                    if (!string.IsNullOrEmpty(strDayOfWeek) && strDayOfWeek.Length > 0)
                    {
                        strDayOfWeek = strDayOfWeek.Trim();
                        strDayOfWeek = strDayOfWeek.Remove(strDayOfWeek.Length - 1);
                    }

                    if (rp.Interval < 2)//每个
                    {
                        if (string.Equals(strLanguages[0].ToLower(), "en_us"))//English
                        {
                            strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_EVERY_MONTHLY", nLanguage), (MonthWeekNum)rp.Instance, strDayOfWeek);
                        }
                        else if (string.Equals(strLanguages[0].ToLower(), "ru") || string.Equals(strLanguages[0].ToLower(), "ru_ru"))//russian
                        {
                            strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_EVERY_MONTHLY", nLanguage), (MonthWeekNumRU)rp.Instance, strDayOfWeek);
                        }
                        else//中文
                        {
                            if (rp.Instance > 4)//每月最后一周
                            {
                                strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_EVERY_MONTHLY_LAST", nLanguage), strDayOfWeek);
                            }
                            else
                            {
                                strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_EVERY_MONTHLY", nLanguage), rp.Instance, strDayOfWeek);
                            }
                        }
                        ThisAddIn.g_log.Info(string.Format("RECURRENCE_EVERY_MONTHLY : {0}", strTemp));
                    }
                    else//每?个
                    {

                        if (string.Equals(strLanguages[0].ToLower(), "en_us"))//English
                        {
                            strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_WITH_MONTHLY", nLanguage), (MonthWeekNum)rp.Instance, strDayOfWeek, rp.Interval);
                        }
                        else if (string.Equals(strLanguages[0].ToLower(), "ru") || string.Equals(strLanguages[0].ToLower(), "ru_ru"))//russian
                        {
                            strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_WITH_MONTHLY", nLanguage), (MonthWeekNumRU)rp.Instance, strDayOfWeek, rp.Interval);
                        }
                        else// (string.Equals(strLanguages[0].ToLower(), "zh_cn"))//chinese
                        {
                            if (rp.Instance > 4)
                            {
                                strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_WITH_MONTHLY_LAST", nLanguage), strDayOfWeek, rp.Interval);
                            }
                            else
                            {
                                strTemp = string.Format(GlobalResourceClass.getMsg("RECURRENCE_WITH_MONTHLY", nLanguage), rp.Instance, strDayOfWeek, rp.Interval);
                            }
                        }
                        ThisAddIn.g_log.Info(string.Format("RECURRENCE_WITH_MONTHLY : {0}", strTemp));
                    }
                }
                strNewString3 = strNewString2.Replace("{Conf_Start_Time}", strTemp);
            }
            else
            {
                strNewString3 = strNewString2;
            }

            //替换模板中的"会议结束"
            bContain = strNewString3.Contains("{Conf_End_Time}");
            string strNewString4 = "";
            if (true == bContain)
            {
                RecurrencePattern rp = ai.GetRecurrencePattern();
                DateTime dateTime = rp.PatternEndDate;

                //time zone
                Outlook.TimeZone tz = ai.StartTimeZone;

                string strRes;
                if (string.Equals(strLanguages[0].ToLower(), "zh_cn"))//中文,2014/11/14 修改,预约过去会议与SMC保持一致
                {
                    strRes = string.Format(GlobalResourceClass.getMsg("RECURRENCE_FROM_TO", nLanguage), rp.PatternStartDate.ToShortDateString(),
                                                                                                rp.PatternEndDate.ToShortDateString(),
                                                                                                rp.StartTime.ToShortTimeString(),
                                                                                                rp.EndTime.ToShortTimeString()) + " " + ai.StartTimeZone.Name;
                }
                else//英文
                {
                    strRes = string.Format(GlobalResourceClass.getMsg("RECURRENCE_FROM_TO", nLanguage), rp.StartTime.ToShortTimeString(),
                                                                                             rp.EndTime.ToShortTimeString(),
                                                                                             rp.PatternStartDate.ToShortDateString(),
                                                                                             rp.PatternEndDate.ToShortDateString()) + " " + ai.StartTimeZone.Name;
                }

                strNewString4 = strNewString3.Replace("{Conf_End_Time}", strRes);
            }
            else
            {
                strNewString4 = strNewString3;
            }

            //替换模板中的"会议接入号"
            bContain = strNewString4.Contains("{Conf_Access_Number}");
            string strNewString5 = "";
            if (true == bContain)
            {
                if (string.IsNullOrEmpty(confInfo.siteAccessInfos[0].confAccessCode))
                {
                    strNewString5 = strNewString4.Replace("{Conf_Access_Number}", "");
                }
                else
                {
                    //2015-6-16 w00322557 有前缀则中间添加“-”分割,若无前缀,则无分隔符
                    if (string.IsNullOrEmpty(ThisAddIn.g_AccountInfo.strLync))
                    {
                        strNewString5 = strNewString4.Replace("{Conf_Access_Number}", confInfo.siteAccessInfos[0].confAccessCode);
                    }
                    else
                    {
                        //2014/10/10 修改,为接入码加入9000- 前缀
                        strNewString5 = strNewString4.Replace("{Conf_Access_Number}", ThisAddIn.g_AccountInfo.strLync + "-" + confInfo.siteAccessInfos[0].confAccessCode);
                    }
                }
            }
            else
            {
                strNewString5 = strNewString4;
            }

            //替换模板中的"终端会场"
            bContain = strNewString5.Contains("{Conf_Sites}");
            string strNewString6 = "";
            if (true == bContain)
            {
                string strTempSites = "";

                //2014/10/20 测试
                ConferenceInfo cInfo = (ConferenceInfo)confInfo;
                for (int i = 0; i < confInfo.siteAccessInfos.Length; i++)
                {
                    SiteAccessInfo sInfo = confInfo.siteAccessInfos[i];

                    if (sInfo.beginTime.ToLocalTime().ToShortDateString() == ai.Start.ToShortDateString())
                    {
                        if ((cInfo.sites[i].uri == sInfo.uri) && (!string.IsNullOrEmpty(sInfo.uri)))
                        {
                            strTempSites += cInfo.sites[i].name + "; ";
                        }
                    }
                }
                strNewString6 = strNewString5.Replace("{Conf_Sites}", strTempSites);
            }

            //替换模板中的"Lync一键入会"
            bContain = strNewString6.Contains("conf_lync_ctc");
            string strNewString7 = "";
            if (true == bContain)
            {
                if (true == ThisAddIn.g_SystemSettings.bLyncCTC)
                {
                    strNewString7 = strNewString6.Replace("conf_lync_ctc", "sip:" + ThisAddIn.g_AccountInfo.strLync + confInfo.siteAccessInfos[0].confAccessCode + ThisAddIn.g_AccountInfo.strMCU);
                }
                else
                {
                    strNewString7 = strNewString6.Replace("conf_lync_ctc", "");
                }
            }
            else
            {
                strNewString7 = strNewString6;
            }

            //替换模板中的"数据会议地址"
            bContain = strNewString7.Contains("conf_living_address");
            string strNewString8 = "";
            if (true == bContain)
            {
                strNewString8 = strNewString7.Replace("conf_living_address", confInfo.recorderAddr);
            }
            else
            {
                strNewString8 = strNewString7;
            }

            //替换模板中的"{Prefix_ISDN}"
            bContain = strNewString8.Contains("{Prefix_ISDN}");
            string strNewString9 = "";
            if (true == bContain)
            {
                strNewString9 = strNewString8.Replace("{Prefix_ISDN}", ThisAddIn.g_AccountInfo.strLync);
            }
            else
            {
                strNewString9 = strNewString8;
            }

            //替换模板中的"{Prefix_Cisco}"
            bContain = strNewString9.Contains("{Prefix_Cisco}");
            string strNewString10 = "";
            if (true == bContain)
            {
                //2015-6-16 w00322557 有前缀则中间添加“-”分割,若无前缀,则无分隔符
                if (string.IsNullOrEmpty(ThisAddIn.g_AccountInfo.strCisco))
                {
                    strNewString10 = strNewString9.Replace("{Prefix_Cisco}", confInfo.siteAccessInfos[0].confAccessCode);
                }
                else
                {
                    strNewString10 = strNewString9.Replace("{Prefix_Cisco}", ThisAddIn.g_AccountInfo.strCisco + "-" + confInfo.siteAccessInfos[0].confAccessCode);
                }
            }
            else
            {
                strNewString10 = strNewString9;
            }

            //
            if (string.IsNullOrEmpty(strNewString10))
            {
                ThisAddIn.g_log.Error("Recurrence template is empty.");
            }
            else
            {
                ThisAddIn.g_log.Info(string.Format("template length is: {0}", strNewString10.Length));
            }

            return strNewString10;
        }
Exemple #9
0
        /// <summary>
        /// 保存打开的约会信息 2014/11/6 
        /// </summary>
        /// <param name="item">需要保存的约会</param>
        private BackUpAppointment copyAppointMentItem(AppointmentItem item)
        {
            string attendences = item.RequiredAttendees;
            try
            {
                if (attendences != null && attendences.IndexOf(";") > 0)
                {
                    attendences = attendences.Substring(attendences.IndexOf(";") + 1);
                }
                else
                {
                    attendences = "";
                }
            }
            catch (System.Exception ex)
            {
                attendences = "";
                ThisAddIn.g_log.Error(string.Format("new inspector error: {0}", ex.Message));
            }

            BackUpAppointment bak_app = BackUpAppointment.backUp(item.Subject, item.Start, item.End, item.Location, item.Resources, attendences, item.Body);
            bak_app.IsRecurring = item.IsRecurring;

            //2014/11/10  备份周期会议的会议属性
            if (item.IsRecurring)
            {
                BackUpRecurrencePattern bakRecurrence = new BackUpRecurrencePattern();
                bak_app.bak_recurrencePattern = bakRecurrence.backUpRePattern(item.GetRecurrencePattern());
            }

            UserProperty up = item.UserProperties.Find(ThisAddIn.PROPERTY_CONFERENCE_PASSWORD, Type.Missing);
            if (up != null)
            {
                bak_app.bak_confPwd = up.Value;
            }
            else
            {
                bak_app.bak_confPwd = ThisAddIn.g_SystemSettings.strConfPWD;
            }

            up = item.UserProperties.Find(ThisAddIn.PROPERTY_VIDEO_SITES_COUNT, Type.Missing);
            if (up != null)
            {
                bak_app.bak_videoCount = up.Value;
            }
            else
            {
                bak_app.bak_videoCount = ThisAddIn.g_SystemSettings.nVideoSitesCount;
            }

            up = item.UserProperties.Find(ThisAddIn.PROPERTY_VOICE_SITES_COUNT, Type.Missing);
            if (up != null)
            {
                bak_app.bak_voiceCount = up.Value;
            }
            else
            {
                bak_app.bak_voiceCount = ThisAddIn.g_SystemSettings.nVoiceSitesCount;
            }

            //is recording
            up = item.UserProperties.Find(ThisAddIn.PROPERTY_IS_RECORDING, Type.Missing);
            if (up != null)
            {
                bak_app.bak_record = up.Value;
            }
            else
            {
                bak_app.bak_record = Convert.ToBoolean(ThisAddIn.g_SystemSettings.nRecording);
            }

            //is living
            up = item.UserProperties.Find(ThisAddIn.PROPERTY_IS_LIVING, Type.Missing);
            if (up != null)
            {
                bak_app.bak_liveBoradcast = up.Value;
            }
            else
            {
                bak_app.bak_liveBoradcast = Convert.ToBoolean(ThisAddIn.g_SystemSettings.nLiving);
            }

            //site rate
            up = item.UserProperties.Find(ThisAddIn.PROPERTY_SITE_RATE, Type.Missing);
            if (up != null)
            {
                bak_app.bak_siteRate = up.Value;
            }
            else
            {
                bak_app.bak_siteRate = ThisAddIn.g_SystemSettings.strSiteRate;
            }

            up = item.UserProperties.Find(ThisAddIn.PROPERTY_SECURITY_LEVEL, Type.Missing);
            if (up != null)
            {
                bak_app.bak_securityLevel = up.Value;
            }
            else
            {
                bak_app.bak_securityLevel = ThisAddIn.g_SystemSettings.nMediaEncryptType;
            }

            up = item.UserProperties.Find(ThisAddIn.PROPERTY_BILL_CODE, Type.Missing);
            if (up != null)
            {
                bak_app.bak_billCode = up.Value;
            }
            else
            {
                bak_app.bak_billCode = ThisAddIn.g_SystemSettings.strBillCode;
            }

            up = item.UserProperties.Find(ThisAddIn.PROPERTY_CPRESOURCE, Type.Missing);
            if (up != null)
            {
                bak_app.bak_cpResource = string.Format("{0}", up.Value);
            }
            else
            {
                bak_app.bak_cpResource = string.Format("{0}", ThisAddIn.g_SystemSettings.nCPResource);
            }
            return bak_app;
        }
Exemple #10
0
        /// <summary>
        /// 修改周期性智真会议
        /// </summary>
        /// <returns>native接口返回值</returns>
        private int editRecurrenceTPConf(AppointmentItem ai, ref RecurrenceConfInfo ConfInfo, MeetingItem meetingItem)
        {
            ThisAddIn.g_log.Info("editRecurrenceTPConf enter");
            Inspector ins = ai.GetInspector;

            string accessCode = null;
            List<SiteInfo> siteInfos = new List<SiteInfo>();

            DateTime? date = null;
            if (OlRecurrenceState.olApptException == ai.RecurrenceState || OlRecurrenceState.olApptOccurrence == ai.RecurrenceState)//修改周期会议的子会议
            {
                if (editBack)//修改回滚,UserProperty中的Xml数据不可用,使用自己的StartTime
                {
                    string s = string.Format("{0} {1}", ai.Start.ToShortDateString(), ai.GetRecurrencePattern().StartTime.ToLongTimeString());
                    date = DateTime.Parse(s).ToUniversalTime();
                }
                else //正常修改
                {
                    UserProperty upRightBeginTime = ai.UserProperties.Find(PROPERTY_RIGHT_BEGIN_TIME, true);
                    string val = upRightBeginTime.Value;

                    List<RecurrenceAppoint> appointList = XmlHelper.Desrialize<List<RecurrenceAppoint>>(val);
                    foreach (RecurrenceAppoint Rappoint in appointList)
                    {
                        if (Rappoint.AppointDate.Equals(ai.Start.ToShortDateString()))
                        {
                            string s = string.Format("{0} {1}", Rappoint.AppointDate, Rappoint.AppointTime);
                            date = DateTime.Parse(s).ToUniversalTime();
                            break;
                        }
                    }

                    if (date == null)//证明修改了时间
                    {
                        return ERROR_CODE_CHANGE_DATE;
                    }
                }
                setRecurrenceConferenceInfo(ref ConfInfo, ai, true, meetingItem);
            }
            else//修改周期会议
            {
                editBack = true;

                setRecurrenceConferenceInfo(ref ConfInfo, ai, false, meetingItem);
            }

            TPOASDKResponse<RecurrenceConfInfo> responseRecurrence = null;
            int resultCode = -1;

            //2015-5-25 w00322557 账号传入“eSDK账号,Outlook邮箱账号”
            //string strAccountName = ThisAddIn.g_AccountInfo.strUserName;
            Outlook.ExchangeUser mainUser = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry.GetExchangeUser();
            string strOutlookAccount = string.Empty;
            if (mainUser != null)
            {
                strOutlookAccount = mainUser.PrimarySmtpAddress;
            }

            string strAccountName = string.Format("{0},{1}", ThisAddIn.g_AccountInfo.strUserName, strOutlookAccount);
            string strAccountPWD = ThisAddIn.g_AccountInfo.strPWD;
            string strServerAddress = ThisAddIn.g_AccountInfo.strServer;

            ThisAddIn.g_log.Debug(string.Format("Account is: {0}", strAccountName));
            ThisAddIn.g_log.Debug("PWD is: ******");
            ThisAddIn.g_log.Debug(string.Format("Server is: {0}", strServerAddress));

            try
            {
                ConferenceMgrService conferenceServiceEx = ConferenceMgrService.Instance(strAccountName, strAccountPWD, strServerAddress);
                responseRecurrence = conferenceServiceEx.editRecurrenceConference(ConfInfo, date);

                //已关联
                resultCode = responseRecurrence.resultCode;

            }
            catch (System.Exception ex)
            {
                editBack = false;
                ThisAddIn.g_log.Error(string.Format("editRecurrenceTPConf exception with: {0}", ex.Message));
                return PARAM_ERROR;
            }

            if (0 == resultCode)
            {
                //预约成功,将返回的会议信息作为属性保存
                if (string.IsNullOrEmpty(ai.Subject))
                {
                    ai.Subject = ConfInfo.name;
                }
                string strNotify = "";
                ConferenceInfo confInfo = null;

                if (responseRecurrence != null)
                {
                    //预约成功,将返回的confId作为属性保存
                    RecurrenceConfInfo retConfInfo = responseRecurrence.result;

                    //2014/10/21 测试
                    confInfo = (ConferenceInfo)retConfInfo;

                    //2014/10/14 新增测试
                    List<RecurrenceAppoint> retConfInfoArray = new List<RecurrenceAppoint>();
                    ArrayList tempCon = new ArrayList();

                    try
                    {
                        RecurrenceAppoint appo = null;
                        for (int i = 0; i < retConfInfo.siteAccessInfos.Length; i++)
                        {
                            DateTime time = retConfInfo.siteAccessInfos[i].beginTime.ToLocalTime();
                            if (!tempCon.Contains(time))
                            {
                                tempCon.Add(time);

                                appo = new RecurrenceAppoint();
                                appo.AppointDate = time.ToShortDateString();
                                appo.AppointTime = time.ToLongTimeString();
                                appo.AccessCode = retConfInfo.siteAccessInfos[i].confAccessCode;

                                //2015-6-17 w00322557 保存会场
                                appo.AppointSites = retConfInfo.sites[i].name + ",";
                                retConfInfoArray.Add(appo);
                            }
                            else
                            {
                                appo.AppointSites += retConfInfo.sites[i].name + ",";
                            }

                            ThisAddIn.g_log.Info(string.Format("Edit RecurrenceAppoint sites name: {0}", retConfInfo.sites[i].name));

                            //保存当天会议的接入码
                            if (time.ToString("yyyy-MM-dd HH:mm") == ai.Start.ToString("yyyy-MM-dd HH:mm"))
                            {
                                accessCode = retConfInfo.siteAccessInfos[i].confAccessCode;
                                SiteInfo info = new SiteInfo();

                                //2014/10/21 测试
                                info.name = confInfo.sites[i].name;
                                siteInfos.Add(info);
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        ThisAddIn.g_log.Error(string.Format("editRecurrenceTPConf exception: {0}", ex.Message));
                    }

                    //HTML模板
                    Microsoft.Office.Interop.Word.Document objDoc = ins.WordEditor as Microsoft.Office.Interop.Word.Document;
                    if (null != objDoc)
                    {
                        string strFilePath = string.Empty;
                        strFilePath = SetNotificationLanguage(GetNotificationCurrentLanguage(ThisAddIn.g_AccountInfo.strLanguage));

                        if (!File.Exists(strFilePath))
                        {
                            ThisAddIn.g_log.Error("notification file path not exist.");
                            return PARAM_ERROR;
                        }

                        //读取会议邮件通知模板内容
                        string textTemplate = System.IO.File.ReadAllText(strFilePath, Encoding.GetEncoding("utf-8"));

                        //ConferenceInfo confInfo = (ConferenceInfo)retConfInfo;
                        //string strNotify = this.replaceContentsInTemplateRecurrence(ai, textTemplate, ref retConfInfo);

                        //2014/10/16 测试

                        if (OlRecurrenceState.olApptException == ai.RecurrenceState)//证明修改的是周期会议的子会议
                        {
                            //传接入码
                            confInfo.accessCode = accessCode;

                            //传会场
                            SiteInfo[] infos = siteInfos.ToArray();
                            confInfo.sites = infos;
                            strNotify = this.replaceContentsInTemplate(ai, textTemplate, ref confInfo);
                            SaveRecuConfReturnUserProperties(retConfInfo, ai, retConfInfoArray);
                        }
                        else
                        {
                            SaveRecurrenceReturnUserProperties(retConfInfo, ai, retConfInfoArray);
                            strNotify = this.replaceContentsInTemplateRecurrence(ai, textTemplate, ref retConfInfo);
                        }

                        //将会议通知模板数据拷贝/粘贴到文档中
                        Clipboard.Clear();
                        VideoConfSettingsForm.CopyHtmlToClipBoard(strNotify);
                        object html = Clipboard.GetData(DataFormats.Html);

                        ThisAddIn.g_log.Info("edit recurrence paste enter");
                        objDoc.Range().WholeStory();
                        //object start = 0;
                        //Range newRang = objDoc.Range(ref start, ref start);

                        //int ioo = objDoc.Sections.Count;
                        //Section sec = objDoc.Sections.Add(Type.Missing, Type.Missing);
                        //sec.Range.InsertBreak(Type.Missing);

                        try
                        {
                            //objDoc.Range().PasteAndFormat(WdRecoveryType.wdPasteDefault);
                            objDoc.Range().PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting);
                        }
                        catch (System.Exception ex)
                        {
                            ThisAddIn.g_log.Error(ex.Message);
                        }
                        //2014/12/27 释放Document
                        Marshal.ReleaseComObject(objDoc);
                        objDoc = null;

                        ThisAddIn.g_log.Info("edit recurrence paste end");
                    }
                }
                SendRecipientsInfo(ai, meetingItem);

                //MessageBoxTimeOut mes = new MessageBoxTimeOut();
                string messageBody = string.Format(GlobalResourceClass.getMsg("OPERATOR_MESSAGE"), GlobalResourceClass.getMsg("OPERATOR_TYPE_MODIFY"));
                //mes.Show(messageBody, GlobalResourceClass.getMsg("OPERATOR_SUCCESS"), 3000);

                WinDialog win = new WinDialog(messageBody, GlobalResourceClass.getMsg("OPERATOR_SUCCESS"), 3000);
                win.ShowDialog();
            }
            else
            {
                //返回错误码,计入日志
                ThisAddIn.g_log.Error(string.Format("editRecurrenceTPConf return: {0}", responseRecurrence.resultCode.ToString()));
            }

            ThisAddIn.g_log.Info("editRecurrenceTPConf exit");
            return resultCode;
        }
        /// <summary>
        /// Adds the attributes to an AppointmentItem
        /// </summary>
        /// <param name="calEvent">The event of a specific calendar</param>
        /// <param name="subject">Title of the event</param>
        /// <param name="startDate">Start date of the event</param>
        /// <param name="recurrenceType">Recurrence type</param>
        /// <param name="endDate">End date for the recurrence</param>
        /// <param name="duration">Duration of the event</param>
        /// <param name="recipients">Recipients for the event</param>
        /// <returns>returns the filled in event so that it can be saved and sent from outlook</returns>
        internal static Outlook.AppointmentItem CreateEvent(Outlook.AppointmentItem calEvent, string subject, string startDate, string recurrenceType, string endDate,
                                                            string duration, string[] recipients)
        {
            string methodTag = "CreateEvent";

            LogWriter.WriteInfo(TAG, methodTag, "Starting: " + methodTag + " in " + TAG);

            Outlook.RecurrencePattern recurrPatt = null;

            if (calEvent != null)
            {
                calEvent.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
                calEvent.Sensitivity   = Outlook.OlSensitivity.olNormal;

                if (subject != null)
                {
                    calEvent.Subject = subject;
                    LogWriter.WriteInfo(TAG, methodTag, "Subject set to: " + subject);
                }
                else
                {
                    LogWriter.WriteWarning(TAG, methodTag, "Subject is null, may cause failures when searching for it");
                }

                if (startDate != null)
                {
                    calEvent.Start = DateTime.Parse(startDate);
                    LogWriter.WriteInfo(TAG, methodTag, "Start date set to: " + startDate);
                }
                else
                {
                    LogWriter.WriteInfo(TAG, methodTag, "No start date provided, using default of the next closest hour");
                    LogWriter.WriteWarning(TAG, methodTag, "No start date provided, may cause failures when searching for it");
                }

                if (duration != null)
                {
                    calEvent.Duration = Convert.ToInt32(duration);
                    LogWriter.WriteInfo(TAG, methodTag, "Duration set to: " + duration);
                }
                else
                {
                    LogWriter.WriteInfo(TAG, methodTag, "No duration provided, using default of 30 minutes");
                }


                if (recurrenceType != null)
                {
                    recurrPatt = calEvent.GetRecurrencePattern();
                    if (endDate != null)
                    {
                        recurrPatt.PatternEndDate = DateTime.ParseExact(endDate, "M/d/yyyy", null);
                        LogWriter.WriteInfo(TAG, methodTag, "End date of recurrence set to: " + endDate);
                    }
                    else
                    {
                        LogWriter.WriteWarning(TAG, methodTag, "Recurrence date not set, infinite recurrence may cause problems when searching");
                    }

                    if (recurrenceType == "Daily")
                    {
                        recurrPatt.RecurrenceType = Outlook.OlRecurrenceType.olRecursDaily;
                    }
                    else if (recurrenceType == "Weekly")
                    {
                        recurrPatt.RecurrenceType = Outlook.OlRecurrenceType.olRecursWeekly;
                    }
                    else if (recurrenceType == "Monthly")
                    {
                        recurrPatt.RecurrenceType = Outlook.OlRecurrenceType.olRecursMonthly;
                    }
                    else if (recurrenceType == "Yearly")
                    {
                        recurrPatt.RecurrenceType = Outlook.OlRecurrenceType.olRecursYearly;
                    }

                    LogWriter.WriteInfo(TAG, methodTag, "Recurrence type set to: " + recurrenceType);
                }

                foreach (String contact in recipients)
                {
                    calEvent.Recipients.Add(contact);
                    LogWriter.WriteInfo(TAG, methodTag, "Adding recipient: " + contact + " to meeting invite");
                }
            }
            else
            {
                LogWriter.WriteWarning(TAG, methodTag, "Calendar event is null, unable to continue with creating event");
                throw new NullReferenceException();
            }

            return(calEvent);
        }
        /// <summary>
        /// Updates the attributes of a specific event
        /// </summary>
        /// <param name="calEvent">Event to be updated</param>
        /// <param name="eventDate">Date of the specific event to be updated M/d/yyyy hh:mm:ss tt</param>
        /// <param name="updatedTitle">Updated title if desired</param>
        /// <param name="updatedStartDate">Updated start date if desired</param>
        /// <param name="updatedDuration">Updated duration if desired</param>
        /// <param name="recipients">Additonal recipients if desired</param>
        /// <returns></returns>
        internal static Outlook.AppointmentItem UpdateEvent(Outlook.AppointmentItem calEvent, string eventDate, string updatedTitle, string updatedStartDate,
                                                            string updatedDuration, string[] recipients)
        {
            string methodTag = "UpdateEvent";

            LogWriter.WriteInfo(TAG, methodTag, "Starting: " + methodTag + " in " + TAG);

            Outlook.AppointmentItem   agendaMeeting = null;
            Outlook.RecurrencePattern recurrPatt    = null;


            if (calEvent != null)
            {
                if (eventDate != null)
                {
                    LogWriter.WriteInfo(TAG, methodTag, "Obtaining specific event on date: " + eventDate + " with title: " + calEvent.Subject);
                    recurrPatt    = calEvent.GetRecurrencePattern();
                    agendaMeeting = recurrPatt.GetOccurrence(DateTime.Parse(eventDate));
                }
                else
                {
                    LogWriter.WriteWarning(TAG, methodTag, "No event date specified, may cause issues finding event if it is a recurring event");
                    agendaMeeting = calEvent;
                }

                if (updatedTitle != null)
                {
                    LogWriter.WriteInfo(TAG, methodTag, "Updating the events title to: " + updatedTitle);
                    agendaMeeting.Subject = updatedTitle;
                }
                else
                {
                    LogWriter.WriteInfo(TAG, methodTag, "No updated subject specified, keeping subject the same");
                }

                if (updatedDuration != null)
                {
                    LogWriter.WriteInfo(TAG, methodTag, "Updating the events duration to: " + updatedDuration);
                    agendaMeeting.Duration = Convert.ToInt32(updatedDuration);
                }
                else
                {
                    LogWriter.WriteInfo(TAG, methodTag, "Updated duration not specified, keepign duration the same");
                }

                foreach (String contact in recipients)
                {
                    agendaMeeting.Recipients.Add(contact);
                    LogWriter.WriteInfo(TAG, methodTag, "Adding recipient: " + contact + " to meeting invite");
                }

                if (updatedStartDate != null)
                {
                    LogWriter.WriteInfo(TAG, methodTag, "Updating the events start date to: " + updatedStartDate);
                    agendaMeeting.Start = DateTime.Parse(updatedStartDate);
                }
                else
                {
                    LogWriter.WriteInfo(TAG, methodTag, "Updated start date not specified, keeping start date the same");
                }


                agendaMeeting.Save();
                LogWriter.WriteInfo(TAG, methodTag, "Event updated sucessfully");
            }
            else
            {
                LogWriter.WriteWarning(TAG, methodTag, "Calendar event is null, unable to continue with update event");
                throw new NullReferenceException();
            }

            return(agendaMeeting);
        }
Exemple #13
0
 public OLCalItem(Outlook.AppointmentItem calItem)
 {
     this.calItem = calItem;
     if (calItem.IsRecurring)
         pattern = calItem.GetRecurrencePattern ();
 }
Exemple #14
0
        private static void ProcessFolder(Outlook.Folder folder, List <HeadsUpItem> returnItems)
        {
            Console.WriteLine(folder.Name);

            DateTime now = DateTime.Now;
            // Set end value
            DateTime lookAhead = now.AddDays(7);
            // Initial restriction is Jet query for date range
            string timeSlotFilter =
                "[Start] >= '" + now.ToString("g")
                + "' AND [Start] <= '" + lookAhead.ToString("g") + "'";

            Outlook.Items items = folder.Items;
            items.Sort("[Start]");
            items.IncludeRecurrences = true;
            items = items.Restrict(timeSlotFilter);
            foreach (object item in items)
            {
                Outlook.AppointmentItem appointment = item as Outlook.AppointmentItem;
                Outlook.TaskItem        task        = item as Outlook.TaskItem;

                if (appointment != null)
                {
                    HeadsUpItem newItem = new HeadsUpItem();
                    newItem.Title     = appointment.Subject;
                    newItem.Start     = appointment.Start;
                    newItem.End       = appointment.End;
                    newItem.Location  = appointment.Location;
                    newItem.Ignorable = true;
                    Outlook.RecurrencePattern pattern = appointment.GetRecurrencePattern();
                    if (appointment.RecurrenceState == Outlook.OlRecurrenceState.olApptOccurrence &&
                        pattern.RecurrenceType == Outlook.OlRecurrenceType.olRecursWeekly)
                    {
                        Console.WriteLine("  Ignore:" + appointment.Subject);
                    }
                    else
                    {
                        newItem.Ignorable = false;
                        Console.WriteLine("  A: " + appointment.Subject);
                        Console.WriteLine("      S: " + appointment.Start.ToString("g"));
                        Console.WriteLine("      E: " + appointment.End.ToString("g"));
                    }

                    returnItems.Add(newItem);
                }
                else if (task != null)
                {
                    Console.WriteLine("  T: " + task.Subject);
                }
                else
                {
                    Console.WriteLine("  ERR: Unknown Type: " + item.GetType());
                }
            }


            foreach (Outlook.Folder subFolder in folder.Folders)
            {
                ProcessFolder(subFolder, returnItems);
            }
        }