Esempio n. 1
0
        private HotBabeSettings checkValues(out ValidationResult result)
        {
            HotBabeSettings settings = new HotBabeSettings
            {
                AlwaysOnTop      = Settings.AlwaysOnTop,
                AutoRun          = Settings.AutoRun,
                ClickThrough     = Settings.ClickThrough,
                DefaultImageName = tbImage.Text,
                Left             = Settings.Left,
                Opacity          = Settings.Opacity,
                Top              = Settings.Top,
                UpdateInterval   = Settings.UpdateInterval,
                BlendImages      = Settings.BlendImages,
                HideOnFullscreen = Settings.HideOnFullscreen
            };

            foreach (ImageInfoEditor editor  in pnlImages.Controls)
            {
                settings.ImageInfos.Add(editor.GetEditorItem());
            }
            foreach (MonitorInfoEditor editor in pnlMonitors.Controls)
            {
                settings.MonitorInfos.Add(editor.GetEditorItem());
            }
            result = SettingsValidationHelper.Validate(settings);
            if (result.ContainsKey("DefaultImageName"))
            {
                errorProvider1.SetError(tbImage, result["DefaultImageName"].ToString());
            }
            return(settings);
        }
        ///<summary>
        /// Checks the validity of the control values
        ///</summary>
        ///<returns></returns>
        public bool CheckValues()
        {
            bool result = true;

            errorProvider1.Clear();
            if (!string.IsNullOrEmpty(tbMeasures.Text) && tbMeasures.Text.Split('=').Length < 2)
            {
                errorProvider1.SetError(tbMeasures,
                                        "Measures should be a series of key=value parts, separated by spaces");
                result = false;
            }
            else
            {
                try
                {
                    ImageInfo        info             = GetEditorItem();
                    ValidationResult validationResult = SettingsValidationHelper.Validate(info);
                    if (!validationResult.IsValid)
                    {
                        result = false;
                        foreach (KeyValuePair <string, ValidationErrorCollection> pair in validationResult)
                        {
                            switch (pair.Key)
                            {
                            case "ImageInfo.ImageFileName":
                            {
                                errorProvider1.SetError(tbImage, pair.Value.ToString());
                            }
                            break;

                            case "ImageInfo.Measures":
                            case "ImageInfo.Measures.Value":
                            case "ImageInfo.Measures.Key":
                            {
                                errorProvider1.SetError(tbMeasures, pair.Value.ToString());
                            }
                            break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Debug("Exception caught and discarded: " + ex.Message +
                                 " at ImageInfoEditor.CheckValues");
                    errorProvider1.SetError(tbMeasures, "The measures are not valid (" + ex.Message + ").");
                    result = false;
                }
            }
            return(result);
        }
        ///<summary>
        /// Checks the validity of the control values
        ///</summary>
        ///<returns></returns>
        public bool CheckValues()
        {
            bool result = true;

            errorProvider1.Clear();

            if (string.IsNullOrEmpty(tbMinValue.Text))
            {
                errorProvider1.SetError(tbMinValue, "The minimum value must be a number between 0 and 99.");
                result = false;
            }
            if (string.IsNullOrEmpty(tbSmooth.Text))
            {
                errorProvider1.SetError(tbSmooth, "The smooth value must be a number between 0 and 1.");
                result = false;
            }
            try
            {
                MonitorInfo      item             = GetEditorItem();
                ValidationResult validationResult = SettingsValidationHelper.Validate(item);
                if (!validationResult.IsValid)
                {
                    result = false;
                    foreach (KeyValuePair <string, ValidationErrorCollection> pair in validationResult)
                    {
                        switch (pair.Key)
                        {
                        case "MonitorInfo.AssemblyFileName":
                        {
                            errorProvider1.SetError(tbAssembly, pair.Value.ToString());
                        }
                        break;

                        case "MonitorInfo.TypeName":
                        {
                            errorProvider1.SetError(cboxMonitor, pair.Value.ToString());
                        }
                        break;

                        case "MonitorInfo.MinValue":
                        {
                            errorProvider1.SetError(tbMinValue, pair.Value.ToString());
                        }
                        break;

                        case "MonitorInfo.Key":
                        {
                            errorProvider1.SetError(tbKey, pair.Value.ToString());
                        }
                        break;

                        case "MonitorInfo.Smooth":
                        {
                            errorProvider1.SetError(tbSmooth, pair.Value.ToString());
                        }
                        break;

                        case "MonitorInfo.UpdateInterval":
                        {
                            errorProvider1.SetError(numUpdateInterval, pair.Value.ToString());
                        }
                        break;

                        case "MonitorInfo.Parameter":
                        {
                            errorProvider1.SetError(tbParameter, pair.Value.ToString());
                        }
                        break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Debug("Exception caught and discarded: " + ex.Message +
                             " at MonitorInfoEditor.CheckValues");
                errorProvider1.SetError(tbAssembly,
                                        string.Format("General conversion error ({0}).", ex.Message));
                result = false;
            }
            return(result);
        }