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)); } } }
// 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()); }
// 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()); }
/// <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))); } }
private void TeamListEventHandler(object sender, JanusProtocolEventArgs e) { e.Response = new Resource(_mimeTypeHtml, HtmlPageBuilder.GetTeamList(_serviceProvider)); }
private void StyleEventHandler(object sender, JanusProtocolEventArgs e) { e.Response = new Resource(_mimeTypeHtml, HtmlPageBuilder.GetNamedStyle(e.Parameters)); }
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)); } }