コード例 #1
0
        /// <summary>
        /// Registers a UIHandler to handle the specified UI using a exsisiting Named Registration
        /// </summary>
        /// <param name="handler">UIHandler to be executed when the specified UI is shown</param>
        /// <param name="registrationName">name of the Registration entry in the NamedRegistrations.xml file compiled in the runtime dll</param>
        /// <param name="notification">The events that you want to handle the targed UI</param>
        public void RegisterUIHandler(UIHandler handler, string registrationName, UIHandlerNotification notification)
        {
            if (processMonitor != null)
            {
                throw new InvalidOperationException("You cannot register UIHandlers after the process is executed");
            }
            if (!namedRegistrations.ContainsKey(registrationName))
            {
                throw new ArgumentException("A registration with the name '" + registrationName + "' could not be found");
            }

            UIHandlerRule namedHandler = namedRegistrations[registrationName];

            //register the handler with the same information as the named entry
            handlerRules.Push(new UIHandlerRule(handler, namedHandler.ProcessName, namedHandler.WindowTitle, notification));
        }
コード例 #2
0
        private void RegisterDefaultUIHandlers()
        {
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NamedRegistrations.xml");

            //HACK: VS.NET renames the file to include the full path but razzle does not (this is very annoying)
            if (stream == null)
            {
                stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Code.Microsoft.Test.Loaders.NamedRegistrations.xml");
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(stream);
            stream.Close();

            foreach (XmlElement element in doc.DocumentElement.SelectNodes("Registration"))
            {
                Type      type    = typeof(ApplicationMonitor).Assembly.GetType(element.GetAttribute("Handler"), true, false);
                UIHandler handler = (UIHandler)Activator.CreateInstance(type, true);
                handler.NamedRegistration = element.GetAttribute("Name");
                if (element.GetAttribute("ProcessName").Length > 0)
                {
                    handler.ProcessName = element.GetAttribute("ProcessName");
                }
                if (element.GetAttribute("WindowTitle").Length > 0)
                {
                    handler.WindowTitle = element.GetAttribute("WindowTitle");
                }
                if (element.GetAttribute("AllowMultipleInvocations").Length > 0)
                {
                    handler.AllowMultipleInvocations = bool.Parse(element.GetAttribute("AllowMultipleInvocations"));
                }

                UIHandlerRule rule = new UIHandlerRule(handler, handler.ProcessName, handler.WindowTitle, UIHandlerNotification.All);
                handlerRules.Push(rule);
                namedRegistrations[handler.NamedRegistration] = rule;
            }
        }