Exemplo n.º 1
0
        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
                    })
                });
            };
        }
Exemplo n.º 2
0
        public TilesModule(Config cfg, TilesService tilesService, RouteRepository routeRepository)
        {
            _cfg = cfg;
            _tilesService = tilesService;
            _routeRepository = routeRepository;

            Get["/Tiles/{zoom}/{x}/{y}"] = GetTile;
            Get["/Tiles/Route/{routeId}"] = GetTileRoute;
        }
Exemplo n.º 3
0
        public MapModule(Config cfg, TrackRepository trackRepository, RouteRepository routeRepository)
        {
            _cfg = cfg;
            _trackRepository = trackRepository;
            _routeRepository = routeRepository;
            this.RequiresAuthentication();

            Get["/Map"] = x => View["Index"];
            Get["/Map/Route/DownloadRt2/{id}"] = DownloadRt2;
            Post["/Map/uploadTrack"] = UploadTrack;
        }
Exemplo n.º 4
0
        public HomeModule(Config cfg)
        {
            Get["/"] = x => Response.AsRedirect("/Map");
            Get["/Home/ExceptionDetails"] = _ =>
            {
                //this.RequiresAnyClaim(new []{"Claim.System.ExceptionLog.View"});
                return Response.AsText(ExceptionLoggerService.GetLog(cfg.AppPath, long.Parse((string)Request.Query["exceptionId"])), "text/xml");
            };

            Get["/Resource/GetRes"] = _ =>
            {
                var res = (string)Request.Query.resName;
                if (string.IsNullOrEmpty(res)) return string.Empty;
                return Response.AsText(Context.Res(res), "text/plain");
            };
        }
Exemplo n.º 5
0
        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) });
            };
        }
Exemplo n.º 6
0
 public TrackModule(Config cfg)
 {
     Get["/Track/{id}"] = _ => View["Index", _.id];
 }