Exemple #1
0
 public void Start(ServicesConfiguration configuration)
 {
     if (status.TryChangeState(ServiceLauncherState.Stopped, ServiceLauncherState.Starting))
     {
         consoleHandler.AddStopHandler(StopAll);
         output.Info("Launching services...\r\n");
         foreach (var servicesGroup in configuration.Groups.OrderByDescending(x => x.Priority))
         {
             foreach (var service in servicesGroup.Services.OrderByDescending(x => x.Priority))
             {
                 if (!status.HasState(ServiceLauncherState.Starting))
                 {
                     return;
                 }
                 try
                 {
                     output.Info(string.Format("Starting {0}...", service.Name));
                     var process = processLauncher.Launch(service);
                     process.OnExit += (sender, args) =>
                     {
                         processes.Remove(process);
                         if (status.HasState(ServiceLauncherState.Stopping) || status.HasState(ServiceLauncherState.Stopped))
                         {
                             return;
                         }
                         output.Error(string.Format("Service {0} has exited", process.Name));
                     };
                     processes.Add(process);
                     output.Info(string.Format("Service {0} launched", service.Name));
                 }
                 catch (Exception exception)
                 {
                     output.Error(string.Format("Service {0} failed to launch", service.Name), exception);
                 }
             }
             threadSleeper.Sleep(servicesGroup.Timeout);
         }
         status.ChangeState(ServiceLauncherState.Started);
         output.Info("\r\nServices were launched");
     }
 }
        private void EnsureInitialized()
        {
            if (_isInitialized)
            {
                return;
            }

            _logger.Warn("Initializing Cache");

            _threadSleeper.Sleep(TimeSpan.FromSeconds(3));

            _isInitialized = true;
        }
        /// <summary>
        ///		Posts string data to a URL and receive a string response.
        /// </summary>
        /// <param name="url">
        ///		The URL to post the data to.
        /// </param>
        /// <param name="postString">
        ///		String data to post to the remote server.
        /// </param>
        /// <returns>
        ///		The string response data from the post request.
        /// </returns>
        public string PostData(string url, string postString)
        {
            var    tryCount = 0;
            string response;

            do
            {
                tryCount++;

                //Delay the subsequent requests
                if (tryCount > 1)
                {
                    _threadSleeper.Sleep(TimeSpan.FromSeconds(1.0));
                }

                response = _poster.PostData(url, postString);
            } while (tryCount < 5 && (response.Length == 0 || response == "-1"));

            return(response);
        }
Exemple #4
0
 private void OnGameStepEvent(object sender, GameStepEventArgs e)
 {
     sleeper.Sleep();
 }