示例#1
0
        async private void ShowAllAppointments()
        {
            try
            {
                FindAppointmentsOptions findOptions = new FindAppointmentsOptions();
                findOptions.MaxCount = 20;
                findOptions.FetchProperties.Add(AppointmentProperties.Subject);
                findOptions.FetchProperties.Add(AppointmentProperties.StartTime);
                findOptions.FetchProperties.Add(AppointmentProperties.Location);
                findOptions.FetchProperties.Add(AppointmentProperties.Details);

                int appointmentsCount = 0;
                IReadOnlyList <Appointment> appointments = await appointmentStore.FindAppointmentsAsync(DateTime.Now, TimeSpan.FromDays(5), findOptions);

                if (appointments != null)
                {
                    appointmentsCount = appointments.Count;
                    if (appointmentsCount > 0)
                    {
                        AppointmentListBox.ItemsSource       = appointments;
                        AppointmentListBox.SelectionChanged += AppointmentListBox_SelectionChanged;
                    }
                }
                status.Log(string.Format(CultureInfo.CurrentCulture,
                                         LocalizableStrings.CALENDAR_FIND_APPOINTMENTS_RESULT, appointmentsCount));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("CalendarPage.ShowAllAppointments: " + ex.ToString());
                status.Log(ex.GetType().ToString());
            }
        }
        private async void StartSearchAppointments()
        {
            listLog.Items.Add("Searching  Appointments...");
            listLog.SelectedIndex = listLog.Items.Count - 1;

            AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);

            FindAppointmentsOptions options = new FindAppointmentsOptions();

            options.FetchProperties.Add(AppointmentProperties.Subject);
            options.FetchProperties.Add(AppointmentProperties.Location);
            options.FetchProperties.Add(AppointmentProperties.Invitees);
            options.FetchProperties.Add(AppointmentProperties.Details);
            options.FetchProperties.Add(AppointmentProperties.StartTime);
            options.FetchProperties.Add(AppointmentProperties.ReplyTime);
            options.FetchProperties.Add(AppointmentProperties.Duration);
            options.FetchProperties.Add(AppointmentProperties.IsCanceledMeeting);
            options.FetchProperties.Add(AppointmentProperties.IsOrganizedByUser);
            options.FetchProperties.Add(AppointmentProperties.OnlineMeetingLink);
            options.FetchProperties.Add(AppointmentProperties.Organizer);
            options.FetchProperties.Add(AppointmentProperties.OriginalStartTime);
            options.FetchProperties.Add(AppointmentProperties.Sensitivity);


            var utcDateTime = new DateTime(DateTime.Now.Year, 01, 01, 00, 00, 0, DateTimeKind.Utc);
            IReadOnlyList <Appointment> apointments = await appointmentStore.FindAppointmentsAsync(utcDateTime, TimeSpan.FromDays(365), options);

            listLog.Items.Add("Total appointments from : " + utcDateTime + " to " + utcDateTime.AddDays(365).ToUniversalTime() + " is: " + apointments.Count.ToString());
            Save_Appointements(apointments);
        }
示例#3
0
        private async Task CalendarCall(object sender, RoutedEventArgs e)
        {
            AppointmentStore calendar = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);

            options1.FetchProperties.Add(AppointmentProperties.Subject);
            options1.FetchProperties.Add(AppointmentProperties.Details);
            options1.FetchProperties.Add(AppointmentProperties.DetailsKind);

            int DaysToCheckForAppointments;

            objTextBox.Text = questionForDaysAppointments;
            await  Speak(sender, e);

            Debug.WriteLine("endiamesooooooooooooooooooooooooooo \n");
            await Task.Delay(TimeSpan.FromSeconds(3));

            await SpeakToComputer(sender, e);

            Debug.WriteLine("I said " + objTextBox.Text);
            if (!(Int32.TryParse(objTextBox.Text.Split(' ').First(), out DaysToCheckForAppointments)))
            {
                Debug.WriteLine(DaysToCheckForAppointments);
                DaysToCheckForAppointments = 1;
            }

            var iteratingAppointments = await calendar.FindAppointmentsAsync(DateTimeOffset.Now, TimeSpan.FromDays(DaysToCheckForAppointments), options1);

            if (!iteratingAppointments.Any())
            {
                objTextBox.Text = "Δεν υπάρχουν ραντεβού για τις επόμενες " + DaysToCheckForAppointments + " μέρες.";

                return;
            }
            foreach (var i in iteratingAppointments)
            {
                var eventName     = i.Subject;
                var eventDay      = i.StartTime.DayOfWeek;
                var eventPlace    = i.Location;
                var timeFormatter = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("hour minute");
                var eventTime     = timeFormatter.Format(i.StartTime.DateTime);

                objTextBox.Text = "Έχεις " + eventName + " στις " + eventDay + " την " + eventPlace + " την " + eventTime;
                if (i == iteratingAppointments.ElementAt(iteratingAppointments.Count() - 1))
                {
                    return;
                }
                stream = await synth.SynthesizeTextToStreamAsync(objTextBox.Text);


                mediaElement.SetSource(stream, stream.ContentType);
                mediaElement.Play();
                await Task.Delay(TimeSpan.FromSeconds(5));
            }

            return;
        }
示例#4
0
        public static async Task <IReadOnlyList <Appointment> > GetAppointments(DateTime startDay, int howManyDays)
        {
            await SetAppointmentStore();

            var findOptions = GetFindOptions();

            return
                (await
                 _appointmentStore.FindAppointmentsAsync(startDay.Date, TimeSpan.FromDays(howManyDays), findOptions));
        }
示例#5
0
        public static async Task <String> GetResponse(string question)
        {
            //AIService aiService;
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(URL);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", clientAccessToken);
            string query = question;

            urlParameters += "?v=" + v + queryString + query + language + sessionId;
            HttpResponseMessage response = client.GetAsync(urlParameters).Result;

            string responseBody = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                dynamic json = JObject.Parse(responseBody);
                answer = json.result.fulfillment.speech;

                if ((string)json["result"]["action"] == "ScheduleEvent")
                {
                    if ((string)json["result"]["parameters"]["startTime"] != null)
                    {
                        startTime = (string)json["result"]["parameters"]["startTime"];
                    }

                    if ((string)json["result"]["parameters"]["endTime"] != null)
                    {
                        endTime = (string)json["result"]["parameters"]["endTime"];
                    }

                    if ((string)json["result"]["parameters"]["title"] != null)
                    {
                        title = (string)json["result"]["parameters"]["title"];
                    }

                    if ((string)json["result"]["parameters"]["date"] != null)
                    {
                        date = (string)json["result"]["parameters"]["date"];
                    }
                }

                if ((string)json["result"]["action"] == "getCalendarEvents")
                {
                    if ((string)json["result"]["parameters"]["date"] != null)
                    {
                        date = (string)json["result"]["parameters"]["date"];
                    }
                }

                if ((bool)json["result"]["actionIncomplete"] == false && (string)json["result"]["action"] == "ScheduleEvent")
                {
                    // Create an Appointment that should be added the user' s appointments provider app.
                    var appointment = new Windows.ApplicationModel.Appointments.Appointment();

                    string   dateTime = AiResponse.date + " " + AiResponse.startTime;
                    DateTime myDate   = DateTime.ParseExact(dateTime, "yyyy-MM-dd HH:mm:ss",
                                                            System.Globalization.CultureInfo.InvariantCulture) + TimeSpan.FromDays(1);
                    appointment.StartTime = myDate;

                    if (AiResponse.endTime != "")
                    {
                        DateTime dt = DateTime.Parse(endTime);
                        endTime = dt.ToString("HH:mm");
                        string start    = startTime.Substring(0, 2);
                        string end      = endTime.Substring(0, 2);
                        int    startT   = Convert.ToInt32(start);
                        int    endT     = Convert.ToInt32(end);
                        int    duration = endT - startT;
                        appointment.Duration = TimeSpan.FromHours(duration);
                    }
                    else
                    {
                        appointment.Duration = TimeSpan.FromHours(1);
                    }

                    appointment.Subject  = AiResponse.title;
                    appointment.Reminder = TimeSpan.FromMinutes(20);

                    String appointmentId = await AppointmentManager.ShowEditNewAppointmentAsync(appointment);

                    //if (appointmentId != String.Empty)
                    //{
                    //    appoint = "Appointment Id: " + appointmentId;
                    //}
                    //else
                    //{
                    //    appoint = "Appointment not added.";
                    //}
                }

                if ((bool)json["result"]["actionIncomplete"] == false && (string)json["result"]["action"] == "getCalendarEvents")
                {
                    AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);

                    //var dateToShow = DateTime.Now.AddDays(0);
                    string   dateT  = AiResponse.date;
                    DateTime myDate = DateTime.ParseExact(dateT, "yyyy-MM-dd",
                                                          System.Globalization.CultureInfo.InvariantCulture) + TimeSpan.FromDays(0);
                    var duration = TimeSpan.FromHours(24);

                    var appCalendars = await appointmentStore.FindAppointmentsAsync(myDate, duration);
                }
            }

            urlParameters = "";
            return(answer);
        }
示例#6
0
        public static async Task <String> GetResponse(string question)
        {
            //AIService aiService;
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(URL);
            //AppointmentStore appointmentStore;
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", clientAccessToken);
            string query = question;

            urlParameters += "?v=" + v + queryString + query + language + sessionId;
            HttpResponseMessage response = client.GetAsync(urlParameters).Result;

            string responseBody = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                dynamic json = JObject.Parse(responseBody);
                answer = json.result.fulfillment.speech;
                string temp = (string)json["result"]["parameters"]["createEvent"];

                if (temp == "create" || temp == "make" || temp == "new" || temp == "put in" || temp == "add an" || temp == "put on" || temp == "I will be busy" || temp == "can I schedule" || temp == "I have an event")
                {
                    if ((bool)json["result"]["actionIncomplete"] == false && (string)json["result"]["action"] == "ScheduleEvent")
                    {
                        if ((string)json["result"]["parameters"]["startTime"] != null)
                        {
                            startTime = (string)json["result"]["parameters"]["startTime"];
                        }

                        if ((string)json["result"]["parameters"]["endTime"] != null)
                        {
                            endTime = (string)json["result"]["parameters"]["endTime"];
                        }

                        if ((string)json["result"]["parameters"]["title"] != null)
                        {
                            title = (string)json["result"]["parameters"]["title"];
                        }

                        if ((string)json["result"]["parameters"]["date"] != null)
                        {
                            date = (string)json["result"]["parameters"]["date"];
                        }
                        var appointment = new Windows.ApplicationModel.Appointments.Appointment();

                        if (AiResponse.startTime == "in the morning" || AiResponse.startTime == "morning")
                        {
                            startTime = "08:00:00";
                        }
                        else if (AiResponse.startTime == "in the afternoon" || AiResponse.startTime == "afternoon")
                        {
                            startTime = "12:00:00";
                        }
                        else if (AiResponse.startTime == "in the evening" || AiResponse.startTime == "evening")
                        {
                            startTime = "17:00:00";
                        }
                        else if (AiResponse.startTime == "night")
                        {
                            startTime = "20:00:00";
                        }

                        string   dateTime = AiResponse.date + " " + AiResponse.startTime;
                        DateTime myDate   = DateTime.ParseExact(dateTime, "yyyy-MM-dd HH:mm:ss",
                                                                System.Globalization.CultureInfo.InvariantCulture) + TimeSpan.FromDays(1);
                        appointment.StartTime = myDate;

                        if (AiResponse.endTime != "")
                        {
                            DateTime dt = DateTime.Parse(endTime);
                            endTime = dt.ToString("HH:mm");
                            string start    = startTime.Substring(0, 2);
                            string end      = endTime.Substring(0, 2);
                            int    startT   = Convert.ToInt32(start);
                            int    endT     = Convert.ToInt32(end);
                            int    duration = endT - startT;
                            appointment.Duration = TimeSpan.FromHours(duration);
                        }
                        else
                        {
                            appointment.Duration = TimeSpan.FromHours(1);
                        }

                        appointment.Subject  = AiResponse.title;
                        appointment.Reminder = TimeSpan.FromMinutes(20);

                        String appointmentId = await AppointmentManager.ShowEditNewAppointmentAsync(appointment);
                    }
                    else if ((bool)json["result"]["actionIncomplete"] == false && (string)json["result"]["action"] == "getCalendarEvents")
                    {
                        if ((string)json["result"]["parameters"]["date"] != null)
                        {
                            date = (string)json["result"]["parameters"]["date"];
                        }

                        AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);

                        //var dateToShow = DateTime.Now.AddDays(0);
                        string   dateT  = AiResponse.date;
                        DateTime myDate = DateTime.ParseExact(dateT, "yyyy-MM-dd",
                                                              System.Globalization.CultureInfo.InvariantCulture) + TimeSpan.FromDays(0);
                        var duration = TimeSpan.FromHours(24);

                        //appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);
                        var appCalendars = await appointmentStore.FindAppointmentsAsync(myDate, duration);

                        //answer = appCalendars.ToString();
                        if (appCalendars.Count == 0)
                        {
                            answer = "You have no events on that date";
                        }
                        else
                        {
                            answer += "\n";
                            foreach (var item in appCalendars)
                            {
                                string dur = "";
                                dur     = item.Duration.TotalMinutes + " minutes";
                                answer += "Event Start Time: " + item.StartTime.LocalDateTime.TimeOfDay + "\nDuration: " + dur + "\n";
                            }
                        }
                    }
                }
                else
                {
                    List <string> responses = new List <string>();
                    //answer = "I am not sure if I understand the question or request";
                    string four  = "I am not sure if I understand the question or request";
                    string one   = "I am a bit confused";
                    string two   = " Not sure if I am understanding";
                    string three = "I did not understand that";
                    responses.Add(four);
                    responses.Add(one);
                    responses.Add(two);
                    responses.Add(three);

                    Random rnd   = new Random();
                    int    n     = rnd.Next(0, 4);
                    var    value = responses.ElementAt(n);
                    answer        = value;
                    urlParameters = "";
                    return(answer);
                }
            }

            urlParameters = "";
            return(answer);
        }
示例#7
0
        //Load Calendar Event
        async Task LoadCalendarEvent()
        {
            try
            {
                Debug.WriteLine("Loading current calendar event.");

                AppointmentStore AppointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);

                IReadOnlyList <Appointment> Appointments = await AppointmentStore.FindAppointmentsAsync(DateTimeNow, TimeSpan.FromDays(1));

                if (Appointments.Any())
                {
                    DateTimeOffset CalendarAppoStartTime = Appointments[0].StartTime;
                    if (!String.IsNullOrEmpty(Appointments[0].Subject))
                    {
                        CalendarAppoName = Appointments[0].Subject;
                    }
                    else
                    {
                        CalendarAppoName = "Unknown event";
                    }
                    if (!String.IsNullOrEmpty(Appointments[0].Location))
                    {
                        CalendarAppoLocation = Appointments[0].Location;
                    }

                    if (Appointments[0].AllDay)
                    {
                        if (CalendarAppoStartTime.Date >= DateTimeNow.AddDays(1).Date)
                        {
                            if (!String.IsNullOrEmpty(CalendarAppoLocation))
                            {
                                CalendarAppoSummary = "(T All day) " + CalendarAppoLocation;
                            }
                            else
                            {
                                CalendarAppoSummary = "Tomorrow all the day";
                            }
                            CalendarAppoDateTime = "Tomorrow all day";
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(CalendarAppoLocation))
                            {
                                CalendarAppoSummary = "(All day) " + CalendarAppoLocation;
                            }
                            else
                            {
                                CalendarAppoSummary = "Today all the day";
                            }
                            CalendarAppoDateTime = "Today all day";
                        }
                    }
                    else
                    {
                        if (CalendarAppoStartTime.Date >= DateTimeNow.AddDays(1).Date)
                        {
                            if (!String.IsNullOrEmpty(CalendarAppoLocation))
                            {
                                if (setDisplay24hClock)
                                {
                                    CalendarAppoSummary  = "(T " + CalendarAppoStartTime.ToString("HH:mm") + ") " + CalendarAppoLocation;
                                    CalendarAppoDateTime = "(T " + CalendarAppoStartTime.ToString("HH:mm") + ")";
                                }
                                else
                                {
                                    CalendarAppoSummary  = "(T " + CalendarAppoStartTime.ToString("h:mm tt", vCultureInfoEng) + ") " + CalendarAppoLocation;
                                    CalendarAppoDateTime = "(T " + CalendarAppoStartTime.ToString("h:mm tt", vCultureInfoEng) + ")";
                                }
                            }
                            else
                            {
                                if (setDisplay24hClock)
                                {
                                    CalendarAppoSummary  = "Tomorrow at " + CalendarAppoStartTime.ToString("HH:mm");
                                    CalendarAppoDateTime = "Tomorrow at " + CalendarAppoStartTime.ToString("HH:mm");
                                }
                                else
                                {
                                    CalendarAppoSummary  = "Tomorrow at " + CalendarAppoStartTime.ToString("h:mm tt", vCultureInfoEng);
                                    CalendarAppoDateTime = "Tomorrow at " + CalendarAppoStartTime.ToString("h:mm tt", vCultureInfoEng);
                                }
                            }
                        }
                        else
                        {
                            //Check if event is active or needs to start
                            if (DateTimeNow >= CalendarAppoStartTime)
                            {
                                TimeSpan EventRemaining = CalendarAppoStartTime.Add(Appointments[0].Duration).Subtract(DateTimeNow);
                                int      RemainDays = EventRemaining.Days; int RemainHours = EventRemaining.Hours; int RemainMinutes = EventRemaining.Minutes;

                                string EventRemainingTime = "";
                                if (RemainDays != 0)
                                {
                                    EventRemainingTime = EventRemainingTime + RemainDays + "d ";
                                }
                                if (RemainHours != 0)
                                {
                                    EventRemainingTime = EventRemainingTime + RemainHours + "h ";
                                }
                                if (RemainMinutes != 0)
                                {
                                    EventRemainingTime = EventRemainingTime + RemainMinutes + "m ";
                                }
                                if (String.IsNullOrEmpty(EventRemainingTime))
                                {
                                    EventRemainingTime = "a minute ";
                                }

                                CalendarAppoEstimated = "Ends in " + EventRemainingTime;
                            }
                            else
                            {
                                //Set event start time
                                if (!String.IsNullOrEmpty(CalendarAppoLocation))
                                {
                                    if (setDisplay24hClock)
                                    {
                                        CalendarAppoSummary = "(" + CalendarAppoStartTime.ToString("HH:mm") + ") " + CalendarAppoLocation;
                                    }
                                    else
                                    {
                                        CalendarAppoSummary = "(" + CalendarAppoStartTime.ToString("h:mm tt", vCultureInfoEng) + ") " + CalendarAppoLocation;
                                    }
                                }
                                else
                                {
                                    if (setDisplay24hClock)
                                    {
                                        CalendarAppoSummary = "Today at " + CalendarAppoStartTime.ToString("HH:mm");
                                    }
                                    else
                                    {
                                        CalendarAppoSummary = "Today at " + CalendarAppoStartTime.ToString("h:mm tt", vCultureInfoEng);
                                    }
                                }

                                //Set time till start
                                TimeSpan EventStart = CalendarAppoStartTime.Subtract(DateTimeNow);
                                int      StartDays = EventStart.Days; int StartHours = EventStart.Hours; int StartMinutes = EventStart.Minutes;

                                string EventStartTime = "";
                                if (StartDays != 0)
                                {
                                    EventStartTime = EventStartTime + StartDays + "d ";
                                }
                                if (StartHours != 0)
                                {
                                    EventStartTime = EventStartTime + StartHours + "h ";
                                }
                                if (StartMinutes != 0)
                                {
                                    EventStartTime = EventStartTime + StartMinutes + "m ";
                                }
                                if (String.IsNullOrEmpty(EventStartTime))
                                {
                                    EventStartTime = "a minute ";
                                }

                                CalendarAppoEstimated = "Starts in " + EventStartTime;
                            }
                        }
                    }
                }
                else
                {
                    Debug.WriteLine("No calendar event has been found.");
                }
            }
            catch { }
        }