Exemplo n.º 1
0
        private void LoadIis()
        {
            if (!PublicNativeMethods.IsProcessElevated)
            {
                // IMPORTANT: only elevated can manipulate IIS.
                return;
            }

            // TODO: load if only on Windows.
            var config = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.System),
                "inetsrv",
                "config",
                "applicationhost.config");

            if (File.Exists(config))
            {
                var data = new ServerTreeNode(
                    _serviceContainer,
                    Environment.MachineName,
                    config,
                    "",
                    "",
                    null,
                    true,
                    WorkingMode.Iis,
                    true);
                RegisterServer(data);
            }
        }
Exemplo n.º 2
0
        private void LoadIisExpress()
        {
            if (!IisExpressServerManager.ServerInstalled)
            {
                return;
            }

            // TODO: load if only on Windows.
            var globalFile = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                "IISExpress",
                "config",
                "applicationhost.config");

            if (File.Exists(globalFile))
            {
                var global = ServerTreeNode.CreateIisExpressNode(
                    _serviceContainer,
                    expressGlobalInstanceName,
                    globalFile,
                    server: null,
                    ignoreInCache: true);
                RegisterServer(global);
            }

            if (!File.Exists(DialogHelper.ListIisExpress))
            {
                return;
            }

            var lines = File.ReadAllLines(DialogHelper.ListIisExpress);

            foreach (var item in lines)
            {
                var parts = item.Split('|');
                if (parts.Length != 2)
                {
                    continue;
                }

                var data = ServerTreeNode.CreateIisExpressNode(
                    _serviceContainer,
                    name: parts[0],
                    fileName: parts[1],
                    server: null,
                    ignoreInCache: false);
                RegisterServer(data);
            }
        }
Exemplo n.º 3
0
 private void RegisterServer(ServerTreeNode data)
 {
     data.ContextMenuStrip = cmsServer;
     if (data.Mode == WorkingMode.IisExpress)
     {
         IisExpressRoot.Nodes.Add(data);
     }
     else if (data.Mode == WorkingMode.Iis)
     {
         IisRoot.Nodes.Add(data);
     }
     else if (data.Mode == WorkingMode.Jexus)
     {
         JexusRoot.Nodes.Add(data);
     }
 }
Exemplo n.º 4
0
        private void LoadJexus()
        {
            if (!File.Exists(DialogHelper.ListJexus))
            {
                return;
            }

            var lines = File.ReadAllLines(DialogHelper.ListJexus);

            foreach (var item in lines)
            {
                var parts = item.Split(',');
                var data  = new ServerTreeNode(_serviceContainer, parts[0], parts[1], parts[4], parts[2], null, bool.Parse(parts[3]), WorkingMode.Jexus, false);
                RegisterServer(data);
            }
        }
Exemplo n.º 5
0
        private void LoadIis()
        {
            // TODO: load if only on Windows.
            var config = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.System),
                "inetsrv",
                "config",
                "applicationhost.config");

            if (File.Exists(config))
            {
                var data = ServerTreeNode.CreateIisNode(
                    _serviceContainer,
                    Environment.MachineName,
                    config);
                RegisterServer(data);
            }
        }
Exemplo n.º 6
0
        private void LoadIisExpress()
        {
            // TODO: load if only on Windows.
            var globalFile = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                "IISExpress",
                "config",
                "applicationhost.config");

            if (File.Exists(globalFile))
            {
                var global = new ServerTreeNode(
                    _serviceContainer,
                    expressGlobalInstanceName,
                    globalFile,
                    "",
                    "",
                    null,
                    true,
                    WorkingMode.IisExpress,
                    true);
                RegisterServer(global);
            }

            if (!File.Exists(DialogHelper.ListIisExpress))
            {
                return;
            }

            var lines = File.ReadAllLines(DialogHelper.ListIisExpress);

            foreach (var item in lines)
            {
                var parts = item.Split('|');
                if (parts.Length != 2)
                {
                    continue;
                }

                var data = new ServerTreeNode(_serviceContainer, parts[0], parts[1], "", "", null, true, WorkingMode.IisExpress, true);
                RegisterServer(data);
            }
        }
Exemplo n.º 7
0
        private void LoadIisExpressQuick(List <string> files)
        {
            if (!File.Exists(DialogHelper.ListIisExpress))
            {
                return;
            }

            var number = 1;

            foreach (var file in files)
            {
                var data = ServerTreeNode.CreateIisExpressNode(
                    _serviceContainer,
                    name: $"IIS Express {number++}",
                    fileName: file,
                    server: null,
                    ignoreInCache: true);
                RegisterServer(data);
            }
        }
Exemplo n.º 8
0
        private void LoadJexus()
        {
            if (!File.Exists(DialogHelper.ListJexus))
            {
                return;
            }

            var lines = File.ReadAllLines(DialogHelper.ListJexus);

            foreach (var item in lines)
            {
                var parts = item.Split(',');
                var data  = ServerTreeNode.CreateJexusNode(
                    _serviceContainer,
                    name: parts[0],
                    hostName: parts[1],
                    credentials: parts[4],
                    hash: parts[2],
                    server: null,
                    isLocalhost: bool.Parse(parts[3]));
                RegisterServer(data);
            }
        }
Exemplo n.º 9
0
        internal void ConnectToServer()
        {
            var names = new List <string>();

            GetAllServers(names, treeView1.Nodes);
            var dialog = new ConnectionWizard(_serviceContainer, names.ToArray());

            if (dialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            var            data = (ConnectionWizardData)dialog.WizardData;
            ServerTreeNode node;

            if (data.Mode == WorkingMode.Jexus)
            {
                node = ServerTreeNode.CreateJexusNode(
                    _serviceContainer,
                    data.Name,
                    data.HostName,
                    data.UserName + "|" + data.Password,
                    data.CertificateHash,
                    data.Server,
                    isLocalhost: true);
                var path   = Path.GetTempFileName();
                var random = Guid.NewGuid().ToString();
                File.WriteAllText(path, random);
                node.IsLocalhost        = AsyncHelper.RunSync(() => ((JexusServerManager)node.ServerManager).LocalhostTestAsync(path, random));
                data.Server.IsLocalhost = node.IsLocalhost;
            }
            else
            {
                node = ServerTreeNode.CreateIisExpressNode(
                    _serviceContainer,
                    data.Name,
                    data.FileName,
                    data.Server,
                    ignoreInCache: false);
            }

            try
            {
                RegisterServer(node);
                // TODO: trigger the load in connection wizard to throw exception earlier.
                node.LoadServer(cmsApplicationPools, cmsSites, cmsSite);
                actSave.Enabled = true;
            }
            catch (Exception ex)
            {
                RollbarLocator.RollbarInstance.Error(ex);
                File.WriteAllText(DialogHelper.DebugLog, ex.ToString());
                var last = ex;
                while (last is AggregateException)
                {
                    last = last.InnerException;
                }

                var message = new StringBuilder();
                message.AppendLine("Could not connect to the specified computer.")
                .AppendLine()
                .AppendFormat("Details: {0}", last?.Message);
                MessageBox.Show(message.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 10
0
        private async void actConnectServer_Execute(object sender, EventArgs e)
        {
            var names = new List <string>();

            names.Add("Start Page");
            foreach (var item in treeView1.Nodes)
            {
                var serverNode = item as ServerTreeNode;
                if (serverNode != null)
                {
                    names.Add(serverNode.DisplayName);
                }
            }

            var dialog = new ConnectionWizard(_serviceContainer, names.ToArray());

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var            data = (ConnectionWizardData)dialog.WizardData;
            ServerTreeNode node;

            if (data.Mode == WorkingMode.Jexus)
            {
                node = new ServerTreeNode(
                    _serviceContainer,
                    data.Name,
                    data.HostName,
                    data.UserName + "|" + data.Password,
                    data.CertificateHash,
                    data.Server,
                    true,
                    WorkingMode.Jexus,
                    false);
                node.SetHandler();
                var path   = Path.GetTempFileName();
                var random = Guid.NewGuid().ToString();
                File.WriteAllText(path, random);
                node.IsLocalhost        = await((JexusServerManager)node.ServerManager).LocalhostTestAsync(path, random);
                data.Server.IsLocalhost = node.IsLocalhost;
            }
            else
            {
                node = new ServerTreeNode(
                    _serviceContainer,
                    data.Name,
                    data.FileName,
                    string.Empty,
                    null,
                    data.Server,
                    true,
                    WorkingMode.IisExpress,
                    false);
            }

            RegisterServer(node);
            await node.LoadServerAsync(cmsApplicationPools, cmsSites, cmsSite);

            actSave.Enabled = true;
        }
Exemplo n.º 11
0
 private void RegisterServer(ServerTreeNode data)
 {
     data.ContextMenuStrip = cmsServer;
     treeView1.Nodes.Add(data);
 }
Exemplo n.º 12
0
        private void actConnectServer_Execute(object sender, EventArgs e)
        {
            var names = new List <string>();

            names.Add("Start Page");
            foreach (var item in treeView1.Nodes)
            {
                var serverNode = item as ServerTreeNode;
                if (serverNode != null)
                {
                    names.Add(serverNode.DisplayName);
                }
            }

            var dialog = new ConnectionWizard(_serviceContainer, names.ToArray());

            if (dialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            var            data = (ConnectionWizardData)dialog.WizardData;
            ServerTreeNode node;

            if (data.Mode == WorkingMode.Jexus)
            {
                node = new ServerTreeNode(
                    _serviceContainer,
                    data.Name,
                    data.HostName,
                    data.UserName + "|" + data.Password,
                    data.CertificateHash,
                    data.Server,
                    true,
                    WorkingMode.Jexus,
                    false);
                node.SetHandler();
                var path   = Path.GetTempFileName();
                var random = Guid.NewGuid().ToString();
                File.WriteAllText(path, random);
                node.IsLocalhost        = AsyncHelper.RunSync(() => ((JexusServerManager)node.ServerManager).LocalhostTestAsync(path, random));
                data.Server.IsLocalhost = node.IsLocalhost;
            }
            else
            {
                node = new ServerTreeNode(
                    _serviceContainer,
                    data.Name,
                    data.FileName,
                    string.Empty,
                    null,
                    data.Server,
                    true,
                    WorkingMode.IisExpress,
                    false);
            }

            try
            {
                RegisterServer(node);
                // TODO: trigger the load in connection wizard to throw exception earlier.
                node.LoadServer(cmsApplicationPools, cmsSites, cmsSite);
                actSave.Enabled = true;
            }
            catch (Exception ex)
            {
                File.WriteAllText(DialogHelper.DebugLog, ex.ToString());
                var last = ex;
                while (last is AggregateException)
                {
                    last = last.InnerException;
                }

                var message = new StringBuilder();
                message.AppendLine("Could not connect to the specified computer.")
                .AppendLine()
                .AppendFormat("Details: {0}", last?.Message);
                MessageBox.Show(message.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }