Exemplo n.º 1
0
        public static FCEventModel ToEvent(Task task)
        {
            var newEvent = new FCEventModel()
            {
                id        = task.Id,
                title     = task.Name,
                app       = "Toodledo",
                completed = false,
                color     = GetColor(task),
                editable  = true,
                repeated  = false,
                priority  = (int)task.Priority
            };

            if (task.Due.TimeOfDay.TotalSeconds.Equals(0))
            {
                newEvent.allDay = true;
                newEvent.start  = (task.Start.Year == 1 ? task.Due.ToString("yyyy-MM-dd") : task.Start.ToString("yyyy-MM-dd"));
                newEvent.end    = (task.Start == task.Due
                    ? task.Due.ToString("yyyy-MM-dd")
                    : task.Due.AddDays(1).ToString("yyyy-MM-dd"));
            }
            else
            {
                newEvent.allDay = false;
                newEvent.start  = (task.Start.Year == 1 ? task.Due.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm") : task.Start.ToString("yyyy-MM-dd HH:mm"));
                newEvent.end    = task.Due.ToString("yyyy-MM-dd HH:mm");
            }
            return(newEvent);
        }
Exemplo n.º 2
0
        public FCEventModel UpdateTask(FCEventModel model)
        {
            Task task;

            if (model.id != 0)
            {
                var query = new TaskQuery()
                {
                    Id = model.id
                };
                task = Tasks.GetTasks(query).Tasks.FirstOrDefault();
            }
            else
            {
                task = new Task();
            }
            if (task != null)
            {
                task = Converter.ToTask(model, task);
            }
            if (model.id == 0)
            {
                var newid = Tasks.AddTask(task);
                model = Converter.ToEvent(Tasks.GetTasks(new TaskQuery()
                {
                    Id = newid
                }).Tasks.FirstOrDefault());
            }
            else
            {
                Tasks.EditTask(task);
            }

            return(model);
        }
Exemplo n.º 3
0
        public IEnumerable <FCEventModel> Events()
        {
            var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", "fbevents.ics");
            var file     = new FileInfo(filePath);
            IICalendarCollection calList = new CalendarCollection();

            var list        = new List <FCEventModel>();
            var fbEventFeed = ConfigurationManager.AppSettings["FBEventFeed"];
            var fbEventKey  = ConfigurationManager.AppSettings["FBEventKey"];
            var fullPath    = fbEventFeed + "&key=" + fbEventKey;

            WebClient client = new WebClient();

            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            if (!IsFileLocked(file) && file.LastWriteTime < DateTime.Now.AddMinutes(-30))
            {
                client.DownloadFile(fullPath, filePath);
            }
            if (!IsFileLocked(file))
            {
                calList = Calendar.LoadFromFile(filePath);
            }

            TimeZoneInfo easternZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

            foreach (var cal in calList)
            {
                foreach (var item in cal.Events)
                {
                    var newEvent = new FCEventModel()
                    {
                        title = item.Summary,
                        start = TimeZoneInfo.ConvertTimeFromUtc(item.Start.Value, easternZone).ToString(),
                        end   = TimeZoneInfo.ConvertTimeFromUtc(item.End.Value, easternZone).ToString()
                    };
                    list.Add(newEvent);
                }
            }

            return(list);
        }
Exemplo n.º 4
0
        public IEnumerable <FCEventModel> DailyForecast()
        {
            var list     = new List <FCEventModel>();
            var request  = new ForecastIORequest(ForecastKey, (float)40.083451, (float)-83.104796, Unit.us);
            var response = request.Get();

            foreach (var day in response.daily.data)
            {
                var newEvent = new FCEventModel()
                {
                    title     = String.Format("{0} - {1}", Math.Round(day.temperatureMax, 0), day.icon),
                    allDay    = true,
                    start     = new DateTime(1970, 1, 1).AddSeconds(day.time).ToString("yyyy-MM-dd"),
                    app       = "Weather",
                    rendering = "background"
                };
                list.Add(newEvent);
            }

            return(list);
        }
Exemplo n.º 5
0
        public IEnumerable <FCEventModel> HourlyForecast()
        {
            var list     = new List <FCEventModel>();
            var request  = new ForecastIORequest(ForecastKey, (float)40.083451, (float)-83.104796, Unit.us);
            var response = request.Get();

            foreach (var hour in response.hourly.data)
            {
                var wTime    = new DateTime(1970, 1, 1).AddSeconds(hour.time);
                var newEvent = new FCEventModel()
                {
                    title     = String.Format("{0} - {1}", Math.Round(hour.temperature, 0), hour.icon),
                    allDay    = false,
                    start     = wTime.ToString("yyyy-MM-dd HH:mm"),
                    end       = wTime.AddMinutes(30).ToString("yyyy-MM-dd HH:mm"),
                    app       = "Weather",
                    rendering = "background"
                };
                list.Add(newEvent);
            }

            return(list);
        }
Exemplo n.º 6
0
        public static Task ToTask(FCEventModel model, Task task)
        {
            task.Name = model.title;
            //if checking/unchecking completed
            if (task.Completed.Year.Equals(1) && model.completed)
            {
                task.Completed = DateTime.Today;
            }
            if (!task.Completed.Year.Equals(1) && !model.completed)
            {
                task.Completed = new DateTime(1, 1, 1);
            }


            //start and end time
            DateTime startTime;
            DateTime endTime;

            if (DateTime.TryParse(model.start, null, System.Globalization.DateTimeStyles.RoundtripKind, out startTime))
            {
                task.Start = model.allDay ? startTime.Date : startTime;
            }
            else
            {
                task.Start = DateTime.MinValue;
            }
            if (DateTime.TryParse(model.end, null, System.Globalization.DateTimeStyles.RoundtripKind, out endTime))
            {
                task.Due = model.allDay && endTime != DateTime.MinValue ? endTime.Date.AddDays(-1) : endTime;
            }
            else
            {
                task.Due = task.Start.Year != 1 ? task.Start.AddMinutes(30) : DateTime.MinValue;
            }

            return(task);
        }