Example #1
0
    /// <summary>
    /// Deletes the workflow scope(s) and culture assignments used for this example. Called when the "Delete objects" button is pressed.
    /// Expects the "CreateExampleObjects" method to be run first.
    /// </summary>
    private bool DeleteObjects()
    {
        CultureInfo culture = CultureInfoProvider.GetCultureInfo("de-de");

        // Remove the example culture from the site
        CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureID, CMSContext.CurrentSiteID);

        // Prepare parameters
        string where = "ScopeStartingPath LIKE '/API-Example%'";
        string orderBy = null;
        int    topN    = 0;
        string columns = null;

        DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(where, orderBy, topN, columns);

        if (!DataHelper.DataSourceIsEmpty(scopes))
        {
            // Loop through all the scopes in case more identical scopes were accidentally created
            foreach (DataRow scopeRow in scopes.Tables[0].Rows)
            {
                // Create scope info object
                WorkflowScopeInfo scope = new WorkflowScopeInfo(scopeRow);

                // Delete the scope
                scope.Delete();
            }

            return(true);
        }

        return(false);
    }
        /// <inheritdoc/>
        public void RemoveSiteCulture(ISite site, string cultureCode)
        {
            // Gets the site and culture objects
            SiteInfo    siteToWork    = SiteInfoProvider.GetSiteInfo(site.SiteName);
            CultureInfo cultureToWork = CultureInfoProvider.GetCultureInfo(cultureCode);

            if ((siteToWork != null) && (cultureToWork != null))
            {
                // Removes the culture from the site
                CultureSiteInfoProvider.RemoveCultureFromSite(cultureToWork.CultureID, siteToWork.SiteID);
            }
        }
    /// <summary>
    /// Removes cultures from edited site. Default culture is skipped and is not removed. Also cultures which
    /// are assigned to documents are not removed.
    /// </summary>
    /// <param name="cultureIds">Set of culture identifiers to delete.</param>
    /// <returns>Returns <c>true</c> if all cultures were successfully removed.</returns>
    private bool RemoveFromSite(IEnumerable <int> cultureIds)
    {
        bool allCulturesDeleted = true;
        bool changed            = false;
        var  defaultCultureCode = CultureHelper.GetDefaultCultureCode(siteInfo.SiteName);
        var  tree = new TreeProvider();

        // Remove all selected items from site
        foreach (int cultureId in cultureIds)
        {
            var culture = CultureInfoProvider.GetCultureInfo(cultureId);
            if (culture == null)
            {
                continue;
            }

            // Skip default culture deletion
            if (culture.CultureCode.EqualsCSafe(defaultCultureCode, true))
            {
                allCulturesDeleted = false;
                Control.AddError(String.Format(ResHelper.GetString("site_edit_cultures.errordeletedefaultculture"), HTMLHelper.HTMLEncode(culture.CultureName)) + '\n');
                continue;
            }

            var cultureDocumentsCount = tree.SelectNodes()
                                        .OnSite(siteInfo.SiteName)
                                        .CombineWithDefaultCulture(false)
                                        .Culture(culture.CultureCode)
                                        .Published(false)
                                        .Count;

            // Skip culture if any document translated to this culture
            if (cultureDocumentsCount > 0)
            {
                allCulturesDeleted = false;
                Control.AddError(String.Format(ResHelper.GetString("site_edit_cultures.errorremoveculturefromsite"), HTMLHelper.HTMLEncode(culture.CultureName)) + '\n');
                continue;
            }

            CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureCode, siteInfo.SiteName);
            changed = true;
        }

        if (changed)
        {
            Control.ShowChangesSaved();
        }

        return(allCulturesDeleted);
    }
    /// <summary>
    /// Removes sites from edited culture.Sites where culture is set as default culture are skipped and not removed.
    /// Also sites where are translated documents in edited culture are not removed.
    /// </summary>
    /// <param name="siteIds">Set of site identifiers to delete.</param>
    /// <returns>Returns <c>true</c> if all sites were successfully removed.</returns>
    private bool RemoveFromCulture(IEnumerable <int> siteIds)
    {
        bool allCulturesDeleted = true;
        var  changed            = false;
        var  tree = new TreeProvider();

        // Remove all selected items
        foreach (int siteId in siteIds)
        {
            var site = SiteInfoProvider.GetSiteInfo(siteId);
            if (site == null)
            {
                continue;
            }

            // Skip sites deletion which have culture set as default one
            if (CultureHelper.GetDefaultCultureCode(site.SiteName).EqualsCSafe(cultureInfo.CultureCode, true))
            {
                allCulturesDeleted = false;
                Control.AddError(string.Format(Control.GetString("culture.errordeletedefaultculture"), site.DisplayName) + '\n');
                continue;
            }

            var cultureDocumentsCount = tree.SelectNodes()
                                        .OnSite(site.SiteName)
                                        .CombineWithDefaultCulture(false)
                                        .Culture(cultureInfo.CultureCode)
                                        .Published(false)
                                        .Count;

            // Skip culture if any document translated to this culture
            if (cultureDocumentsCount > 0)
            {
                allCulturesDeleted = false;
                Control.AddError(string.Format(Control.GetString("culture.ErrorRemoveSiteFromCulture"), site.DisplayName) + '\n');
                continue;
            }

            CultureSiteInfoProvider.RemoveCultureFromSite(cultureInfo.CultureID, site.SiteID);
            changed = true;
        }

        if (changed)
        {
            Control.ShowChangesSaved();
        }

        return(allCulturesDeleted);
    }
Example #5
0
    /// <summary>
    /// Remove culture from site. Called when the "Remove culture from site" button is pressed.
    /// Expects the CreateCultureSite method to be run first.
    /// </summary>
    private bool RemoveCultureFromSite()
    {
        // Get site and culture objects
        SiteInfo    site    = SiteInfoProvider.GetSiteInfo("MyNewSite");
        CultureInfo culture = CultureInfoProvider.GetCultureInfo("ar-sa");

        if ((site != null) && (culture != null))
        {
            // Delete the culture site
            CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureID, site.SiteID);

            return(true);
        }

        return(false);
    }
Example #6
0
    /// <summary>
    /// Deletes the example document structure. Called when the "Delete document structure" button is pressed.
    /// Expects the "CreateDocumentStructure" method to be run first.
    /// </summary>
    private bool DeleteDocumentStructure()
    {
        // Create an instance of the Tree provider first
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Get the API Example folder
        TreeNode node = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/API-Example", "en-us");

        if (node != null)
        {
            // Delete the folder and all child documents
            node.DeleteAllCultures();
        }

        CultureInfo culture = CultureInfoProvider.GetCultureInfo("de-de");

        // Remove the example culture from the site
        CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureID, CMSContext.CurrentSiteID);

        return(true);
    }
Example #7
0
    /// <summary>
    /// Handles OnSelectionChanged event of the UniSelector.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void Control_OnSelectionChanged(object sender, EventArgs e)
    {
        if (siteInfo == null)
        {
            return;
        }

        bool reloadNeeded = false;

        // Remove old items
        string newValues       = ValidationHelper.GetString(Control.Value, String.Empty);
        string removedCultures = DataHelper.GetNewItemsInList(newValues, currentValues);

        if (!String.IsNullOrEmpty(removedCultures))
        {
            string[] removedCultureIDs = removedCultures.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (removedCultureIDs != null)
            {
                // Initialize tree provider
                TreeProvider tree = new TreeProvider();

                // Add all new items to site
                foreach (string cultureID in removedCultureIDs)
                {
                    CultureInfo ci = CultureInfoProvider.GetCultureInfo(ValidationHelper.GetInteger(cultureID, 0));
                    if (ci != null)
                    {
                        // Get the documents assigned to the culture being removed
                        DataSet nodes = tree.SelectNodes(siteInfo.SiteName, "/%", ci.CultureCode, false, null, null, null, -1, false);
                        if (DataHelper.DataSourceIsEmpty(nodes))
                        {
                            CultureSiteInfoProvider.RemoveCultureFromSite(ci.CultureCode, siteInfo.SiteName);
                        }
                        else
                        {
                            reloadNeeded = true;
                            Control.AddError(String.Format(ResHelper.GetString("site_edit_cultures.errorremoveculturefromsite"), ci.CultureCode) + '\n', null);
                        }
                    }
                }
            }
        }

        // Catch license limitations Exception
        try
        {
            // Add new items
            string newCultures = DataHelper.GetNewItemsInList(currentValues, newValues);
            if (!String.IsNullOrEmpty(newCultures))
            {
                string[] newCultureIDs = newCultures.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (newCultureIDs != null)
                {
                    // Add all new items to site
                    foreach (string cultureID in newCultureIDs)
                    {
                        int id = ValidationHelper.GetInteger(cultureID, 0);
                        CultureSiteInfoProvider.AddCultureToSite(id, siteInfo.SiteID);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            reloadNeeded = true;
            Control.ShowError(ex.Message);
        }

        if (reloadNeeded)
        {
            // Get the active cultures from DB
            DataSet ds = CultureInfoProvider.GetCultures("CultureID IN (SELECT CultureID FROM CMS_SiteCulture WHERE SiteID = " + siteInfo.SiteID + ")", null, 0, "CultureID");
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                currentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "CultureID"));
                Control.Value = currentValues;
                Control.Reload(true);
            }
        }
    }
    private void Control_OnSelectionChanged(object sender, EventArgs e)
    {
        int         cultureId = QueryHelper.GetInteger("objectid", 0);
        CultureInfo culture   = GetSafeCulture(cultureId);

        // Get the current sites
        string currentValues = GetCultureSites(cultureId);
        // Get sites from selector
        string newValues = ValidationHelper.GetString(Control.Value, null);

        bool     somethingChanged = false;
        bool     hasErrors        = false;
        int      siteId;
        SiteInfo si;
        DataSet  nodes;

        string[] newItems;

        // Remove old items
        string items = DataHelper.GetNewItemsInList(newValues, currentValues);

        if (!string.IsNullOrEmpty(items))
        {
            newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                TreeProvider tree = new TreeProvider(Control.CurrentUser);
                // Add all new items to site
                foreach (string item in newItems)
                {
                    siteId = ValidationHelper.GetInteger(item, 0);

                    si = SiteInfoProvider.GetSiteInfo(siteId);
                    if ((si != null) && (culture != null))
                    {
                        // Check if site does not contain document from this culture
                        nodes = tree.SelectNodes(si.SiteName, "/%", culture.CultureCode, false, null, null, null, -1, false, 1, "NodeID");
                        if (DataHelper.DataSourceIsEmpty(nodes))
                        {
                            CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureID, siteId);
                            somethingChanged = true;
                        }
                        else
                        {
                            hasErrors = true;
                            Control.ShowError(string.Format(Control.GetString("culture.ErrorRemoveSiteFromCulture"), si.DisplayName));
                            continue;
                        }
                    }
                }
            }
        }

        // Add new items
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!string.IsNullOrEmpty(items))
        {
            newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (newItems != null)
            {
                // Add all new items to site
                foreach (string item in newItems)
                {
                    siteId = ValidationHelper.GetInteger(item, 0);

                    // Add cullture to site
                    si = SiteInfoProvider.GetSiteInfo(siteId);
                    if (si != null)
                    {
                        if (CultureSiteInfoProvider.LicenseVersionCheck(si.DomainName, FeatureEnum.Multilingual, ObjectActionEnum.Insert))
                        {
                            CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, siteId);
                            somethingChanged = true;
                        }
                        else
                        {
                            hasErrors = true;
                            Control.ShowError(Control.GetString("licenselimitation.siteculturesexceeded"));
                            break;
                        }
                    }
                }
            }
        }

        // If there were some errors, reload uniselector
        if (hasErrors)
        {
            Control.Value = GetCultureSites(cultureId);
            Control.Reload(true);
        }

        if (somethingChanged)
        {
            Control.ShowChangesSaved();
        }
    }