| using System; |
| using Telerik.Framework; |
| using Telerik.Cms; |
| using System.Globalization; |
| using Telerik.Localization; |
| using System.Threading; |
| |
| public class GlobalService : IService |
| { |
| public GlobalService() |
| { |
| } |
|
| #region IService Members |
| |
| public void Initialize() |
| { |
| CmsManager.Executed += new EventHandler<Telerik.ExecutedEventArgs>(CmsManager_Executed); |
| } |
| |
| void CmsManager_Executed(object sender, Telerik.ExecutedEventArgs e) |
| { |
| if (e.CommandName == "Publish") |
| { |
| ICmsPage cmsPage = sender as ICmsPage; |
| if (cmsPage != null && LocalizationManager.IsDefaultCulture) |
| { |
| // saves the original current culture |
| CultureInfo currentCulture = Thread.CurrentThread.CurrentUICulture; |
| |
| CmsManager manager = new CmsManager(); |
| |
| int sourceLangID = (cmsPage.LangID == CultureInfo.InvariantCulture.LCID) ? LocalizationManager.DefaultCulture.LCID : cmsPage.LangID; |
| foreach (CultureInfo culture in LocalizationManager.Cultures.Values) |
| { |
| if (culture.LCID == sourceLangID) |
| continue; |
| |
| if (!cmsPage.LanguageVersions.ContainsKey(culture.LCID)) |
| { |
| // changes the culture of the current thread |
| Thread.CurrentThread.CurrentUICulture = culture; |
| |
| // Gets the Cms page for the new culture |
| ICmsPage tempPage = (ICmsPage)manager.GetPage(cmsPage.ID, true); |
| |
| // Checks out the Cms page creating new staged version |
| IStagedPage staged = tempPage.Staged.CheckOut(); |
| |
| // Copies the content from another language version and saves in into database. |
| staged.CopyFromLanguage(sourceLangID); |
| |
| // Gets the page from the database, and checkin (Publish) |
| tempPage = (ICmsPage)manager.GetPage(cmsPage.ID, true); |
| tempPage.Staged.CheckIn(); |
| } |
| } |
| |
| // restores the original culture |
| Thread.CurrentThread.CurrentUICulture = currentCulture; |
| } |
| } |
| } |
|
| #endregion |
| } |
| |