Ejemplo n.º 1
0
        private void ApplyConfiguration(Configuration oldConfiguration)
        {
            // General
            GeneralSettings general = this.configuration.General;

            this.view.HideFromTaskbar = general.HideFromTaskbar;
            // Display (Mouse, Tracking and Watermark)
            this.DisplaySettings = new DisplaySettings()
            {
                Mouse     = configuration.Mouse,
                Tracking  = configuration.Tracking,
                Watermark = configuration.Watermark,
            };
            this.view.TrackingSettings = configuration.Tracking;
            // Hot Keys
            HotKeySettings hotKey = this.configuration.HotKeys;

            this.view.CancelHotKey = hotKey.Cancel;
            this.view.PauseHotKey  = hotKey.Pause;
            this.view.RecordHotKey = hotKey.Record;
            this.view.StopHotKey   = hotKey.Stop;
            this.UpdateHotKeys(oldConfiguration != null ? oldConfiguration.HotKeys : null);
            // Sound
            SoundSettings sound = this.configuration.Sound;

            SoundDevice[] soundDevices = SoundProvider.GetDevices();
            this.view.SoundDevices = soundDevices;
            string      soundDeviceId = sound.DeviceId;
            SoundDevice soundDevice   = null;

            if (!string.IsNullOrEmpty(soundDeviceId))
            {
                soundDevice = SoundProvider.GetDeviceOrDefault(soundDeviceId);
                if (soundDevice != null)
                {
                    // Update configuration if device id is invalid
                    sound.DeviceId = soundDevice.Id;
                }
            }
            this.view.SoundDevice = soundDevice;
            this.SoundSettings    = this.configuration.Sound;
            // Get updated (valid) configuration from recorder
            this.configuration.Sound = this.SoundSettings;
            // Video
            this.recorder.VideoSettings = this.configuration.Video;
            // Get updated (valid) configuration from recorder
            this.configuration.Video = this.recorder.VideoSettings;
            this.UpdateView();
        }
Ejemplo n.º 2
0
        private static Keys GetHotKeyFromConfig(HotKeySettings hotKeysConfig, HotKeyType type)
        {
            switch (type)
            {
            case HotKeyType.Cancel:
                return(hotKeysConfig.Cancel);

            case HotKeyType.Pause:
                return(hotKeysConfig.Pause);

            case HotKeyType.Record:
                return(hotKeysConfig.Record);

            case HotKeyType.Stop:
                return(hotKeysConfig.Stop);

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 3
0
        private void hotKeyManager_HotKey(object sender, KeyEventArgs e)
        {
            Keys           keyValue      = e.KeyData;
            HotKeySettings hotKeysConfig = this.configuration.HotKeys;

            Debug.Assert(hotKeysConfig.Global);
            if (keyValue == hotKeysConfig.Cancel)
            {
                this.Cancel();
            }
            else if (keyValue == hotKeysConfig.Pause)
            {
                this.Pause();
            }
            else if (keyValue == hotKeysConfig.Record)
            {
                this.Record();
            }
            else if (keyValue == hotKeysConfig.Stop)
            {
                this.Stop();
            }
        }
Ejemplo n.º 4
0
 private void UpdateHotKeys(HotKeySettings oldConfig)
 {
     HotKeySettings hotKeysConfig = this.configuration.HotKeys;
      if (hotKeysConfig.Global) {
     List<HotKeyType> hotKeyTypesToRegister = new List<HotKeyType>(new HotKeyType[] {
        HotKeyType.Cancel,
        HotKeyType.Pause,
        HotKeyType.Record,
        HotKeyType.Stop,
     });
     if (this.hotKeyManager == null) {
        this.hotKeyManager = new HotKeyManager();
        this.hotKeyManager.HotKey += new KeyEventHandler(hotKeyManager_HotKey);
     }
     else if (oldConfig != null && oldConfig.Global) {
        // Unregister old hot keys
        Array hotKeyTypes = Enum.GetValues(typeof(HotKeyType));
        foreach (object hotKeyType in hotKeyTypes) {
           Keys oldHotKey = GetHotKeyFromConfig(oldConfig, (HotKeyType)hotKeyType);
           Keys newHotKey = GetHotKeyFromConfig(hotKeysConfig, (HotKeyType)hotKeyType);
           if (oldHotKey == newHotKey) {
              hotKeyTypesToRegister.Remove((HotKeyType)hotKeyType);
           }
           else if (oldHotKey != Keys.None) {
              try {
                 this.hotKeyManager.UnregisterHotKey(oldHotKey);
              }
              catch (InvalidOperationException e) {
                 Trace.TraceWarning(e.ToString());
              }
           }
        }
     }
     // Register new hot keys
     bool allSucceed = true;
     foreach (HotKeyType hotKeyType in hotKeyTypesToRegister) {
        Keys newHotKey = GetHotKeyFromConfig(hotKeysConfig, hotKeyType);
        try {
           this.hotKeyManager.RegisterHotKey(newHotKey);
        }
        catch (ArgumentException e) {
           Trace.TraceWarning(e.ToString());
           allSucceed = false;
        }
        catch (InvalidOperationException e) {
           Trace.TraceWarning(e.ToString());
           allSucceed = false;
        }
     }
     if (!allSucceed) {
        this.view.ShowHotKeyRegisterWarning();
     }
      }
      else if (this.hotKeyManager != null) {
     this.hotKeyManager.HotKey -= hotKeyManager_HotKey;
     this.hotKeyManager.Dispose();
     this.hotKeyManager = null;
      }
 }
Ejemplo n.º 5
0
 private static Keys GetHotKeyFromConfig(HotKeySettings hotKeysConfig, HotKeyType type)
 {
     switch (type) {
     case HotKeyType.Cancel:
        return hotKeysConfig.Cancel;
     case HotKeyType.Pause:
        return hotKeysConfig.Pause;
     case HotKeyType.Record:
        return hotKeysConfig.Record;
     case HotKeyType.Stop:
        return hotKeysConfig.Stop;
     default:
        throw new InvalidOperationException();
      }
 }
Ejemplo n.º 6
0
 private Configuration()
 {
     var properties = Properties.Settings.Default;
      // Read configuration section elements
      // General
      string outputDir = properties.General_OutputDirectory;
      if (string.IsNullOrEmpty(outputDir)) {
     string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
     try {
        outputDir = Path.Combine(myDocuments, outputDirInMyDocs);
     }
     catch (ArgumentException) {
        outputDir = myDocuments;
     }
      }
      GeneralSettings general = new GeneralSettings();
      general.MinimizeOnRecord = properties.General_MinimizeOnRecord;
      general.HideFromTaskbar = properties.General_HideFromTaskbarIfMinimized;
      general.OutputDirectory = outputDir;
      // Hot Keys
      HotKeySettings hotKeys = new HotKeySettings();
      hotKeys.Cancel = properties.HotKeys_Cancel;
      hotKeys.Global = properties.HotKeys_Global;
      hotKeys.Pause = properties.HotKeys_Pause;
      hotKeys.Record = properties.HotKeys_Record;
      hotKeys.Stop = properties.HotKeys_Stop;
      // Mouse
      MouseSettings mouse = new MouseSettings();
      mouse.HighlightCursor = properties.Mouse_HighlightCursor;
      mouse.HighlightCursorColor = properties.Mouse_HighlightCursorColor;
      mouse.HighlightCursorRadious = properties.Mouse_HighlightCursorRadious;
      mouse.RecordCursor = properties.Mouse_RecordCursor;
      // Sound
      SoundSettings sound = new SoundSettings();
      sound.DeviceId = properties.Sound_DeviceId;
      sound.Format = properties.Sound_Format;
      // Tracking
      TrackingSettings tracking = new TrackingSettings();
      tracking.Bounds = properties.Tracking_Bounds;
      tracking.Type = properties.Tracking_Type;
      // Video
      VideoSettings video = new VideoSettings();
      video.Compressor = properties.Video_Compressor;
      video.Fps = properties.Video_Fps;
      video.Quality = properties.Video_Quality;
      // Watermark
      WatermarkSettings waterMark = new WatermarkSettings();
      waterMark.Alignment = properties.Watermark_Alignment;
      waterMark.Color = properties.Watermark_Color;
      waterMark.Display = properties.Watermark_Display;
      waterMark.Font = properties.Watermark_Font;
      waterMark.Margin = properties.Watermark_Margin;
      waterMark.Outline = properties.Watermark_Outline;
      waterMark.OutlineColor = properties.Watermark_OutlineColor;
      waterMark.RightToLeft = properties.Watermark_RightToLeft;
      waterMark.Text = properties.Watermark_Text;
      // Set properties
      this.General = general;
      this.HotKeys = hotKeys;
      this.Mouse = mouse;
      this.Sound = sound;
      this.Tracking = tracking;
      this.Video = video;
      this.Watermark = waterMark;
 }
Ejemplo n.º 7
0
        private void UpdateHotKeys(HotKeySettings oldConfig)
        {
            HotKeySettings hotKeysConfig = this.configuration.HotKeys;

            if (hotKeysConfig.Global)
            {
                List <HotKeyType> hotKeyTypesToRegister = new List <HotKeyType>(new HotKeyType[] {
                    HotKeyType.Cancel,
                    HotKeyType.Pause,
                    HotKeyType.Record,
                    HotKeyType.Stop,
                });
                if (this.hotKeyManager == null)
                {
                    this.hotKeyManager         = new HotKeyManager();
                    this.hotKeyManager.HotKey += new KeyEventHandler(hotKeyManager_HotKey);
                }
                else if (oldConfig != null && oldConfig.Global)
                {
                    // Unregister old hot keys
                    Array hotKeyTypes = Enum.GetValues(typeof(HotKeyType));
                    foreach (object hotKeyType in hotKeyTypes)
                    {
                        Keys oldHotKey = GetHotKeyFromConfig(oldConfig, (HotKeyType)hotKeyType);
                        Keys newHotKey = GetHotKeyFromConfig(hotKeysConfig, (HotKeyType)hotKeyType);
                        if (oldHotKey == newHotKey)
                        {
                            hotKeyTypesToRegister.Remove((HotKeyType)hotKeyType);
                        }
                        else if (oldHotKey != Keys.None)
                        {
                            try {
                                this.hotKeyManager.UnregisterHotKey(oldHotKey);
                            }
                            catch (InvalidOperationException e) {
                                Trace.TraceWarning(e.ToString());
                            }
                        }
                    }
                }
                // Register new hot keys
                bool allSucceed = true;
                foreach (HotKeyType hotKeyType in hotKeyTypesToRegister)
                {
                    Keys newHotKey = GetHotKeyFromConfig(hotKeysConfig, hotKeyType);
                    try {
                        this.hotKeyManager.RegisterHotKey(newHotKey);
                    }
                    catch (ArgumentException e) {
                        Trace.TraceWarning(e.ToString());
                        allSucceed = false;
                    }
                    catch (InvalidOperationException e) {
                        Trace.TraceWarning(e.ToString());
                        allSucceed = false;
                    }
                }
                if (!allSucceed)
                {
                    this.view.ShowHotKeyRegisterWarning();
                }
            }
            else if (this.hotKeyManager != null)
            {
                this.hotKeyManager.HotKey -= hotKeyManager_HotKey;
                this.hotKeyManager.Dispose();
                this.hotKeyManager = null;
            }
        }