コード例 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var scheduler      = TaskScheduler.FromCurrentSynchronizationContext();
            var outlookService = new OutlookCalendarService();

            outlookService.GetOutlookAppointmentsAsync(0, 2).ContinueWith(task => AddEventToTest(task.Result, scheduler));
        }
コード例 #2
0
        private void Button_Click_Outlook(object sender, RoutedEventArgs e)
        {
            MyGrid.IsEnabled = false;
            var outlookService = new OutlookCalendarService();

            outlookService.GetOutlookAppointmentsAsync(0, 3).ContinueWith(ContinuationAction, TaskScheduler.FromCurrentSynchronizationContext());
        }
コード例 #3
0
        private async Task GetOutlookProfileListInternal()
        {
            OutlookProfileList = await OutlookCalendarService.GetOutLookProfieListAsync();

            if (OutlookProfileList == null)
            {
                MessageService.ShowMessageAsync("Failed to fetch outlook profiles. Please try again.");
            }
        }
コード例 #4
0
        private void GetInformation(IEnumerable <Calendar> list, TaskScheduler currentSynchronizationContext, GoogleCalendarService googleCalenderService)
        {
            string calenderId = string.Empty;
            var    calender   = list.FirstOrDefault(calendar => calendar.Name.Contains("Office"));

            if (calender != null)
            {
                calenderId = calender.Id;
            }
            var outlookService = new OutlookCalendarService();

            GetEqualAppointments(googleCalenderService, outlookService, calenderId).ContinueWith(ContinuationActionGoogleAppointments, currentSynchronizationContext);
        }
コード例 #5
0
        public async Task TestOutlookCalendarServiceSample()
        {
            // arrange
            var service = new OutlookCalendarService(
                msaToken: new TokenEntity()
            {
                TokenType   = "bearer",
                AccessToken = TestContext.Parameters["OUTLOOK_TEST_TOKEN"]
            }
                );

            // act
            var result = await service.GetEventsSample();

            // assert
            Assert.IsNotNull(result);
        }
コード例 #6
0
        private async Task CleanOutlookCalendarInternal()
        {
            if ((SelectedProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.AlternateMailBoxCalendar) &&
                 (SelectedProfile.OutlookSettings.OutlookMailBox == null || SelectedProfile.OutlookSettings.OutlookFolder == null)) ||
                (SelectedProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.AlternateProfile) &&
                 string.IsNullOrEmpty(SelectedProfile.OutlookSettings.OutlookProfileName)))
            {
                MessageService.ShowMessageAsync("Please select a Outlook calendar to reset.");
                return;
            }

            var task =
                await
                MessageService.ShowConfirmMessage(
                    "Are you sure you want to reset events from 10 year past and 10 year future?");

            if (task != MessageDialogResult.Affirmative)
            {
                return;
            }

            var calendarSpecificData = new Dictionary <string, object>
            {
                {
                    "ProfileName", SelectedProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.AlternateProfile)
                        ? SelectedProfile.OutlookSettings.OutlookProfileName
                        : null
                },
                {
                    "OutlookCalendar", SelectedProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.AlternateMailBoxCalendar)
                        ? SelectedProfile.OutlookSettings.OutlookFolder
                        : null
                },
                { "AddAsAppointments", SelectedProfile.CalendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AsAppointments) }
            };

            var result = await OutlookCalendarService.ClearCalendar(calendarSpecificData);

            if (!result)
            {
                MessageService.ShowMessageAsync("Reset calendar failed.");
            }
        }
コード例 #7
0
        private async Task ResetOutlookCalendarInternal()
        {
            if ((IsDefaultMailBox == OutlookOptionsEnum.AlternateCalendar &&
                 (SelectedOutlookMailBox == null || SelectedOutlookCalendar == null)) ||
                (IsDefaultProfile == OutlookOptionsEnum.AlternateProfile &&
                 string.IsNullOrEmpty(SelectedOutlookProfileName)))
            {
                MessageService.ShowMessageAsync("Please select a Outlook calendar to reset.");
                return;
            }

            var task =
                await
                MessageService.ShowConfirmMessage(
                    "Are you sure you want to reset events from 10 year past and 10 year future?");

            if (task != MessageDialogResult.Affirmative)
            {
                return;
            }

            var calendarSpecificData = new Dictionary <string, object>
            {
                {
                    "ProfileName", IsDefaultProfile != OutlookOptionsEnum.DefaultProfile
                        ? SelectedOutlookProfileName
                        : null
                },
                {
                    "OutlookCalendar", IsDefaultMailBox != OutlookOptionsEnum.DefaultCalendar
                        ? SelectedOutlookCalendar
                        : null
                },
                { "AddAsAppointments", AddAsAppointments }
            };

            var result = await OutlookCalendarService.ResetCalendar(calendarSpecificData);

            if (!result)
            {
                MessageService.ShowMessageAsync("Reset calendar failed.");
            }
        }
コード例 #8
0
        public static async Task <System.Collections.Generic.List <Models.CalendarEntry> > GetCalendars(TokenEntity msaToken, TokenEntity googleToken,
                                                                                                        ILogger logger)
        {
            var start  = DateTime.Now.Date.AddDays(-7);
            var end    = DateTime.Now.Date.AddDays(Constants.CalendarWeeks * 7);
            var events = new System.Collections.Generic.List <CalendarEntry>();

            try
            {
                var holidays = new System.Collections.Generic.List <CalendarEntry>();

                // combine public and school holidays
                var publicHolidaysService = new PublicHolidaysService();
                var schoolHolidaysService = new SchoolHolidaysService();

                holidays.AddRange(await publicHolidaysService.GetEvents(start, end));
                holidays.AddRange(await schoolHolidaysService.GetEvents(start, end, logger));
                var deduplicatedHolidays = holidays.GroupBy(x => x.Date).Select(y => y.First()).ToList <CalendarEntry>();
                events.AddRange(deduplicatedHolidays);

                var googleCalendarService = new GoogleCalendarService(
                    googleToken,
                    calendarId: Util.GetEnvironmentVariable("GOOGLE_CALENDAR_ID"),
                    timeZone: Util.GetEnvironmentVariable("CALENDAR_TIMEZONE"));
                var googleEvents = await googleCalendarService.GetEvents(start, end, isPrimary : true);

                events.AddRange(googleEvents);

                var outlookCalendarService = new OutlookCalendarService(msaToken,
                                                                        timeZone: Util.GetEnvironmentVariable("CALENDAR_TIMEZONE"));
                var outlookEvents = await outlookCalendarService.GetEvents(start, end, isSecondary : true);

                events.AddRange(outlookEvents);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(events);
        }
コード例 #9
0
        public async Task TestOutlookCalendarService1Week()
        {
            // arrange
            var service = new OutlookCalendarService(
                msaToken: new TokenEntity()
            {
                TokenType   = "bearer",
                AccessToken = TestContext.Parameters["OUTLOOK_TEST_TOKEN"]
            }
                );

            var start = new DateTime(2019, 4, 22);
            var end   = new DateTime(2019, 5, 25);

            // act
            var result = await service.GetEvents(start, end);

            // assert
            Assert.IsNotNull(result);
            Assert.Greater(result.Count, 0);
        }
コード例 #10
0
 private void Button_Click_Outlook(object sender, RoutedEventArgs e)
 {
     MyGrid.IsEnabled = false;
     var outlookService = new OutlookCalendarService();
     outlookService.GetOutlookAppointmentsAsync(0, 3).ContinueWith(ContinuationAction, TaskScheduler.FromCurrentSynchronizationContext());
 }
コード例 #11
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
     var outlookService = new OutlookCalendarService();
     outlookService.GetOutlookAppointmentsAsync(0, 2).ContinueWith(task => AddEventToTest(task.Result, scheduler));
 }
コード例 #12
0
        private void GetInformation(IEnumerable<Calendar> list, TaskScheduler currentSynchronizationContext, GoogleCalendarService googleCalenderService)
        {
            string calenderId = string.Empty;
            var calender = list.FirstOrDefault(calendar => calendar.Name.Contains("Office"));

            if (calender != null)
            {
                calenderId = calender.Id;
            }
            var outlookService = new OutlookCalendarService();

            GetEqualAppointments(googleCalenderService, outlookService, calenderId).ContinueWith(ContinuationActionGoogleAppointments, currentSynchronizationContext);
        }
コード例 #13
0
        private async Task<List<Appointment>> GetEqualAppointments(GoogleCalendarService googleCalenderService, OutlookCalendarService outlookCalendarService, string calenderId)
        {
            List<Appointment> googleAppointments = await googleCalenderService.GetCalendarEventsInRangeAsync(0, 2, calenderId);
            List<Appointment> outLookAppointments = await outlookCalendarService.GetOutlookAppointmentsAsync(0, 2);

            return (from lookAppointment in outLookAppointments
                    let isAvailable = googleAppointments.Any(appointment => appointment.Equals(lookAppointment))
                    where isAvailable
                    select lookAppointment).ToList();
        }
コード例 #14
0
 private List <OutlookMailBox> GetOutlookMailBox()
 {
     return(OutlookCalendarService.GetAllMailBoxes(SelectedProfile.OutlookSettings.OutlookProfileName ?? string.Empty));
 }
コード例 #15
0
        private async Task <List <Appointment> > GetEqualAppointments(GoogleCalendarService googleCalenderService, OutlookCalendarService outlookCalendarService, string calenderId)
        {
            List <Appointment> googleAppointments = await googleCalenderService.GetCalendarEventsInRangeAsync(0, 2, calenderId);

            List <Appointment> outLookAppointments = await outlookCalendarService.GetOutlookAppointmentsAsync(0, 2);

            return((from lookAppointment in outLookAppointments
                    let isAvailable = googleAppointments.Any(appointment => appointment.Equals(lookAppointment))
                                      where isAvailable
                                      select lookAppointment).ToList());
        }
コード例 #16
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "get", Route = null)] HttpRequest req,
            [Table(Constants.TOKEN_TABLE, partitionKey: Constants.TOKEN_PARTITIONKEY, rowKey: Constants.MSATOKEN_ROWKEY)] TokenEntity msaToken,
            [Table(Constants.TOKEN_TABLE, partitionKey: Constants.TOKEN_PARTITIONKEY, rowKey: Constants.GOOGLETOKEN_ROWKEY)] TokenEntity googleToken,
            ILogger log)
        {
            string googleCalendarResult;
            string outlookCalendarResult;
            int    statusCode = StatusCodes.Status200OK;

            // check Google calendar
            try
            {
                var calendarService = new GoogleCalendarService(
                    googleToken,
                    calendarId: Util.GetEnvironmentVariable("GOOGLE_CALENDAR_ID"),
                    timeZone: Util.GetEnvironmentVariable("CALENDAR_TIMEZONE"));
                var result = await calendarService.GetEventsSample();

                googleCalendarResult = result?.Count.ToString() ?? "empty resultset";
                log.LogInformation(googleCalendarResult);
            }
            catch (Exception ex)
            {
                googleCalendarResult = ex.Message;
                log.LogError(ex, nameof(GoogleCalendarService));
                statusCode = StatusCodes.Status424FailedDependency;
            }

            // check Outlook calender
            try
            {
                var calendarService = new OutlookCalendarService(msaToken,
                                                                 timeZone: Util.GetEnvironmentVariable("CALENDAR_TIMEZONE"));
                var result = await calendarService.GetEventsSample();

                outlookCalendarResult = result?.Count.ToString() ?? "empty resultset";
                log.LogInformation(googleCalendarResult);
            }
            catch (Exception ex)
            {
                outlookCalendarResult = ex.Message;
                log.LogError(ex, nameof(OutlookCalendarService));
                statusCode = StatusCodes.Status424FailedDependency;
            }

            // check MSA Token
            if (msaToken == null)
            {
                statusCode = StatusCodes.Status424FailedDependency;
            }

            // check Google Token
            if (googleToken == null)
            {
                statusCode = StatusCodes.Status424FailedDependency;
            }

            // assemble service info
            return(statusCode == StatusCodes.Status200OK
                 ? (ActionResult) new OkObjectResult(new
            {
                home = Environment.GetEnvironmentVariable("HOME", EnvironmentVariableTarget.Process),
                webSiteName = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME", EnvironmentVariableTarget.Process),
                appRoot = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase),
                staticFilesRoot = Util.GetApplicationRoot(),
                googleCalendarResult,
                outlookCalendarResult,
                msaToken,
                googleToken
            })
                 : (ActionResult) new StatusCodeResult(statusCode));
        }