/// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="parameter"></param>
        protected override void Invoke(object parameter)
        {
            CommandConverter typeConverter = new CommandConverter();
            RoutedUICommand  commandToExecute;

            try
            {
                commandToExecute = typeConverter.ConvertFromString(this.Command) as RoutedUICommand;
            }
            catch (Exception e)
            {
                throw new ArgumentException(String.Format("Unable to convert \"{0}\" to a routed event. Verify that the specified string is a properly registered routed event and try again.", this.Command), e);
            }

            commandToExecute.Execute(this.CommandParameter, this.Target);
        }
Exemplo n.º 2
0
        private TypeConverter GetTypeConverter(Type targetType)
        {
            if (!typeConverterDictionary.ContainsKey(targetType))
            {
                if (targetType == typeof(ICommand))
                {
                    CommandConverter converter = new CommandConverter(commandDictionary);
                    typeConverterDictionary.Add(targetType, converter);
                }
                else
                {
                    // Geht davon aus, dass sich alle TypeConverter in derselben Assembly befinden
                    List <Type> typeConverterTypeList = (from t in Assembly.GetAssembly(typeof(TypeConverterBase)).GetTypes()
                                                         where t.GetCustomAttributes(typeof(TargetTypeConverterAttribute), false).Length == 1
                                                         select t).ToList();

                    Type typeConverterType = null;

                    foreach (Type type in typeConverterTypeList)
                    {
                        TargetTypeConverterAttribute attribute = (TargetTypeConverterAttribute)(type.GetCustomAttributes(typeof(TargetTypeConverterAttribute), false))[0];
                        if (attribute.TargetType == targetType)
                        {
                            typeConverterType = type;
                            break;
                        }
                    }

                    if (typeConverterType != null)
                    {
                        typeConverterDictionary.Add(targetType, Activator.CreateInstance(typeConverterType) as TypeConverter);
                    }
                    else
                    {
                        typeConverterDictionary.Add(targetType, null);
                    }
                }
            }

            if (typeConverterDictionary.ContainsKey(targetType))
            {
                return(typeConverterDictionary[targetType]);
            }

            return(null);
        }
Exemplo n.º 3
0
        public MainWindow() : base()
        {
            LogFinder     = new LogFinder();
            app.LogFinder = LogFinder;

            // s.Source = app.Files;
            // var d = CollectionViewSource.GetDefaultView(app.     );
            // int c = (from x in d.SortDescriptions select x).Count();
            // app.Files.Add(new Item(null));
            // Logger.Trace($"{c}");
            InitializeComponent();

            Binding binding = new Binding
            {
                Source = Application.Current,
                Path   = new PropertyPath("LogWindowType")
            };

            SetBinding(LogWindowTypeProperty, binding);

            // DebugWindow debugWindow = new DebugWindow();
            // debugWindow.Show();

            foreach (FieldInfo f in typeof(StartupActions).GetFields(
                         BindingFlags.Static | BindingFlags.Public | BindingFlags.ExactBinding))
            {
                var      fieldValue = f.GetValue(null);
                Delegate d          = fieldValue as Delegate;
                if (d != null)
                {
                    if (!d.GetMethodInfo().GetParameters().Any())
                    {
                        Action a = d as Action;
                        Debug.Assert(a != null);
                        Task.Run(a);
                    }
                }
            }

            // ConsoleWindow consoleWindow = new ConsoleWindow();
            // consoleWindow.Show();
            if (LogWindowType != null)
            {
                _logWindow = LogWindowType.GetConstructor(Type.EmptyTypes).Invoke(null) as Window;
                //_logWindow.ShowActivated = true;
                _logWindow.Show();
            }

            Task.Run(() =>
            {
            });


            ObjectDataProvider o = TryFindResource("DrivesProvider") as ObjectDataProvider;
            var typ = o.ObjectInstance.GetType().ToString();

            Logger.Info($"{o.ObjectInstance}");

            CommandBindings.Add(
                app.LogFinder.FindLogsCommandBinding);

            CommandManager.AddPreviewExecutedHandler(this, (sender, args) =>
            {
                CommandConverter con = new CommandConverter();
                string cmd           = WhatCommand(args.Command);
                var convertFrom      = con.ConvertToString(args.Command);
                //Logger.Info($"{convertFrom} {convertFrom.GetType().FullName}");
                Logger.Info(
                    $" executed {cmd} {args.Parameter} {args.Source} {args.OriginalSource} {args.RoutedEvent}");
            });

            // CollectionViewSource s = new CollectionViewSource();
            // var def = CollectionViewSource.GetDefaultView(LogFinder.Files);
            // Logger.Debug($"{def}");
            // Logger.Debug($"{def}");
            //
            //
            // CollectionViewSource src = new XCol();
            //
            // Binding binding = new Binding
            // {
            //     Source = def
            // };
            //
            // FilesListView.SetBinding(ItemsControl.ItemsSourceProperty,binding);
            //
            // //            FilesListView.ItemsSource = app.Files;
            //            FilesListView.

            /*            Binding binding = new Binding("FullName")
             *          {
             *              Source = this.Files
             *
             *          };
             *
             *          var itemsSourceProperty = ItemsControl.ItemsSourceProperty;
             *
             *          BindingOperations.SetBinding(FilesListView, itemsSourceProperty, binding);
             */
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                var typeInfos = assembly.DefinedTypes.Where((info, i) => info.IsSubclassOf(typeof(TraceSource)));
                if (typeInfos.Count() > 0)
                {
                    var s2 = String.Join(" ",
                                         typeInfos);
                    var         @join = s2;
                    NLog.Logger l     = NLog.LogManager.GetLogger(
                        Path.GetFileName(assembly.Location));
                    foreach (var t in typeInfos)
                    {
                        l.Info(t.Name);
                    }

                    //l.Info($"{assembly.Location} {@join}");
                }
            }
        }
Exemplo n.º 4
0
 public Database(IDbConnection connection, string providerName)
 {
     this.connection = connection;
     this.providerName = providerName;
     this.commandConverter = new CommandConverter(this.connection, this.providerName);
 }
        /// <summary>
        ///  Return an object that should be set on the targetObject's targetProperty
        ///  for this markup extension.  For a StaticExtension this is a static field
        ///  or property value.
        /// </summary>
        /// <param name="serviceProvider">Object that can provide services for the markup extension.</param>
        /// <returns>
        ///  The object to set on this property.
        /// </returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (Member == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionStaticMember));
            }

            object value;

            if (MemberType != null)
            {
                value = SystemResourceKey.GetSystemResourceKey(MemberType.Name + "." + Member);
                if (value != null)
                {
                    return(value);
                }
            }
            else
            {
                value = SystemResourceKey.GetSystemResourceKey(Member);
                if (value != null)
                {
                    return(value);
                }

                // Validate the _member

                int dotIndex = Member.IndexOf('.');
                if (dotIndex < 0)
                {
                    throw new ArgumentException(SR.Get(SRID.MarkupExtensionBadStatic, Member));
                }

                // Pull out the type substring (this will include any XML prefix, e.g. "av:Button")

                string typeString = Member.Substring(0, dotIndex);
                if (typeString == string.Empty)
                {
                    throw new ArgumentException(SR.Get(SRID.MarkupExtensionBadStatic, Member));
                }

                // Get the IXamlTypeResolver from the service provider

                if (serviceProvider == null)
                {
                    throw new ArgumentNullException("serviceProvider");
                }

                IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
                if (xamlTypeResolver == null)
                {
                    throw new ArgumentException(SR.Get(SRID.MarkupExtensionNoContext, GetType().Name, "IXamlTypeResolver"));
                }

                // Use the type resolver to get a Type instance

                MemberType = xamlTypeResolver.Resolve(typeString);

                // Get the member name substring

                Member = Member.Substring(dotIndex + 1, Member.Length - dotIndex - 1);
            }

            value = CommandConverter.GetKnownControlCommand(MemberType, Member);
            if (value != null)
            {
                return(value);
            }

            return(base.ProvideValue(serviceProvider));
        }
Exemplo n.º 6
0
        // Token: 0x06006C01 RID: 27649 RVA: 0x001F15A4 File Offset: 0x001EF7A4
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (base.Member == null)
            {
                throw new InvalidOperationException(SR.Get("MarkupExtensionStaticMember"));
            }
            object obj;

            if (base.MemberType != null)
            {
                obj = SystemResourceKey.GetSystemResourceKey(base.MemberType.Name + "." + base.Member);
                if (obj != null)
                {
                    return(obj);
                }
            }
            else
            {
                obj = SystemResourceKey.GetSystemResourceKey(base.Member);
                if (obj != null)
                {
                    return(obj);
                }
                int num = base.Member.IndexOf('.');
                if (num < 0)
                {
                    throw new ArgumentException(SR.Get("MarkupExtensionBadStatic", new object[]
                    {
                        base.Member
                    }));
                }
                string text = base.Member.Substring(0, num);
                if (text == string.Empty)
                {
                    throw new ArgumentException(SR.Get("MarkupExtensionBadStatic", new object[]
                    {
                        base.Member
                    }));
                }
                if (serviceProvider == null)
                {
                    throw new ArgumentNullException("serviceProvider");
                }
                IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;
                if (xamlTypeResolver == null)
                {
                    throw new ArgumentException(SR.Get("MarkupExtensionNoContext", new object[]
                    {
                        base.GetType().Name,
                        "IXamlTypeResolver"
                    }));
                }
                base.MemberType = xamlTypeResolver.Resolve(text);
                base.Member     = base.Member.Substring(num + 1, base.Member.Length - num - 1);
            }
            obj = CommandConverter.GetKnownControlCommand(base.MemberType, base.Member);
            if (obj != null)
            {
                return(obj);
            }
            return(base.ProvideValue(serviceProvider));
        }