Пример #1
0
        public static void ExportWorkout(IWorkout workout, Stream exportStream)
        {
            List<IWorkout> workouts = new List<IWorkout>();

            workouts.Add(workout);

            ExportWorkouts(workouts, exportStream);
        }
Пример #2
0
 void OnWorkoutStepTargetChanged(IWorkout modifiedWorkout, RegularStep modifiedStep, ITarget modifiedTarget, PropertyChangedEventArgs changedProperty)
 {
     UpdateWorkoutStepsCopy();
 }
Пример #3
0
 void OnWorkoutStepDurationChanged(IWorkout modifiedWorkout, RegularStep modifiedStep, IDuration modifiedDuration, PropertyChangedEventArgs changedProperty)
 {
     UpdateWorkoutStepsCopy();
 }
Пример #4
0
 void OnWorkoutStepChanged(IWorkout modifiedWorkout, IStep modifiedStep, PropertyChangedEventArgs changedProperty)
 {
     UpdateWorkoutStepsCopy();
 }
Пример #5
0
        void OnWorkoutChanged(IWorkout modifiedWorkout, PropertyChangedEventArgs changedProperty)
        {
            if (changedProperty.PropertyName == "Steps" ||
                changedProperty.PropertyName == "PartsCount")
            {
                UpdateWorkoutStepsCopy();
            }

            TriggerStepChanged(new PropertyChangedEventArgs("ParentWorkout"));
        }
Пример #6
0
        public static string GetWorkoutFilename(IWorkout workout, GarminWorkoutManager.FileFormats format)
        {
            string fileName = workout.Name;

            // Replace invalid characters by underscores
            fileName = fileName.Replace('\\', '_');
            fileName = fileName.Replace('/', '_');
            fileName = fileName.Replace(':', '_');
            fileName = fileName.Replace('*', '_');
            fileName = fileName.Replace('?', '_');
            fileName = fileName.Replace('"', '_');
            fileName = fileName.Replace('<', '_');
            fileName = fileName.Replace('>', '_');
            fileName = fileName.Replace('|', '_');
            fileName = fileName.Replace('.', '_');
            fileName = fileName.Replace('&', '_');
            fileName = fileName.Replace('%', '_');

            if (format == GarminWorkoutManager.FileFormats.TCX)
            {
                fileName += ".tcx";
            }
            else if (format == GarminWorkoutManager.FileFormats.FIT)
            {
                fileName += ".fit";
            }
            else
            {
                Debug.Assert(false);
            }

            return fileName;
        }
        private void DeleteSelectedWorkouts()
        {
            GarminWorkoutManager.Instance.RemoveWorkouts(SelectedConcreteWorkouts);

            SelectedWorkout = null;
            SelectedSteps = null;
            UpdateUIFromWorkouts();
        }
Пример #8
0
        public static void ExportWorkoutToFIT(IWorkout workout, Stream exportStream, bool updateExportDate)
        {
            MemoryStream dataStream = new MemoryStream();

            // Reserve size for header
            dataStream.Write(new Byte[12], 0, 12);

            // File id message
            FITMessage fileIdMessage = new FITMessage(FITGlobalMessageIds.FileId);
            FITMessageField fileType = new FITMessageField((Byte)FITFileIdFieldsIds.FileType);
            FITMessageField manufacturerId = new FITMessageField((Byte)FITFileIdFieldsIds.ManufacturerId);
            FITMessageField productId = new FITMessageField((Byte)FITFileIdFieldsIds.ProductId);
            FITMessageField serialNumber = new FITMessageField((Byte)FITFileIdFieldsIds.SerialNumber);
            FITMessageField exportDate = new FITMessageField((Byte)FITFileIdFieldsIds.ExportDate);
            FITMessageField number = new FITMessageField((Byte)FITFileIdFieldsIds.Number);

            fileType.SetEnum((Byte)FITFileTypes.Workout);
            manufacturerId.SetUInt16(1);
            productId.SetUInt16(20119);
            serialNumber.SetUInt32z(0);
            exportDate.SetUInt32(workout.CreationTimestamp);
            number.SetUInt16(0xFFFF);

            fileIdMessage.AddField(serialNumber);
            fileIdMessage.AddField(exportDate);
            fileIdMessage.AddField(manufacturerId);
            fileIdMessage.AddField(productId);
            fileIdMessage.AddField(number);
            fileIdMessage.AddField(fileType);
            fileIdMessage.Serialize(dataStream);

            // File creator message
            FITMessage fileCreatorMessage = new FITMessage(FITGlobalMessageIds.FileCreator);
            FITMessageField software = new FITMessageField((Byte)FITFileCreatorFieldsIds.SoftwareVersion);
            FITMessageField hardware = new FITMessageField((Byte)FITFileCreatorFieldsIds.HardwareVersion);

            software.SetUInt16(3605);
            hardware.SetUInt8(0);

            fileCreatorMessage.AddField(software);
            fileCreatorMessage.AddField(hardware);
            fileCreatorMessage.Serialize(dataStream);

            // Write workout
            workout.SerializeToFIT(dataStream);

            // Write FIT header at the start of the stream
            GarminFitnessByteRange headerSize = new GarminFitnessByteRange(12);
            GarminFitnessByteRange protocolVersion = new GarminFitnessByteRange((Byte)((FITConstants.FITProtocolMajorVersion << 4) | FITConstants.FITProtocolMinorVersion));
            GarminFitnessUInt16Range profileVersion = new GarminFitnessUInt16Range((UInt16)((FITConstants.FITProfileMajorVersion * FITConstants.FITProfileMajorVersionMultiplier) + FITConstants.FITProfileMinorVersion));
            GarminFitnessInt32Range dataSize = new GarminFitnessInt32Range(0);

            dataStream.Seek(0, SeekOrigin.Begin);
            dataSize.Value = (int)dataStream.Length - 12;

            headerSize.Serialize(dataStream);
            protocolVersion.Serialize(dataStream);
            profileVersion.Serialize(dataStream);
            dataSize.Serialize(dataStream);
            dataStream.Write(Encoding.UTF8.GetBytes(FITConstants.FITFileDescriptor), 0, 4);

            // Write CRC
            GarminFitnessUInt16Range crc = new GarminFitnessUInt16Range(FITUtils.ComputeStreamCRC(dataStream));
            dataStream.Seek(0, SeekOrigin.End);
            crc.Serialize(dataStream);

            // Write all data to output stream
            exportStream.Write(dataStream.GetBuffer(), 0, (int)dataStream.Length);

            if (updateExportDate)
            {
                workout.LastExportDate = DateTime.Now;
            }
        }
        private void WorkoutsList_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete && SelectedConcreteWorkouts.Count > 0)
            {
                DeleteSelectedWorkouts();
            }
            else if (e.Control)
            {
                if (SelectedConcreteWorkouts.Count > 0)
                {
                    if(e.KeyCode == Keys.C)
                    {
                        CopyWorkoutSelection();

                        RefreshClipboardControls();
                    }
                    else if (e.KeyCode == Keys.X)
                    {
                        CutWorkoutSelection();

                        RefreshClipboardControls();
                    }
                }

                if (e.KeyCode == Keys.V && Clipboard.ContainsData(Constants.WorkoutsClipboardID))
                {
                    PasteWorkoutsFromClipboard();

                    RefreshClipboardControls();
                }
                else if (e.KeyCode == Keys.N)
                {
                    // New regular step
                    if (SelectedCategory != null)
                    {
                        SelectedWorkout = GarminWorkoutManager.Instance.CreateWorkout(SelectedCategory);
                        SelectedCategory = null;
                        WorkoutNameText.Focus();
                    }
                }
            }
        }
        void OnWorkoutStepTargetChanged(IWorkout modifiedWorkout, RegularStep modifiedStep, ITarget modifiedTarget, PropertyChangedEventArgs changedProperty)
        {
            if (InvokeRequired)
            {
                Invoke(new WorkoutStepTargetChangedDelegate(OnWorkoutStepTargetChanged),
                       new object[] {modifiedWorkout, modifiedStep, modifiedTarget, changedProperty});
            }
            else
            {
                if (SelectedWorkout == modifiedWorkout)
                {
                    // Refresh the steps list so it updates the name/description
                    StepsList.Invalidate();

                    if (changedProperty.PropertyName == "ConcreteTarget")
                    {
                        UpdateTargetPanelVisibility();
                    }

                    if (modifiedStep == SelectedStep)
                    {
                        UpdateUIFromTarget();
                    }
                }
            }
        }
        void OnWorkoutStepRepeatDurationChanged(IWorkout modifiedWorkout, RepeatStep modifiedStep, IRepeatDuration modifiedDuration, PropertyChangedEventArgs changedProperty)
        {
            if (InvokeRequired)
            {
                Invoke(new WorkoutStepRepeatDurationChangedDelegate(OnWorkoutStepRepeatDurationChanged),
                       new object[] { modifiedWorkout, modifiedStep, modifiedDuration, changedProperty });
            }
            else
            {
                if (SelectedWorkout == modifiedWorkout)
                {
                    // Refresh the steps list so it updates the name/description
                    StepsList.Invalidate();

                    if (modifiedStep == SelectedStep)
                    {
                        UpdateUIFromDuration();
                    }
                }
            }
        }
        private void OnWorkoutStepChanged(IWorkout modifiedWorkout, IStep stepChanged, PropertyChangedEventArgs changedProperty)
        {
            if (InvokeRequired)
            {
                Invoke(new WorkoutStepChangedDelegate(OnWorkoutStepChanged),
                       new object[] { modifiedWorkout, stepChanged, changedProperty });
            }
            else
            {
                if (SelectedWorkout != null && SelectedWorkout.ConcreteWorkout == modifiedWorkout.ConcreteWorkout)
                {
                    // Refresh the steps list so it updates the name/description
                    WorkoutsList.Invalidate();
                    StepsList.Invalidate();

                    // When a property changes in a workout's step, this callback executes
                    if (SelectedStep == stepChanged)
                    {
                        if ((changedProperty.PropertyName == "ForceSplitOnStep" && SelectedWorkout is WorkoutPart))
                        {
                            BuildStepsList();
                        }

                        UpdateUIFromStep();
                    }

                    if (changedProperty.PropertyName == "LinkSteps")
                    {
                        BuildStepsList();
                    }
                }
                else if (SelectedStep is WorkoutLinkStep)
                {
                    WorkoutLinkStep concreteStep = SelectedStep as WorkoutLinkStep;

                    if (modifiedWorkout.ConcreteWorkout == concreteStep.LinkedWorkout)
                    {
                        UpdateUIFromStep();
                    }
                }
            }
        }
        private void OnWorkoutChanged(IWorkout modifiedWorkout, PropertyChangedEventArgs changedProperty)
        {
            if (InvokeRequired)
            {
                Invoke(new WorkoutChangedDelegate(OnWorkoutChanged),
                       new object[] { modifiedWorkout, changedProperty });
            }
            else
            {
                // When a property changes in a workout, this is triggered
                if (changedProperty.PropertyName == "Name" ||
                    changedProperty.PropertyName == "Category" ||
                    changedProperty.PropertyName == "PartsCount")
                {
                    int modifiedWorkoutChildrenCount = -1;
                    WorkoutWrapper modifiedWrapper = GetWorkoutWrapper(modifiedWorkout.ConcreteWorkout);

                    if (changedProperty.PropertyName == "PartsCount")
                    {
                        CleanUpWorkoutPartsSelection();
                        modifiedWorkoutChildrenCount = modifiedWrapper.Children.Count;
                    }

                    BuildWorkoutsList();

                    if (changedProperty.PropertyName == "PartsCount" && modifiedWorkoutChildrenCount == 0)
                    {
                        WorkoutsList.SetExpanded(modifiedWrapper, true);
                    }
                }

                if (changedProperty.PropertyName == "Schedule")
                {
                    RefreshWorkoutCalendar();
                    RefreshCalendarView();
                }

                if (SelectedWorkout != null &&
                    SelectedWorkout.ConcreteWorkout == modifiedWorkout)
                {
                    if (changedProperty.PropertyName == "Steps")
                    {
                        BuildWorkoutsList();
                        BuildStepsList();

                        // Update the new step buttons
                        RefreshWorkoutSelectionControls();
                    }
                    else
                    {
                        RefreshUIFromWorkouts();
                    }
                }
            }
        }
        private void NewWorkoutButton_Click(object sender, EventArgs e)
        {
            Debug.Assert(SelectedCategory != null);

            SelectedWorkout = GarminWorkoutManager.Instance.CreateWorkout(SelectedCategory);
            SelectedCategory = null;
            WorkoutNameText.Focus();
        }
Пример #15
0
 public ExportWorkoutTask(IWorkout workout)
     : base(TaskTypes.ExportWorkout)
 {
     m_Workouts = new List<IWorkout>();
     m_Workouts.Add(workout);
 }
Пример #16
0
 public static void ExportWorkoutToFIT(IWorkout workout, Stream exportStream)
 {
     ExportWorkoutToFIT(workout, exportStream, true);
 }
        public void RefreshUIFromLogbook()
        {
            SelectedCategory = null;
            SelectedWorkout = null;
            SelectedSteps = null;

            RefreshCalendarView();
            if (PluginMain.GetApplication().Logbook != null)
            {
                BuildWorkoutsList();
            }

            RefreshClipboardControls();
        }
 public void SelectWorkout(Workout workout)
 {
     SelectedWorkout = workout;
 }
Пример #19
0
 void OnWorkoutChanged(IWorkout modifiedWorkout, PropertyChangedEventArgs changedProperty)
 {
     if (changedProperty.PropertyName == "PartsCount")
     {
         UpdateSplitsCache();
     }
 }