Пример #1
0
        private SoundResourcesManager()
        {
            _settings  = new TemperatureUISettingsHandler();
            _resources = new SortedSet <ResourcePlayer>(new ResourceNameComparer());

            ResourceSet resourceSet = Properties.Resources.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

            foreach (DictionaryEntry entry in resourceSet)
            {
                if (entry.Value is UnmanagedMemoryStream)
                {
                    _resources.Add(new ResourcePlayer()
                    {
                        ResourceName = entry.Key.ToString(),
                        Stream       = entry.Value as Stream
                    });
                }
            }

            if (_resources.Count > 0)
            {
                var resource = GetByResourceName(_settings.SoundResourceName);
                if (resource == null)
                {
                    resource = GetResourcesList()[0];
                }
                SelectedSound = resource;
            }
        }
Пример #2
0
        public TemperatureUI()
        {
            InitializeComponent();

            _settings = new TemperatureUISettingsHandler();

            FormClosed += (s, e) =>
            {
                if ((e as FormClosedEventArgs).CloseReason == CloseReason.UserClosing) OnViewExit(s, e);
            };

            #region Init ThermometerPictureBox
            thermometerPictureBox.MarginLeft = 20;
            thermometerPictureBox.MarginRight = 20;
            thermometerPictureBox.MarginTop = 5;
            thermometerPictureBox.MarginBottom = 35;
            thermometerPictureBox.Value = 0;
            #endregion

            #region Init controls values
            nupTemperatureAlertLevel.Minimum = TemperatureUISettingsHandler.MIN_TEMPERATURE_ALERT_LEVEL;
            nupTemperatureAlertLevel.Maximum = TemperatureUISettingsHandler.MAX_TEMPERATURE_ALERT_LEVEL;
            trackBarTemperatureAlertLevel.Minimum = TemperatureUISettingsHandler.MIN_TEMPERATURE_ALERT_LEVEL;
            trackBarTemperatureAlertLevel.Maximum = TemperatureUISettingsHandler.MAX_TEMPERATURE_ALERT_LEVEL;
            SetTemperatureAlertLevel(_settings.TemperatureAlertLevel);

            nupUpdateTime.Minimum = TemperatureUISettingsHandler.MIN_UPDATE_TIME / 1000;
            nupUpdateTime.Maximum = TemperatureUISettingsHandler.MAX_UPDATE_TIME / 1000;
            trackbarUpdateTime.Minimum = TemperatureUISettingsHandler.MIN_UPDATE_TIME / 1000;
            trackbarUpdateTime.Maximum = TemperatureUISettingsHandler.MAX_UPDATE_TIME / 1000;
            SetUpdateTime(_settings.UpdateTime);

            SetNotificationMethod(_settings.Notification);

            if (SoundResourcesManager.Instance.SelectedSound != null) UpdateSoundName();
            else btnChangeSound.Enabled = false; //no resource available
            #endregion

            #region Attach value change events
            labelAvgCPUsTemperature.BorderStyle = BorderStyle.None;
            labelAvgCPUsTemperature.Paint += (s, e) =>
            {
                if (labelAvgCPUsTemperature.BorderStyle != BorderStyle.None)
                    ControlPaint.DrawBorder(e.Graphics, labelAvgCPUsTemperature.DisplayRectangle, Color.Red, ButtonBorderStyle.Solid);
            };

            nupTemperatureAlertLevel.MouseWheel += DoNothing_MouseWheel;
            nupTemperatureAlertLevel.ValueChanged += (s, e) => UpdateTemperatureAlertValue((int)nupTemperatureAlertLevel.Value);
            nupTemperatureAlertLevel.MouseUp += (s, e) => UpdateTemperatureAlertValue((int)nupTemperatureAlertLevel.Value, true);
            nupTemperatureAlertLevel.LostFocus += (s, e) => SetTemperatureAlertLevel(_lastSavedTemperatureAlertLevel);
            trackBarTemperatureAlertLevel.MouseWheel += DoNothing_MouseWheel;
            trackBarTemperatureAlertLevel.ValueChanged += (s, e) => UpdateTemperatureAlertValue(trackBarTemperatureAlertLevel.Value);
            trackBarTemperatureAlertLevel.MouseUp += (s, e) => UpdateTemperatureAlertValue(trackBarTemperatureAlertLevel.Value, true);
            trackBarTemperatureAlertLevel.LostFocus += (s, e) => SetTemperatureAlertLevel(_lastSavedTemperatureAlertLevel);

            nupUpdateTime.MouseWheel += DoNothing_MouseWheel;
            nupUpdateTime.ValueChanged += (s, e) => UpdateUpdateTimeValue((int)nupUpdateTime.Value * 1000);
            nupUpdateTime.MouseUp += (s, e) => UpdateUpdateTimeValue((int)nupUpdateTime.Value * 1000, true);
            nupUpdateTime.LostFocus += (s, e) => SetUpdateTime(_lastSavedUpdateTime);
            trackbarUpdateTime.MouseWheel += DoNothing_MouseWheel;
            trackbarUpdateTime.ValueChanged += (s, e) => UpdateUpdateTimeValue(trackbarUpdateTime.Value * 1000);
            trackbarUpdateTime.MouseUp += (s, e) => UpdateUpdateTimeValue(trackbarUpdateTime.Value * 1000, true);
            trackbarUpdateTime.LostFocus += (s, e) => SetUpdateTime(_lastSavedUpdateTime);

            rbMessageAndSoundNotif.CheckedChanged += RB_CheckedChanged;
            rbMessageNotif.CheckedChanged += RB_CheckedChanged;
            rbNoNotif.CheckedChanged += RB_CheckedChanged;
            #endregion

            FormClosing += (s, e) =>
            {
                if (e.CloseReason == CloseReason.UserClosing)
                {
                    Hide();
                    e.Cancel = true;
                }
            };

            ApplyTheme();
        }
 public RemoteTemperatureMonitor() : base()
 {
     Settings = new TemperatureUISettingsHandler();
     OpenServiceCommunicationAsync();
 }