using System; using System.Data; using CMS.GlobalHelper; using CMS.ResourceManager; using CMS.SiteProvider; using CMS.UIControls; [Title(Text = "UI cultures", ImageUrl = "CMSModules/CMS_UICultures/module.png")] public partial class CMSAPIExamples_Code_Development_UICultures_Default : CMSAPIExamplePage { #region "Initialization" protected void Page_Load(object sender, EventArgs e) { // Uiculture apiCreateUICulture.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(CreateUICulture); apiGetAndUpdateUICulture.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndUpdateUICulture); apiGetAndBulkUpdateUICultures.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndBulkUpdateUICultures); apiDeleteUICulture.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(DeleteUICulture); // Resourcestring apiCreateResourceString.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(CreateResourceString); apiGetAndUpdateResourceString.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(GetAndUpdateResourceString); apiDeleteResourceString.RunExample += new CMSAPIExamples_Controls_APIExample.OnRunExample(DeleteResourceString); } #endregion #region "Mass actions" /// /// Runs all creating and managing examples. /// public override void RunAll() { base.RunAll(); // Uiculture apiCreateUICulture.Run(); apiGetAndUpdateUICulture.Run(); apiGetAndBulkUpdateUICultures.Run(); // Resourcestring apiCreateResourceString.Run(); apiGetAndUpdateResourceString.Run(); } /// /// Runs all cleanup examples. /// public override void CleanUpAll() { base.CleanUpAll(); // Resourcestring apiDeleteResourceString.Run(); // Uiculture apiDeleteUICulture.Run(); } #endregion #region "API examples - UI culture" /// /// Creates UI culture. Called when the "Create culture" button is pressed. /// private bool CreateUICulture() { // Create new UI culture object UICultureInfo newCulture = new UICultureInfo(); // Set the properties newCulture.UICultureName = "My new culture"; newCulture.UICultureCode = "my-cu"; // Save the UI culture UICultureInfoProvider.SetUICultureInfo(newCulture); return true; } /// /// Gets and updates UI culture. Called when the "Get and update culture" button is pressed. /// Expects the CreateUICulture method to be run first. /// private bool GetAndUpdateUICulture() { // Get the UI culture UICultureInfo updateCulture = UICultureInfoProvider.GetUICultureInfo("my-cu"); if (updateCulture != null) { // Update the properties updateCulture.UICultureName = updateCulture.UICultureName.ToLower(); // Save the changes UICultureInfoProvider.SetUICultureInfo(updateCulture); return true; } return false; } /// /// Gets and bulk updates UI cultures. Called when the "Get and bulk update cultures" button is pressed. /// Expects the CreateUICulture method to be run first. /// private bool GetAndBulkUpdateUICultures() { // Prepare the parameters string where = "UICultureCode LIKE N'my-cu%'"; // Get the data DataSet cultures = UICultureInfoProvider.GetUICultures(where, null); if (!DataHelper.DataSourceIsEmpty(cultures)) { // Loop through the individual items foreach (DataRow cultureDr in cultures.Tables[0].Rows) { // Create object from DataRow UICultureInfo modifyCulture = new UICultureInfo(cultureDr); // Update the properties modifyCulture.UICultureName = modifyCulture.UICultureName.ToUpper(); // Save the changes UICultureInfoProvider.SetUICultureInfo(modifyCulture); } return true; } return false; } /// /// Deletes UI culture. Called when the "Delete culture" button is pressed. /// Expects the CreateUICulture method to be run first. /// private bool DeleteUICulture() { // Get the UI culture UICultureInfo deleteCulture = UICultureInfoProvider.GetUICultureInfo("my-cu"); // Delete the UI culture UICultureInfoProvider.DeleteUICultureInfo(deleteCulture); return (deleteCulture != null); } #endregion #region "API examples - Resource string" /// /// Creates resource string in default culture. Called when the "Create resourcestring" button is pressed. /// Expects the CreateUICulture method to be run first. /// private bool CreateResourceString() { // Create new resource string object ResourceStringInfo newString = new ResourceStringInfo(); // Set the properties newString.StringKey = "Test.MyNewResourceString"; newString.UICultureCode = SqlResourceManager.DefaultUICulture; newString.TranslationText = "My new resource string translation."; newString.StringIsCustom = true; // Save the resource string SqlResourceManager.SetResourceStringInfo(newString); return true; } /// /// Gets and updates resource string. Called when the "Get and update resource string" button is pressed. /// Expects the CreateResourceString method to be run first. /// private bool GetAndUpdateResourceString() { // Get the resource string ResourceStringInfo updateString = SqlResourceManager.GetResourceStringInfo("Test.MyNewResourceString"); if (updateString != null) { // Update the properties updateString.StringKey = updateString.StringKey.ToLower(); // Save the changes SqlResourceManager.SetResourceStringInfo(updateString); return true; } return false; } /// /// Deletes resource string. Called when the "Delete resource string" button is pressed. /// Expects the CreateResourceString method to be run first. /// private bool DeleteResourceString() { // Get the resource string ResourceStringInfo deleteString = SqlResourceManager.GetResourceStringInfo("Test.MyNewResourceString"); // Delete the resource string SqlResourceManager.DeleteResourceStringInfo(deleteString); return (deleteString != null); } #endregion }