コード例 #1
0
        internal HeartRateForm(
            IHeartRateService service,
            string settingsFilename,
            DateTime now)
        {
            try
            {
                _settings = HeartRateSettings.CreateDefault(settingsFilename);
                LoadSettingsLocked();
                _settings.Save();
                _service         = service;
                _startedAt       = now;
                _iconBitmap      = new Bitmap(_iconWidth, _iconHeight);
                _iconGraphics    = Graphics.FromImage(_iconBitmap);
                _measurementFont = new Font(
                    _settings.FontName, _iconWidth,
                    GraphicsUnit.Pixel);
                _watchdog = new HeartRateServiceWatchdog(
                    TimeSpan.FromSeconds(10), _service);

                InitializeComponent();

                FormBorderStyle = _settings.Sizable
                    ? FormBorderStyle.Sizable
                    : FormBorderStyle.SizableToolWindow;
            }
            catch
            {
                TryDispose(service);
                throw;
            }
        }
コード例 #2
0
 private HeartRateSettingsProtocol(HeartRateSettings settings)
 {
     Version             = settings.Version;
     FontName            = settings.FontName;
     AlertLevel          = settings.AlertLevel;
     UIFontName          = settings.UIFontName;
     UIFontStyle         = settings.UIFontStyle.ToString();
     UIFontUseSize       = settings.UIFontUseSize;
     UIFontSize          = settings.UIFontSize;
     UIWindowSizeX       = settings.UIWindowSizeX;
     UIWindowSizeY       = settings.UIWindowSizeY;
     UITextAlignment     = settings.UITextAlignment.ToString();
     WarnLevel           = settings.WarnLevel;
     AlertTimeout        = (int)settings.AlertTimeout.TotalMilliseconds;
     DisconnectedTimeout = (int)settings.DisconnectedTimeout.TotalMilliseconds;
     Color              = ColorToString(settings.Color);
     WarnColor          = ColorToString(settings.WarnColor);
     UIColor            = ColorToString(settings.UIColor);
     UIWarnColor        = ColorToString(settings.UIWarnColor);
     UIBackgroundColor  = ColorToString(settings.UIBackgroundColor);
     UIBackgroundFile   = settings.UIBackgroundFile;
     UIBackgroundLayout = settings.UIBackgroundLayout.ToString();
     Sizable            = settings.Sizable;
     LogFormat          = settings.LogFormat;
     LogDateFormat      = settings.LogDateFormat ?? DateTimeFormatter.DefaultColumn;
     LogFile            = settings.LogFile ?? " ";
     IBIFile            = settings.IBIFile ?? " ";
 }
コード例 #3
0
        private void uxMenuEditSettings_Click(object sender, EventArgs e)
        {
            var thread = new Thread(() => {
                using (var process = Process.Start(new ProcessStartInfo
                {
                    FileName = HeartRateSettings.GetFilename(),
                    UseShellExecute = true,
                    Verb = "EDIT"
                }))
                {
                    process.WaitForExit();
                }

                lock (_updateSync)
                {
                    LoadSettingsLocked();
                }
            })
            {
                IsBackground = true,
                Name         = "Edit config"
            };

            thread.Start();
        }
コード例 #4
0
 public HeartRateForm() : this(
         Environment.CommandLine.Contains("--test")
         ? (IHeartRateService) new TestHeartRateService()
         : new HeartRateService(),
         HeartRateSettings.GetFilename(),
         DateTime.Now)
 {
 }
コード例 #5
0
        private void UpdateUICore()
        {
            if (uxBpmLabel.Font.FontFamily.Name != _settings.UIFontName ||
                uxBpmLabel.Font.Style != _settings.UIFontStyle ||
                _lastSettings?.UIFontUseSize != _settings.UIFontUseSize ||
                _lastSettings?.UIFontSize != _settings.UIFontSize)
            {
                UpdateLabelFontLocked();
            }

            if (uxBpmLabel.TextAlign != _settings.UITextAlignment)
            {
                uxBpmLabel.TextAlign = _settings.UITextAlignment;
                UpdateSubmenus();
            }

            if (uxBpmLabel.BackgroundImageLayout != _settings.UIBackgroundLayout)
            {
                uxBpmLabel.BackgroundImageLayout = _settings.UIBackgroundLayout;
                UpdateSubmenus();
            }

            if (uxBpmLabel.BackColor != _settings.UIBackgroundColor)
            {
                uxBpmLabel.BackColor = _settings.UIBackgroundColor;
            }

            if (_lastSettings?.UIBackgroundFile != _settings.UIBackgroundFile)
            {
                var oldBackgroundImage = uxBpmLabel.BackgroundImage;
                var backgroundFile     = _settings.UIBackgroundFile;

                if (!string.IsNullOrWhiteSpace(backgroundFile) &&
                    File.Exists(backgroundFile))
                {
                    try
                    {
                        var image = Image.FromFile(backgroundFile);
                        uxBpmLabel.BackgroundImage = image;
                        oldBackgroundImage.TryDispose();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show($"Unable to load background image file \"{backgroundFile}\" due to error: {e}");
                    }
                }
                else
                {
                    uxBpmLabel.BackgroundImage = null;
                    oldBackgroundImage.TryDispose();
                }
            }

            _lastSettings = _settings.Clone();

            Invalidate();
        }
コード例 #6
0
        public static void Save(HeartRateSettings settings)
        {
            Debug.WriteLine($"Saving to {_filename}");

            var protocol = new HeartRateSettingsProtocol(settings);

            using (var fs = File.OpenWrite(_filename))
            {
                _serializer.Serialize(fs, protocol);
            }
        }
コード例 #7
0
        internal static void Save(HeartRateSettings settings, string filename)
        {
            Debug.WriteLine($"Saving to {filename}");

            var protocol = new HeartRateSettingsProtocol(settings);

            using (var fs = File.Open(filename,
                                      FileMode.Create, FileAccess.Write))
            {
                _serializer.Serialize(fs, protocol);
            }
        }
コード例 #8
0
 private HeartRateSettingsProtocol(HeartRateSettings settings)
 {
     Version             = settings.Version;
     FontName            = settings.FontName;
     AlertLevel          = settings.AlertLevel;
     UIFontName          = settings.UIFontName;
     WarnLevel           = settings.WarnLevel;
     AlertTimeout        = (int)settings.AlertTimeout.TotalMilliseconds;
     DisconnectedTimeout = (int)settings.DisconnectedTimeout.TotalMilliseconds;
     Color             = ColorToString(settings.Color);
     WarnColor         = ColorToString(settings.WarnColor);
     UIColor           = ColorToString(settings.UIColor);
     UIWarnColor       = ColorToString(settings.UIWarnColor);
     UIBackgroundColor = ColorToString(settings.UIBackgroundColor);
 }
コード例 #9
0
        private void UpdateUICore()
        {
            uxBpmLabel.BackColor = _settings.UIBackgroundColor;

            var fontx = _settings.UIFontName;

            if (uxBpmLabel.Font.FontFamily.Name != fontx)
            {
                UpdateLabelFontLocked();
            }

            if (_lastSettings?.UIBackgroundFile != _settings.UIBackgroundFile)
            {
                var oldBackgroundImage = uxBpmLabel.BackgroundImage;
                var backgroundFile     = _settings.UIBackgroundFile;

                if (!string.IsNullOrWhiteSpace(backgroundFile) &&
                    File.Exists(backgroundFile))
                {
                    try
                    {
                        var image = Image.FromFile(backgroundFile);
                        uxBpmLabel.BackgroundImage = image;
                        oldBackgroundImage.TryDispose();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show($"Unable to load background image file \"{backgroundFile}\" due to error: {e}");
                    }
                }
                else
                {
                    uxBpmLabel.BackgroundImage = null;
                    oldBackgroundImage.TryDispose();
                }
            }

            if (_lastSettings?.UIBackgroundLayout != _settings.UIBackgroundLayout)
            {
                uxBpmLabel.BackgroundImageLayout = _settings.UIBackgroundLayout;
            }

            _lastSettings = _settings.Clone();
        }
コード例 #10
0
 private HeartRateSettingsProtocol(HeartRateSettings settings)
 {
     Version             = settings.Version;
     FontName            = settings.FontName;
     AlertLevel          = settings.AlertLevel;
     UIFontName          = settings.UIFontName;
     WarnLevel           = settings.WarnLevel;
     AlertTimeout        = (int)settings.AlertTimeout.TotalMilliseconds;
     DisconnectedTimeout = (int)settings.DisconnectedTimeout.TotalMilliseconds;
     Color             = ColorToString(settings.Color);
     WarnColor         = ColorToString(settings.WarnColor);
     UIColor           = ColorToString(settings.UIColor);
     UIWarnColor       = ColorToString(settings.UIWarnColor);
     UIBackgroundColor = ColorToString(settings.UIBackgroundColor);
     Sizable           = settings.Sizable;
     LogFormat         = settings.LogFormat;
     LogDateFormat     = settings.LogDateFormat ?? DateTimeFormatter.DefaultColumn;
     LogFile           = settings.LogFile ?? " ";
 }
コード例 #11
0
        internal HeartRateForm(
            IHeartRateService service,
            string settingsFilename,
            DateTime now)
        {
            try
            {
                // Order of operations -- _startedAt has to be set before
                // `LoadSettingsLocked` is called.
                _startedAt = now;

                _settings = HeartRateSettings.CreateDefault(settingsFilename);
                LoadSettingsLocked();
                _settings.Save();
                _service         = service;
                _iconBitmap      = new Bitmap(_iconWidth, _iconHeight);
                _iconGraphics    = Graphics.FromImage(_iconBitmap);
                _measurementFont = new Font(
                    _settings.FontName, _iconWidth,
                    GraphicsUnit.Pixel);
                _watchdog = new HeartRateServiceWatchdog(
                    TimeSpan.FromSeconds(10), _service);

                InitializeComponent();

                FormBorderStyle = _settings.Sizable
                    ? FormBorderStyle.Sizable
                    : FormBorderStyle.SizableToolWindow;

                CreateEnumSubmenu <ContentAlignment>(textAlignmentToolStripMenuItem,
                                                     textAlignmentToolStripMenuItemItem_Click);

                CreateEnumSubmenu <ImageLayout>(backgroundImagePositionToolStripMenuItem,
                                                backgroundImagePositionToolStripMenuItemItem_Click);
            }
            catch
            {
                service.TryDispose();
                throw;
            }
        }
コード例 #12
0
 public LogFile(HeartRateSettings settings, string filename)
     : base(filename)
 {
     _settings = settings;
 }