コード例 #1
0
        public TrainingPlan FromXml(IStatelessSession session, string xmlContent)
        {
            try
            {
                TrainingPlan plan = new TrainingPlan();
                XDocument    xml  = XDocument.Parse(xmlContent);

                var trainingPlanElement = xml.Element("TrainingPlan");
                plan.Author   = readValue(trainingPlanElement, "Author");
                plan.Language = readValue(trainingPlanElement, "Language");
                //plan.BasedOnId = readGuid(trainingPlanElement, "BasedOnId");
                plan.Comment      = readValue(trainingPlanElement, "Comment");
                plan.CreationDate = readDateTime(trainingPlanElement, "CreationDate").Value;
                plan.Difficult    = readEnum <TrainingPlanDifficult>(trainingPlanElement, "Difficult");
                plan.Purpose      = readEnum <WorkoutPlanPurpose>(trainingPlanElement, "Purpose");
                plan.GlobalId     = readGuid(trainingPlanElement, "GlobalId").Value;
                //plan.ProfileId = readGuid(trainingPlanElement, "ProfileId").Value;
                plan.Name         = readValue(trainingPlanElement, "Name");
                plan.Url          = readValue(trainingPlanElement, "Url");
                plan.RestSeconds  = readInt(trainingPlanElement, "RestSeconds").Value;
                plan.TrainingType = readEnum <TrainingType>(trainingPlanElement, "TrainingType");
                int position = 0;
                foreach (var dayNode in trainingPlanElement.Element("Days").Descendants("Day"))
                {
                    TrainingPlanDay day = new TrainingPlanDay();
                    plan.Days.Add(day);
                    day.TrainingPlan = plan;
                    day.Position     = position;
                    day.GlobalId     = readGuid(dayNode, "GlobalId").Value;
                    day.Name         = readValue(dayNode, "Name");

                    readTrainingEntries(session, day, dayNode);

                    readSuperSets(day, dayNode);
                    position++;
                }

                return(plan);
            }
            catch (VerificationException)
            {
                throw;
            }
            catch (Exception)
            {
                throw new FormatException("Selected xml doesn't contain training plan or it is damaged");
            }
        }
コード例 #2
0
        private void readTrainingEntries(IStatelessSession session, TrainingPlanDay day, XElement dayNode)
        {
            int position = 0;

            foreach (var entryNode in dayNode.Element("Entries").Descendants("Entry"))
            {
                TrainingPlanEntry entry = new TrainingPlanEntry();
                day.Entries.Add(entry);
                entry.Position = position;
                entry.Day      = day;
                entry.GlobalId = readGuid(entryNode, "GlobalId").Value;
                entriesMap.Add(readGuid(entryNode, "GlobalId").Value, entry);
                entry.Comment  = readValue(entryNode, "Comment");
                entry.Exercise = session.Get <Exercise>(readGuid(entryNode, "ExerciseId").Value);
                if (entry.Exercise == null)
                {
                    entry.Exercise = deletedExercise;
                }
                entry.RestSeconds = readInt(entryNode, "RestSeconds").Value;
                position++;

                foreach (var setNode in entryNode.Element("Sets").Descendants("Set"))
                {
                    TrainingPlanSerie set = new TrainingPlanSerie();
                    entry.Sets.Add(set);
                    set.Entry               = entry;
                    set.Comment             = readValue(setNode, "Comment");
                    set.GlobalId            = readGuid(setNode, "GlobalId").Value;
                    set.RepetitionNumberMax = readInt(setNode, "RepetitionNumberMax");
                    set.RepetitionNumberMin = readInt(setNode, "RepetitionNumberMin");
                    if (readValue(setNode, "RepetitionsType") == "NotSet")
                    {
                        set.RepetitionsType = SetType.Normalna;
                    }
                    else
                    {
                        set.RepetitionsType = readEnum <SetType>(setNode, "RepetitionsType");
                    }

                    set.DropSet = readEnum <DropSetType>(setNode, "DropSet");
                }
            }
        }
コード例 #3
0
 private void readSuperSets(TrainingPlanDay day, XElement dayNode)
 {
     foreach (var superSetNode in dayNode.Element("SuperSets").Descendants("SuperSet"))
     {
         var superSetId = readGuid(superSetNode, "SuperSetId").Value;
         foreach (var entryIdNode in superSetNode.Element("Entries").Descendants("EntryId"))
         {
             var oldEntryId = new Guid(entryIdNode.Value);
             if (entriesMap.ContainsKey(oldEntryId))
             {
                 var entry = entriesMap[oldEntryId];
                 if (entry != null)
                 {
                     entry.GroupName = superSetId.ToString();
                 }
             }
             else
             {
                 Debug.Fail("Here should be an entry!");
             }
         }
     }
 }