Создает контент для WebBrowserForm.HtmlPageBuilder.
Inheritance: ServiceConsumer
Exemple #1
0
        public JanusProtocolDispatcher(IServiceProvider serviceProvider)
        {
            _serviceProvider = serviceProvider;

            _pageBuilder    = new HtmlPageBuilder(serviceProvider);
            _xmlPageBuilder = new XmlPageBuilder(serviceProvider, _pageBuilder);

            var methods = GetType().GetMethods(
                BindingFlags.DeclaredOnly
                | BindingFlags.Instance
                | BindingFlags.Public
                | BindingFlags.NonPublic
                | BindingFlags.Static);

            foreach (var mi in methods)
            {
                var attribute =
                    Attribute.GetCustomAttribute(mi, typeof(JanusProtocolEventHandlerAttribute))
                    as JanusProtocolEventHandlerAttribute;

                if (attribute != null)
                {
                    _handlers.Add(attribute.Id,
                                  (JanusProtocolEventHandler)Delegate.CreateDelegate(typeof(JanusProtocolEventHandler), this, mi.Name));
                }
            }
        }
Exemple #2
0
// ReSharper restore ConvertToConstant
// ReSharper restore RedundantDefaultFieldInitializer

		public XmlPageBuilder(IServiceProvider serviceProvider, HtmlPageBuilder pageBuilder)
			: base(serviceProvider)
		{
			_serviceProvider = serviceProvider;
			_pageBuilder = pageBuilder;

			var xslStream = Assembly.GetExecutingAssembly()
				.GetRequiredResourceStream(_resourcePrefix + "Message.xsl");

			using (XmlReader xr = new XmlTextReader(xslStream))
				_xslTransform.Load(xr, null, null);

			_formatters =
				new Lazy<FormatterData[]>(
					() =>
						serviceProvider
							.GetRegisteredElements<MessageFormatterInfo>()
							.Select(info => new FormatterData(info, (IMessageFormatter)info.FormatterType.CreateInstance(serviceProvider)))
							.ToArray());
		}
Exemple #3
0
// ReSharper restore ConvertToConstant
// ReSharper restore RedundantDefaultFieldInitializer

        public XmlPageBuilder(IServiceProvider serviceProvider, HtmlPageBuilder pageBuilder)
            : base(serviceProvider)
        {
            _serviceProvider = serviceProvider;
            _pageBuilder     = pageBuilder;

            var xslStream = Assembly.GetExecutingAssembly()
                            .GetRequiredResourceStream(_resourcePrefix + "Message.xsl");

            using (XmlReader xr = new XmlTextReader(xslStream))
                _xslTransform.Load(xr, null, null);

            _formatters =
                new Lazy <FormatterData[]>(
                    () =>
                    serviceProvider
                    .GetRegisteredElements <MessageFormatterInfo>()
                    .Select(info => new FormatterData(info, (IMessageFormatter)info.FormatterType.CreateInstance(serviceProvider)))
                    .ToArray());
        }
Exemple #4
0
        /// <summary>
        /// Распределяет запросы протокола по обработчикам.
        /// </summary>
        /// <param name="uri">Путь запроса.</param>
        /// <returns>Результат обработки запроса.</returns>
        public Resource DispatchRequest(string uri)
        {
            try
            {
                var info = JanusProtocolInfo.Parse(uri);

                var resource = info != null ? info.ResourceName : uri;

                if (!_handlers.ContainsKey(resource))
                {
                    throw new ArgumentException(string.Format(SR.ResourceNotFound, resource));
                }

                System.Diagnostics.Debug.Assert(info != null);

                var jpea = new JanusProtocolEventArgs(info.Parameters);
                _handlers[resource](this, jpea);
                return(jpea.Response);
            }
            catch (Exception e)
            {
                return(new Resource(_mimeTypeHtml, HtmlPageBuilder.GetExceptionMessage(uri, e)));
            }
        }
Exemple #5
0
 private void TeamListEventHandler(object sender, JanusProtocolEventArgs e)
 {
     e.Response = new Resource(_mimeTypeHtml, HtmlPageBuilder.GetTeamList(_serviceProvider));
 }
Exemple #6
0
 private void StyleEventHandler(object sender, JanusProtocolEventArgs e)
 {
     e.Response = new Resource(_mimeTypeHtml, HtmlPageBuilder.GetNamedStyle(e.Parameters));
 }
Exemple #7
0
 private void MessageAbsentEventHandler(object sender, JanusProtocolEventArgs e)
 {
     e.Response = new Resource(_mimeTypeHtml, HtmlPageBuilder.GetAbsentMessageText(_serviceProvider, e.Id));
 }
		public JanusProtocolDispatcher(IServiceProvider serviceProvider)
		{
			_serviceProvider = serviceProvider;

			_pageBuilder    = new HtmlPageBuilder(serviceProvider);
			_xmlPageBuilder = new XmlPageBuilder(serviceProvider, _pageBuilder);

			var methods = GetType().GetMethods(
				BindingFlags.DeclaredOnly
				| BindingFlags.Instance
				| BindingFlags.Public
				| BindingFlags.NonPublic
				| BindingFlags.Static);

			foreach (var mi in methods)
			{
				var attribute =
					Attribute.GetCustomAttribute(mi, typeof(JanusProtocolEventHandlerAttribute))
						as JanusProtocolEventHandlerAttribute;
				
				if (attribute != null)
					_handlers.Add(attribute.Id,
						(JanusProtocolEventHandler)Delegate.CreateDelegate(typeof(JanusProtocolEventHandler), this, mi.Name));
			}
		}