private void OnUpdatePreset(object sender, EventArgs e)
        {
            //get current coordinates
            System.Collections.ObjectModel.Collection <object> objResult = EnvironmentManager.Instance.SendMessage(
                new VideoOS.Platform.Messaging.Message(MessageId.Control.PTZGetAbsoluteRequest), _camera.FQID);

            PTZGetAbsoluteRequestData datRequestData = (PTZGetAbsoluteRequestData)objResult[0];
            double pan  = datRequestData.Pan;
            double tilt = datRequestData.Tilt;
            double zoom = datRequestData.Zoom;

            objResult.Clear();

            Item   currentlySelectedPresetItem = comboBoxPresets.SelectedItem as Item;
            string currentlySelectedPresetName = currentlySelectedPresetItem.Name;

            try
            {
                Camera          camera    = new Camera(_camera.FQID);
                PtzPresetFolder folder    = camera.PtzPresetFolder;
                PtzPreset       ptzPreset = folder.PtzPresets.Where(x => x.Name == currentlySelectedPresetName).FirstOrDefault();
                if (ptzPreset != null)
                {
                    ptzPreset.Pan  = pan;
                    ptzPreset.Tilt = tilt;
                    ptzPreset.Zoom = zoom;
                    ptzPreset.Save();
                }
            }
            catch (Exception ex)
            {
                EnvironmentManager.Instance.Log(true, "Update Preset", ex.Message);
                MessageBox.Show(ex.Message, "Exception in Update preset", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void buttonCreatePreset_Click(object sender, EventArgs e)
        {
            //get current coordinates
            System.Collections.ObjectModel.Collection <object> objResult = EnvironmentManager.Instance.SendMessage(
                new VideoOS.Platform.Messaging.Message(MessageId.Control.PTZGetAbsoluteRequest), _camera.FQID);

            PTZGetAbsoluteRequestData datRequestData = (PTZGetAbsoluteRequestData)objResult[0];
            double pan  = datRequestData.Pan;
            double tilt = datRequestData.Tilt;
            double zoom = datRequestData.Zoom;

            objResult.Clear();
            try
            {
                Camera          camera = new Camera(_camera.FQID);
                PtzPresetFolder folder = camera.PtzPresetFolder;
                folder.AddPtzPreset(textBoxPresetName.Text, "", pan, tilt, zoom);
            }
            catch (Exception ex)
            {
                EnvironmentManager.Instance.Log(true, "Create Preset", ex.Message);
                MessageBox.Show(ex.Message, "Exception in Create preset", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            refreshList();
            textBoxPresetName.Text = "new preset name";
        }
        /// <summary>
        /// We take a ptz preset and see if it is a preset imported from device, if it is we know that imported presets are used and we cannot set a preset.
        /// Imported ptz preset are set in the device.
        /// </summary>
        /// <returns></returns>
        private bool isSettablePresets()
        {
            bool            result          = true;
            Camera          camera          = new Camera(_camera.FQID);
            PtzPresetFolder ptzPresetFolder = camera.PtzPresetFolder;

            if (ptzPresetFolder == null)
            {
                return(false);
            }

            PtzPreset ptzPreset = ptzPresetFolder.PtzPresets.FirstOrDefault();

            if (ptzPreset != null)
            {
                // If for a preset the DevicePresetInternalId is not blank the preset is imported from device.
                result = ptzPreset.DevicePresetInternalId == "";
            }
            return(result);
        }
        private void OnDeletePreset(object sender, EventArgs e)
        {
            Item   currentlySelectedPresetItem = comboBoxPresets.SelectedItem as Item;
            string currentlySelectedPresetName = currentlySelectedPresetItem.Name;

            try
            {
                Camera          camera    = new Camera(_camera.FQID);
                PtzPresetFolder folder    = camera.PtzPresetFolder;
                PtzPreset       ptzPreset = folder.PtzPresets.Where(x => x.Name == currentlySelectedPresetName).FirstOrDefault();
                if (ptzPreset != null)
                {
                    folder.RemovePtzPreset(ptzPreset.Path);
                }
            }
            catch (Exception ex)
            {
                EnvironmentManager.Instance.Log(true, "Remove Preset", ex.Message);
                MessageBox.Show(ex.Message, "Exception in Remove preset", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            refreshList();
        }