Exemplo n.º 1
0
    /// <summary>
    /// Deletes staging tasks. Called when the "Delete tasks" button is pressed.
    /// Expects the CreateStagingServer method to be run first.
    /// </summary>
    private bool DeleteTasks()
    {
        // Get server
        ServerInfo server = ServerInfoProvider.GetServerInfo("MyNewServer", SiteContext.CurrentSiteID);

        if (server != null)
        {
            // Get tasks for the server
            DataSet tasks = StagingTaskInfoProvider.SelectTaskList(SiteContext.CurrentSiteID, server.ServerID, null, null);

            if (!DataHelper.DataSourceIsEmpty(tasks))
            {
                foreach (DataRow taskDr in tasks.Tables[0].Rows)
                {
                    // Create task info object from data row
                    StagingTaskInfo deleteTask = new StagingTaskInfo(taskDr);

                    // Delete the task
                    StagingTaskInfoProvider.DeleteTaskInfo(deleteTask);
                }

                return(true);
            }

            apiDeleteTasks.ErrorMessage = "No tasks found.";
        }

        return(false);
    }
Exemplo n.º 2
0
 protected override void OnPreRender(EventArgs e)
 {
     // Get task data
     if (taskId > 0)
     {
         StagingTaskInfo ti = StagingTaskInfoProvider.GetTaskInfo(taskId);
         if (ti != null)
         {
             lblInfo.Text += String.Format(GetString("Task.LogTaskInfo"), HTMLHelper.HTMLEncode(ti.TaskTitle));
         }
     }
     // Get server data
     if (serverId > 0)
     {
         ServerInfo si = ServerInfoProvider.GetServerInfo(serverId);
         if (si != null)
         {
             if (lblInfo.Text != "")
             {
                 lblInfo.Text += "<br /><br />";
             }
             lblInfo.Text += String.Format(GetString("Task.LogServerInfo"), si.ServerDisplayName);
         }
     }
     lblInfo.Visible = (lblInfo.Text != "");
     base.OnPreRender(e);
 }
Exemplo n.º 3
0
    /// <summary>
    /// Synchronizes all tasks. Called when the "Get and synchronize tasks" button is pressed.
    /// Expects the CreateStagingServer method to be run first and that there are tasks logged
    /// for the server.
    /// </summary>
    private bool GetAndSynchronizeTasks()
    {
        // Get server
        ServerInfo server = ServerInfoProvider.GetServerInfo("MyNewServer", SiteContext.CurrentSiteID);

        if (server != null)
        {
            // Get tasks for the server
            DataSet tasks = StagingTaskInfoProvider.SelectTaskList(SiteContext.CurrentSiteID, server.ServerID, null, null);

            if (!DataHelper.DataSourceIsEmpty(tasks))
            {
                foreach (DataRow taskDr in tasks.Tables[0].Rows)
                {
                    // Create task info object from data row
                    StagingTaskInfo task = new StagingTaskInfo(taskDr);

                    // Synchronize the task
                    if (!string.IsNullOrEmpty(StagingHelper.RunSynchronization(task.TaskID, server.ServerID)))
                    {
                        apiGetAndSynchronizeTasks.ErrorMessage = "Synchronization failed.";
                        return(false);
                    }
                }

                return(true);
            }

            apiGetAndSynchronizeTasks.ErrorMessage = "No tasks found.";
        }

        return(false);
    }
Exemplo n.º 4
0
        /// <inheritdoc/>
        public IServer Update(IServer server, bool isReplace = true)
        {
            // Gets the staging server
            ServerInfo updateServer = ServerInfoProvider.GetServerInfo(server.ServerName, server.ServerSiteID);

            if (updateServer != null)
            {
                if (isReplace)
                {
                    updateServer = server.UndoActLike();
                }
                else
                {
                    // Updates the server properties
                    updateServer.ServerDisplayName    = server.ServerDisplayName ?? updateServer.ServerDisplayName;
                    updateServer.ServerURL            = server.ServerURL ?? updateServer.ServerURL;
                    updateServer.ServerEnabled        = server.ServerEnabled == null ? updateServer.ServerEnabled : (bool)server.ServerEnabled;
                    updateServer.ServerAuthentication = server.ServerAuthentication;
                    updateServer.ServerUsername       = server.ServerUsername ?? updateServer.ServerUsername;
                    updateServer.ServerPassword       = server.ServerPassword ?? updateServer.ServerPassword;
                }

                // Saves the updated server to the database
                ServerInfoProvider.SetServerInfo(updateServer);
            }

            return(updateServer.ActLike <IServer>());
        }
Exemplo n.º 5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check 'Manage servers' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.staging", "ManageServers"))
        {
            RedirectToAccessDenied("cms.staging", "ManageServers");
        }

        rfvServerDisplayName.ErrorMessage = GetString("Server_Edit.ErrorEmptyServerDisplayName");
        rfvServerName.ErrorMessage        = GetString("Server_Edit.ErrorEmptyServerCodeName");
        rfvServerURL.ErrorMessage         = GetString("Server_Edit.ErrorEmptyServerURL");

        radUserName.CheckedChanged += Authentication_CheckedChanged;
        radX509.CheckedChanged     += Authentication_CheckedChanged;
        ScriptHelper.RegisterStartupScript(this, typeof(string), "setHelpTopic", ScriptHelper.GetScript("parent.frames['stagingHeader'].SetHelpTopic('helpTopic', 'new_server');"));

        string currentServer = GetString("Server_Edit.NewItemCaption");

        serverID = QueryHelper.GetInteger("serverID", 0);
        if (serverID > 0)
        {
            // Check hash
            if (!QueryHelper.ValidateHash("hash"))
            {
                RedirectToAccessDenied(ResHelper.GetString("dialogs.badhashtitle"));
            }

            if (!RequestHelper.IsPostBack() && (Request.QueryString["saved"] != null))
            {
                lblInfo.Visible = true;
                lblInfo.Text    = GetString("General.ChangesSaved");
            }

            serverObj = ServerInfoProvider.GetServerInfo(serverID);
            // Set edited object
            EditedObject  = serverObj;
            currentServer = serverObj.ServerDisplayName;

            // Fill editing form
            if (!RequestHelper.IsPostBack())
            {
                LoadData(serverObj);
            }
        }

        // Associate server checker control
        serverChecker.TextBoxControlID = txtServerURL.ID;

        // Initializes page title control
        InitializeBreadcrumbs(currentServer);

        if (serverID > 0)
        {
            CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Staging_Server/object.png");
        }
        else
        {
            CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Staging_Server/new.png");
        }
    }
Exemplo n.º 6
0
    /// <summary>
    /// Deletes staging server. Called when the "Delete server" button is pressed.
    /// Expects the CreateStagingServer method to be run first.
    /// </summary>
    private bool DeleteStagingServer()
    {
        // Get the staging server
        ServerInfo deleteServer = ServerInfoProvider.GetServerInfo("MyNewServer", SiteContext.CurrentSiteID);

        // Delete the staging server
        ServerInfoProvider.DeleteServerInfo(deleteServer);

        return(deleteServer != null);
    }
Exemplo n.º 7
0
        public HttpResponseMessage ShowGeneralInformation()
        {
            string     serverName = "", url = "", lastModified = "", lastStart = "";
            SiteInfo   site;
            string     siteName = "", siteDomainName = "", siteLastModified = "", licenseExpiration = "";
            ServerInfo serverInfo;
            long       virtualMemory, workingPeak;

            try
            {
                siteName   = SiteContext.CurrentSiteName;
                serverName = StagingTaskInfoProvider.ServerName;
                site       = SiteContext.CurrentSite;
                if (site != null)
                {
                    siteDomainName   = site.DomainName;
                    siteLastModified = site.SiteLastModified.ToShortDateString();
                    serverInfo       = ServerInfoProvider.GetServerInfo(serverName, site.SiteID);
                    if (serverInfo != null)
                    {
                        lastModified = serverInfo.ServerLastModified.ToShortDateString();
                    }
                }


                lastStart = CMSApplication.ApplicationStart.ToShortDateString();

                virtualMemory = SystemHelper.GetVirtualMemorySize();
                workingPeak   = SystemHelper.GetPeakWorkingSetSize();

                licenseExpiration = LicenseHelper.ApplicationExpires.ToShortDateString();

                //everything is OK, general information are also returned
                return(Request.CreateResponse(HttpStatusCode.OK, new {
                    serverName = serverName,
                    serverURL = url,
                    serverLastModified = lastModified,
                    serverLastStart = lastStart,
                    virtualMemory = virtualMemory,
                    workingPeak = workingPeak,
                    siteName = siteName,
                    siteDomainName = siteDomainName,
                    siteLastModified = siteLastModified,
                    licenseExpiration = licenseExpiration,
                }));
            }
            catch (NullReferenceException e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new { errorMessage = e.Message }));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.ServiceUnavailable, new { errorMessage = e.Message }));
            }
        }
Exemplo n.º 8
0
        /// <inheritdoc/>
        public void Delete(IServer server)
        {
            // Gets the staging server
            ServerInfo deleteServer = ServerInfoProvider.GetServerInfo(server.ServerName, server.ServerSiteID);

            if (deleteServer != null)
            {
                // Deletes the staging server
                ServerInfoProvider.DeleteServerInfo(deleteServer);
            }
        }
Exemplo n.º 9
0
    /// <summary>
    /// Gets and updates staging server. Called when the "Get and update server" button is pressed.
    /// Expects the CreateStagingServer method to be run first.
    /// </summary>
    private bool GetAndUpdateStagingServer()
    {
        // Get the staging server
        ServerInfo updateServer = ServerInfoProvider.GetServerInfo("MyNewServer", SiteContext.CurrentSiteID);

        if (updateServer != null)
        {
            // Update the properties
            updateServer.ServerDisplayName = updateServer.ServerDisplayName.ToLowerCSafe();

            // Save the changes
            ServerInfoProvider.SetServerInfo(updateServer);

            return(true);
        }

        return(false);
    }
Exemplo n.º 10
0
 /// <inheritdoc/>
 public IServer GetServer(string serverName, int serverSiteId)
 {
     return((ServerInfoProvider.GetServerInfo(serverName, serverSiteId) as ServerInfo)?.ActLike <IServer>());
 }
Exemplo n.º 11
0
 /// <inheritdoc/>
 public IServer GetServer(int id)
 {
     return((ServerInfoProvider.GetServerInfo(id) as ServerInfo)?.ActLike <IServer>());
 }
Exemplo n.º 12
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check 'Manage servers' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("cms.staging", "ManageServers"))
        {
            RedirectToAccessDenied("cms.staging", "ManageServers");
        }

        string errorMessage = new Validator().NotEmpty(txtServerDisplayName, GetString("General.requiresDisplayName")).NotEmpty(txtServerName, GetString("General.RequiresCodeName")).
                              IsCodeName(txtServerName.Text, GetString("general.invalidcodename"))
                              .Result;

        if (errorMessage == "")
        {
            // Server name must be unique
            serverObj = ServerInfoProvider.GetServerInfo(txtServerName.Text.Trim(), CMSContext.CurrentSite.SiteID);

            // If server name is unique
            if ((serverObj == null) || (serverObj.ServerID == serverID))
            {
                // If server name is unique -> determine whether it is update or insert
                if ((serverObj == null))
                {
                    // Get ServerInfo object by primary key
                    serverObj = ServerInfoProvider.GetServerInfo(serverID) ?? new ServerInfo();
                }

                serverObj.ServerSiteID          = CMSContext.CurrentSite.SiteID;
                serverObj.ServerX509ServerKeyID = txtServerX509ServerKeyID.Text.Trim();
                serverObj.ServerPassword        = encryptedPassword.Value.ToString();
                serverObj.ServerAuthentication  = (radX509.Checked) ? ServerAuthenticationEnum.X509 : ServerAuthenticationEnum.UserName;
                serverObj.ServerDisplayName     = txtServerDisplayName.Text.Trim();
                serverObj.ServerURL             = txtServerURL.Text.Trim();
                serverObj.ServerX509ClientKeyID = txtServerX509ClientKeyID.Text.Trim();
                serverObj.ServerName            = txtServerName.Text.Trim();
                serverObj.ServerUsername        = txtServerUsername.Text.Trim();
                serverObj.ServerEnabled         = chkServerEnabled.Checked;

                ServerInfoProvider.SetServerInfo(serverObj);

                // Refresh breadcrumbs
                InitializeBreadcrumbs(serverObj.ServerDisplayName);

                ShowChangesSaved();

                if (serverID <= 0)
                {
                    string detailUrl = "Server_Edit.aspx?serverid=" + serverObj.ServerID + "&saved=1";
                    detailUrl = URLHelper.AddParameterToUrl(detailUrl, "hash", QueryHelper.GetHash(detailUrl));

                    URLHelper.Redirect(detailUrl);
                }
            }
            else
            {
                ShowError(GetString("Server_Edit.ServerNameExists"));
            }
        }
        else
        {
            ShowError(errorMessage);
        }
    }