コード例 #1
0
ファイル: IWorkout.cs プロジェクト: Digresiv/garminworkouts
        public void ScheduleWorkout(DateTime date)
        {
            // Force it to be at noon
            DateTime midDaySchedule = new DateTime(date.Date.Year, date.Date.Month, date.Day, 12, 0, 0);
            GarminFitnessDate temp = new GarminFitnessDate(midDaySchedule);

            if (!ScheduledDates.Contains(temp) && date.Ticks >= DateTime.Today.Ticks)
            {
                ScheduledDates.Add(temp);

                TriggerWorkoutChangedEvent(new PropertyChangedEventArgs("Schedule"));
            }
        }
コード例 #2
0
ファイル: IWorkout.cs プロジェクト: Digresiv/garminworkouts
        public void Serialize(XmlNode parentNode, String nodeName, XmlDocument document)
        {
            if (GetSplitPartsCount() > 1)
            {
                List<WorkoutPart> splitParts = ConcreteWorkout.SplitInSeperateParts();

                foreach (WorkoutPart part in splitParts)
                {
                    part.Serialize(parentNode, nodeName, document);
                }
            }
            else
            {
                XmlNode childNode;
                XmlNode workoutNode = document.CreateElement(nodeName);
                XmlAttribute attribute;

                StepsExtensions.Clear();
                STExtensions.Clear();

                parentNode.AppendChild(workoutNode);

                // Sport attribute
                attribute = document.CreateAttribute(null, "Sport", null);
                attribute.Value = Constants.GarminCategoryTCXString[(int)Options.Instance.GetGarminCategory(Category)];
                workoutNode.Attributes.Append(attribute);

                // Name
                NameInternal.Serialize(workoutNode, "Name", document);

                // Export all steps
                Steps.Serialize(workoutNode, "", document);

                // Scheduled dates
                foreach (DateTime scheduledDate in ScheduledDates)
                {
                    GarminFitnessDate currentSchedule = new GarminFitnessDate(scheduledDate.ToUniversalTime());
                    currentSchedule.Serialize(workoutNode, "ScheduledOn", document);
                }

                // Notes
                if (Notes != String.Empty && Notes != null)
                {
                    NotesInternal.Serialize(workoutNode, "Notes", document);
                }

                // Creator tag (required by 610XT)
                XmlNode creatorNode = document.CreateElement("Creator");
                XmlAttribute attributeNode = document.CreateAttribute(Constants.XsiTypeTCXString, Constants.xsins);

                attributeNode.Value = "Device_t";
                creatorNode.Attributes.Append(attributeNode);
                workoutNode.AppendChild(creatorNode);
                creatorNode.AppendChild(document.CreateElement("Name"));

                XmlNode unitIdNode = document.CreateElement("UnitId");
                unitIdNode.AppendChild(document.CreateTextNode("1234567890"));
                creatorNode.AppendChild(unitIdNode);

                XmlNode productIdNode = document.CreateElement("ProductID");
                productIdNode.AppendChild(document.CreateTextNode("0"));
                creatorNode.AppendChild(productIdNode);

                XmlNode versionNode = document.CreateElement("Version");
                creatorNode.AppendChild(versionNode);

                XmlNode versionMajorNode = document.CreateElement("VersionMajor");
                versionMajorNode.AppendChild(document.CreateTextNode("0"));
                versionNode.AppendChild(versionMajorNode);
                XmlNode versionMinorNode = document.CreateElement("VersionMinor");
                versionMinorNode.AppendChild(document.CreateTextNode("0"));
                versionNode.AppendChild(versionMinorNode);
                XmlNode buildMajorNode = document.CreateElement("BuildMajor");
                buildMajorNode.AppendChild(document.CreateTextNode("0"));
                versionNode.AppendChild(buildMajorNode);
                XmlNode buildMinorNode = document.CreateElement("BuildMinor");
                buildMinorNode.AppendChild(document.CreateTextNode("0"));
                versionNode.AppendChild(buildMinorNode);

                // Extensions
                childNode = document.CreateElement(Constants.ExtensionsTCXString);
                workoutNode.AppendChild(childNode);

                // Steps extensions
                if (StepsExtensions.Count > 0)
                {
                    XmlNode extensionsNode = document.CreateElement("Steps");

                    // xmlns namespace attribute
                    attribute = document.CreateAttribute("xmlns");
                    attribute.Value = "http://www.garmin.com/xmlschemas/WorkoutExtension/v1";
                    extensionsNode.Attributes.Append(attribute);

                    for (int i = 0; i < StepsExtensions.Count; ++i)
                    {
                        XmlNode currentExtension = StepsExtensions[i];

                        extensionsNode.AppendChild(currentExtension);
                    }
                    childNode.AppendChild(extensionsNode);

                    StepsExtensions.Clear();
                }

                // ST extension
                if (STExtensions.Count > 0)
                {
                    XmlNode extensionsNode = document.CreateElement("SportTracksExtensions");
                    attribute = document.CreateAttribute("xmlns");
                    attribute.Value = "http://www.zonefivesoftware.com/sporttracks/plugins/?p=garmin-fitness";
                    extensionsNode.Attributes.Append(attribute);

                    // Category
                    XmlNode categoryNode = document.CreateElement("SportTracksCategory");
                    categoryNode.AppendChild(document.CreateTextNode(Category.ReferenceId));
                    extensionsNode.AppendChild(categoryNode);

                    for (int i = 0; i < STExtensions.Count; ++i)
                    {
                        XmlNode currentExtension = STExtensions[i];

                        extensionsNode.AppendChild(currentExtension);
                    }
                    childNode.AppendChild(extensionsNode);

                    STExtensions.Clear();
                }
            }
        }
コード例 #3
0
ファイル: IWorkout.cs プロジェクト: Digresiv/garminworkouts
        public void RemoveScheduledDate(DateTime date)
        {
            GarminFitnessDate temp = new GarminFitnessDate(date);

            if (ScheduledDates.Contains(temp))
            {
                ScheduledDates.Remove(temp);

                TriggerWorkoutChangedEvent(new PropertyChangedEventArgs("Schedule"));
            }
        }
コード例 #4
0
        private void RefreshWorkoutSelectionControls()
        {
            // None or multiple selection
            if (SelectedWorkout == null)
            {
                StepSplit.Enabled = false;
                ExportDateTextLabel.Enabled = false;
                ExportDateLabel.Enabled = false;

                if (SelectedConcreteWorkouts.Count == 0)
                {
                    RemoveWorkoutButton.Enabled = false;
                    CalendarSplit.Panel2.Enabled = false;
                }
                else
                {
                    RemoveWorkoutButton.Enabled = SelectedConcreteWorkouts.Count > 0;
                    CalendarSplit.Panel2.Enabled = SelectedConcreteWorkouts.Count > 0;
                }

            }
            else
            {
                GarminFitnessDate selectedDate = new GarminFitnessDate(WorkoutCalendar.SelectedDate);

                StepSplit.Enabled = true;
                AddStepButton.Enabled = SelectedWorkout.CanAcceptNewStep(1, SelectedStep);
                AddRepeatButton.Enabled = SelectedWorkout.CanAcceptNewStep(2, SelectedStep);
                AddLinkStepButton.Enabled = AddStepButton.Enabled &&
                                            GarminWorkoutManager.Instance.Workouts.Count > 1;
                CalendarSplit.Panel2.Enabled = true;
                ExportDateTextLabel.Enabled = true;
                ExportDateLabel.Enabled = true;

                RemoveWorkoutButton.Enabled = SelectedConcreteWorkouts.Count > 0;
                CalendarSplit.Panel2.Enabled = SelectedConcreteWorkouts.Count > 0;
            }

            RefreshWorkoutCalendar();
        }
コード例 #5
0
        void OnCalendarSelectedChanged(object sender, EventArgs e)
        {
            List<IWorkout> newSelection = new List<IWorkout>();
            GarminFitnessDate selectedDate = new GarminFitnessDate(PluginMain.GetApplication().Calendar.Selected);

            // Find the workouts planned on the selected date
            for (int i = 0; i < GarminWorkoutManager.Instance.Workouts.Count; ++i)
            {
                IWorkout currentWorkout = GarminWorkoutManager.Instance.Workouts[i];

                if (currentWorkout.ScheduledDates.Contains(selectedDate))
                {
                    newSelection.Add(currentWorkout);
                }
            }

            SelectedWorkouts = newSelection;
            WorkoutCalendar.SelectedDate = PluginMain.GetApplication().Calendar.Selected;
        }
コード例 #6
0
ファイル: Workout.cs プロジェクト: Digresiv/garminworkouts
        public void Deserialize_V4(Stream stream, DataVersion version)
        {
            byte[] intBuffer = new byte[sizeof(Int32)];
            Int32 scheduledDatesCount;

            Deserialize_V0(stream, version);

            // Scheduled dates
            stream.Read(intBuffer, 0, sizeof(Int32));
            scheduledDatesCount = BitConverter.ToInt32(intBuffer, 0);
            ScheduledDates.Clear();
            for (int i = 0; i < scheduledDatesCount; ++i)
            {
                GarminFitnessDate newDate = new GarminFitnessDate();

                newDate.Deserialize(stream, version);
                ScheduleWorkout(newDate);
            }
        }
コード例 #7
0
ファイル: Workout.cs プロジェクト: Digresiv/garminworkouts
        public override void Deserialize(XmlNode parentNode)
        {
            XmlNode STExtensionsNode = null;
            bool nameRead = false;

            m_Notes.Value = "";
            ScheduledDates.Clear();

            for (int i = 0; i < parentNode.ChildNodes.Count; ++i)
            {
                XmlNode child = parentNode.ChildNodes.Item(i);

                if (child.Name == "Name")
                {
                    m_Name.Deserialize(child);
                    nameRead = true;
                }
                else if (child.Name == "Notes")
                {
                    m_Notes.Deserialize(child);
                }
                else if (child.Name == "ScheduledOn")
                {
                    GarminFitnessDate newDate = new GarminFitnessDate();

                    newDate.Deserialize(child);
                    ScheduleWorkout(newDate);
                }
                else if (child.Name == Constants.ExtensionsTCXString)
                {
                    for (int j = 0; j < child.ChildNodes.Count; ++j)
                    {
                        XmlNode currentNode = child.ChildNodes[j];

                        // This condition remains for backsward compatibility with V0 exports
                        if (currentNode.Name == "SportTracksCategory" &&
                            currentNode.FirstChild.ChildNodes.Count == 1 &&
                            currentNode.FirstChild.FirstChild.GetType() == typeof(XmlText))
                        {
                            XmlText categoryNode = (XmlText)child.FirstChild.FirstChild;

                            Category = Utils.FindCategoryByIDSafe(categoryNode.Value);
                        }
                        else if (currentNode.Name == "SportTracksExtensions")
                        {
                            STExtensionsNode = currentNode;
                        }
                    }
                }
            }

            if (!nameRead)
            {
                throw new GarminFitnessXmlDeserializationException("Information missing in the XML node", parentNode);
            }

            m_Name.Value = GarminWorkoutManager.Instance.GetUniqueName(Name);

            Steps.Deserialize(parentNode);

            if (STExtensionsNode != null)
            {
                HandleSTExtension(STExtensionsNode);
            }
        }