Esempio n. 1
0
        public CompareOptionsViewModel(ISchedulers schedulers, CompareOptions compareOptions)
        {
            ContextLinesInput = new IntegerInputViewModel(schedulers, compareOptions.ContextLines, 0)
                                .DisposeWith(_disposable);
            InterhunkLinesInput = new IntegerInputViewModel(schedulers, compareOptions.InterhunkLines, 0)
                                  .DisposeWith(_disposable);
            DiffAlgorithm = new EnumViewModel <DiffAlgorithm>(compareOptions.Algorithm)
                            .DisposeWith(_disposable);
            IndentHeuristic = new ViewSubject <bool>(compareOptions.IndentHeuristic)
                              .DisposeWith(_disposable);
            SimilarityOptions = new SimilarityOptionsViewModel(schedulers, compareOptions.Similarity)
                                .DisposeWith(_disposable);

            CompareOptionsObservable = Observable
                                       .CombineLatest(ContextLinesInput.Value,
                                                      InterhunkLinesInput.Value,
                                                      DiffAlgorithm.Value,
                                                      IndentHeuristic,
                                                      SimilarityOptions.SimilarityObservable,
                                                      (contextLines,
                                                       interhunkLines,
                                                       algorithm,
                                                       indentHeuristic,
                                                       similarityOptions)
                                                      => new CompareOptions()
            {
                ContextLines      = contextLines,
                InterhunkLines    = interhunkLines,
                Similarity        = similarityOptions,
                IncludeUnmodified = false,
                Algorithm         = algorithm,
                IndentHeuristic   = indentHeuristic,
            });
        }
Esempio n. 2
0
        public void EnumViewModel_Ctor()
        {
            EnumViewModel viewModel = new EnumViewModel(FitnessSortOption.Entity, "Test");

            Assert.Equal(FitnessSortOption.Entity, viewModel.Value);
            Assert.Equal("Test", viewModel.DisplayName);
        }
Esempio n. 3
0
        /// <summary>
        /// Formats the enum values.
        /// </summary>
        /// <param name="enumType">Type of the enum.</param>
        /// <returns></returns>
        private string FormatEnumValues(Type enumType)
        {
            var sb = new StringBuilder();

            foreach (Enum item in Enum.GetValues(enumType))
            {
                if (sb.Length > 0)
                {
                    sb.AppendLine();
                }

                sb.Append(Convert.ToInt32(item));
                sb.Append(":(");
                sb.Append(item.ToString());

                var label = EnumViewModel.EnumToLabel(item);
                if (!string.IsNullOrEmpty(label))
                {
                    sb.Append(", ");
                    sb.Append(label);
                }

                sb.Append(")");
            }

            return(sb.ToString());
        }
Esempio n. 4
0
        internal static object ToClientValue(Type serverType, object value)
        {
            if (serverType.IsEnum)
            {
                value = EnumViewModel.EnumToLabel(value as Enum);
            }
            else if (serverType == typeof(Nullable <int>))
            {
                if (value == null)
                {
                    value = 0;
                }
            }
            else if (serverType == typeof(Nullable <Guid>))
            {
                if (value == null)
                {
                    value = Guid.Empty;
                }
                value = value.ToString();
            }
            else if (serverType == typeof(Guid))
            {
                value = value.ToString();
            }

            return(value);
        }
Esempio n. 5
0
        // [TypeFilter(typeof(AuthorizeAction), Arguments = new object[] { "Read" })]
        public IActionResult SummaryView()
        {   // returns listing view
            EnumViewModel model = new EnumViewModel();

            InitAccessModel(model);
            return(View(model));
        }
Esempio n. 6
0
        public override object GetValue(object component)
        {
            var mp     = this.Property;
            var entity = component as Entity;

            if (mp is IRefProperty)
            {
                if (mp is IRefIdProperty)
                {
                    return(entity.GetRefNullableId(mp as IRefIdProperty));
                }
                if (mp is IRefEntityProperty)
                {
                    return(entity.GetRefEntity(mp as IRefEntityProperty));
                }
            }

            if (mp is IListProperty)
            {
                return(entity.GetLazyList(mp as IListProperty));
            }

            var value = entity.GetProperty(mp);

            //枚举值在为界面返回值时,应该返回 Label
            if (value != null && TypeHelper.IsEnumNullable(mp.PropertyType))
            {
                value = EnumViewModel.EnumToLabel((Enum)value).Translate();
            }

            return(value);
        }
Esempio n. 7
0
        protected override FrameworkElement CreateEditingElement()
        {
            this._cb      = new ComboBox();
            this._cb.Name = this.Meta.Name;
            this._cb.SelectedValuePath = "EnumValue";
            this._cb.DisplayMemberPath = "TranslatedLabel";

            this.ResetBinding(this._cb);

            //cb.Items.Clear();
            var propertyType = this.Meta.PropertyMeta.Runtime.PropertyType;

            foreach (var item in EnumViewModel.GetByEnumType(propertyType))
            {
                this._cb.Items.Add(item);
            }
            if (TypeHelper.IsNullable(propertyType))
            {
                //这种组合下,不能随意录入值、可以选择文本、按上下键选择项。缺点是不能通过输入搜索项。
                this._cb.IsEditable      = true;
                this._cb.IsReadOnly      = true;
                this._cb.PreviewKeyDown += On_cb_PreviewKeyDown;
            }

            this.AddReadOnlyComponent(this._cb, ComboBox.IsEnabledProperty, false);

            this.SetAutomationElement(this._cb);

            this._cb.SelectionChanged   += On_cb_SelectionChanged;
            this._cb.DropDownOpened     += On_cb_DropDownOpened;
            this._cb.DataContextChanged += On_cb_DataContextChanged;

            return(this._cb);
        }
        public void EnumViewModelConverter_Convert()
        {
            EnumViewModelConverter converter = new EnumViewModelConverter();

            List <Enum> enumValues = new List <Enum>();

            enumValues.AddRange(Enum.GetValues(typeof(FitnessType)).Cast <Enum>());
            enumValues.AddRange(Enum.GetValues(typeof(FitnessSortOption)).Cast <Enum>());

            object result;

            foreach (Enum val in enumValues)
            {
                result = converter.Convert(val, null, null, null);
                EnumViewModel viewModel = (EnumViewModel)result;
                Assert.Equal(val, viewModel.Value);
                Assert.True(!(String.IsNullOrEmpty(viewModel.DisplayName)));
            }

            result = converter.Convert((FitnessType)20, null, null, null);
            Assert.Null(result);

            result = converter.Convert((FitnessSortOption)20, null, null, null);
            Assert.Null(result);

            result = converter.Convert(null, null, null, null);
            Assert.Null(result);
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            comboMode.DataSource = EnumViewModel <EduVolumeDirectoryMode> .GetValues(ViewModelContext, false);

            comboMode.DataBind();
        }
Esempio n. 10
0
        // [TypeFilter(typeof(AuthorizeAction), Arguments = new object[] { "Write" })]
        public IActionResult Index()
        {
            EnumViewModel model = new EnumViewModel();

            InitAccessModel(model);
            model.EnumMaster.ID = 0;
            return(View(model));
        }
Esempio n. 11
0
        public IViewComponentResult Invoke(string nomeLabel, string nomeCampo, List <SelectListItem> lista)
        {
            var model = new EnumViewModel()
            {
                NomeLabel = nomeLabel, Campo = nomeCampo, ListaEnum = lista
            };

            return(View(model));
        }
Esempio n. 12
0
        protected override void OnInit(System.EventArgs e)
        {
            base.OnInit(e);

            comboTypeOfValues.DataSource = EnumViewModel <ScienceRecordTypeOfValues>
                                           .GetValues(new ViewModelContext (this), false);

            comboTypeOfValues.DataBind();
        }
Esempio n. 13
0
        public void UtilsTest_EnumViewModel_Parse_Null()
        {
            var value = EnumViewModel.Parse(null, typeof(FavorateTypeWithLabel));

            Assert.IsNull(value);

            value = EnumViewModel.Parse(string.Empty, typeof(FavorateTypeWithLabel));
            Assert.IsNull(value);
        }
Esempio n. 14
0
        public void SetValue()
        {
            var value = TestEnum.Third;
            var vm    = new EnumViewModel <TestEnum>(TestEnum.First);

            using var _ = vm.Value
                          .Subscribe(newVal => value = newVal);
            Assert.AreEqual(TestEnum.First, value);
            vm.Value.OnNext(TestEnum.Second);
            Assert.AreEqual(TestEnum.Second, value);
        }
Esempio n. 15
0
        public void Values()
        {
            var vm = new EnumViewModel <TestEnum>(TestEnum.First);

            Assert.IsTrue(new List <TestEnum>()
            {
                TestEnum.First, TestEnum.Second, TestEnum.Third
            }
                          .Zip(vm.Values)
                          .All((vals) => vals.First == vals.Second));
        }
        internal static MappingBase GetFor(EnumViewModel model)
        {
            switch (model)
            {
            case EnumViewModel.MappingAirplaneEntity:
                return(new MappingAirplaneEntity());

            default:
                throw new NotImplementedException(string.Format("The mapping for type {0} is not implemented.", model));
            }
        }
Esempio n. 17
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            comboMode.DataSource = EnumViewModel <EduProgramProfileDirectoryMode> .GetValues(ViewModelContext, false);

            comboMode.DataBind();

            radioTimeToLearnDisplayMode.DataSource = EnumViewModel <TimeToLearnDisplayMode> .GetValues(ViewModelContext, false);

            radioTimeToLearnDisplayMode.DataBind();
        }
Esempio n. 18
0
        public void OnEnumChangedTest()
        {
            bool isCalled = false;

            var prop = new EnumProperty(typeof(Hoge));
            var vm   = new EnumViewModel(prop);

            vm.OnChanged.Subscribe(x => isCalled = true);

            vm.EnumValue.Value = Hoge.B;
            isCalled.IsTrue();
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            radioSelectionMode.DataSource = EnumViewModel <DivisionSelectionMode> .GetValues(ViewModelContext, false);

            radioSelectionMode.DataBind();
            radioSelectionMode.SelectedIndex = (int)DefaultMode;

            comboDivision.Visible = DefaultMode == DivisionSelectionMode.List;
            treeDivision.Visible  = DefaultMode == DivisionSelectionMode.Tree;
        }
		public ObjectGraphControl()
		{
			InitializeComponent();
			
			debuggerService = DebuggerService.CurrentDebugger as WindowsDebugger;
			if (debuggerService == null) throw new ApplicationException("Only windows debugger is currently supported");
			
			this.layoutViewModel = new EnumViewModel<LayoutDirection>();
			this.layoutViewModel.PropertyChanged += new PropertyChangedEventHandler(layoutViewModel_PropertyChanged);
			this.cmbLayoutDirection.DataContext = this.layoutViewModel;
			
			this.graphDrawer = new GraphDrawer(this.canvas);
		}
        public void EnumViewModelConverter_ConvertBack()
        {
            EnumViewModelConverter converter = new EnumViewModelConverter();
            object result;

            EnumViewModel viewModel = new EnumViewModel(FitnessType.Raw, "Test");

            result = converter.ConvertBack(viewModel, null, null, null);
            Assert.Equal(viewModel.Value, result);

            result = converter.ConvertBack(null, null, null, null);
            Assert.Null(result);
        }
        /// <summary>
        /// 获取动态属性的值。
        /// </summary>
        /// <param name="dynamicProperty">对应的动态属性的名称。</param>
        /// <param name="desiredType">需要转换的类型。</param>
        /// <returns></returns>
        public object GetDynamicProperty(string dynamicProperty, Type desiredType = null)
        {
            var result = this[dynamicProperty];

            if (desiredType != null && result != null)
            {
                if (desiredType.IsEnum)
                {
                    result = EnumViewModel.Parse(result as string, desiredType);
                }
                result = TypeHelper.CoerceValue(desiredType, result);
            }

            return(result);
        }
Esempio n. 23
0
        public JsonResult GetCategory()
        {
            var list = new List <EnumViewModel>();

            foreach (var value in Enum.GetValues(typeof(Enums.Category)))
            {
                var s = new EnumViewModel
                {
                    EnumString = value.ToString(),
                    Id         = Convert.ToInt32(value)
                };
                list.Add(s);
            }
            return(Json(list));
        }
Esempio n. 24
0
        // [TypeFilter(typeof(AuthorizeAction), Arguments = new object[] { "Write" })]
        public IActionResult Update(long ID)
        {  // returns Update view
            EnumViewModel model = new EnumViewModel();

            InitAccessModel(model);
            model.EnumMaster = _interface.GetData(ID);
            if (model != null)
            {
                return(View("Index", model));
            }
            else
            {
                resp.Message = "";
                return(Json(resp));
            }
        }
        public ObjectGraphControl()
        {
            InitializeComponent();

            debuggerService = DebuggerService.CurrentDebugger as WindowsDebugger;
            if (debuggerService == null)
            {
                throw new ApplicationException("Only windows debugger is currently supported");
            }

            this.layoutViewModel = new EnumViewModel <LayoutDirection>();
            this.layoutViewModel.PropertyChanged += new PropertyChangedEventHandler(layoutViewModel_PropertyChanged);
            this.cmbLayoutDirection.DataContext   = this.layoutViewModel;

            this.graphDrawer = new GraphDrawer(this.canvas);
        }
Esempio n. 26
0
        public EnumBoxConfig(Type enumType)
        {
            this.queryMode    = "local";
            this.displayField = "text";
            this.valueField   = "text";
            var models = EnumViewModel.GetByEnumType(enumType);

            this.store = new ArrayStoreConfig
            {
                fields = new string[] { "text", "value" },
                data   = models.Select(vm => new EnumModel
                {
                    text  = vm.Label,
                    value = (int)(object)vm.EnumValue
                }).ToArray()
            };
        }
        public SimilarityOptionsViewModel(ISchedulers schedulers, SimilarityOptions similarityOptions)
        {
            RenameDetectionMode = new EnumViewModel <RenameDetectionMode>(similarityOptions.RenameDetectionMode)
                                  .DisposeWith(_disposable);
            BreakRewriteThresholdInput = new IntegerInputViewModel(schedulers, similarityOptions.BreakRewriteThreshold)
                                         .DisposeWith(_disposable);
            CopyThresholdInput = new IntegerInputViewModel(schedulers, similarityOptions.CopyThreshold)
                                 .DisposeWith(_disposable);
            RenameFromRewriteThresholdInput = new IntegerInputViewModel(schedulers, similarityOptions.RenameFromRewriteThreshold)
                                              .DisposeWith(_disposable);
            RenameLimitInput = new IntegerInputViewModel(schedulers, similarityOptions.RenameLimit)
                               .DisposeWith(_disposable);
            RenameThresholdInput = new IntegerInputViewModel(schedulers, similarityOptions.RenameThreshold)
                                   .DisposeWith(_disposable);
            WhitespaceMode = new EnumViewModel <WhitespaceMode>(similarityOptions.WhitespaceMode)
                             .DisposeWith(_disposable);

            SimilarityObservable = Observable
                                   .CombineLatest(
                RenameDetectionMode.Value,
                BreakRewriteThresholdInput.Value,
                CopyThresholdInput.Value,
                RenameFromRewriteThresholdInput.Value,
                RenameLimitInput.Value,
                RenameThresholdInput.Value,
                WhitespaceMode.Value,
                (
                    renameDetectionMode,
                    breakRewriteThreshold,
                    copyThreshold,
                    renameFromRewirteThreshold,
                    renameLimit,
                    renameThreshold,
                    whitespaceMode)
                => new SimilarityOptions()
            {
                RenameDetectionMode        = renameDetectionMode,
                BreakRewriteThreshold      = breakRewriteThreshold,
                CopyThreshold              = copyThreshold,
                RenameFromRewriteThreshold = renameFromRewirteThreshold,
                RenameLimit     = renameLimit,
                RenameThreshold = renameThreshold,
                WhitespaceMode  = whitespaceMode,
            });
        }
        /// <summary>
        /// 获取指定名称的动态属性值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dynamicProperty">对应的动态属性的名称。</param>
        /// <param name="defaultValue">如果属性还没有值,则返回这个默认值。</param>
        /// <returns></returns>
        public T GetDynamicPropertyOrDefault <T>(string dynamicProperty, T defaultValue = default(T))
        {
            object result;

            if (_dynamics != null)
            {
                if (_dynamics.TryGetValue(dynamicProperty, out result))
                {
                    var desiredType = typeof(T);
                    if (desiredType.IsEnum)
                    {
                        result = EnumViewModel.Parse(result as string, desiredType);
                    }
                    return((T)TypeHelper.CoerceValue(desiredType, result));
                }
            }

            return(defaultValue);
        }
Esempio n. 29
0
        internal static object ToServerValue(Type serverType, object value)
        {
            if (serverType.IsEnum)
            {
                value = EnumViewModel.Parse(value as string, serverType);
            }
            else if (serverType == typeof(Nullable <int>))
            {
                var intValue = Convert.ToInt32(value);
                if (intValue == 0)
                {
                    value = null;
                }
                else if (!(value is int))
                {
                    value = intValue;
                }
            }
            else if (serverType == typeof(Nullable <Guid>))
            {
                if (value != null)
                {
                    var guidValue = Guid.Parse(value.ToString());
                    if (guidValue == Guid.Empty)
                    {
                        value = null;
                    }
                }
            }
            else if (serverType == typeof(Guid))
            {
                if (value != null)
                {
                    value = Guid.Parse(value.ToString());
                }
                else
                {
                    value = Guid.Empty;
                }
            }

            return(value);
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            // fill division levels
            radioDivisionLevel.DataSource = EnumViewModel <DivisionLevel> .GetValues(ViewModelContext, false);

            radioDivisionLevel.DataBind();

            // bind divisions
            divisionSelector.DataSource = new FlatQuery <DivisionInfo> (ModelContext).ListOrderBy(d => d.Title);
            divisionSelector.DataBind();

            // fill edulevels list
            foreach (var eduLevel in new EduLevelQuery(ModelContext).List())
            {
                listEduLevels.AddItem(UniversityFormatHelper.FormatShortTitle(eduLevel.ShortTitle, eduLevel.Title), eduLevel.EduLevelID.ToString());
            }
        }
Esempio n. 31
0
        protected virtual string ReadProperty(WPFEntityPropertyViewMeta property)
        {
            var data = string.Empty;

            try
            {
                if (property.IsReference)
                {
                    var displayPath = property.DisplayPath();
                    var value       = ObjectHelper.GetPropertyValue(this._currentRow, displayPath);
                    if (value != null)
                    {
                        data = value.ToString();
                    }
                }
                else
                {
                    var mp = property.PropertyMeta.ManagedProperty;
                    if (mp != null)
                    {
                        var value = this._currentRow.GetProperty(mp);
                        if (value != null)
                        {
                            if (TypeHelper.IsEnumNullable(mp.PropertyType))
                            {
                                data = EnumViewModel.EnumToLabel((Enum)value).Translate();
                            }
                            else
                            {
                                data = value.ToString();
                            }
                        }
                    }
                }
            }
            catch
            {
                //尽量尝试读取值,读取出错,则忽略错误。
            }

            return(data);
        }