Пример #1
0
        /// <summary>
        /// Adds the specified collection of objects to <see cref="EventsCollection"/>.
        /// </summary>
        /// <param name="eventsCollection"><see cref="EventsCollection"/> to add objects to.</param>
        /// <param name="timedObjects">Objects to add to <paramref name="eventsCollection"/>.</param>
        /// <exception cref="ArgumentNullException">
        /// <para>One of the following errors occured:</para>
        /// <list type="bullet">
        /// <item>
        /// <description><paramref name="eventsCollection"/> is <c>null</c>.</description>
        /// </item>
        /// <item>
        /// <description><paramref name="timedObjects"/> is <c>null</c>.</description>
        /// </item>
        /// </list>
        /// </exception>
        public static void AddObjects(this EventsCollection eventsCollection, IEnumerable <ITimedObject> timedObjects)
        {
            ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection);
            ThrowIfArgument.IsNull(nameof(timedObjects), timedObjects);

            var timedEventsObjects = timedObjects.GetObjects(ObjectType.TimedEvent);

            if (timedEventsObjects.Count == 0)
            {
                return;
            }

            var eventsCollectionToAdd = new EventsCollection();

            AddTimedEventsToEventsCollection(eventsCollectionToAdd, timedEventsObjects);

            var newEventsCount = eventsCollection.Count + eventsCollectionToAdd.Count;
            var allTimedEvents = new[] { eventsCollection, eventsCollectionToAdd }
            .GetTimedEventsLazy(newEventsCount, false)
            .Select(e => e.Item1)
            .ToArray();

            eventsCollection.Clear();
            AddTimedEventsToEventsCollection(eventsCollection, allTimedEvents);
        }
        /// <summary>
        /// Removes all the <see cref="TimedEvent"/> that match the conditions defined by the specified predicate.
        /// </summary>
        /// <param name="eventsCollection"><see cref="EventsCollection"/> to search for events to remove.</param>
        /// <returns>Count of removed timed events.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="eventsCollection"/> is <c>null</c>.</exception>
        public static int RemoveTimedEvents(this EventsCollection eventsCollection)
        {
            ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection);

            var result = eventsCollection.Count;

            eventsCollection.Clear();
            return(result);
        }
Пример #3
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;
            }
        }
Пример #4
0
 private void CreateCommands()
 {
     RefreshEventsCommand = new Command(() =>
     {
         try
         {
             IsBusy = true;
             EventsCollection.Clear();
             cts.Cancel();
             cts.Dispose();
             cts = new CancellationTokenSource();
             LoadEvents(_type, true);
         }
         catch (Exception) {}
         finally
         {
             IsBusy = false;
         }
     });
 }
Пример #5
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;
        }
Пример #6
0
 public void Clear()
 {
     EventsCollection.Clear();
 }