Ejemplo n.º 1
0
        private IEnumerable <DisplayEvent> ToDisplayEvents(IUserEventsCollectionPage events)
        {
            var eventResults = events.Select(e => new DisplayEvent(e.Subject, e.Start.DateTime, e.End.DateTime));

            var currentEvents = eventResults.OrderBy(e => e.Start)
                                .Where(e => e.Start.DayOfYear >= DateTime.Now.DayOfYear &&
                                       e.Start.DayOfYear <= DateTime.Now.DayOfYear + 1 &&
                                       e.End >= DateTime.Now);

            // Set HasBegan on passed event with active end time
            foreach (var ev in currentEvents)
            {
                if (ev.Start.TimeOfDay <= DateTime.Now.TimeOfDay)
                {
                    ev.HasBegan = true;
                }
            }

            return(currentEvents);
        }
Ejemplo n.º 2
0
        public static async Task <IEnumerable <TaskTarea> > GetUserTasks(string mail, DateTime from, DateTime to)
        {
            var err = "";
            IUserEventsCollectionPage tasks = null;

            try
            {
                try
                {
                    var tasks1 = await GetGraphClient(token).Users[mail].Request().GetAsync();


                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("-------------------------------------------------------");
                    Console.WriteLine("Acceso Correcto para el Usuario");
                    Console.WriteLine("         " + tasks1.Id + " " + tasks1.DisplayName + " " + tasks1.GivenName + " " + tasks1.JobTitle + "           ");
                    Console.WriteLine("         " + tasks1.City + " " + tasks1.Department + " " + tasks1.Country);
                    Console.WriteLine("         " + tasks1.MobilePhone + " " + tasks1.MySite);
                    Console.WriteLine("         " + tasks1.OfficeLocation + " " + tasks1.StreetAddress);
                    foreach (var phone in tasks1.BusinessPhones)
                    {
                        Console.WriteLine("telefono : " + phone.ToString());
                    }
                    Console.WriteLine("-------------------------------------------------------");
                    Console.ResetColor();
                    var utcFrom = from.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm");
                    var utcTo   = to.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm");
                    tasks = await GetGraphClient(token).Users[mail].Events
                            .Request().Top(1000)
                            .Select("subject, body, start, end")
                            .Filter($"start/dateTime le '{utcTo}' and end/dateTime ge '{utcFrom}'")
                            .GetAsync();
                }
                catch (ServiceException e)
                {
                    switch (e.Error.Code)
                    {
                    case "Request_ResourceNotFound":
                    case "ResourceNotFound":
                    case "ErrorItemNotFound":
                    case "itemNotFound":
                        err = JsonConvert.SerializeObject(new { Message = $"User '{email}' was not found." }, Formatting.Indented);
                        break;

                    case "ErrorInvalidUser":
                        err = JsonConvert.SerializeObject(new { Message = $"The requested user '{email}' is invalid." }, Formatting.Indented);
                        break;

                    case "AuthenticationFailure":
                        err = JsonConvert.SerializeObject(new { e.Error.Message }, Formatting.Indented);
                        break;

                    //case "TokenNotFound":
                    //    await httpContext.ChallengeAsync();
                    //    err = JsonConvert.SerializeObject(new { e.Error.Message }, Formatting.Indented);
                    //    break;
                    default:
                        err = JsonConvert.SerializeObject(new { Message = e.Error.Code }, Formatting.Indented);
                        break;
                    }
                }

                return(tasks.Select(x => new TaskTarea
                {
                    Title = x.Subject,
                    Status = 2,
                    Id = -1,
                    Notes = x.Body.Content,
                    Start = DateTime.Parse(x.Start.DateTime).ToUniversalTime(),
                    End = DateTime.Parse(x.End.DateTime).ToUniversalTime(),
                    Type = 4,
                    IsEditable = false,
                    ExternalId = x.Id
                }));
            }
            catch (Exception e)
            {
                Colorear();
                if (err == "")
                {
                    Console.WriteLine(e);
                }
                else
                {
                    Console.WriteLine(err);
                }
                Console.ResetColor();
                return(new List <TaskTarea>());
            }
        }