/// <summary> /// Assigns given cultures to the edited site. /// </summary> /// <param name="cultureIds">Identifiers of cultures meant for adding.</param> /// <returns>Returns <c>true</c> if all cultures were successfully added.</returns> private bool AddToSite(IEnumerable <int> cultureIds) { bool allCulturesAdded = true; try { bool changed = false; foreach (int cultureId in cultureIds) { CultureSiteInfoProvider.AddCultureToSite(cultureId, siteInfo.SiteID); changed = true; } if (changed) { Control.ShowChangesSaved(); } } catch (Exception ex) { allCulturesAdded = false; Control.ShowError(ex.Message); } return(allCulturesAdded); }
/// <summary> /// Assign the culture that is set as default content culture to the current site. /// </summary> private void HandleReAssigningCulture() { if (RequestHelper.IsPostBack()) { string arg = ValidationHelper.GetString(Control.Page.Request[Page.postEventArgumentID], String.Empty); if (arg.EqualsCSafe(ASSIGN_ARGUMENT_NAME)) { string culture = CultureHelper.GetDefaultCultureCode(siteInfo.SiteName); // Only default content culture is allowed to be assigned to the site in case there is no multilingual license CultureSiteInfoProvider.RemoveSiteCultures(siteInfo.SiteName); CultureSiteInfoProvider.AddCultureToSite(culture, siteInfo.SiteName); // Get info object of the default content culture to set value of the UniSelector CultureInfo ci = CultureInfoProvider.GetCultureInfoForCulture(culture); if (ci != null) { Control.Value = Convert.ToString(ci.CultureID); reloadData = true; } Control.ShowChangesSaved(); } } }
/// <inheritdoc/> public void AddSiteCulture(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)) { // Assigns the culture to the site CultureSiteInfoProvider.AddCultureToSite(cultureToWork.CultureID, siteToWork.SiteID); } }
/// <summary> /// OkClick Handler. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { string culture = ValidationHelper.GetString(cultureSelector.Value, ""); if ((culture != "") && ((currentCulture.ToLowerCSafe() != culture.ToLowerCSafe()) || chkDocuments.Checked)) { // Set new culture SiteInfo si = SiteInfo.Provider.Get(siteId); if (si != null) { try { // Set default culture and change current culture label SettingsKeyInfoProvider.SetValue("CMSDefaultCultureCode", si.SiteName, culture.Trim()); if (PageRoutingHelper.HideLanguagePrefixForDefaultCultureUrl(si.SiteName)) { new PageUrlPathCultureFormatChanger(siteId).ChangeForCulture(currentCulture, PageRoutingUrlCultureFormatEnum.LanguagePrefix); new PageUrlPathCultureFormatChanger(siteId).ChangeForCulture(culture, PageRoutingUrlCultureFormatEnum.DomainDriven); } // Change culture of documents if (chkDocuments.Checked) { // Change culture of the documents TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser); tree.ChangeCulture(si.SiteName, currentCulture, culture); } if (!LicenseHelper.CheckFeature(RequestContext.CurrentDomain, FeatureEnum.Multilingual)) { // If not multilingual, remove all cultures from the site and assign new culture CultureSiteInfoProvider.RemoveSiteCultures(si.SiteName); CultureSiteInfoProvider.AddCultureToSite(culture, si.SiteName); } ltlScript.Text = ScriptHelper.GetScript("wopener.ChangeCulture('" + chkDocuments.Checked + "'); CloseDialog();"); } catch (Exception ex) { LogAndShowError("Sites", "ChangeDefaultCulture", ex); } } } else { ltlScript.Text = ScriptHelper.GetScript("CloseDialog();"); } }
/// <summary> /// Adds culture to site. Called when the "Add culture to site" button is pressed. /// Expects the CreateCulture method to be run first. /// </summary> private bool AddCultureToSite() { // Get the culture CultureInfo culture = CultureInfoProvider.GetCultureInfo("MyNewCulture"); if (culture != null) { // Add culture to the site CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, SiteContext.CurrentSiteID); return(true); } return(false); }
/// <summary> /// Creates culture site. Called when the "Create site" button is pressed. /// </summary> private bool AddCultureToSite() { // Get site and culture objects SiteInfo site = SiteInfoProvider.GetSiteInfo("MyNewSite"); CultureInfo culture = CultureInfoProvider.GetCultureInfo("ar-sa"); if ((site != null) && (culture != null)) { // Add culture to site CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, site.SiteID); return(true); } return(false); }
/// <summary> /// Creates the initial document strucutre used for the example. Called when the "Create document structure" button is pressed. /// </summary> private bool CreateDocumentStructure() { // Add a new culture to the current site CultureInfo culture = CultureInfoProvider.GetCultureInfo("de-de"); CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, CMSContext.CurrentSiteID); // Create new instance of the Tree provider TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); // Get parent node TreeNode parentNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", "en-us"); if (parentNode != null) { // Create the API Example folder TreeNode newNode = TreeNode.New("CMS.Folder", tree); newNode.DocumentName = "API Example"; newNode.DocumentCulture = "en-us"; newNode.Insert(parentNode); parentNode = newNode; // Create the Source folder - the document to be moved will be stored here newNode = TreeNode.New("CMS.Folder", tree); newNode.DocumentName = "Source"; newNode.DocumentCulture = "en-us"; newNode.Insert(parentNode); // Create the Target folder - a document will be moved here newNode = TreeNode.New("CMS.Folder", tree); newNode.DocumentName = "Target"; newNode.DocumentCulture = "en-us"; newNode.Insert(parentNode); return(true); } return(false); }
/// <summary> /// Assigns given sites to the edited culture. /// </summary> /// <param name="siteIds">Identifiers of sites meant for adding.</param> /// <returns>Returns <c>true</c> if all cultures were successfully added.</returns> private bool AddToCulture(IEnumerable <int> siteIds) { bool allSitesAdded = true; bool changed = false; try { foreach (int siteId in siteIds) { var site = SiteInfoProvider.GetSiteInfo(siteId); if (site == null) { continue; } if (CultureSiteInfoProvider.LicenseVersionCheck(site.DomainName, FeatureEnum.Multilingual, ObjectActionEnum.Insert)) { CultureSiteInfoProvider.AddCultureToSite(cultureInfo.CultureID, siteId); changed = true; } else { allSitesAdded = false; Control.ShowError(Control.GetString("licenselimitation.siteculturesexceeded")); break; } } if (changed) { Control.ShowChangesSaved(); } } catch (Exception ex) { allSitesAdded = false; Control.ShowError(ex.Message); } return(allSitesAdded); }
/// <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); } } }
/// <summary> /// Assigns another culture to the current site, then creates the document structure and workflow scope needed for this example. Called when the "Create example objects" button is pressed. /// </summary> private bool CreateExampleObjects() { // Add a new culture to the current site CultureInfo culture = CultureInfoProvider.GetCultureInfo("de-de"); CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, CMSContext.CurrentSiteID); // Create a new tree provider TreeProvider tree = new TreeProvider(CMSContext.CurrentUser); // Get the root node TreeNode parent = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", "en-us"); if (parent != null) { // Create the API example folder TreeNode node = TreeNode.New("CMS.Folder", tree); node.DocumentName = "API Example"; node.DocumentCulture = "en-us"; // Insert it to database DocumentHelper.InsertDocument(node, parent, tree); parent = node; // Create the Source folder for moving node = TreeNode.New("CMS.Folder", tree); node.DocumentName = "Source"; node.DocumentCulture = "en-us"; DocumentHelper.InsertDocument(node, parent, tree); // Create the Target folder for moving node = TreeNode.New("CMS.Folder", tree); node.DocumentName = "Target"; node.DocumentCulture = "en-us"; DocumentHelper.InsertDocument(node, parent, tree); // Get the default workflow WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("default"); if (workflow != null) { // Get the example folder data node = DocumentHelper.GetDocument(parent, tree); // Create new workflow scope WorkflowScopeInfo scope = new WorkflowScopeInfo(); // Assign to the default workflow and current site and set starting alias path to the example document scope.ScopeWorkflowID = workflow.WorkflowID; scope.ScopeStartingPath = node.NodeAliasPath; scope.ScopeSiteID = CMSContext.CurrentSiteID; // Save the scope into the database WorkflowScopeInfoProvider.SetWorkflowScopeInfo(scope); return(true); } else { apiCreateExampleObjects.ErrorMessage = "The default workflow was not found."; } } return(false); }
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(); } }