Exemplo n.º 1
0
 public void AddEvent(EventDescriptor ev)
 {
     EventsCollection.Add(ev);
     while (EventsCollection.Count > 1000)
     {
         EventsCollection.RemoveAt(0);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Saves all events that were managed with the current <see cref="TimedEventsManager"/> updating
        /// underlying events collection.
        /// </summary>
        /// <remarks>
        /// This method will rewrite content of the events collection was used to construct the current
        /// <see cref="TimedEventsManager"/> with events were managed by this manager. Also all delta-times
        /// of wrapped events will be recalculated according to the <see cref="TimedEvent.Time"/> of
        /// event wrappers.
        /// </remarks>
        public void SaveChanges()
        {
            _eventsCollection.Clear();

            var time = 0L;

            foreach (var e in Events)
            {
                var midiEvent = e.Event;
                midiEvent.DeltaTime = e.Time - time;
                _eventsCollection.Add(midiEvent);

                time = e.Time;
            }
        }
Exemplo n.º 3
0
        async void SyncSchedules()
        {
            if (!IsBusy)
            {
                Exception Error = null;
                BarberSchedulesList.Clear();
                EventsCollection.Clear();

                try
                {
                    IsBusy = true;
                    var Repository = new Repository();
                    var Items      = await Repository.GetSchedule();

                    foreach (var Schedule in Items)
                    {
                        BarberSchedulesList.Add(Schedule);

                        eventAppointment.From      = Schedule.DateTime;
                        eventAppointment.To        = eventAppointment.From.AddHours(0.5);
                        eventAppointment.EventName = Schedule.Service;
                        eventAppointment.Color     = Color.ForestGreen;

                        EventsCollection.Add(eventAppointment);
                    }
                }
                catch (Exception ex)
                {
                    Error = ex;
                }
                finally
                {
                    IsBusy = false;
                }
                if (Error != null)
                {
                    await _pageDialogService.DisplayAlertAsync("Erro", Error.Message, "OK");
                }
            }
            return;
        }
Exemplo n.º 4
0
        private void LoadEvents(int type, bool updateRequested)
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                IsBusy = true;
                try
                {
                    cts.Token.ThrowIfCancellationRequested();
                    List <Models.Event> events = new List <Models.Event>();
                    if (Preferences.ContainsKey("events_key"))
                    {
                        var eventsSerialized = Preferences.Get("events_key", "null");
                        if (eventsSerialized is null || eventsSerialized.Length <= 0 || updateRequested)
                        {
                            //events = await App.EventManager.GetDataListAsync("event/type=" + type);

                            events           = await App.EventManager.GetDataListAsync("event");
                            eventsSerialized = JsonConvert.SerializeObject(events, Newtonsoft.Json.Formatting.None,
                                                                           new JsonSerializerSettings
                            {
                                NullValueHandling = NullValueHandling.Ignore
                            });
                            Preferences.Set("events_key", eventsSerialized);
                            events = events.FindAll(x => x.Type == type);
                        }
                        else
                        {
                            events = JsonConvert.DeserializeObject <List <Models.Event> >(eventsSerialized);
                            events = events.FindAll(x => x.Type == type);
                        }

                        foreach (var item in events)
                        {
                            EventsCollection.Add(item);
                        }
                        //EventsCollection = new ObservableCollection<Models.Event>(events);
                    }
                    IsBusy = false;
                } catch (OperationCanceledException) { IsBusy = false; }