Example #1
0
        public void Load(int port)
        {
            _logger.Information("Loading from cache, for port {0}", port);

            var files = Directory.GetFiles(_cacheFolder);

            _logger.Information(string.Format("Found {0} simulations in the cache", files.Length));

            foreach (var file in files)
            {
                var fileNameFields = file.Split(".".ToCharArray());

                // ReSharper disable once AssignNullToNotNullAttribute
                var currentPort = int.Parse(Path.GetFileName(path: fileNameFields[0]));
                var type        = fileNameFields[1];
                var payload     = File.ReadAllText(file);

                if (port != 0)
                {
                    if (currentPort == port)
                    {
                        _broker.Initialise(currentPort, type, payload);
                        break;
                    }
                    continue;
                }

                _broker.Initialise(currentPort, type, payload);
            }
        }
Example #2
0
        public async Task <HttpResponseMessage> Register(int port, string type)
        {
            Logger.Information("Client at IP '{0}' requested a simulation of type {1} on port {2}.", Helper.GetClientIp(Request), type, port);

            try
            {
                var payload = await Request.Content.ReadAsStringAsync();

                CachingProvider.Save(port, type, payload);
                Broker.Initialise(port, type, payload);

                return(Request.CreateResponse(HttpStatusCode.OK, string.Format("Port {0} is configured to respond by the specified payload.", port)));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Could not start the server. {0}", ex));
            }
        }