Exemplo n.º 1
0
        public async Task Init()
        {
            // Creates a new site object
            SiteInfo newSite = new SiteInfo
            {
                DisplayName = "New site",
                SiteName    = "NewSite",
                Status      = SiteStatusEnum.Running,
                DomainName  = "127.0.0.1",
            };

            if (SiteInfoProvider.GetSiteInfo(newSite.SiteName) == null)
            {
                SiteInfoProvider.SetSiteInfo(newSite);
            }

            SiteContext.CurrentSite = newSite;

            var roleInfo = new RoleInfo
            {
                RoleDisplayName = "Role for tests",
                RoleName        = "RoleForTests",
                SiteID          = SiteContext.CurrentSiteID,
            };

            store = new RoleStore();
            role  = new Role(roleInfo);
            await store.CreateAsync(role);
        }
Exemplo n.º 2
0
    /// <summary>
    /// Gets and bulk updates sites. Called when the "Get and bulk update sites" button is pressed.
    /// Expects the CreateSite method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateSites()
    {
        // Prepare the parameters
        string where = "SiteName LIKE N'MyNewSite%'";

        // Get the data
        DataSet sites = SiteInfoProvider.GetSites(where, null);

        if (!DataHelper.DataSourceIsEmpty(sites))
        {
            // Loop through the individual items
            foreach (DataRow siteDr in sites.Tables[0].Rows)
            {
                // Create object from DataRow
                SiteInfo modifySite = new SiteInfo(siteDr);

                // Update the properties
                modifySite.DisplayName = modifySite.DisplayName.ToUpper();

                // Save the changes
                SiteInfoProvider.SetSiteInfo(modifySite);
            }

            return(true);
        }

        return(false);
    }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public ISite Update(ISite site, bool isReplace = true)
        {
            // Gets the site
            SiteInfo updateSite = SiteInfoProvider.GetSiteInfo(site.SiteName);

            if (updateSite != null)
            {
                if (isReplace)
                {
                    updateSite = site.UndoActLike();
                }
                else
                {
                    // Updates the site properties
                    updateSite.DisplayName = site.DisplayName;
                    updateSite.DomainName  = site.DomainName;
                    updateSite.SiteName    = site.SiteName;
                    updateSite.Status      = site.Status;
                }

                // Saves the modified site to the database
                SiteInfoProvider.SetSiteInfo(updateSite);
            }

            return(updateSite.ActLike <ISite>());
        }
Exemplo n.º 4
0
    /// <summary>
    /// Takes all sites offline.
    /// </summary>
    private void TakeSitesOffline()
    {
        var sites   = SiteInfoProvider.GetSites("(SiteIsOffline IS NULL) OR (SiteIsOffline = 0)", null);
        var siteIDs = new List <int>(sites.Items.Count);

        foreach (var site in sites)
        {
            site.SiteIsOffline = true;
            SiteInfoProvider.SetSiteInfo(site);
            siteIDs.Add(site.SiteID);
        }
        PersistentStorageHelper.SetValue("SeparateDBSites", siteIDs);
    }
Exemplo n.º 5
0
        /// <inheritdoc/>
        public ISite Create(ISite site)
        {
            var siteInfo = new SiteInfo
            {
                DisplayName = site.DisplayName,
                SiteName    = site.SiteName,
                Status      = site.Status,
                DomainName  = site.DomainName,
            };

            SiteInfoProvider.SetSiteInfo(siteInfo);

            return(siteInfo.ActLike <ISite>());
        }
Exemplo n.º 6
0
    /// <summary>
    /// Takes sites online.
    /// </summary>
    private void TakeSitesOnline()
    {
        var siteIDs = (List <int>)PersistentStorageHelper.GetValue("SeparateDBSites");

        if ((siteIDs != null) && (siteIDs.Count > 0))
        {
            foreach (var siteID in siteIDs)
            {
                SiteInfo site = SiteInfoProvider.GetSiteInfo(siteID);
                site.SiteIsOffline = false;
                SiteInfoProvider.SetSiteInfo(site);
            }
        }
        PersistentStorageHelper.RemoveValue("SeparateDBSites");
    }
Exemplo n.º 7
0
    /// <summary>
    /// Creates site. Called when the "Create site" button is pressed.
    /// </summary>
    private bool CreateSite()
    {
        // Create new site object
        SiteInfo newSite = new SiteInfo();

        // Set the properties
        newSite.DisplayName = "My new site";
        newSite.SiteName    = "MyNewSite";
        newSite.Status      = SiteStatusEnum.Stopped;
        newSite.DomainName  = "127.0.0.1";

        // Save the site
        SiteInfoProvider.SetSiteInfo(newSite);

        return(true);
    }
Exemplo n.º 8
0
    /// <summary>
    /// Takes all sites offline.
    /// </summary>
    private void TakeSitesOffline()
    {
        var sites = SiteInfoProvider.GetSites()
                    .WhereNull("SiteIsOffline")
                    .Or()
                    .WhereEquals("SiteIsOffline", 0)
                    .TypedResult;

        var siteIDs = new List <int>(sites.Items.Count);

        foreach (var site in sites)
        {
            site.SiteIsOffline = true;
            SiteInfoProvider.SetSiteInfo(site);
            siteIDs.Add(site.SiteID);
        }
        PersistentStorageHelper.SetValue("SeparateDBSites", siteIDs);
    }
Exemplo n.º 9
0
    /// <summary>
    /// Gets and updates site. Called when the "Get and update site" button is pressed.
    /// Expects the CreateSite method to be run first.
    /// </summary>
    private bool GetAndUpdateSite()
    {
        // Get the site
        SiteInfo updateSite = SiteInfoProvider.GetSiteInfo("MyNewSite");

        if (updateSite != null)
        {
            // Update the properties
            updateSite.DisplayName = updateSite.DisplayName.ToLower();

            // Save the changes
            SiteInfoProvider.SetSiteInfo(updateSite);

            return(true);
        }

        return(false);
    }
Exemplo n.º 10
0
            public void SetUp()
            {
                mSite = CreateSiteInfo();
                SiteInfoProvider.SetSiteInfo(mSite);

                var emailTemplate = CreateEmailTemplateInfo(mSite.SiteID);

                EmailTemplateInfoProvider.SetEmailTemplateInfo(emailTemplate);

                mNewsletter = CreateNewsletterInfo(mSite.SiteID, emailTemplate.TemplateID);
                NewsletterInfoProvider.SetNewsletterInfo(mNewsletter);

                mNewsletterSubscriptionSettings = CreateNewsletterSubscriptionSettings(false);
                mNewsletterSubscriptionService  = new NewsletterSubscriptionService();
                Service.Use <IActivityLogService, ActivityLogServiceInMemoryFake>();

                SiteContext.CurrentSite = mSite;
            }
Exemplo n.º 11
0
    /// <summary>
    /// Saves the data and optionally changes site's offline status.
    /// </summary>
    /// <param name="changeOffline">Indicates whether to change offline status</param>
    protected void Save(bool changeOffline)
    {
        string message = txtMessage.Value;
        string url     = txtURL.Text.Trim();

        // Check emptiness when site is going to off-line state
        if (changeOffline && !si.SiteIsOffline || !changeOffline && si.SiteIsOffline)
        {
            if (radURL.Checked && String.IsNullOrEmpty(url))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("sm.offlinemode.urlempty");
                return;
            }
        }

        // Update site info
        if (radMessage.Checked)
        {
            si.SiteOfflineMessage     = message;
            si.SiteOfflineRedirectURL = null;
        }
        else
        {
            si.SiteOfflineMessage     = null;
            si.SiteOfflineRedirectURL = url;
        }

        if (changeOffline)
        {
            // Change the offline status
            si.SiteIsOffline = !si.SiteIsOffline;
        }

        SiteInfoProvider.SetSiteInfo(si);

        lblInfo.Visible = true;
        lblInfo.Text    = GetString("general.changessaved");
    }
Exemplo n.º 12
0
 protected void InsertDefaultSite()
 {
     SiteInfoProvider.SetSiteInfo(mFakeFactory.InitSite());
 }
Exemplo n.º 13
0
    /// <summary>
    /// Save edited site.
    /// </summary>
    private bool SaveSite(SiteInfo oldSi)
    {
        // Correct domain name and return it to textbox
        txtDomainName.Text = URLHelper.RemoveProtocol(txtDomainName.Text);

        // Get SiteInfo with the given siteID
        SiteInfo si = oldSi.Clone();

        if (siteId > 0)
        {
            try
            {
                // Keep information about running status
                bool runSite = (si.Status == SiteStatusEnum.Running);

                if (si.DisplayName != txtDisplayName.Text)
                {
                    // Refresh the breadcrumb
                    ScriptHelper.RefreshTabHeader(Page, null);
                }

                // Update SiteInfo parameters
                si.SiteName              = txtCodeName.Text;
                si.Description           = txtDescription.Text;
                si.DisplayName           = txtDisplayName.Text;
                si.DomainName            = txtDomainName.Text;
                si.DefaultVisitorCulture = ValidationHelper.GetString(cultureSelector.Value, "");
                si.SiteID = siteId;
                si.SiteDefaultStylesheetID     = ValidationHelper.GetInteger(ctrlSiteSelectStyleSheet.Value, 0);
                si.SiteDefaultEditorStylesheet = ValidationHelper.GetInteger(ctrlEditorSelectStyleSheet.Value, 0);
                si.Status = SiteStatusEnum.Stopped;

                // Save SiteInfo
                SiteInfoProvider.SetSiteInfo(si);

                // Remove cached cultures for site
                CultureInfoProvider.ClearSiteCultures(true);

                // Clear settings if sitename changes
                if (si.SiteName.ToLower() != txtCodeName.Text.Trim().ToLower())
                {
                    SettingsKeyProvider.Clear(true);
                }

                // Reindex hashtable with sessions if SiteName changes and change info message
                if (oldSi.SiteName != txtCodeName.Text)
                {
                    SessionManager.ReindexSessionsInfosHashtable(oldSi.SiteName, txtCodeName.Text);
                    if (SearchIndexInfoProvider.SearchEnabled)
                    {
                        lblInfo.Text = String.Format(GetString("general.changessaved") + " " + GetString("srch.indexrequiresrebuild"), "<a href=\"javascript:" + Page.ClientScript.GetPostBackEventReference(this, "saved") + "\">" + GetString("General.clickhere") + "</a>");
                    }
                }

                if (runSite)
                {
                    DataSet ds = SiteInfoProvider.CheckDomainNameForCollision(txtDomainName.Text.Trim(), si.SiteID);
                    if (!DataHelper.DataSourceIsEmpty(ds))
                    {
                        SiteInfo runningsi = SiteInfoProvider.GetSiteInfo(ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["SiteID"], 0));
                        if (runningsi != null)
                        {
                            string collisionSite   = HTMLHelper.HTMLEncode(runningsi.DisplayName);
                            string collisionDomain = HTMLHelper.HTMLEncode(ValidationHelper.GetString(ds.Tables[0].Rows[0]["SiteDomainAliasName"], ""));

                            lblError.Text    = String.Format(GetString("SiteDomain.RunError"), collisionSite, collisionDomain, HTMLHelper.HTMLEncode(si.DisplayName));
                            lblError.Visible = true;
                        }
                    }
                    else
                    {
                        // Run current site
                        SiteInfoProvider.RunSite(si.SiteName);
                    }
                }
            }
            catch (RunningSiteException exc)
            {
                lblError.Visible = true;
                lblError.Text    = exc.Message;
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }