public ControlNameSearchResultViewModel(SearchResultType resultType, string controlName, HighlightedTextInfo highlightedTextInfo)
 {
     this.ResultType          = resultType;
     this.ResultTypeText      = EnumToStringConverter.Convert(this.ResultType);
     this.ControlName         = controlName;
     this.HighlightedTextInfo = highlightedTextInfo;
 }
Ejemplo n.º 2
0
        public void EnumToStringConverterTest()
        {
            var conv = new EnumToStringConverter();

            var a = MockEnum.Simple;
            var b = MockEnum.MultipleWordsInTheName;

            var aForward = conv.Convert(a, typeof(MockEnum), null, _cult) as string;
            var bForward = conv.Convert(b, typeof(MockEnum), null, _cult) as string;

            Assert.AreEqual("Simple", aForward);
            Assert.AreEqual("Multiple Words In The Name", bForward);

            var aBack = conv.ConvertBack(aForward, typeof(MockEnum), null, _cult);
            var bBack = conv.ConvertBack(bForward, typeof(MockEnum), null, _cult);

            Assert.AreEqual(a, aBack);
            Assert.AreEqual(b, bBack);
        }
        public void EnumToStringConverter_ShouldReturn_EmptyString_For_Given_Values(object value)
        {
            var result = _converter.Convert(value);

            Assert.Equal(result, String.Empty);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Filters the specified content.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <param name="filterText"></param>
        public bool Filter(object content, string filterText)
        {
            if (filterText == null)
            {
                return(false);
            }

            filterText = filterText.ToLower();
            IDebugState debugState = content as IDebugState;

            if (debugState != null)
            {
                string convertedActivityType = Convert.ToString(_enumToStringConverter.Convert(debugState.ActivityType, null, null, null));
                if (convertedActivityType.ToLower().Contains(filterText))
                {
                    return(true);
                }

                if (debugState.ActivityType.ToString().ToLower().Contains(filterText))
                {
                    return(true);
                }
                if (debugState.DisplayName != null && debugState.DisplayName.ToLower().Contains(filterText))
                {
                    return(true);
                }
                if (debugState.ActivityType == ActivityType.Step && debugState.Name != null && debugState.Name.ToLower().Contains(filterText))
                {
                    return(true);
                }
                if (debugState.ActivityType == ActivityType.Workflow && debugState.Server != null && debugState.Server.ToLower().Contains(filterText))
                {
                    return(true);
                }
                if (debugState.Version != null && debugState.Version.ToLower().Contains(filterText))
                {
                    return(true);
                }

                if (debugState.ActivityType == ActivityType.Step)
                {
                    string convertedDuration = Convert.ToString(_timeSpanToStringConverter.Convert(debugState.Duration, null, null, null));
                    if (convertedDuration.ToLower().Contains(filterText))
                    {
                        return(true);
                    }
                }

                if (debugState.ActivityType == ActivityType.Workflow)
                {
                    string convertedStartTime = Convert.ToString(_dateTimeToStringConverter.Convert(debugState.StartTime, null, null, null));
                    if (debugState.StateType == StateType.Before && convertedStartTime.ToLower().Contains(filterText))
                    {
                        return(true);
                    }

                    string convertedEndTime = Convert.ToString(_dateTimeToStringConverter.Convert(debugState.EndTime, null, null, null));
                    if (debugState.StateType == StateType.After && convertedEndTime.ToLower().Contains(filterText))
                    {
                        return(true);
                    }
                }

                if (debugState.Inputs != null && debugState.Inputs.Any(o => o.Contains(filterText)))
                {
                    return(true);
                }
                if (debugState.Outputs != null && debugState.Outputs.Any(o => o.Contains(filterText)))
                {
                    return(true);
                }
            }
            else if (content is string && content.ToString().ToLower().Contains(filterText))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
 public void CanConvertEnumToString(TestEnum value, string expected)
 {
     Assert.That(_converter.Convert(value, typeof(string), null, CultureInfo.InvariantCulture), Is.EqualTo(expected));
 }
Ejemplo n.º 6
0
        private void Disect()
        {
            stackVals.Children.Clear();
            stackKeys.Children.Clear();

            List <UiInfo> infos = new List <UiInfo>();

            ItemToShow.GetType().GetProperties().ForEach(x =>
            {
                try
                {
                    var ui = x.GetCustomAttribute(typeof(UiInformationAttribute), true);
                    if (ui != null)
                    {
                        var item       = ui as UiInformationAttribute;
                        bool isVisible = true;
                        if (!string.IsNullOrEmpty(item.IsVisible))
                        {
                            // must look for function
                            var method = ItemToShow.GetType().GetMethod(item.IsVisible, BindingFlags.NonPublic | BindingFlags.Instance);
                            if (method == null)
                            {
                                var message =
                                    StringExt.Format("Missing method: {0} for UiInformationAttribute in class {1}", item.IsVisible,
                                                     ItemToShow.GetType().Name);
                                _log.Error(message);
                                throw new UiInformationException(message);
                            }
                            if (method.ReturnType != typeof(bool))
                            {
                                var message =
                                    StringExt.Format("UiInformationAttribute.IsVisible: {0} method must return a bool", item.IsVisible);
                                _log.Error(message);
                                throw new UiInformationException(message);
                            }
                            isVisible = (bool)method.Invoke(ItemToShow, null);
                        }

                        if (isVisible)
                        {
                            infos.Add(new UiInfo()
                            {
                                Attribute = item, Prop = x
                            });
                        }
                    }
                }
                catch (Exception pokemon)
                {
                    _log.Error(pokemon.Message, pokemon);
                    throw;
                }
            });

            infos.Sort(
                (info, uiInfo) =>
            {
                if (info.Attribute.Position < uiInfo.Attribute.Position)
                {
                    return(-1);
                }
                if (info.Attribute.Position > uiInfo.Attribute.Position)
                {
                    return(1);
                }
                return(0);
            });

            foreach (var uiInfo in infos)
            {
                var labelKey = new StackPanel()
                {
                    Height = ItemSize, HorizontalAlignment = HorizontalAlignment.Left
                };

                string name = uiInfo.Attribute.Name;
                if (name == null)
                {
                    var nameProperty = ItemToShow.GetType().GetProperty(uiInfo.Attribute.NameProperty, BindingFlags.Instance | BindingFlags.NonPublic);
                    name = (string)nameProperty.GetMethod.Invoke(ItemToShow, null);
                }

                labelKey.Children.Add(new Label()
                {
                    Content = name,
                    Style   = (FindResource("LabelNamePanelList") as Style)
                });
                stackKeys.Children.Add(labelKey);
                var binding = new Binding(uiInfo.Prop.Name);
                binding.Source = ItemToShow;

                if (uiInfo.Prop.PropertyType.IsEnum)
                {
                    binding.Converter = new EnumToStringConverter();
                }

                var child = new Label()
                {
                    Style = (FindResource("LabelValuePanelList") as Style), HorizontalAlignment = HorizontalAlignment.Left
                };
                var labelVal = new StackPanel()
                {
                    Height = ItemSize, HorizontalAlignment = HorizontalAlignment.Left
                };
                labelVal.Children.Add(child);
                child.SetBinding(Label.ContentProperty, binding);
                stackVals.Children.Add(labelVal);
                if (uiInfo.Attribute.Editor != null)
                {
                    var control = Activator.CreateInstance(uiInfo.Attribute.Editor) as Control;

                    if (control != null)
                    {
                        control.HorizontalAlignment = HorizontalAlignment.Left;
                        control.VerticalAlignment   = VerticalAlignment.Center;
                        control.FontSize            = 20;
                        control.Height = ItemSize;
                    }

                    if (control is ComboBox && uiInfo.Prop.PropertyType.IsEnum)
                    {
                        var converter = new EnumToStringConverter();
                        foreach (var val in uiInfo.Prop.PropertyType.GetEnumValues())
                        {
                            var convertedVal = converter.Convert(val, null, null, null);
                            (control as ComboBox).Items.Add(convertedVal);
                        }
                    }
                    Editor editor = child.BindEditor().Set(control);
                    editor.OnEditorShow += EditorOnOnEditorShow;
                    _editors.Add(editor);
                }
            }
        }