Пример #1
0
        public Task Filter()
        {
            if (!FilterQuery.IsNullOrEmpty())
            {
                try
                {
                    if (FilterQuery != _lastFilterQuery)
                    {
                        if (_lastFilterQuery.IsNullOrEmpty())
                        {
                            _cachedEvents = Events;
                        }
                        _lastFilterQuery = FilterQuery;
                        char[] toTrim = { ' ', '"', '\'' };
                        var    query  = FilterQuery.Trim(toTrim);
                        Events = _dbs.GetEvents(query).ToObservableCollection();
                    }
                }
                catch (Newtonsoft.Json.JsonException)
                {
                    throw new FormatException("Incorrect oauth token file format. Restore or delete it and try again");
                }
                catch (DataException)
                {
                    throw new DataException("Failed to modify database. Verify the connection and try again");
                }
            }
            else if (_cachedEvents != null)
            {
                Events = _cachedEvents;
            }

            return(Task.CompletedTask);
        }
Пример #2
0
        private EventPeriod <GXEvent>[] FetchEvents(int year)
        {
            var result     = new EventPeriod <GXEvent> [quarter];
            var yearEvents = _dbs.GetEvents(e => e.StartDate.Year == year);

            for (int i = 1; i <= quarter; i++)
            {
                Quarter qt;
                if (Enum.TryParse("Q" + i, out qt))
                {
                    var quarterEvents = yearEvents.Where(e => (e.StartDate.Month >= 12 / quarter * (i - 1) + 1) &&
                                                         (e.StartDate.Month <= 12 / quarter * i))
                                        .OrderBy(e => e.StartDate).ToArray();
                    result[i - 1] = new EventPeriod <GXEvent>(qt, quarterEvents);
                }
            }
            return(result);
        }