Пример #1
0
 public void RenewPerset(Exercise item)
 {
     PersetExercises = PersetExercises.Union(new IExercise[] { item }, new ExercisePersetComparer())
                       .OrderBy(x => x.Category)
                       .ThenBy(x => x.Name)
                       .ToList();
 }
Пример #2
0
        public void LoadData()
        {
            StreamResourceInfo info = GetLocalizedResourceStream();
            XElement           root = XElement.Load(info.Stream);

            try
            {
                IEnumerable <XElement> categories = root.Elements(XName.Get("Category"));

                PersetExercises = categories.SelectMany(x =>
                {
                    var catName = x.Attribute(XName.Get("Name"));
                    if (catName == null)
                    {
                        throw new NullReferenceException("Attribute 'Name' not founded");
                    }

                    string categotyName = catName.Value;

                    return(x.Elements(XName.Get("Exercise")).Select(ex =>
                    {
                        XAttribute nameAttribute = ex.Attribute(XName.Get("Name"));
                        if (nameAttribute == null)
                        {
                            throw new NullReferenceException("Attribute 'Name' not founded");
                        }

                        XAttribute withoutWeightAttribute = ex.Attribute(XName.Get("WithoutWeight"));

                        // ReSharper disable once SimplifyConditionalTernaryExpression
                        bool withoutWeight = withoutWeightAttribute != null ? Convert.ToBoolean(withoutWeightAttribute.Value) : false;

                        return (IExercise) new PersetExercise {
                            Category = categotyName, Name = nameAttribute.Value, WithoutWeight = withoutWeight
                        };
                    }));
                })
                                  .Union(RepoExercise.Instance.FindAll().Cast <IExercise>(), new ExercisePersetComparer())
                                  .OrderBy(x => x.Category)
                                  .ThenBy(x => x.Name)
                                  .ToList();
            }
            catch (Exception)
            {
                MessageBox.Show("Error in xml file parse.");
                IsDataLoaded = false;
                return;
            }

            PersetCategories = PersetExercises.Select(x => x.Category).Distinct().ToList();
            IsDataLoaded     = false;
        }