Exemple #1
0
 private void TimerCallback(object state)
 {
     if (_processing)
     {
         return;
     }
     _processing = true;
     try
     {
         var statusData = OnFetchStatus?.Invoke();
         if (statusData == null)
         {
             _processing = false;
             return;
         }
         Core.Log.LibDebug("Sending status data to the diagnostic queue.");
         _queueClient = _queueClient ?? Core.Services.GetQueueClient(_queueName);
         _queueClient.SendAsync(statusData).WaitAndResults();
     }
     catch (Exception ex)
     {
         Core.Log.Write(ex);
     }
     _processing = false;
 }
        /// <inheritdoc />
        /// <summary>
        /// Action to execute when the trigger occurs
        /// </summary>
        protected override void OnAction()
        {
            var status = OnFetchStatus?.Invoke();

            try
            {
                if (status == null)
                {
                    return;
                }
                var now      = Core.Now;
                var filename = FileNameFormat
                               .Replace("{yyyy}", now.ToString("yyyy"))
                               .Replace("{MM}", now.ToString("MM"))
                               .Replace("{dd}", now.ToString("dd"))
                               .Replace("{HH}", now.ToString("HH"))
                               .Replace("{mm}", now.ToString("mm"));

                var filePath = SPath.Combine(AppContext.BaseDirectory, Path, filename);
                var folder   = SPath.GetDirectoryName(filePath);
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                Serializer.SerializeToFile(status, filePath);
            }
            catch (Exception ex)
            {
                Core.Log.Write(ex);
            }
        }
Exemple #3
0
 private void TimerCallback(object state)
 {
     if (!_enabled)
     {
         return;
     }
     if (Interlocked.CompareExchange(ref _processing, 1, 0) == 1)
     {
         return;
     }
     try
     {
         var statusData = OnFetchStatus?.Invoke();
         if (statusData is null)
         {
             Interlocked.Exchange(ref _processing, 0);
             return;
         }
         Core.Log.LibDebug("Sending status data to the diagnostic queue.");
         if (_queueClient is null)
         {
             _queueClient = Core.Services.GetQueueRawClient(_queueName, true);
             Core.Status.AttachChild(_queueClient, this);
         }
         _queueClient.SendAsync(statusData).WaitAndResults();
     }
     catch (UriFormatException fException)
     {
         Core.Log.Warning($"Disabling {nameof(MessagingStatusTransport)}. Reason: {fException.Message}");
         _enabled = false;
         _timer.Dispose();
     }
     catch (Exception ex)
     {
         Core.Log.Write(ex);
     }
     Interlocked.Exchange(ref _processing, 0);
 }
Exemple #4
0
        public HttpStatusTransport(int port = 80)
        {
            var htmlPage       = this.GetAssembly().GetResourceString("Status.htm");
            var xmlSerializer  = new XmlTextSerializer();
            var jsonSerializer = new JsonTextSerializer()
            {
                UseCamelCase = true
            };

            _httpServer = new SimpleHttpServer();
            _httpServer.AddGetHandler("/", ctx =>
            {
                ctx.Response.Write(htmlPage);
            });
            _httpServer.AddGetHandler("/xml", ctx =>
            {
                if (OnFetchStatus == null)
                {
                    return;
                }
                var statuses             = OnFetchStatus.Invoke();
                ctx.Response.ContentType = SerializerMimeTypes.Xml;
                xmlSerializer.Serialize(statuses, ctx.Response.OutputStream);
            });
            _httpServer.AddGetHandler("/json", ctx =>
            {
                if (OnFetchStatus == null)
                {
                    return;
                }
                var statuses             = OnFetchStatus.Invoke();
                ctx.Response.ContentType = SerializerMimeTypes.Json;
                jsonSerializer.Serialize(statuses, ctx.Response.OutputStream);
            });
            _httpServer.AddGetHandler("/gccollect", ctx =>
            {
                GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                ctx.Response.ContentType = SerializerMimeTypes.Json;
                ctx.Response.Write("true");
            });
            _httpServer.AddGetHandler("/discovery", ctx =>
            {
                var services       = DiscoveryService.GetRegisteredServices();
                var statusServices = services.Where(s => s.Category == DiscoveryService.FrameworkCategory && s.Name == "STATUS.HTTP").ToArray();
                ctx.Response.WriteLine("<html><head><title>Discovered Status Services</title></head><body style='padding:30px;'><h1 style='text-align:center;'>Discovered status services</h1>");
                foreach (var g in statusServices.GroupBy(s => new { s.EnvironmentName, s.MachineName }).OrderBy(s => s.Key.EnvironmentName))
                {
                    ctx.Response.WriteLine($"<h3>Environment: {g.Key.EnvironmentName} - Machine: {g.Key.MachineName}</h3>");
                    ctx.Response.WriteLine("<ul>");
                    foreach (var ss in g)
                    {
                        var dct = (Dictionary <string, object>)ss.Data.GetValue();
                        ctx.Response.WriteLine("<li style='list-style-type: none;'>");
                        foreach (var ssAddress in ss.Addresses)
                        {
                            ctx.Response.WriteLine($"<a href='http://{ssAddress.ToString()}:{dct["Port"]}/' target='_blank' style='text-decoration: none;color: blue;'>{ssAddress.ToString()}</a> /");
                        }
                        ctx.Response.WriteLine($" {ss.ApplicationName}</li>");
                    }
                    ctx.Response.WriteLine("</ul>");
                }
                ctx.Response.WriteLine("</body></html>");
            });
            StartListening(port).WaitAsync();
            Core.Status.DeAttachObject(_httpServer);
        }
Exemple #5
0
 public StatusItemCollection GetStatus()
 => OnFetchStatus?.Invoke();