Beispiel #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string valueStr = "null";

            if (value == null)
            {
                Logger.Debug("Convert with null value object");
            }
            else
            {
                valueStr = $"{value} ({value.GetType()})";
            }


            Logger.Debug($"Call to {nameof(Convert)} ({valueStr}), {targetType}, {parameter}, {culture})");
            WpfLogEventInfo i = (WpfLogEventInfo)value;
            List <WpfLogEventInfoCommand> r = new List <WpfLogEventInfoCommand>();
            WpfLogEventInfoCommand        e = new WpfLogEventInfoCommand
            {
                Command = DiagnosticCommands.ShowLogEventInfoCommand, WpfLogEventInfo = i
            };

            r.Add(e);
            Logger.Debug($"Returning {r}");
            return(r);
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            byte[]          b    = System.Convert.FromBase64String(X);
            var             json = System.Text.Encoding.UTF8.GetString(b);
            WpfLogEventInfo i    = JsonConvert.DeserializeObject <WpfLogEventInfo>(json);

            return(i);
        }
Beispiel #3
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            Logger.Debug("ConvertFrom");

            if (value is string s)
            {
                byte[]          b    = System.Convert.FromBase64String(s);
                var             json = Encoding.UTF8.GetString(b);
                WpfLogEventInfo i    = JsonConvert.DeserializeObject <WpfLogEventInfo>(json);
                return(i);
            }

            return(base.ConvertFrom(context, culture, value));
        }
 public JsonStoreMarkupExtension(WpfLogEventInfo i)
 {
 }
Beispiel #5
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
                                         Type destinationType)
        {
            if (context != null)
            {
                var o = context.GetService(typeof(IProvideValueTarget));
                if (o == null)
                {
                    Logger.Debug("no servie");
                }

                var o2 = context.GetService(typeof(IDestinationTypeProvider));
                if (o2 == null)
                {
                    Logger.Debug("no servie");
                }

                var instance    = context.Instance;
                var instanceStr = $"[{instance.GetType()}]";
                if (instance is FrameworkElement fElem)
                {
                    var elemStr = $"Name={fElem.Name}";
                    instanceStr += elemStr;
                }

                if (context.PropertyDescriptor != null)
                {
                    var propType          = context.PropertyDescriptor.PropertyType;
                    var propName          = context.PropertyDescriptor.Name;
                    var propComponentType = context.PropertyDescriptor.ComponentType;
                    var propString        = $"[{propType}] [{propComponentType}].[{propName}]";
                    Logger.Debug($"prop: {propString}");
                }

                Logger.Debug($"instance: {instanceStr}");

                if (o is IProvideValueTarget service)
                {
                    Logger.Debug($"{service.TargetObject}.{service.TargetProperty}");
                }
            }

            Logger.Debug("ConvertTo");
            if (typeof(MarkupExtension).IsAssignableFrom(destinationType))
            {
                if (value == null)
                {
                    return(new NullExtension());
                }

                WpfLogEventInfo i    = (WpfLogEventInfo)value;
                var             json = JsonConvert.SerializeObject(i);

                return(new TestMarkupExtension(
                           System.Convert.ToBase64String(Encoding.UTF8.GetBytes(json))));
            }
            else if (destinationType == typeof(String))
            {
                WpfLogEventInfo i    = (WpfLogEventInfo)value;
                var             json = JsonConvert.SerializeObject(i);

                return(System.Convert.ToBase64String(Encoding.UTF8.GetBytes(json)));
            }

            Logger.Debug("beep");
            return(base.ConvertTo(context, culture, value, destinationType));
        }
 public TestMarkupExtension(WpfLogEventInfo i)
 {
 }