Exemplo n.º 1
0
        public TopService(INancyBootstrapper ninjectNancyBootstrapper, ServiceSettings serviceSettings, Logger logger, IScheduler scheduler)
        {
            _serviceSettings = serviceSettings;
            _ninjectNancyBootstrapper = ninjectNancyBootstrapper;
            _scheduler = scheduler;
            _logger = logger;

            logger.Info("Service was created with base url {0}", serviceSettings.BaseUrl);
            Trace.WriteLine("Service was created with base url: "+serviceSettings.BaseUrl);
        }
Exemplo n.º 2
0
        public AdminModule(ServiceSettings serviceSettings,
            IKernel kernel,
            IDocumentStore documentStore
            )
            : base("/admin")
        {
            Get["/settings"] = x =>
                                   {

                                       ContainerBootstrapper.ReloadAllStoreSettings(kernel);

                                       return Response.AsJson(new ServiceEndpoints.Admin.GetRemoteServiceConfiguration.Response
                                                               {
                                                                   ServiceBaseUrl = serviceSettings.BaseUrl
                                                               });
                                   };
            Get["/info"] = x => Response.AsJson("OK");

            Get["/store/domain-counter"] = x =>
                                            {
                                                var listId = (string)Request.Query["listId"];
                                                var group = (string)Request.Query["group"];
                                                using (var session = documentStore.OpenSession())
                                                {
                                                    RavenQueryStatistics ravenQueryStatistics;
                                                    return Response.AsJson(session.Query<Contacts_DomainGroupCounter.ReduceResult, Contacts_DomainGroupCounter>()
                                                        .Where(result => result.ListId == listId && result.DomainGroup == group)
                                                        .Statistics(out ravenQueryStatistics)
                                                        .Select(result => new { result.Count, result.DomainGroup, ravenQueryStatistics.IsStale }));
                                                }
                                            };

            Get["/test"] = x =>
                {
                    return Response.AsJson(new
                        {
                            CreativeId = "creatives/1",
                            Sex = "contacts/1"
                        });
                };

            Get["/drone-domains"] = x =>
                {
                    using (var session = documentStore.OpenSession())
                    {
                        return
                            Response.AsText(string.Join(Environment.NewLine, session
                                                                                 .Query<Drone>()
                                                                                 .ToList()
                                                                                 .Where(drone => drone.LastUpdated > DateTime.UtcNow.AddMinutes(-6))
                                                                                 .Select(drone => drone.Domain)
                                                                                 .ToList()));
                    }
                };

            Get["/drone-exceptions"] = x =>
                {
                    using (var session = documentStore.OpenSession())
                    {
                        return
                            Response.AsText(string.Join(Environment.NewLine, session
                                                                                 .Query<Drones_Exceptions.ReduceResult, Drones_Exceptions>()
                                                                                 .First(result => result.Group == "All")
                                                                                 .Exceptions.Distinct(new LambdaComparer<string>((m, n) => m.Substring(20) == n.Substring(20)))));
                    }
                };

            Get["/ex"] = _ =>
                {
                    throw new Exception("test");
                };
        }
        private void HyperMedia(NancyContext x, ServiceSettings settings)
        {
            if (!((string)x.Request.Query["hypermedia"]).HasValue())
                return;

            var contents = x.Response.Contents;
            x.Response.Contents = stream =>
                {
                    var memStream = new MemoryStream();
                    contents(memStream);
                    memStream.Position = 0;

                    using (var reader = new StreamReader(memStream))
                    {
                        var responseContent = reader.ReadToEnd();
                        responseContent = Regex.Replace(responseContent, "\"(\\w+?/\\d{1,})\"", match => "\"" + settings.BaseUrl + "/sys/by-id?id=" + match.Groups[1].Value + "\"");

                        var sw = new StreamWriter(stream, Encoding.Default);
                        sw.Write(responseContent);
                        sw.Flush();
                    }
                };
        }
Exemplo n.º 4
0
 public UrlCreator(UrlHelper urlHelper, ServiceSettings serviceSettings)
 {
     _urlHelper = urlHelper;
     _serviceSettings = serviceSettings;
 }