예제 #1
0
        public static Scheduler Create(IServiceEntry entry)
        {
            var s = new Scheduler(entry);

            entry.Container.OnInit();
            return(s);
        }
예제 #2
0
        public static async Task <Scheduler> CreateAsync(IServiceEntry entry)
        {
            var s = new Scheduler(entry);
            await entry.Container.OnInitAsync();

            return(s);
        }
        public void MarkServiceAlerted(IServiceEntry service)
        {
            using (var db = new LiteDatabase(_dbName))
            {
                var store = db.GetCollection <ServiceHistory>(_tableName);
                store.EnsureIndex(x => x.ServiceEntry.Name);

                var match = store.FindOne(x => service.Name == x.ServiceEntry.Name);

                if (match != null)
                {
                    match.LastAlert = DateTimeOffset.Now;
                    store.Update(match);
                }
                else
                {
                    store.Insert(new ServiceHistory
                    {
                        ServiceEntry = service,
                        LastAlert    = DateTimeOffset.Now,
                        LastStatus   = ""
                    });
                }
            }
        }
예제 #4
0
 protected void Dispose(bool disposing)
 {
     if (this.disposed)
     {
         return;
     }
     if (disposing)
     {
         if (this.listener != null)
         {
             if (this.listener.IsListening)
             {
                 this.listener.Stop();
             }
             this.listener.Close();
             this.listener = null;
         }
         if (this.serviceEntry != null)
         {
             this.serviceEntry.Dispose();
             this.serviceEntry          = null;
             this.serviceRequestHandler = null;
         }
     }
     this.disposed = true;
 }
예제 #5
0
        public bool Equals([AllowNull] IServiceEntry other)
        {
            if (other is null)
            {
                return(false);
            }

            return(other.Name.Equals(this.Name) &&
                   other.Url.Equals(this.Url));
        }
예제 #6
0
        public void Start()
        {
            if (this.isStarted == 1)
            {
                return;
            }
            if (this.listener == null)
            {
                this.listener = new HttpListener();
            }
            if (this.serviceEntry == null)
            {
                try
                {
                    string str  = this.serviceName;
                    string str1 = str;
                    if (str != null)
                    {
                        if (str1 == "Blob")
                        {
                            this.serviceEntry = new BlobServiceEntry();
                        }
                        else if (str1 == "Queue")
                        {
                            this.serviceEntry = new QueueServiceEntry();
                        }
                        else
                        {
                            if (str1 != "Table")
                            {
                                throw new Exception("Blob, Queue & Table configuration missing");
                            }
                            this.serviceEntry = new TableServiceEntry();
                        }
                        this.serviceRequestHandler = this.serviceEntry as ServiceRequestHandler;
                        this.serviceEntry.Initialize(this);
                        this.serviceEntry.Start();
                        this.listener.Prefixes.Add(this.UrlBase);
                        this.listener.Start();
                        this.listenerThread = new Thread(new ThreadStart(this.Run));
                        this.listenerThread.Start();
                        return;
                    }
                    throw new Exception("Blob, Queue & Table configuration missing");
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    this.Stop();
                    Logger <IRestProtocolHeadLogger> .Instance.Error.Log(exception.Message);

                    throw;
                }
            }
        }
예제 #7
0
        public void SetServiceStatus(IServiceEntry service, string status)
        {
            var existing = GetHistoryByServiceEntry(service);

            if (existing is null)
            {
                var historyRecord = new ServiceHistory
                {
                    Id           = Guid.NewGuid(),
                    ServiceEntry = service,
                    LastStatus   = status
                };

                _historyRecords.Add(historyRecord);
            }
            else
            {
                existing.LastStatus = status;
            }
        }
예제 #8
0
        public void MarkServiceAlerted(IServiceEntry service)
        {
            var existing = GetHistoryByServiceEntry(service);

            if (existing is null)
            {
                var historyRecord = new ServiceHistory
                {
                    Id           = Guid.NewGuid(),
                    ServiceEntry = service,
                    LastAlert    = DateTimeOffset.Now
                };

                _historyRecords.Add(historyRecord);
            }
            else
            {
                existing.LastAlert = DateTimeOffset.Now;
            }
        }
예제 #9
0
        public async Task <CheckResult> CheckServiceAsync(IServiceEntry service, CancellationToken cancelToken)
        {
            if (service is null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            CheckResult result;

            try
            {
                _logger.LogTrace("Checking Service: {@Service}", service);
                var response = await _client.GetAsync(service.Url, cancelToken);

                _logger.LogDebug("Check Response ({Name}): {Response}", service.Name, response);

                result = new CheckResult
                {
                    Service   = service,
                    IsSuccess = response.IsSuccessStatusCode,
                    ErrorText = response.ReasonPhrase
                };
            }
            catch (Exception ex)
            {
                _logger.LogDebug(ex, "Exception Thrown On Service Check for {@Service}", service);
                result = new CheckResult
                {
                    Service   = service,
                    IsSuccess = false,
                    ErrorText = ex.Message
                };
            }

            return(result);
        }
        public void SetServiceStatus(IServiceEntry service, string status)
        {
            using (var db = new LiteDatabase(_dbName))
            {
                var store = db.GetCollection <ServiceHistory>(_tableName);
                store.EnsureIndex(x => x.ServiceEntry.Name);

                var match = store.FindOne(x => service.Name == x.ServiceEntry.Name);

                if (match != null)
                {
                    match.LastStatus = status;
                    store.Update(match);
                }
                else
                {
                    store.Insert(new ServiceHistory
                    {
                        ServiceEntry = service,
                        LastStatus   = status
                    });
                }
            }
        }
예제 #11
0
 public void Stop()
 {
     if (this.listener != null)
     {
         Interlocked.CompareExchange(ref this.isStarted, 0, 1);
         if (this.listener.IsListening)
         {
             this.listener.Stop();
         }
         this.listener.Close();
         this.listener = null;
     }
     if (this.serviceEntry != null)
     {
         this.serviceEntry.Stop();
         this.serviceEntry          = null;
         this.serviceRequestHandler = null;
     }
     if (this.listenerThread != null)
     {
         this.listenerThread.Abort();
         this.listenerThread = null;
     }
 }
예제 #12
0
 /// <summary>
 /// 初始化调度器
 /// </summary>
 /// <param name="entry"></param>
 private Scheduler(IServiceEntry entry)
 {
     _entry = entry ?? throw new ArgumentNullException(nameof(entry));
 }
예제 #13
0
        private ServiceHistory GetHistoryByServiceEntry(IServiceEntry entry)
        {
            var existing = _historyRecords.Where(x => x.ServiceEntry.Name == entry.Name).FirstOrDefault();

            return(existing);
        }