Ejemplo n.º 1
0
        /// <summary>
        /// Deletes a server.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="velocityContext"></param>
        private void DeleteServer(IRequest request, Hashtable velocityContext)
        {
            // Retrieve the details
            string serverName = request.GetText("ServerName");

            // Validate the details
            if (string.IsNullOrEmpty(serverName))
            {
                velocityContext["Error"] = this.translations.Translate("Server name has not been set");
                return;
            }

            // Find the server
            XmlDocument configFile = LoadConfig();
            XmlElement  serverEl   = configFile.SelectSingleNode(
                string.Format(
                    "/dashboard/remoteServices/servers/server[@name='{0}']",
                    serverName)) as XmlElement;
            ServerLocation location = null;

            if (serverEl != null)
            {
                // Get and remove the existing server config
                foreach (ServerLocation locationToCheck in servicesConfiguration.Servers)
                {
                    if (locationToCheck.Name == serverName)
                    {
                        location = locationToCheck;
                        break;
                    }
                }
                if (location != null)
                {
                    List <ServerLocation> locations = new List <ServerLocation>(servicesConfiguration.Servers);
                    locations.Remove(location);
                    servicesConfiguration.Servers = locations.ToArray();
                }

                // Remove it from the config file
                serverEl.ParentNode.RemoveChild(serverEl);
                SaveConfig(configFile);

                velocityContext["Result"] = this.translations.Translate("Server has been deleted");
                CachingDashboardConfigurationLoader.ClearCache();
            }
            else
            {
                velocityContext["Error"] = this.translations.Translate("Unable to find server");
                return;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Uninstalls a package.
        /// </summary>
        /// <param name="cruiseRequest"></param>
        /// <param name="velocityContext"></param>
        private void UninstallPackage(ICruiseRequest cruiseRequest, Hashtable velocityContext)
        {
            // Get the manager to install the package
            List <PackageImportEventArgs> events = manager.UninstallPackage(
                cruiseRequest.Request.GetText("PackageName"));

            if (events != null)
            {
                // Pass on the details
                velocityContext["Result"]  = this.translations.Translate("Package has been uninstalled");
                velocityContext["Install"] = true;
                velocityContext["Events"]  = events;

                // Need to reset the cache, otherwise the configuration will not be loaded
                CachingDashboardConfigurationLoader.ClearCache();
            }
            else
            {
                velocityContext["Error"] = this.translations.Translate("Unable to uninstall package");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Executes the action.
        /// </summary>
        /// <param name="cruiseRequest"></param>
        /// <returns></returns>
        public IResponse Execute(ICruiseRequest cruiseRequest)
        {
            this.translations = Translations.RetrieveCurrent();
            Hashtable velocityContext = new Hashtable();

            velocityContext["Error"] = string.Empty;
            if (ValidateSession(velocityContext))
            {
                // Initialise the default values
                velocityContext["Result"]         = string.Empty;
                velocityContext["InstallPackage"] = string.Empty;

                // Retrieve the form values
                string action = cruiseRequest.Request.GetText("Action") ?? string.Empty;
                string type   = cruiseRequest.Request.GetText("Type");
                string name   = cruiseRequest.Request.GetText("Name");

                // Check to see if there is an action to perform
                if (action == this.translations.Translate("Reload dashboard"))
                {
                    CachingDashboardConfigurationLoader.ClearCache();
                    velocityContext["Result"] = this.translations.Translate("The dashboard configuration has been reloaded");
                }
                else if (action == string.Empty)
                {
                    // Do nothing, the user hasn't asked for anything but this is needed so the
                    // default doesn't display an error
                }
                else if (action == this.translations.Translate("Save"))
                {
                    SaveServer(cruiseRequest.Request, velocityContext);
                }
                else if (action == this.translations.Translate("Delete"))
                {
                    DeleteServer(cruiseRequest.Request, velocityContext);
                }
                else if (action == this.translations.Translate("Import"))
                {
                    ImportPackage(HttpContext.Current, velocityContext);
                }
                else if (action == this.translations.Translate("Install"))
                {
                    InstallPackage(cruiseRequest, velocityContext);
                }
                else if (action == this.translations.Translate("Uninstall"))
                {
                    UninstallPackage(cruiseRequest, velocityContext);
                }
                else if (action == this.translations.Translate("Remove"))
                {
                    RemovePackage(cruiseRequest, velocityContext);
                }
                else if (action == this.translations.Translate("Logout"))
                {
                    Logout();
                }
                else
                {
                    velocityContext["Error"] = this.translations.Translate("Unknown action '{0}'", action);
                }

                // Retrieve the services and packages
                velocityContext["Servers"] = servicesConfiguration.Servers;
                List <PackageManifest> packages = manager.ListPackages();
                packages.Sort();
                velocityContext["BuildPackages"]     = packages.Where(p => p.Group == PackageManager.PackageGroup.Build.ToString());
                velocityContext["DashboardPackages"] = packages.Where(p => p.Group == PackageManager.PackageGroup.Dashboard.ToString());
                velocityContext["ProjectPackages"]   = packages.Where(p => p.Group == PackageManager.PackageGroup.Project.ToString());
                velocityContext["ServerPackages"]    = packages.Where(p => p.Group == PackageManager.PackageGroup.Server.ToString());


                // Generate the view
                if (action == "Logout")
                {
                    return(viewGenerator.GenerateView("AdminLogin.vm", velocityContext));
                }
                else
                {
                    return(viewGenerator.GenerateView("AdministerDashboard.vm", velocityContext));
                }
            }
            else
            {
                // Generate the view
                return(viewGenerator.GenerateView("AdminLogin.vm", velocityContext));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Save the server details
        /// </summary>
        /// <param name="request"></param>
        /// <param name="velocityContext"></param>
        private void SaveServer(IRequest request, Hashtable velocityContext)
        {
            // Retrieve the details
            string newName             = request.GetText("newName");
            string oldName             = request.GetText("oldName");
            string serverUri           = request.GetText("serverUri");
            bool   serverForceBuild    = request.GetChecked("serverForceBuild");
            bool   serverStartStop     = request.GetChecked("serverStartStop");
            bool   backwardsCompatible = request.GetChecked("serverBackwardsCompatible");

            // Validate the details
            if (string.IsNullOrEmpty(newName))
            {
                velocityContext["Error"] = this.translations.Translate("Name is a compulsory value");
                return;
            }
            if (string.IsNullOrEmpty(serverUri))
            {
                velocityContext["Error"] = this.translations.Translate("URI is a compulsory value");
                return;
            }

            // Find the server
            XmlDocument configFile = LoadConfig();
            XmlElement  serverEl   = configFile.SelectSingleNode(
                string.Format(
                    "/dashboard/remoteServices/servers/server[@name='{0}']",
                    oldName)) as XmlElement;
            ServerLocation location = null;

            if (serverEl == null)
            {
                // If the element wasn't found, start a new one
                serverEl = configFile.CreateElement("server");
                configFile.SelectSingleNode("/dashboard/remoteServices/servers")
                .AppendChild(serverEl);

                // Add the new server
                location = new ServerLocation();
                ServerLocation[] locations = new ServerLocation[servicesConfiguration.Servers.Length + 1];
                servicesConfiguration.Servers.CopyTo(locations, 0);
                locations[servicesConfiguration.Servers.Length] = location;
                servicesConfiguration.Servers = locations;
            }
            else
            {
                // Get the existing server config
                foreach (ServerLocation locationToCheck in servicesConfiguration.Servers)
                {
                    if (locationToCheck.Name == oldName)
                    {
                        location = locationToCheck;
                        break;
                    }
                }
            }

            // Set all the properties
            serverEl.SetAttribute("name", newName);
            serverEl.SetAttribute("url", serverUri);
            serverEl.SetAttribute("allowForceBuild", serverForceBuild ? "true" : "false");
            serverEl.SetAttribute("allowStartStopBuild", serverStartStop ? "true" : "false");
            serverEl.SetAttribute("backwardsCompatible", backwardsCompatible ? "true" : "false");
            SaveConfig(configFile);
            if (location != null)
            {
                location.Name                = newName;
                location.Url                 = serverUri;
                location.AllowForceBuild     = serverForceBuild;
                location.AllowStartStopBuild = serverStartStop;
                location.BackwardCompatible  = backwardsCompatible;
            }

            velocityContext["Result"] = this.translations.Translate("Server has been saved");
            CachingDashboardConfigurationLoader.ClearCache();
        }