Example #1
0
 public BatchUploaderService(IConfiguration configuration, ILogger <BatchUploaderService> logger)
 {
     _configuration = configuration;
     _logger        = logger;
     Started        = false;
     Status         = ServiceStatusEnum.Idle;
 }
 public LobbyChatService(ILogger logger, IServiceProvider provider)
 {
     this.logger        = logger;
     this.provider      = provider;
     this.lobbies       = new ConcurrentDictionary <int, LobbyChatRoom>();
     this.ServiceStatus = ServiceStatusEnum.Active;
 }
 public LobbyChatService(ILogger logger)
 {
     this.logger        = logger;
     this.lobbies       = new ConcurrentDictionary <int, LobbyChatRoom>();
     this.ServiceStatus = ServiceStatusEnum.Active;
     this.mainLobby     = GetOrAddLobby(1, "Main Lobby", OpCodes.LOBBY_TYPE_MAIN, out var _);
 }
Example #4
0
        public static ServiceStatusEnum DohvatiStatusCisServisa()
        {
            ServiceStatusEnum status = ServiceStatusEnum.unknown;

            try
            {
                Controller.StatusService.GetStatus ss = new Controller.StatusService.GetStatus();
                string result = ss.Status();

                switch (result)
                {
                case "green":
                    status = ServiceStatusEnum.green;
                    break;

                case "yellow":
                    status = ServiceStatusEnum.yellow;
                    break;

                case "red":
                    status = ServiceStatusEnum.red;
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(String.Format("Greška kod dohvata statusa:{0}", ex.Message));
                throw;
            }

            return(status);
        }
 public GameClientService(ILogger logger, ILobbyChatService lobbyChatService, IServiceProvider provider)
 {
     this.logger           = logger;
     this.lobbyChatService = lobbyChatService;
     this.provider         = provider;
     this.clients          = new List <GameClientAsync>();
     this.ServiceStatus    = ServiceStatusEnum.Active;
 }
Example #6
0
 public static void SetServiceStatus(int serviceId, ServiceStatusEnum serviceStatus, bool success)
 {
     if (!string.IsNullOrEmpty(Settings.Instance.ServiceStatusDatabasePath))
     {
         SetServiceStatus(serviceId, serviceStatus);
         DatabaseController.SetExtensionSuccessStatus(serviceId, success, Settings.Instance.ServiceStatusDatabasePath);
     }
 }
Example #7
0
 public static void SetServiceStatus(int serviceId, ServiceStatusEnum serviceStatus)
 {
     if (!string.IsNullOrEmpty(Settings.Instance.ServiceStatusDatabasePath))
     {
         ServiceStatusDatabase.Service service = DatabaseController.GetService(serviceId);
         service.ServiceStatus = (ServiceStatusDatabase.Service.ServiceStatusEnum)serviceStatus;
         DatabaseController.SetStatus(service);
     }
 }
        private async Task InternalConnectionLoop(CancellationToken token)
        {
            listener.Start();
            uint clientIds = 1;

            using (token.Register(() =>
            {
                this.ServiceStatus = ServiceStatusEnum.Inactive;
                listener.Stop();
                listener = null;
            }))
            {
                this.ServiceStatus = ServiceStatusEnum.Active;
                while (!token.IsCancellationRequested)
                {
                    try
                    {
                        logger.Verbose("Invoking AcceptTcpClientAsync()");
                        var incomingConnection = await listener.AcceptTcpClientAsync();

                        logger.Verbose($"AcceptTcpClientAsync() has returned with a client, migrating to {nameof(IClientProviderService)}");
                        clientProviderService.AddClient(incomingConnection, clientIds++);
                        logger.Verbose("Client Provider Service now has the client");
                    }
                    catch (ObjectDisposedException ode)
                    {
                        logger.Error(ode, "The service was told to shutdown, or errored, after an incoming connection attempt was made. It is probably safe to ignore this Error as the listener is already shutting down");
                    }
                    catch (InvalidOperationException ioe)
                    {
                        // Either tcpListener.Start wasn't called (a bug!)
                        // or the CancellationToken was cancelled before
                        // we started accepting (giving an InvalidOperationException),
                        // or the CancellationToken was cancelled after
                        // we started accepting (giving an ObjectDisposedException).
                        //
                        // In the latter two cases we should surface the cancellation
                        // exception, or otherwise rethrow the original exception.
                        logger.Error(ioe, $"The {nameof(ClientConnectionService)} was told to shutdown, or errored, before an incoming connection attempt was made. More context is necessary to see if this Error can be safely ignored");
                        if (token.IsCancellationRequested)
                        {
                            logger.Error(ioe, $"The {nameof(ClientConnectionService)} was told to shutdown.");
                        }
                        else
                        {
                            logger.Error(ioe, $"The {nameof(ClientConnectionService)} was not told to shutdown. Please present this log to someone to investigate what went wrong while executing the code");
                        }
                    }
                    catch (OperationCanceledException oce)
                    {
                        logger.Error(oce, $"The {nameof(ClientConnectionService)} was told to explicitly shutdown and no further action is necessary");
                    }
                }
                this.ServiceStatus = ServiceStatusEnum.Inactive;
            }
        }
Example #9
0
        private void DoWork(object state)
        {
            try
            {
                // Is the upload queue
                if (Directory.GetFiles("/app/outputs", "*.result", SearchOption.AllDirectories).Length >
                    _configuration.GetValue <int>("BatchClient:MaxPendingUploads"))
                {
                    _logger.LogWarning("Maximum pending uploads reached. Pausing downloader service.");
                    Status = ServiceStatusEnum.Paused;
                    return;
                }

                _timer?.Change(Timeout.Infinite, 0);
                Status = ServiceStatusEnum.Running;

                var pendingFilesCount = Directory.GetFiles("/app/inputs", "*.").Length;
                if (pendingFilesCount <= 1)
                {
                    _telemetry.TrackTrace("Downloading new batch...");
                    _logger.LogInformation("Downloading new batch...");
                    var batchClient = new BatchClient(_configuration);
                    var result      = batchClient.GetNewBatchAsync().Result;
                    foreach (var output in result.Outputs)
                    {
                        output.BatchId = result.BatchId;
                        File.WriteAllText($"/app/inputs/{output.InputId}.json", JsonConvert.SerializeObject(output));
                    }
                    var wc = new WebClient();
                    foreach (var input in result.Inputs)
                    {
                        var fileName = "/app/inputs/" + input.InputId;
                        wc.DownloadFile(new Uri(input.Parameters), $"{fileName}.part");
                        File.Move($"{fileName}.part", fileName);
                    }

                    _telemetry.TrackTrace($"Downloaded batch {result.BatchId}");
                    _logger.LogInformation($"Downloaded batch {result.BatchId}");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error downloading new batch");
                _telemetry.TrackException(ex);
            }
            _timer?.Change(TimeSpan.FromSeconds(_configuration.GetValue <int>("BatchClient:DownloaderIntervalInSeconds")),
                           TimeSpan.FromSeconds(_configuration.GetValue <int>("BatchClient:DownloaderIntervalInSeconds")));
            Status = ServiceStatusEnum.Idle;
        }
Example #10
0
        internal ServiceStatusEnum Check(string serviceDisplayName, string serverLocation = null)
        {
            if (serverLocation == null)
            {
                serverLocation = Environment.MachineName;
            }
            ServiceStatusEnum serviceStatus = ServiceStatusEnum.Undefined;

            ServiceController[] services = ServiceController.GetServices();
            foreach (var service in services)
            {
                if (service.DisplayName == serviceDisplayName)
                {
                    serviceStatus = Parse(service.Status);
                }
            }
            return(serviceStatus);
        }
 /// <summary>
 /// Sets the Status property
 /// </summary>
 /// <param name="status">Status property</param>
 /// <returns>this instance</returns>
 public GetServiceStatusResult WithStatus(ServiceStatusEnum status)
 {
     this.statusField = status;
     return this;
 }
 /// <summary>
 /// Sets the Status property.
 /// </summary>
 /// <param name="status">Status property.</param>
 /// <returns>this instance.</returns>
 public GetServiceStatusResult WithStatus(ServiceStatusEnum? status)
 {
     this._status = status;
     return this;
 }
 public ServiceStatusEvent(ServiceStatusEnum status)
 {
     Status = status;
 }
Example #14
0
 public ServiceStatusEvent(ServiceStatusEnum status)
 {
     Status = status;
 }