internal bool LoadAdvancedSetting()
        {
            AdvancedSetting advancedSetting = FileAccessor.GetFileAccessor.LoadSettingFile <AdvancedSetting>(Define.SETTING_FILENAME_ADVANCED);

            if (advancedSetting == null)
            {
                Logger.Error(CLASS_NAME, "LoadAdvancedSetting", $"Load AdvancedSetting failed. FileName:[{Define.SETTING_FILENAME_ADVANCED}]");
                advancedSetting = new AdvancedSetting()
                {
                    LogRetentionDays        = 30,
                    LogLevel                = LogLevel.INFO,
                    SpeedUpSearch           = false,
                    TargetFileExtensionList = new List <string>() //todo:初期値はこれで良いか?
                    {
                        "txt"
                    }
                };
            }

            if (AddSetting(typeof(AdvancedSetting), advancedSetting) == false)
            {
                //todo:log
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        internal AdvancedSetting GetAdvancedSetting()
        {
            object setting = SettingManager.GetSettingManager.GetSetting(typeof(AdvancedSetting));

            if (setting == null)
            {
                Logger.Error(CLASS_NAME, "GetAdvancedSetting", $"Get AdvancedSetting failed. FileName:[{Define.SETTING_FILENAME_ADVANCED}]");
                setting = new AdvancedSetting()
                {
                    LogRetentionDays        = 30,
                    LogLevel                = LogLevel.INFO,
                    SpeedUpSearch           = false,
                    TargetFileExtensionList = new List <string>() //todo:初期値はこれで良いか?
                    {
                        "txt"
                    }
                };
            }

            return(setting as AdvancedSetting);
        }
        private void ApplyAdvancedSetting()
        {
            if (_model == null)
            {
                //todo:log
                return;
            }

            AdvancedSetting advancedSetting = _model.GetAdvancedSetting();

            if (advancedSetting == null)
            {
                Logger.Fatal(CLASS_NAME, "ApplyAdvancedSetting", "advancedSetting is null!");
                return;
            }

            LogOutputLevel   = (double)advancedSetting.LogLevel; //todo:安全なキャスト
            LogRetentionDays = advancedSetting.LogRetentionDays;
            UseFastSearch    = advancedSetting.SpeedUpSearch;
            if (advancedSetting.TargetFileExtensionList.Contains("txt")) //todo:リスト検索方法
            {
                IsTxtTarget = true;
            }
        }
 public IHttpActionResult Get()
 {
     return(Ok(AdvancedSetting.GetAll().Select(x => new AdvancedSettingViewModel(x)).ToList()));
 }
        public BindingMember(MemberInfo propertyInfo, object baseObject, BindingMember parent = null, bool lean = false)
        {
            BoundSources = new List <BoundSource>();

            _propertyInfo = propertyInfo as PropertyInfo;
            _baseObject   = baseObject;

            PropertyName = propertyInfo.Name;

            if (lean)
            {
                return;
            }

            _defaultValueAttribute      = GetAttribute <DefaultValueAttribute>(propertyInfo);
            _limitAttribute             = GetAttribute <LimitAttribute>(propertyInfo);
            _displayNameAttribute       = GetAttribute <DisplayNameAttribute>(propertyInfo);
            _descriptionAttribute       = GetAttribute <DescriptionAttribute>(propertyInfo);
            _uiControlAttribute         = GetAttribute <UIControlAttribute>(propertyInfo);
            _categoryAttribute          = GetAttribute <CategoryAttribute>(propertyInfo);
            _advancedAttribute          = GetAttribute <AdvancedSetting>(propertyInfo);
            _limitBindingAttribute      = GetAttribute <LimitBindingAttribute>(propertyInfo);
            _isGroupControllerAttribute = GetAttribute <IsGroupController>(propertyInfo);
            _groupAttribute             = GetAttribute <GroupAttribute>(propertyInfo);

            //Core.Logger.Verbose($"Created Binding Member for {propertyInfo.Name}");

            var notify = baseObject as INotifyPropertyChanged;

            if (notify != null)
            {
                //Core.Logger.Verbose($"Registering Property Changed for {baseObject.GetType().Name} ({propertyInfo.Name})");
                notify.PropertyChanged += NotifyOnPropertyChanged;
            }

            //_bindingAttribute = GetAttribute<BindingAttribute>(propertyInfo);

            _BindingAttributes = propertyInfo.GetCustomAttributes(typeof(BindingAttribute)).OfType <BindingAttribute>().ToList();

            if (_categoryAttribute == null && parent != null && parent.Category != null)
            {
                _categoryAttribute = new CategoryAttribute(parent.Category);
            }

            // The parent property of embedded TrinitySettings objects can define a category
            // When children do not have one explicitly set.
            if (_categoryAttribute == null && parent != null && parent.Category != null)
            {
                _categoryAttribute = new CategoryAttribute(parent.Category);
            }

            // GroupControllers notify other instances that a category has changed.
            // Applicable listners can then refresh their state in the UI.
            OnCategoryChanged += categoryId =>
            {
                if (categoryId == GroupId)
                {
                    OnPropertyChanged(nameof(IsEnabled));
                }
            };

            IsNoLabel = _uiControlAttribute != null && _uiControlAttribute.Options.HasFlag(UIControlOptions.NoLabel);

            //IsUseDescription = _uiControlAttribute != null && _uiControlAttribute.Options.HasFlag(UIControlOptions.UseDescription);

            IsInline = _uiControlAttribute != null && _uiControlAttribute.Options.HasFlag(UIControlOptions.Inline);

            if (_limitAttribute != null)
            {
                Range = new Range
                {
                    Min = _limitAttribute.Low,
                    Max = _limitAttribute.High
                };
            }

            _type = _baseObject.GetType();

            if (_limitBindingAttribute != null)
            {
                var lowSource  = _limitBindingAttribute.LowSource;
                var highSource = _limitBindingAttribute.HighSource;

                if (!BotMain.IsRunning)
                {
                    using (ZetaDia.Memory.AcquireFrame())
                    {
                        Range = new Range
                        {
                            Min                     = lowSource != null?GetMemberValue <double>(lowSource) : _limitBindingAttribute.Low,
                                                Max = highSource != null?GetMemberValue <double>(highSource) : _limitBindingAttribute.High
                        };
                    }
                }
                else
                {
                    Range = new Range
                    {
                        Min                     = lowSource != null?GetMemberValue <double>(lowSource) : _limitBindingAttribute.Low,
                                            Max = highSource != null?GetMemberValue <double>(highSource) : _limitBindingAttribute.High
                    };
                }
            }

            if (_BindingAttributes != null && _BindingAttributes.Any())
            {
                var attributes = _BindingAttributes.OrderBy(a => a.Order).ToList();
                foreach (var bindingAttr in attributes)
                {
                    var member = GetMember(bindingAttr);
                    var prop   = member as PropertyInfo;
                    if (prop == null)
                    {
                        continue;
                    }
                    var boundSource = new BoundSource
                    {
                        Member = new BindingMember(prop, baseObject, this),
                        Items  = GetBoundItems(prop, bindingAttr)
                    };
                    BoundSources.Add(boundSource);
                }
            }

            if (IsGroupController)
            {
                ChangeGroup(GroupId, Value);
            }

            Source = new BoundSource
            {
                Member = this,
                Items  = GetBoundItems(propertyInfo)
            };
        }
        /// <summary>適用ボタン押下時処理</summary>
        /// <param name="parameter"></param>
        private void ExecuteApply(object parameter)
        {
            //todo:メソッド切り出し、Modelに処理を渡す
            #region GeneralSetting

            double convFontSize = 0;
            if (double.TryParse(FontSize, out convFontSize) == false)
            {
                //todo:log. default
            }

            GeneralSetting generalSetting = new GeneralSetting//todo:既存のApplyGeneralSettings等使って細かく切り出せるのでは? 下のも含め
            {
                WrappingText         = this.WrappingText,
                ShowingLineCount     = this.ShowingLineCount,
                ShowingNumberOfLines = this.ShowingLineNumber,
                ShowingWordCount     = this.ShowingWordCount,
                ShowingNewLine       = this.ShowingNewLine,
                ShowingTab           = this.ShowingTab,
                ShowingSpace         = this.ShowingSpace,
                FontSize             = convFontSize,
                FontColor            = this.FontColor.ToString(),
                MainFontName         = MainFont != null ? MainFont.FontName : string.Empty, //todo:デフォルト値
                SubFontName          = SubFont != null ? SubFont.FontName : string.Empty    //todo:デフォルト値
            };

            FileAccessor.GetFileAccessor.SaveSettingFile(Define.SETTING_FILENAME_GENERAL, generalSetting, typeof(GeneralSetting));
            Model.Manager.SettingManager.GetSettingManager.UpdateOrAddSetting(typeof(GeneralSetting), generalSetting);

            #endregion

            #region SearchAndSynonymSetting

            int margin = 0;
            if (int.TryParse(SearchResultMargin, out margin) == false)
            {
                //todo:ログ出し、規定値
            }

            int resultCount = 0;
            if (int.TryParse(SearchResultDisplayCount, out resultCount) == false)
            {
                //todo:ログ出し、規定値
            }

            SearchAndSynonymSetting searchAndSynonymSetting = new SearchAndSynonymSetting()
            {
                SearchResultBackGroundColor = SearchResultBackGround.ToString(),
                SearchResultFontColor       = SearchResultFontColor.ToString(),
                SearchResultFontColorKind   = SearchResultFontColorKind,

                SynonymSearchResultColor1  = SynonymSearchResultColor1.ToString(),
                SynonymSearchResultColor2  = SynonymSearchResultColor2.ToString(),
                SynonymSearchResultColor3  = SynonymSearchResultColor3.ToString(),
                SynonymSearchResultColor4  = SynonymSearchResultColor4.ToString(),
                SynonymSearchResultColor5  = SynonymSearchResultColor5.ToString(),
                SynonymSearchResultColor6  = SynonymSearchResultColor6.ToString(),
                SynonymSearchResultColor7  = SynonymSearchResultColor7.ToString(),
                SynonymSearchResultColor8  = SynonymSearchResultColor8.ToString(),
                SynonymSearchResultColor9  = SynonymSearchResultColor9.ToString(),
                SynonymSearchResultColor10 = SynonymSearchResultColor10.ToString(),

                SynonymSearchFontColor     = SynonymSearchResultFontColor.ToString(),
                SynonymSearchFontColorKind = SynonymSearchResultFontColorKind,
                SearchResultMargin         = margin,
                SearchResultDisplayCount   = resultCount
            };

            FileAccessor.GetFileAccessor.SaveSettingFile(Define.SETTING_FILENAME_SEARCH, searchAndSynonymSetting, typeof(SearchAndSynonymSetting));
            Model.Manager.SettingManager.GetSettingManager.UpdateOrAddSetting(typeof(SearchAndSynonymSetting), searchAndSynonymSetting);


            #endregion

            #region AdvancedSetting

            int resultDisplayCount = 0;
            if (int.TryParse(SearchResultDisplayCount, out resultDisplayCount) == false)
            {
                resultDisplayCount = 100;//todo 規定値
            }

            AdvancedSetting advancedSetting = new AdvancedSetting
            {
                LogLevel                = ConvertDoubleToLogLevel(LogOutputLevel),
                SpeedUpSearch           = UseFastSearch,
                LogRetentionDays        = Convert.ToInt32(LogRetentionDays),
                TargetFileExtensionList = GetTargetExtensionsList()
            };

            FileAccessor.GetFileAccessor.SaveSettingFile(Define.SETTING_FILENAME_ADVANCED, advancedSetting, typeof(AdvancedSetting));
            Model.Manager.SettingManager.GetSettingManager.UpdateOrAddSetting(typeof(AdvancedSetting), advancedSetting);

            #endregion

            //todo:完了ダイアログ表示

            // 変更を通知する
            //todo:変更有無検知と、ウィンドウを閉じた際に通知するようにして不要な変更イベント発火を抑制する
            Model.Manager.SettingManager.GetSettingManager.NotifySettingChanged(SettingKind.All);
        }
Esempio n. 7
0
 public AdvancedSettingViewModel(AdvancedSetting advSetting)
 {
     name  = advSetting.Name;
     value = advSetting.Value;
     icon  = advSetting.Icon;
 }