Example #1
0
 public void Configure(Server server, int port, string virtualPath, string physicalPath, string installPath,
     bool disallowRemoteConnections)
 {
     _server = server;
     _disallowRemoteConnections = disallowRemoteConnections;
     _port = port;
     _virtualPath = virtualPath;
     _lowerCasedVirtualPath = CultureInfo.InvariantCulture.TextInfo.ToLower(_virtualPath);
     _lowerCasedVirtualPathWithTrailingSlash = virtualPath.EndsWith("/") ? virtualPath : (virtualPath + "/");
     _lowerCasedVirtualPathWithTrailingSlash =
         CultureInfo.InvariantCulture.TextInfo.ToLower(_lowerCasedVirtualPathWithTrailingSlash);
     _physicalPath = physicalPath;
     _installPath = installPath;
     _physicalClientScriptPath = installPath + @"\asp.netclientfiles\";
     string fileVersion =
     // ReSharper disable AssignNullToNotNullAttribute
         FileVersionInfo.GetVersionInfo(typeof (HttpRuntime).Module.FullyQualifiedName).FileVersion;
     // ReSharper restore AssignNullToNotNullAttribute
     string str2 = fileVersion.Substring(0, fileVersion.LastIndexOf('.'));
     _lowerCasedClientScriptPathWithTrailingSlashV10 = "/aspnet_client/system_web/" +
                                                       fileVersion.Replace('.', '_') + "/";
     _lowerCasedClientScriptPathWithTrailingSlashV11 = "/aspnet_client/system_web/" + str2.Replace('.', '_') +
                                                       "/";
     _onSocketAccept = new WaitCallback(OnSocketAccept);
     _onStart = new WaitCallback(OnStart);
     _onAppDomainUnload = new EventHandler(OnAppDomainUnload);
     Thread.GetDomain().DomainUnload += _onAppDomainUnload;
 }
Example #2
0
 private void Stop()
 {
     if (server == null) return;
     server.Stop();
     server = null;
     txtPhisicalDirectory.Enabled = true;
     btnBrowse.Enabled = true;
     txtPort.Enabled = true;
     txtVirtualDirectory.Enabled = true;
     chkDisallowRemoteConnections.Enabled = true;
     lnkWiki.Enabled = false;
     lnkWiki.Text = "None";
     btnStartStop.Text = "Start";
     itmStartStop.Text = "Start";
     itmStartStop.Image = Resources.run;
     itmOpen.Enabled = false;
     //this.notifyIcon.Icon = Resources.WikiSmallGray;
 }
Example #3
0
        private void Start()
        {
            string text = txtPhisicalDirectory.Text;
            if (text.StartsWith(@".\") || text.StartsWith(@"\"))
            {
                string currentDirectory = Environment.CurrentDirectory;
                if (currentDirectory.EndsWith(@"\"))
                {
                    currentDirectory = currentDirectory.Substring(0, currentDirectory.Length - 2);
                }
                while (text.StartsWith(@".\"))
                {
                    currentDirectory = currentDirectory.Substring(0, currentDirectory.LastIndexOf(@"\"));
                    text = text.Substring(2);
                }
                text = currentDirectory + text;
            }
            if (!Directory.Exists(text))
            {
                MessageBox.Show("Physical Directory does not exist.\r\n" + text, "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Hand);
                return;
            }
            try
            {
                int num = int.Parse(txtPort.Text);
                if ((num <= 0) || (num > 0xffff))
                {
                    throw new Exception();
                }
            }
            catch
            {
                MessageBox.Show(@"Invalid Port number (it must be greater than zero and smaller than 65535).", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            if ((txtVirtualDirectory.Text.Length != 0) && txtVirtualDirectory.Text.StartsWith("/"))
            {
                if (server != null)
                {
                    server.Stop();
                }
                try
                {
                    server = new Server(int.Parse(txtPort.Text), txtVirtualDirectory.Text, text,
                                        chkDisallowRemoteConnections.Checked);
                    server.Start();
                }
                catch (Exception exception)
                {
                    if (!publishingTried)
                    {
                        GacUtil.Install(Application.StartupPath + @"\lightAspServer.dll");
                        publishingTried = true;
                        try
                        {
                            server = new Server(int.Parse(txtPort.Text), txtVirtualDirectory.Text, text,
                                                chkDisallowRemoteConnections.Checked);
                            server.Start();
                            UpdateUi();
                            SaveSetings(text, txtVirtualDirectory.Text, txtPort.Text,
                                        chkDisallowRemoteConnections.Checked.ToString());
                        }
                        catch
                        {
                            MessageBox.Show(
                                "Unable to start the Server.\r\n\r\n" + exception.Message + "\r\n\r\n" +
                                exception.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            return;
                        }
                    }
                    MessageBox.Show(
                        "Unable to start the Server.\r\n\r\n" + exception.Message + "\r\n\r\n" + exception.StackTrace,
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return;
                }
            }
            else
            {
                MessageBox.Show(@"Invalid Virtual Directory.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }

            UpdateUi();
            SaveSetings(text, txtVirtualDirectory.Text, txtPort.Text, chkDisallowRemoteConnections.Checked.ToString());
        }
Example #4
0
 private void OnAppDomainUnload(object unusedObject, EventArgs unusedEventArgs)
 {
     Thread.GetDomain().DomainUnload -= _onAppDomainUnload;
     if (!_stopped)
     {
         Stop();
         _server.Restart();
         _server = null;
     }
 }