Example #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.ViewModules.DeleteStumpModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public DeleteStumpModule(IStumpsHost stumpsHost)
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            Get["/proxy/{serverId}/stumps/{stumpId}/delete"] = _ =>
            {
                var serverId = (string)_.serverId;
                var stumpId = (string)_.stumpId;
                var server = stumpsHost.FindServer(serverId);
                var stump = server.FindStump(stumpId);

                var model = new
                {
                    StumpName = stump.StumpName,
                    StumpId = stump.StumpId,
                    ProxyId = server.ServerId
                };

                return View["deletestump", model];

            };
        }
Example #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="AddWebsiteModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public AddWebsiteModule(IStumpsHost stumpsHost)
        {
            stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost));

            Get["/AddWebsite"] = _ =>
            {
                var port = NetworkInformation.FindRandomOpenPort();

                var model = new
                {
                    OpenPort = port
                };

                return(View["addwebsite", model]);
            };

            Post["/AddWebsite"] = _ =>
            {
                var hostNameTextBox = ((string)(Request.Form.hostNameTextBox.Value ?? string.Empty)).Trim();
                var portTextBox     = ((string)(Request.Form.portTextBox.Value ?? string.Empty)).Trim();
                var useSslCheckBox  = ((string)(Request.Form.useSslCheckBox.Value ?? "off")).Trim();

                int port;
                port = int.TryParse(portTextBox, out port) ? port : 0;
                var useSsl = useSslCheckBox.Equals("on", StringComparison.OrdinalIgnoreCase);

                if (!string.IsNullOrEmpty(hostNameTextBox) && port > 0)
                {
                    stumpsHost.CreateServerInstance(hostNameTextBox, port, useSsl, true);
                }

                return(Response.AsRedirect("/"));
            };
        }
Example #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.ApiModules.ProxyServerModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public ProxyServerModule(IStumpsHost stumpsHost)
            : base("/api")
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            Get["/proxy"] = _ =>
            {

                var modelList = new List<ProxyServerDetailsModel>();
                var serverList = stumpsHost.FindAll();

                foreach (var server in serverList)
                {
                    var model = new ProxyServerDetailsModel
                    {
                        AutoStart = server.AutoStart,
                        ExternalHostName = server.RemoteServerHostName,
                        IsRunning = server.IsRunning,
                        Port = server.ListeningPort,
                        RecordCount = server.Recordings.Count,
                        RecordTraffic = server.RecordTraffic,
                        RequestsServed = server.TotalRequestsServed,
                        StumpsCount = server.StumpCount,
                        StumpsServed = server.RequestsServedWithStump,
                        ProxyId = server.ServerId,
                        UseSsl = server.UseSsl
                    };

                    modelList.Add(model);
                }

                return Response.AsJson(modelList);

            };

            Post["/proxy"] = _ =>
            {
                var model = this.Bind<ProxyServerModel>();

                stumpsHost.CreateServerInstance(model.ExternalHostName, model.Port, model.UseSsl, model.AutoStart);

                return HttpStatusCode.Created;
            };

            Delete["/proxy/{serverId}"] = _ =>
            {
                var serverId = (string)_.serverId;

                stumpsHost.DeleteServerInstance(serverId);

                return HttpStatusCode.OK;
            };
        }
Example #4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.ViewModules.StumpEditorModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public StumpEditorModule(IStumpsHost stumpsHost)
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            Get["/proxy/{serverId}/recording/{recordIndex}/newstump"] = _ =>
            {
                var serverId = (string)_.serverId;
                var recordIndex = (int)_.recordIndex;
                var server = stumpsHost.FindServer(serverId);

                var model = new
                {
                    StumpName = "Stump - " + System.Environment.TickCount.ToString(CultureInfo.InvariantCulture),
                    Origin = (int)StumpOrigin.RecordedContext,
                    StumpId = string.Empty,
                    ProxyId = server.ServerId,
                    ExternalHostName = server.UseSsl ? server.RemoteServerHostName + " (SSL)" : server.RemoteServerHostName,
                    LocalWebsite = "http://localhost:" + server.ListeningPort.ToString(CultureInfo.InvariantCulture) + "/",
                    BackUrl = "/proxy/" + serverId + "/recordings",
                    CreateButtonText = "Create New Stump",
                    LoadRecord = true,
                    LoadStump = false,
                    RecordIndex = recordIndex
                };

                return View["stumpeditor", model];
            };

            Get["/proxy/{serverId}/stumps/{stumpId}"] = _ =>
            {
                var serverId = (string)_.serverId;
                var stumpId = (string)_.stumpId;
                var server = stumpsHost.FindServer(serverId);
                var stump = server.FindStump(stumpId);

                var model = new
                {
                    StumpName = stump.StumpName,
                    Origin = (int)StumpOrigin.ExistingStump,
                    StumpId = stump.StumpId,
                    ProxyId = server.ServerId,
                    ExternalHostName = server.UseSsl ? server.RemoteServerHostName + " (SSL)" : server.RemoteServerHostName,
                    LocalWebsite = "http://localhost:" + server.ListeningPort.ToString(CultureInfo.InvariantCulture) + "/",
                    BackUrl = "/proxy/" + serverId + "/stumps",
                    CreateButtonText = "Save Stump",
                    LoadRecord = false,
                    LoadStump = true,
                    RecordIndex = 0
                };

                return View["stumpeditor", model];
            };
        }
Example #5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="StumpEditorModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public StumpEditorModule(IStumpsHost stumpsHost)
        {
            stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost));

            Get["/proxy/{serverId}/recording/{recordIndex}/newstump"] = _ =>
            {
                var serverId    = (string)_.serverId;
                var recordIndex = (int)_.recordIndex;
                var server      = stumpsHost.FindServer(serverId);

                var model = new
                {
                    StumpName        = $"Stump - {Environment.TickCount}",
                    Origin           = (int)StumpOrigin.RecordedContext,
                    StumpId          = string.Empty,
                    ProxyId          = server.ServerId,
                    ExternalHostName = server.UseSsl ? server.RemoteServerHostName + " (SSL)" : server.RemoteServerHostName,
                    LocalWebsite     = $"http://localhost:{server.ListeningPort}/",
                    BackUrl          = $"/proxy/{serverId}/recordings",
                    CreateButtonText = "Create New Stump",
                    LoadRecord       = true,
                    LoadStump        = false,
                    RecordIndex      = recordIndex
                };

                return(View["stumpeditor", model]);
            };

            Get["/proxy/{serverId}/stumps/{stumpId}"] = _ =>
            {
                var serverId = (string)_.serverId;
                var stumpId  = (string)_.stumpId;
                var server   = stumpsHost.FindServer(serverId);
                var stump    = server.FindStump(stumpId);

                var model = new
                {
                    StumpName        = stump.StumpName,
                    Origin           = (int)StumpOrigin.ExistingStump,
                    StumpId          = stump.StumpId,
                    ProxyId          = server.ServerId,
                    ExternalHostName = server.UseSsl ? server.RemoteServerHostName + " (SSL)" : server.RemoteServerHostName,
                    LocalWebsite     = $"http://localhost:{server.ListeningPort}/",
                    BackUrl          = $"/proxy/{serverId}/stumps",
                    CreateButtonText = "Save Stump",
                    LoadRecord       = false,
                    LoadStump        = true,
                    RecordIndex      = 0
                };

                return(View["stumpeditor", model]);
            };
        }
Example #6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ProxyServerModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public ProxyServerModule(IStumpsHost stumpsHost) : base("/api")
        {
            stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost));

            Get["/proxy"] = _ =>
            {
                var modelList  = new List <ProxyServerDetailsModel>();
                var serverList = stumpsHost.FindAll();

                foreach (var server in serverList)
                {
                    var model = new ProxyServerDetailsModel
                    {
                        AutoStart        = server.AutoStart,
                        ExternalHostName = server.RemoteServerHostName,
                        IsRunning        = server.IsRunning,
                        Port             = server.ListeningPort,
                        RecordCount      = server.Recordings.Count,
                        RecordTraffic    = server.RecordTraffic,
                        RequestsServed   = server.TotalRequestsServed,
                        StumpsCount      = server.StumpCount,
                        StumpsServed     = server.RequestsServedWithStump,
                        ProxyId          = server.ServerId,
                        UseSsl           = server.UseSsl
                    };

                    modelList.Add(model);
                }

                return(Response.AsJson(modelList));
            };

            Post["/proxy"] = _ =>
            {
                var model = this.Bind <ProxyServerModel>();

                stumpsHost.CreateServerInstance(model.ExternalHostName, model.Port, model.UseSsl, model.AutoStart);

                return(HttpStatusCode.Created);
            };

            Delete["/proxy/{serverId}"] = _ =>
            {
                var serverId = (string)_.serverId;

                stumpsHost.DeleteServerInstance(serverId);

                return(HttpStatusCode.OK);
            };
        }
Example #7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.Bootstrapper"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public Bootstrapper(IStumpsHost stumpsHost)
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            using (var resourceStream = this.GetType().Assembly.GetManifestResourceStream("Stumps.Web.Resources.favicon.ico"))
            {
                _favIcon = StreamUtility.ConvertStreamToByteArray(resourceStream);
            }

            _host = stumpsHost;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="PortAvailableModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public PortAvailableModule(IStumpsHost stumpsHost) : base("/api")
        {
            stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost));

            Get["/portAvailable/{port}"] = _ =>
            {
                var port = _.port;

                var model = new PortAvailableModel
                {
                    PortAvailable = !NetworkInformation.IsPortBeingUsed(port),
                };

                return(Response.AsJson(model));
            };
        }
Example #9
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.ViewModules.MainModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public MainModule(IStumpsHost stumpsHost)
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            Get["/"] = _ =>
            {

                var servers = stumpsHost.FindAll();
                servers = servers.OrderBy(x => x.RemoteServerHostName).ToList();

                var list = new ArrayList();

                var hostName = ResolveMachineName();

                foreach (var server in servers)
                {
                    var schema = server.UseHttpsForIncommingConnections ? "https" : "http";

                    list.Add(
                        new
                        {
                            State = ModuleHelper.StateValue(server, "running", "stopped", "recording"),
                            StateImage = ModuleHelper.StateValue(server, "svr_run.png", "svr_stp.png", "svr_rec.png"),
                            ExternalHostName = server.UseSsl ? server.RemoteServerHostName + " (SSL)" : server.RemoteServerHostName,
                            RequestsServed = PrettyNumber(server.TotalRequestsServed),
                            StumpsServed = PrettyNumber(server.RequestsServedWithStump),
                            LocalWebsite = string.Format("{0}://{1}:{2}/", schema, hostName, server.ListeningPort),
                            ProxyId = server.ServerId,
                            IsRunning = server.IsRunning ? "isRunning" : string.Empty,
                            IsRecording = server.RecordTraffic ? "isRecording" : string.Empty,
                            RecordingCount = PrettyNumber(server.Recordings.Count),
                            StumpsCount = PrettyNumber(server.StumpCount)
                        });

                }

                var model = new
                {
                    Websites = list
                };
                return View["main", model];

            };
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="DeleteWebsiteModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public DeleteWebsiteModule(IStumpsHost stumpsHost)
        {
            stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost));

            Get["/proxy/{serverId}/delete"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server   = stumpsHost.FindServer(serverId);

                var model = new
                {
                    ProxyId          = server.ServerId,
                    ExternalHostName = server.RemoteServerHostName
                };

                return(View["deletewebsite", model]);
            };
        }
Example #11
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.ViewModules.RecordingsModule"/> class.
        /// </summary>
        /// <param name="serverHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="serverHost"/> is <c>null</c>.</exception>
        public RecordingsModule(IStumpsHost serverHost)
        {
            if (serverHost == null)
            {
                throw new ArgumentNullException("serverHost");
            }

            Get["/proxy/{serverId}/recordings"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server = serverHost.FindServer(serverId);

                var recordingModelArray = new ArrayList();

                var lastIndex = -1;

                var recordingList = server.Recordings.Find(-1);
                for (var i = 0; i < recordingList.Count; i++)
                {
                    var recordingModel = new
                    {
                        Index = i,
                        Method = recordingList[i].Request.HttpMethod,
                        RawUrl = recordingList[i].Request.RawUrl,
                        StatusCode = recordingList[i].Response.StatusCode
                    };

                    recordingModelArray.Add(recordingModel);
                    lastIndex = i;
                }

                var model = new
                {
                    ProxyId = server.ServerId,
                    ExternalHostName = server.UseSsl ? server.RemoteServerHostName + " (SSL)" : server.RemoteServerHostName,
                    LocalWebsite = "http://localhost:" + server.ListeningPort.ToString(CultureInfo.InvariantCulture) + "/",
                    IsRecording = server.RecordTraffic,
                    LastIndex = lastIndex,
                    Recordings = recordingModelArray
                };

                return View["recordings", model];
            };
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.ApiModules.ProxyServerStatusModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public ProxyServerStatusModule(IStumpsHost stumpsHost)
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            Get["/api/proxy/{serverId}/status"] = _ =>
            {

                var serverId = (string)_.serverId;
                var server = stumpsHost.FindServer(serverId);

                var model = new RunningStatusModel
                {
                    IsRunning = server.IsRunning
                };

                return Response.AsJson(model);

            };

            Put["/api/proxy/{serverId}/status"] = _ =>
            {

                var serverId = (string)_.serverId;
                var environment = stumpsHost.FindServer(serverId);

                var model = this.Bind<RunningStatusModel>();

                if (model.IsRunning && !environment.IsRunning)
                {
                    stumpsHost.Start(serverId);
                }
                else if (!model.IsRunning && environment.IsRunning)
                {
                    stumpsHost.Shutdown(serverId);
                }

                return Response.AsJson(model);

            };
        }
Example #13
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.ApiModules.PortAvailableModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public PortAvailableModule(IStumpsHost stumpsHost)
            : base("/api")
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            Get["/portAvailable/{port}"] = _ =>
            {
                var port = _.port;

                var model = new PortAvailableModel
                {
                    PortAvailable = !NetworkInformation.IsPortBeingUsed(port),
                };

                return Response.AsJson(model);
            };
        }
Example #14
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MainModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public MainModule(IStumpsHost stumpsHost)
        {
            stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost));

            Get["/"] = _ =>
            {
                var servers = stumpsHost.FindAll();
                servers = servers.OrderBy(x => x.RemoteServerHostName).ToList();

                var list = new ArrayList();

                var hostName = ResolveMachineName();

                foreach (var server in servers)
                {
                    var schema = server.UseHttpsForIncomingConnections ? "https" : "http";

                    list.Add(new
                    {
                        State            = ModuleHelper.StateValue(server, "running", "stopped", "recording"),
                        StateImage       = ModuleHelper.StateValue(server, "svr_run.png", "svr_stp.png", "svr_rec.png"),
                        ExternalHostName = server.UseSsl ? server.RemoteServerHostName + " (SSL)" : server.RemoteServerHostName,
                        RequestsServed   = PrettyNumber(server.TotalRequestsServed),
                        StumpsServed     = PrettyNumber(server.RequestsServedWithStump),
                        LocalWebsite     = $"{schema}://{hostName}:{server.ListeningPort}/",
                        ProxyId          = server.ServerId,
                        IsRunning        = server.IsRunning ? "isRunning" : string.Empty,
                        IsRecording      = server.RecordTraffic ? "isRecording" : string.Empty,
                        RecordingCount   = PrettyNumber(server.Recordings.Count),
                        StumpsCount      = PrettyNumber(server.StumpCount)
                    });
                }

                var model = new
                {
                    Websites = list
                };

                return(View["main", model]);
            };
        }
Example #15
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="RecordingsModule"/> class.
        /// </summary>
        /// <param name="serverHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="serverHost"/> is <c>null</c>.</exception>
        public RecordingsModule(IStumpsHost serverHost)
        {
            serverHost = serverHost ?? throw new ArgumentNullException(nameof(serverHost));

            Get["/proxy/{serverId}/recordings"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server   = serverHost.FindServer(serverId);

                var recordingModelArray = new ArrayList();

                var lastIndex = -1;

                var recordingList = server.Recordings.Find(-1);
                for (var i = 0; i < recordingList.Count; i++)
                {
                    var recordingModel = new
                    {
                        Index      = i,
                        Method     = recordingList[i].Request.HttpMethod,
                        RawUrl     = recordingList[i].Request.RawUrl,
                        StatusCode = recordingList[i].Response.StatusCode
                    };

                    recordingModelArray.Add(recordingModel);
                    lastIndex = i;
                }

                var model = new
                {
                    ProxyId          = server.ServerId,
                    ExternalHostName = server.UseSsl ? server.RemoteServerHostName + " (SSL)" : server.RemoteServerHostName,
                    LocalWebsite     = $"http://localhost:{server.ListeningPort}/",
                    IsRecording      = server.RecordTraffic,
                    LastIndex        = lastIndex,
                    Recordings       = recordingModelArray
                };

                return(View["recordings", model]);
            };
        }
Example #16
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="StumpsWebServer" /> class.
        /// </summary>
        /// <param name="host">The Stumps Server host.</param>
        /// <param name="port">The port used to listen for traffic.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="host"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="port" /> is invalid.</exception>
        /// <exception cref="InvalidOperationException">The port is already being used.</exception>
        public StumpsWebServer(IStumpsHost host, int port)
        {
            host = host ?? throw new ArgumentNullException(nameof(host));

            if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException(nameof(port));
            }

            if (NetworkInformation.IsPortBeingUsed(port))
            {
                throw new InvalidOperationException("The port is already being used.");
            }

            var urlString = string.Format(
                System.Globalization.CultureInfo.InvariantCulture, "http://localhost:{0}/", port);

            var bootStrapper = new Bootstrapper(host);

            _server = new NancyHost(bootStrapper, new Uri(urlString));
        }
Example #17
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DeleteStumpModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public DeleteStumpModule(IStumpsHost stumpsHost)
        {
            stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost));

            Get["/proxy/{serverId}/stumps/{stumpId}/delete"] = _ =>
            {
                var serverId = (string)_.serverId;
                var stumpId  = (string)_.stumpId;
                var server   = stumpsHost.FindServer(serverId);
                var stump    = server.FindStump(stumpId);

                var model = new
                {
                    StumpName = stump.StumpName,
                    StumpId   = stump.StumpId,
                    ProxyId   = server.ServerId
                };

                return(View["deletestump", model]);
            };
        }
Example #18
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.ViewModules.DeleteWebsiteModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public DeleteWebsiteModule(IStumpsHost stumpsHost)
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            Get["/proxy/{serverId}/delete"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server = stumpsHost.FindServer(serverId);

                var model = new
                {
                    ProxyId = server.ServerId,
                    ExternalHostName = server.RemoteServerHostName
                };

                return View["deletewebsite", model];
            };
        }
Example #19
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.ViewModules.AddWebsiteModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public AddWebsiteModule(IStumpsHost stumpsHost)
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            Get["/AddWebsite"] = _ =>
            {
                var port = NetworkInformation.FindRandomOpenPort();

                var model = new
                {
                    OpenPort = port
                };

                return View["addwebsite", model];
            };

            Post["/AddWebsite"] = _ =>
            {

                var hostNameTextBox = ((string)(Request.Form.hostNameTextBox.Value ?? string.Empty)).Trim();
                var portTextBox = ((string)(Request.Form.portTextBox.Value ?? string.Empty)).Trim();
                var useSslCheckBox = ((string)(Request.Form.useSslCheckBox.Value ?? "off")).Trim();

                int port;
                port = int.TryParse(portTextBox, out port) ? port : 0;
                var useSsl = useSslCheckBox.Equals("on", StringComparison.OrdinalIgnoreCase);

                if (!string.IsNullOrEmpty(hostNameTextBox) && port > 0)
                {
                    stumpsHost.CreateServerInstance(hostNameTextBox, port, useSsl, true);
                }

                return Response.AsRedirect("/");

            };
        }
Example #20
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="T:Stumps.Web.ViewModules.StumpsOverviewModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="T:Stumps.Server.IStumpsHost"/> used by the instance.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public StumpsOverviewModule(IStumpsHost stumpsHost)
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            Get["/proxy/{serverId}/stumps"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server = stumpsHost.FindServer(serverId);

                var stumpModelArray = new ArrayList();

                var stumpContractList = server.FindAllContracts();
                stumpContractList = stumpContractList.OrderBy(x => x.StumpName).ToList();

                foreach (var contract in stumpContractList)
                {
                    var stumpModel = new
                    {
                        StumpId = contract.StumpId,
                        StumpName = contract.StumpName
                    };

                    stumpModelArray.Add(stumpModel);
                }

                var model = new
                {
                    ProxyId = server.ServerId,
                    ExternalHostName = server.UseSsl ? server.RemoteServerHostName + " (SSL)" : server.RemoteServerHostName,
                    LocalWebsite = "http://localhost:" + server.ListeningPort.ToString(CultureInfo.InvariantCulture) + "/",
                    Stumps = stumpModelArray
                };

                return View["stumpsoverview", model];
            };
        }
Example #21
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Stumps.Web.StumpsWebServer" /> class.
        /// </summary>
        /// <param name="host">The Stumps Server host.</param>
        /// <param name="port">The port used to listen for traffic.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="host"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException"><paramref name="port" /> is invalid.</exception>
        /// <exception cref="System.InvalidOperationException">The port is already being used.</exception>
        public StumpsWebServer(IStumpsHost host, int port)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort)
            {
                throw new ArgumentOutOfRangeException("port");
            }

            if (NetworkInformation.IsPortBeingUsed(port))
            {
                throw new InvalidOperationException("The port is already being used.");
            }

            var urlString = string.Format(
                System.Globalization.CultureInfo.InvariantCulture, "http://localhost:{0}/", port);

            var bootStrapper = new Bootstrapper(host);
            _server = new NancyHost(bootStrapper, new Uri(urlString));
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="StumpsOverviewModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public StumpsOverviewModule(IStumpsHost stumpsHost)
        {
            stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost));

            Get["/proxy/{serverId}/stumps"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server   = stumpsHost.FindServer(serverId);

                var stumpModelArray = new ArrayList();

                var stumpContractList = server.FindAllContracts();
                stumpContractList = stumpContractList.OrderBy(x => x.StumpName).ToList();

                foreach (var contract in stumpContractList)
                {
                    var stumpModel = new
                    {
                        StumpId   = contract.StumpId,
                        StumpName = contract.StumpName
                    };

                    stumpModelArray.Add(stumpModel);
                }

                var model = new
                {
                    ProxyId          = server.ServerId,
                    ExternalHostName = server.UseSsl ? $"{server.RemoteServerHostName} (SSL)" : server.RemoteServerHostName,
                    LocalWebsite     = $"http://localhost:{server.ListeningPort}/",
                    Stumps           = stumpModelArray
                };

                return(View["stumpsoverview", model]);
            };
        }
Example #23
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ProxyServerStatusModule"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public ProxyServerStatusModule(IStumpsHost stumpsHost)
        {
            stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost));

            Get["/api/proxy/{serverId}/status"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server   = stumpsHost.FindServer(serverId);

                var model = new RunningStatusModel
                {
                    IsRunning = server.IsRunning
                };

                return(Response.AsJson(model));
            };

            Put["/api/proxy/{serverId}/status"] = _ =>
            {
                var serverId    = (string)_.serverId;
                var environment = stumpsHost.FindServer(serverId);

                var model = this.Bind <RunningStatusModel>();

                if (model.IsRunning && !environment.IsRunning)
                {
                    stumpsHost.Start(serverId);
                }
                else if (!model.IsRunning && environment.IsRunning)
                {
                    stumpsHost.Shutdown(serverId);
                }

                return(Response.AsJson(model));
            };
        }
Example #24
0
        public RecordingModule(IStumpsHost stumpsHost)
        {
            stumpsHost = stumpsHost ?? throw new ArgumentNullException(nameof(stumpsHost));

            Get["/api/proxy/{serverId}/recording"] = _ =>
            {
                var serverId    = (string)_.serverId;
                var environment = stumpsHost.FindServer(serverId);
                var afterIndex  = -1;

                if (Request.Query.after != null)
                {
                    var afterIndexString = (string)Request.Query.after;
                    afterIndex = int.TryParse(afterIndexString, out afterIndex) ? afterIndex : -1;
                }

                var recordingList = environment.Recordings.Find(afterIndex);
                var modelList     = new List <RecordingModel>();

                foreach (var recording in recordingList)
                {
                    afterIndex++;

                    var model = new RecordingModel
                    {
                        Index             = afterIndex,
                        Date              = recording.ReceivedDate,
                        Method            = recording.Request.HttpMethod,
                        RawUrl            = recording.Request.RawUrl,
                        RequestSize       = recording.Request.BodyLength,
                        ResponseSize      = recording.Response.BodyLength,
                        StatusCode        = recording.Response.StatusCode,
                        StatusDescription = recording.Response.StatusDescription
                    };

                    modelList.Add(model);
                }

                return(Response.AsJson(modelList));
            };

            Get["/api/proxy/{serverId}/recording/{recordIndex}"] = _ =>
            {
                var serverId    = (string)_.serverId;
                var recordIndex = (int)_.recordIndex;
                var server      = stumpsHost.FindServer(serverId);

                var record = server.Recordings.FindAt(recordIndex);

                var model = new RecordingDetailsModel
                {
                    Index                     = recordIndex,
                    RequestBody               = string.Empty,
                    RequestBodyIsImage        = record.Request.BodyType == HttpBodyClassification.Image,
                    RequestBodyIsText         = record.Request.BodyType == HttpBodyClassification.Text,
                    RequestBodyLength         = record.Request.BodyLength,
                    RequestBodyUrl            = "/api/proxy/" + serverId + "/recording/" + recordIndex + "/request",
                    RequestHttpMethod         = record.Request.HttpMethod,
                    RequestRawUrl             = record.Request.RawUrl,
                    RequestDate               = record.ReceivedDate,
                    ResponseBody              = string.Empty,
                    ResponseBodyIsImage       = record.Response.BodyType == HttpBodyClassification.Image,
                    ResponseBodyIsText        = record.Response.BodyType == HttpBodyClassification.Text,
                    ResponseBodyLength        = record.Response.BodyLength,
                    ResponseBodyUrl           = "/api/proxy/" + serverId + "/recording/" + recordIndex + "/response",
                    ResponseStatusCode        = record.Response.StatusCode,
                    ResponseStatusDescription = record.Response.StatusDescription
                };

                model.RequestBody = record.Request.BodyType == HttpBodyClassification.Text
                                         ? record.Request.GetBodyAsString()
                                         : string.Empty;

                model.ResponseBody = record.Response.BodyType == HttpBodyClassification.Text
                                          ? record.Response.GetBodyAsString()
                                          : string.Empty;

                model.RequestHeaders  = GenerateHeaderModels(record.Request);
                model.ResponseHeaders = GenerateHeaderModels(record.Response);

                return(Response.AsJson(model));
            };

            Get["/api/proxy/{serverId}/recording/{recordIndex}/request"] = _ =>
            {
                var serverId    = (string)_.serverId;
                var recordIndex = (int)_.recordIndex;
                var environment = stumpsHost.FindServer(serverId);

                var record = environment.Recordings.FindAt(recordIndex);

                var ms = new System.IO.MemoryStream(record.Request.GetBody());

                return(Response.FromStream(ms, record.Request.Headers["Content-Type"]));
            };

            Get["/api/proxy/{serverId}/recording/{recordIndex}/response"] = _ =>
            {
                var serverId    = (string)_.serverId;
                var recordIndex = (int)_.recordIndex;
                var server      = stumpsHost.FindServer(serverId);

                var record = server.Recordings.FindAt(recordIndex);

                var ms = new System.IO.MemoryStream(record.Response.GetBody());

                return(Response.FromStream(ms, record.Response.Headers["Content-Type"]));
            };

            Get["/api/proxy/{serverId}/recording/status"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server   = stumpsHost.FindServer(serverId);

                var model = new RecordStatusModel
                {
                    RecordTraffic = server.RecordTraffic
                };

                return(Response.AsJson(model));
            };

            Put["/api/proxy/{serverId}/recording/status"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server   = stumpsHost.FindServer(serverId);

                var model = this.Bind <RecordStatusModel>();

                if (model.RecordTraffic)
                {
                    server.Recordings.Clear();
                }

                server.RecordTraffic = model.RecordTraffic;

                return(Response.AsJson(model));
            };
        }
Example #25
0
        public RecordingModule(IStumpsHost stumpsHost)
        {
            if (stumpsHost == null)
            {
                throw new ArgumentNullException("stumpsHost");
            }

            Get["/api/proxy/{serverId}/recording"] = _ =>
            {
                var serverId = (string)_.serverId;
                var environment = stumpsHost.FindServer(serverId);
                var afterIndex = -1;

                if (Request.Query.after != null)
                {
                    var afterIndexString = (string)Request.Query.after;
                    afterIndex = int.TryParse(afterIndexString, out afterIndex) ? afterIndex : -1;
                }

                var recordingList = environment.Recordings.Find(afterIndex);
                var modelList = new List<RecordingModel>();

                foreach (var recording in recordingList)
                {
                    afterIndex++;

                    var model = new RecordingModel
                    {
                        Index = afterIndex,
                        Date = recording.ReceivedDate,
                        Method = recording.Request.HttpMethod,
                        RawUrl = recording.Request.RawUrl,
                        RequestSize = recording.Request.BodyLength,
                        ResponseSize = recording.Response.BodyLength,
                        StatusCode = recording.Response.StatusCode,
                        StatusDescription = recording.Response.StatusDescription
                    };

                    modelList.Add(model);
                }

                return Response.AsJson(modelList);
            };

            Get["/api/proxy/{serverId}/recording/{recordIndex}"] = _ =>
            {
                var serverId = (string)_.serverId;
                var recordIndex = (int)_.recordIndex;
                var server = stumpsHost.FindServer(serverId);

                var record = server.Recordings.FindAt(recordIndex);

                var model = new RecordingDetailsModel
                {
                    Index = recordIndex,
                    RequestBody = string.Empty,
                    RequestBodyIsImage = record.Request.BodyType == HttpBodyClassification.Image,
                    RequestBodyIsText = record.Request.BodyType == HttpBodyClassification.Text,
                    RequestBodyLength = record.Request.BodyLength,
                    RequestBodyUrl = "/api/proxy/" + serverId + "/recording/" + recordIndex + "/request",
                    RequestHttpMethod = record.Request.HttpMethod,
                    RequestRawUrl = record.Request.RawUrl,
                    RequestDate = record.ReceivedDate,
                    ResponseBody = string.Empty,
                    ResponseBodyIsImage = record.Response.BodyType == HttpBodyClassification.Image,
                    ResponseBodyIsText = record.Response.BodyType == HttpBodyClassification.Text,
                    ResponseBodyLength = record.Response.BodyLength,
                    ResponseBodyUrl = "/api/proxy/" + serverId + "/recording/" + recordIndex + "/response",
                    ResponseStatusCode = record.Response.StatusCode,
                    ResponseStatusDescription = record.Response.StatusDescription
                };

                model.RequestBody = record.Request.BodyType == HttpBodyClassification.Text
                                         ? record.Request.GetBodyAsString()
                                         : string.Empty;

                model.ResponseBody = record.Response.BodyType == HttpBodyClassification.Text
                                          ? record.Response.GetBodyAsString()
                                          : string.Empty;

                model.RequestHeaders = GenerateHeaderModels(record.Request);
                model.ResponseHeaders = GenerateHeaderModels(record.Response);

                return Response.AsJson(model);
            };

            Get["/api/proxy/{serverId}/recording/{recordIndex}/request"] = _ =>
            {
                var serverId = (string)_.serverId;
                var recordIndex = (int)_.recordIndex;
                var environment = stumpsHost.FindServer(serverId);

                var record = environment.Recordings.FindAt(recordIndex);

                var ms = new System.IO.MemoryStream(record.Request.GetBody());

                return Response.FromStream(ms, record.Request.Headers["Content-Type"]);
            };

            Get["/api/proxy/{serverId}/recording/{recordIndex}/response"] = _ =>
            {
                var serverId = (string)_.serverId;
                var recordIndex = (int)_.recordIndex;
                var server = stumpsHost.FindServer(serverId);

                var record = server.Recordings.FindAt(recordIndex);

                var ms = new System.IO.MemoryStream(record.Response.GetBody());

                return Response.FromStream(ms, record.Response.Headers["Content-Type"]);
            };

            Get["/api/proxy/{serverId}/recording/status"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server = stumpsHost.FindServer(serverId);

                var model = new RecordStatusModel
                {
                    RecordTraffic = server.RecordTraffic
                };

                return Response.AsJson(model);
            };

            Put["/api/proxy/{serverId}/recording/status"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server = stumpsHost.FindServer(serverId);

                var model = this.Bind<RecordStatusModel>();

                if (model.RecordTraffic)
                {
                    server.Recordings.Clear();
                }

                server.RecordTraffic = model.RecordTraffic;

                return Response.AsJson(model);
            };
        }
Example #26
0
        public StumpsModule(IStumpsHost serverHost)
        {
            serverHost = serverHost ?? throw new ArgumentNullException(nameof(serverHost));

            Get["/api/proxy/{serverId}/stumps/{stumpId}"] = _ =>
            {
                var serverId = (string)_.serverId;
                var stumpId  = (string)_.stumpId;
                var server   = serverHost.FindServer(serverId);
                var stump    = server.FindStump(stumpId);

                var model = CreateStumpModel(stump, serverId, stumpId);

                return(Response.AsJson(model));
            };

            Get["/api/proxy/{serverId}/stumps/{stumpId}/request"] = _ =>
            {
                var serverId = (string)_.serverId;
                var stumpId  = (string)_.stumpId;
                var server   = serverHost.FindServer(serverId);
                var stump    = server.FindStump(stumpId);

                var ms = new System.IO.MemoryStream(stump.OriginalRequest.GetBody());

                return(Response.FromStream(ms, stump.OriginalRequest.Headers["Content-Type"]));
            };

            Get["/api/proxy/{serverId}/stumps/{stumpId}/response"] = _ =>
            {
                var serverId = (string)_.serverId;
                var stumpId  = (string)_.stumpId;
                var server   = serverHost.FindServer(serverId);
                var stump    = server.FindStump(stumpId);

                var ms = new System.IO.MemoryStream(stump.Response.GetBody());

                return(Response.FromStream(ms, stump.Response.Headers["Content-Type"] ?? string.Empty));
            };

            Post["/api/proxy/{serverId}/stumps"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server   = serverHost.FindServer(serverId);

                var model    = this.Bind <StumpModel>();
                var contract = CreateContractFromRecord(model, server);

                server.CreateStump(contract);

                return(HttpStatusCode.OK);
            };

            Put["/api/proxy/{serverId}/stumps/{stumpId}"] = _ =>
            {
                var serverId = (string)_.serverId;
                var server   = serverHost.FindServer(serverId);

                var model    = this.Bind <StumpModel>();
                var contract = CreateContractFromStump(model, server);

                if (server.FindStump(contract.StumpId).Equals(null))
                {
                    throw new ArgumentException("Stump name cannot be null.");
                }

                if (server.StumpNameExists(contract.StumpName))
                {
                    var oldStump = server.FindStump(contract.StumpId);
                    if (!oldStump.StumpName.Equals(contract.StumpName, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new ArgumentException("Attempting to create a stump with a name that already exists.");
                    }
                }

                server.DeleteStump(model.StumpId);
                server.CreateStump(contract);

                var stump = server.FindStump(model.StumpId);

                var returnModel = CreateStumpModel(stump, serverId, model.StumpId);

                return(Response.AsJson(returnModel));
            };

            Delete["/api/proxy/{serverId}/stumps/{stumpId}/delete"] = _ =>
            {
                var serverId = (string)_.serverId;
                var stumpId  = (string)_.stumpId;
                var server   = serverHost.FindServer(serverId);
                server.DeleteStump(stumpId);

                return(HttpStatusCode.OK);
            };

            Get["/api/proxy/{serverId}/stumps/isStumpNameAvailable/{stumpName}"] = _ =>
            {
                var serverId  = (string)_.serverId;
                var stumpName = (string)_.stumpName;
                var server    = serverHost.FindServer(serverId);

                var isStumpNameAvailable = !server.StumpNameExists(stumpName);

                var model = new
                {
                    StumpNameIsAvailable = isStumpNameAvailable
                };

                return(Response.AsJson(model));
            };
        }
Example #27
0
        public StumpsModule(IStumpsHost serverHost)
        {
            if (serverHost == null)
            {
                throw new ArgumentNullException("serverHost");
            }

            Get["/api/proxy/{serverId}/stumps/{stumpId}"] = _ =>
            {

                var serverId = (string)_.serverId;
                var stumpId = (string)_.stumpId;
                var server = serverHost.FindServer(serverId);
                var stump = server.FindStump(stumpId);

                var model = CreateStumpModel(stump, serverId, stumpId);

                return Response.AsJson(model);

            };

            Get["/api/proxy/{serverId}/stumps/{stumpId}/request"] = _ =>
            {
                var serverId = (string)_.serverId;
                var stumpId = (string)_.stumpId;
                var server = serverHost.FindServer(serverId);
                var stump = server.FindStump(stumpId);

                var ms = new System.IO.MemoryStream(stump.OriginalRequest.GetBody());

                return Response.FromStream(ms, stump.OriginalRequest.Headers["Content-Type"]);
            };

            Get["/api/proxy/{serverId}/stumps/{stumpId}/response"] = _ =>
            {
                var serverId = (string)_.serverId;
                var stumpId = (string)_.stumpId;
                var server = serverHost.FindServer(serverId);
                var stump = server.FindStump(stumpId);

                var ms = new System.IO.MemoryStream(stump.Response.GetBody());

                return Response.FromStream(ms, stump.Response.Headers["Content-Type"] ?? string.Empty);
            };

            Post["/api/proxy/{serverId}/stumps"] = _ =>
            {

                var serverId = (string)_.serverId;
                var server = serverHost.FindServer(serverId);

                var model = this.Bind<StumpModel>();
                var contract = CreateContractFromRecord(model, server);

                server.CreateStump(contract);

                return HttpStatusCode.OK;

            };

            Put["/api/proxy/{serverId}/stumps/{stumpId}"] = _ =>
            {

                var serverId = (string)_.serverId;

                var server = serverHost.FindServer(serverId);

                var model = this.Bind<StumpModel>();
                var contract = CreateContractFromStump(model, server);

                if (server.FindStump(contract.StumpId).Equals(null))
                {
                    throw new ArgumentException("Stump name cannot be null.");
                }

                if (server.StumpNameExists(contract.StumpName))
                {
                    var oldStump = server.FindStump(contract.StumpId);
                    if (!oldStump.StumpName.Equals(contract.StumpName, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new ArgumentException("Attempting to create a stump with a name that already exists.");
                    }
                }

                server.DeleteStump(model.StumpId);
                server.CreateStump(contract);

                var stump = server.FindStump(model.StumpId);

                var returnModel = CreateStumpModel(stump, serverId, model.StumpId);

                return Response.AsJson(returnModel);

            };

            Delete["/api/proxy/{serverId}/stumps/{stumpId}/delete"] = _ =>
            {

                var serverId = (string)_.serverId;
                var stumpId = (string)_.stumpId;
                var server = serverHost.FindServer(serverId);
                server.DeleteStump(stumpId);

                return HttpStatusCode.OK;

            };

            Get["/api/proxy/{serverId}/stumps/isStumpNameAvailable/{stumpName}"] = _ =>
            {

                var serverId = (string)_.serverId;
                var stumpName = (string)_.stumpName;
                var server = serverHost.FindServer(serverId);

                var isStumpNameAvailable = !server.StumpNameExists(stumpName);

                var model = new
                {
                    StumpNameIsAvailable = isStumpNameAvailable
                };

                return Response.AsJson(model);

            };
        }
Example #28
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {

                _disposed = true;

                if (_host != null)
                {
                    _host.Dispose();
                    _host = null;
                }

                base.Dispose();

            }
        }
Example #29
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Bootstrapper"/> class.
        /// </summary>
        /// <param name="stumpsHost">The <see cref="IStumpsHost"/> used by the instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stumpsHost"/> is <c>null</c>.</exception>
        public Bootstrapper(IStumpsHost stumpsHost)
        {
            _host = stumpsHost ?? throw new ArgumentNullException("stumpsHost");

            _favIcon = Convert.FromBase64String(WebResources.FaviconBase64);
        }