本文整理汇总了C#中IStore.ResolveMessageType方法的典型用法代码示例。如果您正苦于以下问题:C# IStore.ResolveMessageType方法的具体用法?C# IStore.ResolveMessageType怎么用?C# IStore.ResolveMessageType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStore
的用法示例。
在下文中一共展示了IStore.ResolveMessageType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MessagingModule
public MessagingModule(Config cfg, IStore store)
: base("/Admin/Messaging")
{
Get["/"] = _ => View["Admin/Messaging/Index"];
Get["/Messages"] = _ => Response.AsJson(new { store.Messages });
Get["/Message/{message}/"] = _ =>
{
Type t = store.ResolveMessageType(_.message);
string kind = "other";
if (typeof(Neva.Messaging.IQuery).IsAssignableFrom(t)) kind = "Query";
if (typeof(Neva.Messaging.ICommand).IsAssignableFrom(t)) kind = "Command";
if (typeof(Neva.Messaging.IEvent).IsAssignableFrom(t)) kind = "Event";
return Response.AsJson(new
{
Name = _.message,
Kind = kind,
Properties = t.GetProperties().Select(p => new
{
p.Name,
p.PropertyType,
IsXml = p.GetCustomAttributes(typeof(XmlAttribute), false).Length > 0
})
});
};
}
示例2: MessagingModule
public MessagingModule(Config cfg, IBus bus, IQueryJSonBus reader, IStore store, IResourceContext ctx, IExceptionLoggerService exceptionLoggerService)
{
Get["/query/{name}"] = _ =>
{
long exId = 0;
try
{
var t = store.ResolveMessageType(_["name"]);
if (t == null) throw new Exception("Query not found : " + _["name"]);
var q = (IQuery)Activator.CreateInstance(t);
NevaUtils.ObjectHelper.FillFromString(q, n => Request.Query[n]);
MethodInfo method = typeof(IQueryJSonBus).GetMethod("Read");
MethodInfo generic = method.MakeGenericMethod(t);
var json = (string)generic.Invoke(reader, new object[] { q });
return Response.AsText(json, "application/json");
}
catch (Exception ex)
{
exId = exceptionLoggerService.Log(new Exception("Unable to read query : " + _["name"], ex));
}
return Response.AsJson(new { ExceptionId = exId.ToString(CultureInfo.InvariantCulture) });
};
Post["/command/{name}"] = _ =>
{
long exId = 0;
string cmdId = null;
try
{
var t = store.ResolveMessageType(_.name);
if (t == null) throw new Exception("Command not found : " + _["name"]);
var c = (ICommand)Activator.CreateInstance(t);
//var ci = ctx.CurrentCultureId == 12
// ? new System.Globalization.CultureInfo("fr-FR")
// : new System.Globalization.CultureInfo("en-GB");
var ci = CultureInfo.InvariantCulture;
NevaUtils.ObjectHelper.FillFromString(c, n => Request.Form[n], ci);
var eWrapper = new EventDispatcherWrapper(bus);
MethodInfo method =
typeof(IBus).GetMethods().SingleOrDefault(m => m.Name == "Send" && m.GetParameters().Count() == 2);
System.Diagnostics.Debug.Assert(method != null, "IBus should contains Send methode with 2 parameters");
MethodInfo generic = method.MakeGenericMethod(t);
var r = (CommandResult)generic.Invoke(bus, new object[] { c, eWrapper });
cmdId = r.CommandId;
return Response.AsJson(new
{
ExceptionId = 0,
r.CommandId,
r.CommandValidationErrors,
Events = eWrapper.Events.Select(e => new { Name = e.GetType().FullName, Payload = e }).ToArray()
});
}
catch (Exception ex)
{
if (ex.InnerException is UnauthorizedAccessException)
return new HtmlResponse(HttpStatusCode.Forbidden);
exId = exceptionLoggerService.Log(new Exception("Unable to execute command : " + _["name"], ex));
}
return Response.AsJson(new { cmdId, ExceptionId = exId.ToString(CultureInfo.InvariantCulture) });
};
}