Exemplo n.º 1
0
        public void TestPollingInterval()
        {
            var loggerMock = new Mock <IAnimalFactLogger>();

            loggerMock.Setup(l => l.WriteAsync(It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <string>())).Verifiable();
            var logger = loggerMock.Object;

            var animalFactsMock = new Mock <IAnimalFacts>();

            animalFactsMock.Setup(a => a.GetRandomFactAsync(It.IsAny <string>())).ReturnsAsync(() => new AnimalFact()).Verifiable();
            var facts = animalFactsMock.Object;

            var poller = new PollingEngine(logger, facts);

            poller.Start(new PollingConfiguration {
                Amount = 1, Animal = "cat", Interval = 1
            });

            Task.Delay(TimeSpan.FromSeconds(2)).Wait();

            poller.Stop();

            loggerMock.Verify(l => l.WriteAsync(It.IsAny <DateTime>(), It.IsAny <string>(), It.IsAny <string>()), Times.AtLeast(2));
            animalFactsMock.Verify(a => a.GetRandomFactAsync(It.IsAny <string>()), Times.AtLeast(2));
        }
Exemplo n.º 2
0
        public IEnumerable <string> GetHAProxyCounterKeys(string nodeKey)
        {
            var node = PollingEngine.GetNode("HAProxy", nodeKey) as HAProxyNode;

            if (node == null)
            {
                return(Enumerable.Empty <string>());
            }
            return(node.Counters.Select(x => x.Key).OrderBy(x => x));
        }
Exemplo n.º 3
0
        public override void Handle()
        {
            var node = PollingEngine.GetNode("HAProxy", Node_Name) as HAProxyNode;

            if (node != null)
            {
                node.Count("Client IP: " + Client_IP, this);
                node.Count("URL: " + this.GetUnique_HTTP_Request_URL(), this);
            }
        }
Exemplo n.º 4
0
        public ActionResult PollAll(string type, string key)
        {
            if (type.IsNullOrEmpty() || key.IsNullOrEmpty())
            {
                return(ContentNotFound());
            }

            PollingEngine.Poll(type, key);

            return(Json(new { success = true }));
        }
Exemplo n.º 5
0
        public ActionResult Poll(Guid?id)
        {
            if (!id.HasValue)
            {
                return(ContentNotFound());
            }

            var success = PollingEngine.Poll(id.Value);

            return(Json(new { success }));
        }
Exemplo n.º 6
0
        public ActionResult Poll(string type, string key, Guid?id)
        {
            if (!type.HasValue() || !key.HasValue())
            {
                return(ContentNotFound());
            }

            var success = PollingEngine.Poll(type, key, id);

            return(Json(new { success }));
        }
Exemplo n.º 7
0
 public ActionResult PollDown()
 {
     try
     {
         PollingEngine.PollAllAsync(true);
         return(Json(true));
     }
     catch (Exception e)
     {
         return(JsonError("Error polling all nodes: " + e.Message));
     }
 }
Exemplo n.º 8
0
 public ActionResult JsonNodes(string type, string uniqueKey, Guid?guid = null)
 {
     if (type.IsNullOrEmpty())
     {
         return(JsonError("type is missing"));
     }
     if (uniqueKey.IsNullOrEmpty())
     {
         return(JsonError("uniqueKey is missing"));
     }
     try
     {
         var pollResult = PollingEngine.Poll(type, uniqueKey, guid, sync: true);
         return(Json(pollResult));
     }
     catch (Exception e)
     {
         return(JsonError("Error polling node: " + e.Message));
     }
 }
Exemplo n.º 9
0
        public ActionResult Debug()
        {
            var sb = new StringBuilder()
                     .AppendFormat("Request IP: {0}\n", Current.RequestIP)
                     .AppendFormat("Request User: {0}\n", Current.User.AccountName)
                     .AppendFormat("Request Roles: {0}\n", Current.User.RawRoles)
                     .AppendLine()
                     .AppendLine("Headers:");

            foreach (string k in Request.Headers.Keys)
            {
                sb.AppendFormat("  {0}: {1}\n", k, Request.Headers[k]);
            }

            var ps = PollingEngine.GetPollingStatus();

            sb.AppendLine()
            .AppendLine("Polling Info:")
            .AppendLine(ps.GetPropertyNamesAndValues());
            return(TextPlain(sb));
        }
Exemplo n.º 10
0
        public async Task <ActionResult> PollNodes(string type, string[] key, Guid?guid = null)
        {
            if (type.IsNullOrEmpty())
            {
                return(JsonError("type is missing"));
            }
            if (!(key?.Any() ?? false))
            {
                return(JsonError("key is missing"));
            }
            try
            {
                var polls   = key.Select(k => PollingEngine.PollAsync(type, k, guid));
                var results = await Task.WhenAll(polls).ConfigureAwait(false);

                return(Json(results.Aggregate(true, (current, r) => current & r)));
            }
            catch (Exception e)
            {
                return(JsonError("Error polling node: " + e.Message));
            }
        }
Exemplo n.º 11
0
        public ActionResult Debug()
        {
            var sb = StringBuilderCache.Get()
                     .AppendLine("Request Info")
                     .Append("  IP: ").AppendLine(Current.RequestIP)
                     .Append("  User: "******"  Roles: ").AppendLine(Current.User.Role.ToString())
                     .AppendLine()
                     .AppendLine("Headers");

            foreach (string k in Request.Headers.Keys)
            {
                sb.AppendFormat("  {0}: {1}\n", k, Request.Headers[k]);
            }

            var ps = PollingEngine.GetPollingStatus();

            sb.AppendLine()
            .AppendLine("Polling Info")
            .AppendLine(ps.GetPropertyNamesAndValues(prefix: "  "));
            return(TextPlain(sb.ToStringRecycle()));
        }
Exemplo n.º 12
0
        protected void Application_Start()
        {
            // disable the X-AspNetMvc-Version: header
            MvcHandler.DisableMvcResponseHeader = true;

            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
            RegisterBundles(BundleTable.Bundles);
            //BundleTable.EnableOptimizations = true;

            SetupMiniProfiler();

            Exceptional.Exceptional.Settings.GetCustomData = GetCustomErrorData;

            TaskScheduler.UnobservedTaskException += (sender, args) => Current.LogException(args.Exception);

            // enable custom model binder
            ModelBinders.Binders.DefaultBinder = new ProfiledModelBinder();

            // When settings change, reload the app pool
            Current.Settings.OnChanged += HttpRuntime.UnloadAppDomain;

            PollingEngine.Configure(t => HostingEnvironment.QueueBackgroundWorkItem(_ => t()));
        }
Exemplo n.º 13
0
 Task <MiniProfiler> IAsyncStorage.LoadAsync(Guid id) => LoadAsync(id) ?? Task.FromResult(PollingEngine.GetCache(id)?.Profiler);
Exemplo n.º 14
0
 protected void Application_End()
 {
     PollingEngine.StopPolling();
 }
Exemplo n.º 15
0
        public NodeStatusViewModel GetNodeStatus(string nodeType, string nodeKey, bool?includeData = false)
        {
            var node = PollingEngine.GetNode(HttpUtility.UrlDecode(nodeType), HttpUtility.UrlDecode(nodeKey));

            return(GetNodeStatusViewModel(node, includeData));
        }
 MiniProfiler IStorage.Load(Guid id) => Load(id) ?? PollingEngine.GetCache(id)?.Profiler;
Exemplo n.º 17
0
 private void OnShutdown()
 {
     PollingEngine.StopPolling();
 }