private void ExecuteCommand <TCommand>(TCommand command, IExecutionContext executionContext) where TCommand : ICommand { if (command == null) { return; } var cx = CreateExecutionContext(executionContext); var handler = _commandHandlerFactory.Create <TCommand>(); if (handler == null) { throw new MissingHandlerMappingException(typeof(TCommand)); } try { _modelValidationService.Validate(command); _executePermissionValidationService.Validate(command, handler, cx); handler.Execute(command, cx); } catch (Exception ex) { _commandLogService.LogFailed(command, cx, ex); throw; } _commandLogService.Log(command, cx); }
private async Task ExecuteCommandAsync <TCommand>(TCommand command, IExecutionContext executionContext) where TCommand : ICommand { if (command == null) { return; } var cx = await CreateExecutionContextAsync(executionContext); var handler = _commandHandlerFactory.CreateAsyncHandler <TCommand>(); if (handler == null) { throw new MissingHandlerMappingException(typeof(TCommand)); } try { _modelValidationService.Validate(command); _executePermissionValidationService.Validate(command, handler, cx); await handler.ExecuteAsync(command, cx); } catch (Exception ex) { await _commandLogService.LogFailedAsync(command, cx, ex); throw; } await _commandLogService.LogAsync(command, cx); }
private TResult ExecuteQuery <TQuery, TResult>(TQuery query, IExecutionContext executionContext) where TQuery : IQuery <TResult> { if (query == null) { return(default(TResult)); } var cx = CreateExecutionContext(executionContext); var handler = _queryHandlerFactory.Create <TQuery, TResult>(); if (handler == null) { throw new MissingHandlerMappingException(typeof(TQuery)); } _modelValidationService.Validate(query); _executePermissionValidationService.Validate(query, handler, cx); var result = handler.Execute(query, cx); return(result); }
/// <summary> /// Creates the SiteMap xml document. /// </summary> public XDocument ToXml() { XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; var doc = new XDocument( new XDeclaration("1.0", "UTF-8", "yes"), new XProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"sitemap.xsl\"")); var urlset = new XElement(ns + "urlset", new XAttribute(XNamespace.Xmlns + "xsi", xsi), new XAttribute(xsi + "schemaLocation", "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd")); doc.Add(urlset); foreach (var resource in Resources .OrderByDescending(p => p.Priority) .ThenBy(p => p.Url)) { _modelValidationService.Validate(resource); var el = new XElement(ns + "url", new XElement(ns + "loc", _uriResolver.MakeAbsolute(resource.Url))); if (resource.LastModifiedDate.HasValue) { el.Add(new XElement(ns + "lastmod", resource.LastModifiedDate.Value.ToString("yyyy-MM-dd"))); } if (resource.Priority.HasValue) { el.Add(new XElement(ns + "priority", resource.Priority.Value.ToString("0.0", CultureInfo.InvariantCulture))); } urlset.Add(el); } return(doc); }