Beispiel #1
0
        /// <summary>
        /// Filters activities for a category (and it's subcategories), and includes only those activities with a HeartRateTrack.
        /// </summary>
        /// <param name="category">Category to filter for</param>
        /// <param name="activityList">List of activities to be filtered from.</param>
        /// <returns>Returns a list of activities filtered by category</returns>
        internal static IEnumerable <IActivity> FilterActivities(IActivityCategory category, IList <IActivity> activityList)
        {
            IList <IActivity> filteredActivities = new List <IActivity>();
            ActivityInfoCache info = ActivityInfoCache.Instance;
            IActivityCategory activityCategory;

            foreach (IActivity activity in activityList)
            {
                activityCategory = info.GetInfo(activity).Activity.Category;
                while (true)
                {
                    if (activityCategory == category)
                    {
                        // Include Activity
                        filteredActivities.Add(info.GetInfo(activity).Activity);
                        break;
                    }
                    else if (activityCategory.Parent != null)
                    {
                        // Keep searching
                        activityCategory = activityCategory.Parent;
                    }
                    else
                    {
                        // Exclude Activity
                        break;
                    }
                }
            }

            return(filteredActivities);
        }
Beispiel #2
0
        public static ActivityInfo GetActivityInfo(IActivity activity, bool includeStopped)
        {
            if (activity == null)
            {
                Debug.Assert(false, "Activity is unexpectedly null");
                return(null);
            }

            if (!systemProperty)
            {
                systemProperty = true;
                Plugin.GetApplication().SystemPreferences.PropertyChanged += new PropertyChangedEventHandler(SystemPreferences_PropertyChanged);
            }

            if (!activityInfos.ContainsKey(activity))
            {
                if (!activityPropLists.Contains(activity))
                {
                    //activityGps controls if the property listener is added
                    activity.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Activity_PropertyChanged);
                    activityPropLists.Add(activity);
                }
                activityInfos.Add(activity, null);
            }

            if (activityInfos[activity] == null)
            {
                activityInfos[activity] = new Dictionary <bool, ActivityInfo>();
            }
            if (!activityInfos[activity].ContainsKey(includeStopped))
            {
                activityInfos[activity].Add(includeStopped, null);
            }
            if (activityInfos[activity][includeStopped] == null)
            {
                ActivityInfoCache   c = new ActivityInfoCache();
                ActivityInfoOptions t = new ActivityInfoOptions(false, includeStopped);
                c.Options = t;
                //if (this.Pauses != activity.TimerPauses)
                //{
                //    IActivity activity2 = Plugin.GetApplication().Logbook.Activities.AddCopy(activity);
                //    activity = activity2;
                //    activity.TimerPauses.Clear();
                //    foreach (IValueRange<DateTime> p in this.Pauses)
                //    {
                //        activity.TimerPauses.Add(p);
                //    }
                //    activity.Category = Plugin.GetApplication().Logbook.ActivityCategories[1];
                //    if (activity.Category.SubCategories.Count > 0)
                //    {
                //        activity.Category = activity.Category.SubCategories[0];
                //    }
                //}
                if (activity != null)
                {
                    activityInfos[activity][includeStopped] = c.GetInfo(activity);
                }
                else
                {
                    //TODO: This data should not be used, just return any activity to avoid exceptions
                    Debug.Assert(false, "Activity was checked to be not null, now is");
                    activityInfos[activity][includeStopped] = ActivityInfoCache.Instance.GetInfo(Plugin.GetApplication().Logbook.Activities[0]);
                }
            }
            return(activityInfos[activity][includeStopped]);
        }