public void ConfigureTab_Uses_Tab_SkinSrc_If_SkinSrc_Set()
        {
            //Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings {
                PortalId = ValidPortalId, DefaultPortalSkin = DefaultSkin
            };
            var validTab = new TabInfo {
                TabID = ValidTabId, PortalID = ValidPortalId, SkinSrc = TabSkin
            };

            settings.ActiveTab = validTab;

            var mockLocaleController = new Mock <ILocaleController>();

            mockLocaleController.Setup(c => c.GetLocales(It.IsAny <int>())).Returns(new Dictionary <string, Locale>());
            LocaleController.RegisterInstance(mockLocaleController.Object);

            var mockTabController = new Mock <ITabController>();

            mockTabController.Setup(c => c.GetTabsByPortal(ValidPortalId)).Returns(new TabCollection(new List <TabInfo> {
                validTab
            }));
            mockTabController.Setup(c => c.GetTabsByPortal(HostPortalId)).Returns(new TabCollection());
            TabController.SetTestableInstance(mockTabController.Object);

            //Act
            controller.ConfigureActiveTab(settings);

            //Assert
            Assert.AreEqual(TabSkin, settings.ActiveTab.SkinSrc);
        }
 public void TearDown()
 {
     Globals.DependencyProvider = null;
     this.navigationManager     = null;
     TabController.ClearInstance();
     LocaleController.ClearInstance();
 }
Example #3
0
        public void GetActiveTab_Sets_StartDate_And_EndDate_Of_Tab_If_Not_Set()
        {
            //Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings {
                PortalId = ValidPortalId, CultureCode = Null.NullString
            };
            var validTab = new TabInfo {
                TabID = ValidTabId, PortalID = ValidPortalId
            };

            var mockLocaleController = new Mock <ILocaleController>();

            mockLocaleController.Setup(c => c.GetLocales(It.IsAny <int>())).Returns(new Dictionary <string, Locale>());
            LocaleController.RegisterInstance(mockLocaleController.Object);

            var mockTabController = new Mock <ITabController>();

            mockTabController.Setup(c => c.GetTabsByPortal(ValidPortalId)).Returns(new TabCollection(new List <TabInfo> {
                validTab
            }));
            mockTabController.Setup(c => c.GetTabsByPortal(HostPortalId)).Returns(new TabCollection());
            TabController.SetTestableInstance(mockTabController.Object);

            //Act
            var tab = controller.GetActiveTab(ValidTabId, settings);

            //Assert
            Assert.AreEqual(DateTime.MinValue, tab.StartDate);
            Assert.AreEqual(DateTime.MaxValue, tab.EndDate);
        }
Example #4
0
        public void Get_Success()
        {
            // Arrange
            var context = new TestCaseContext();
            var sut     = new LocaleController(
                context.Logger,
                context.SessionManager);

            var locale = "ru-ru";

            Mock.Get(context.Session.LocaleManager).Setup(
                m => m.GetLocale())
            .Returns(locale);

            // Act
            var actionResult = sut.Get(context.Session.Id);

            // Assert
            Assert.NotNull(actionResult);
            var objectResult = actionResult.Result as ObjectResult;

            Assert.NotNull(objectResult);
            Assert.Equal(200, objectResult.StatusCode);
            var result = objectResult.Value as ApiResponse <GetLocaleResponse>;

            Assert.NotNull(result);
            Assert.True(result.Success);
            Assert.Null(result.Error);
            var payload = result.Payload;

            Assert.NotNull(payload);
            Assert.Equal(locale, payload.Locale);
        }
Example #5
0
    public static void AddLanguageSwitchSettings(string SwitchType, bool ListTypeFlags, bool ListTypeName, bool ListTypeBoth, string ListAlign, bool EnableCarousel, string DropDownType, int PortalID, int UserModuleID)
    {
        List <LanguageSwitchKeyValue> lstSettings = new List <LanguageSwitchKeyValue>();

        lstSettings.Add(new LanguageSwitchKeyValue("SwitchType", SwitchType.ToString()));
        lstSettings.Add(new LanguageSwitchKeyValue("ListTypeFlag", ListTypeFlags.ToString()));
        lstSettings.Add(new LanguageSwitchKeyValue("ListTypeName", ListTypeName.ToString()));
        lstSettings.Add(new LanguageSwitchKeyValue("ListTypeBoth", ListTypeBoth.ToString()));
        lstSettings.Add(new LanguageSwitchKeyValue("ListAlign", ListAlign.ToString()));
        lstSettings.Add(new LanguageSwitchKeyValue("EnableCarousel", EnableCarousel.ToString()));
        lstSettings.Add(new LanguageSwitchKeyValue("DropDownType", DropDownType.ToString()));
        foreach (LanguageSwitchKeyValue obj in lstSettings)
        {
            obj.AddedBy  = "superuser";
            obj.IsActive = true;
        }
        try
        {
            LocaleController.AddLanguageSwitchSettings(lstSettings, UserModuleID, PortalID);
        }
        catch (Exception)
        {
            throw;
        }
    }
Example #6
0
    protected void imbUpdate_Click(object sender, EventArgs e)
    {
        List <LocalModuleInfo> lstLocalModuleTitle = new List <LocalModuleInfo>();

        foreach (GridViewRow gvRow in gdvLocalModuleTitle.Rows)
        {
            TextBox         txtLocalModuleTitle = (TextBox)gvRow.FindControl("txtLocalModuleTitle");
            LocalModuleInfo objInfo             = new LocalModuleInfo();
            objInfo.UserModuleID     = int.Parse(gdvLocalModuleTitle.DataKeys[int.Parse(gvRow.DataItemIndex.ToString())]["UserModuleID"].ToString());
            objInfo.LocalModuleTitle = txtLocalModuleTitle.Text;
            objInfo.CultureCode      = ddlAvailableLocales.SelectedValue.ToString();
            lstLocalModuleTitle.Add(objInfo);
        }

        try
        {
            LocaleController.AddUpdateLocalModuleTitle(lstLocalModuleTitle);
            LoadModuleTitles();
            SageFrame.Common.CacheHelper.Clear("MegaMenuNepInd");
            SageFrame.Common.CacheHelper.Clear("MegaMenuNepBuss");
            SageFrame.Common.CacheHelper.Clear("MegaMenuEngInd");
            SageFrame.Common.CacheHelper.Clear("MegaMenuEngBiz");
        }
        catch (Exception)
        {
            throw;
        }
    }
Example #7
0
        public void Get_Error()
        {
            // Arrange
            var context = new TestCaseContext();
            var sut     = new LocaleController(
                context.Logger,
                context.SessionManager);

            Mock.Get(context.Session.LocaleManager).Setup(
                m => m.GetLocale())
            .Throws(new Exception("message"));

            // Act
            var actionResult = sut.Get(context.Session.Id);

            // Assert
            Assert.NotNull(actionResult);
            var objectResult = actionResult.Result as ObjectResult;

            Assert.NotNull(objectResult);
            Assert.Equal(500, objectResult.StatusCode);
            var result = objectResult.Value as ApiResponse <GetLocaleResponse>;

            Assert.NotNull(result);
            Assert.False(result.Success);
            Assert.NotNull(result.Error);
            Assert.Null(result.Payload);
        }
        public void ConfigureTab_Uses_PortalSettings_DefaultSkin_If_SkinSrc_Not_Set()
        {
            // Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings {
                PortalId = ValidPortalId, DefaultPortalSkin = DefaultSkin, DefaultPortalContainer = DefaultContainer, CultureCode = Null.NullString
            };
            var validTab = new TabInfo {
                TabID = ValidTabId, PortalID = ValidPortalId
            };

            settings.ActiveTab = validTab;

            this.mockHostController.Setup(c => c.GetString("DefaultPortalSkin")).Returns(DefaultSkin);
            this.mockHostController.Setup(c => c.GetString("DefaultPortalContainer")).Returns("DefaultPortalContainer");

            var mockLocaleController = new Mock <ILocaleController>();

            mockLocaleController.Setup(c => c.GetLocales(It.IsAny <int>())).Returns(new Dictionary <string, Locale>());
            LocaleController.RegisterInstance(mockLocaleController.Object);

            var mockTabController = new Mock <ITabController>();

            mockTabController.Setup(c => c.GetTabsByPortal(ValidPortalId)).Returns(new TabCollection(new List <TabInfo> {
                validTab
            }));
            mockTabController.Setup(c => c.GetTabsByPortal(HostPortalId)).Returns(new TabCollection());
            TabController.SetTestableInstance(mockTabController.Object);

            // Act
            controller.ConfigureActiveTab(settings);

            // Assert
            Assert.AreEqual(DefaultSkin, settings.ActiveTab.SkinSrc);
        }
Example #9
0
        public void GetActiveTab_Gets_Correct_Tab_If_Valid_Host_TabId()
        {
            //Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings {
                PortalId = ValidPortalId, CultureCode = Null.NullString
            };
            var validTab = new TabInfo {
                TabID = HostTabId, PortalID = HostPortalId
            };

            var mockLocaleController = new Mock <ILocaleController>();

            mockLocaleController.Setup(c => c.GetLocales(It.IsAny <int>())).Returns(new Dictionary <string, Locale>());
            LocaleController.RegisterInstance(mockLocaleController.Object);

            var mockTabController = new Mock <ITabController>();

            mockTabController.Setup(c => c.GetTabsByPortal(HostPortalId)).Returns(new TabCollection(new List <TabInfo> {
                validTab
            }));
            mockTabController.Setup(c => c.GetTabsByPortal(ValidPortalId)).Returns(new TabCollection());
            TabController.SetTestableInstance(mockTabController.Object);

            //Act
            var tab = controller.GetActiveTab(HostTabId, settings);

            //Assert
            Assert.AreEqual(validTab.TabID, tab.TabID);
        }
        public void ConfigureTab_Builds_Breadcrumbs_For_Tab()
        {
            // Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings {
                PortalId = ValidPortalId, CultureCode = Null.NullString
            };
            var validTab = new TabInfo {
                TabID = ValidTabId, PortalID = ValidPortalId, SkinSrc = GlobalTabSkin
            };

            settings.ActiveTab = validTab;

            var mockLocaleController = new Mock <ILocaleController>();

            mockLocaleController.Setup(c => c.GetLocales(It.IsAny <int>())).Returns(new Dictionary <string, Locale>());
            LocaleController.RegisterInstance(mockLocaleController.Object);

            var mockTabController = new Mock <ITabController>();

            mockTabController.Setup(c => c.GetTabsByPortal(ValidPortalId)).Returns(new TabCollection(new List <TabInfo> {
                validTab
            }));
            mockTabController.Setup(c => c.GetTabsByPortal(HostPortalId)).Returns(new TabCollection());
            TabController.SetTestableInstance(mockTabController.Object);

            this.mockHostController.Setup(c => c.GetString("DefaultPortalContainer")).Returns("DefaultPortalContainer");

            // Act
            controller.ConfigureActiveTab(settings);

            // Assert
            Assert.NotNull(settings.ActiveTab.BreadCrumbs);
            Assert.AreEqual(1, settings.ActiveTab.BreadCrumbs.Count);
        }
Example #11
0
        public void ConfigureTab_Formats_Tab_ContainerSrc_If_Neccessary()
        {
            //Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings {
                PortalId = ValidPortalId, DefaultPortalContainer = DefaultContainer, CultureCode = Null.NullString
            };
            var validTab = new TabInfo {
                TabID = ValidTabId, PortalID = ValidPortalId, ContainerSrc = GlobalTabContainer
            };

            settings.ActiveTab         = validTab;
            settings.ActiveTab.SkinSrc = TabSkin;

            var mockLocaleController = new Mock <ILocaleController>();

            mockLocaleController.Setup(c => c.GetLocales(It.IsAny <int>())).Returns(new Dictionary <string, Locale>());
            LocaleController.RegisterInstance(mockLocaleController.Object);

            var mockTabController = new Mock <ITabController>();

            mockTabController.Setup(c => c.GetTabsByPortal(ValidPortalId)).Returns(new TabCollection(new List <TabInfo> {
                validTab
            }));
            mockTabController.Setup(c => c.GetTabsByPortal(HostPortalId)).Returns(new TabCollection());
            TabController.SetTestableInstance(mockTabController.Object);

            //Act
            controller.ConfigureActiveTab(settings);

            //Assert
            Assert.AreEqual(SkinController.FormatSkinSrc(GlobalTabContainer, settings), settings.ActiveTab.ContainerSrc);
        }
Example #12
0
        public void GetActiveTab_Gets_Splash_Tab_If_InValid_TabId_And_Both_HomeTab_And_SplashTab_Set()
        {
            //Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings {
                PortalId = ValidPortalId, SplashTabId = SplashTabId, HomeTabId = HomeTabId, CultureCode = Null.NullString
            };
            var splashTabId = new TabInfo {
                TabID = SplashTabId, PortalID = ValidPortalId
            };
            var homeTabId = new TabInfo {
                TabID = HomeTabId, PortalID = ValidPortalId
            };

            var mockLocaleController = new Mock <ILocaleController>();

            mockLocaleController.Setup(c => c.GetLocales(ValidPortalId)).Returns(new Dictionary <string, Locale>());
            LocaleController.RegisterInstance(mockLocaleController.Object);

            var mockTabController = new Mock <ITabController>();

            mockTabController.Setup(c => c.GetTabsByPortal(ValidPortalId)).Returns(new TabCollection(new List <TabInfo> {
                splashTabId, homeTabId
            }));
            TabController.SetTestableInstance(mockTabController.Object);

            //Act
            var tab = controller.GetActiveTab(InValidTabId, settings);

            //Assert
            Assert.AreEqual(SplashTabId, tab.TabID);
        }
Example #13
0
        public void Setup()
        {
            _sfp                  = new StandardFolderProvider();
            _folderInfo           = new Mock <IFolderInfo>();
            _fileInfo             = new Mock <IFileInfo>();
            _fileWrapper          = new Mock <IFile>();
            _directoryWrapper     = new Mock <IDirectory>();
            _folderManager        = new Mock <IFolderManager>();
            _fileManager          = new Mock <IFileManager>();
            _pathUtils            = new Mock <IPathUtils>();
            _portalControllerMock = new Mock <IPortalController>();
            _portalControllerMock.Setup(p => p.GetPortalSettings(Constants.CONTENT_ValidPortalId))
            .Returns(GetPortalSettingsDictionaryMock());
            _portalControllerMock.Setup(p => p.GetCurrentPortalSettings()).Returns(GetPortalSettingsMock());
            _cryptographyProviderMock = new Mock <CryptographyProvider>();
            _cryptographyProviderMock.Setup(c => c.EncryptParameter(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Guid.NewGuid().ToString("N"));
            _localeControllerMock = new Mock <ILocaleController>();
            _localeControllerMock.Setup(l => l.GetLocales(Constants.CONTENT_ValidPortalId)).Returns(new Dictionary <string, Locale>
            {
                { "en-us", new Locale() }
            });

            FileWrapper.RegisterInstance(_fileWrapper.Object);
            DirectoryWrapper.RegisterInstance(_directoryWrapper.Object);
            FolderManager.RegisterInstance(_folderManager.Object);
            FileManager.RegisterInstance(_fileManager.Object);
            PathUtils.RegisterInstance(_pathUtils.Object);
            PortalController.SetTestableInstance(_portalControllerMock.Object);
            ComponentFactory.RegisterComponentInstance <CryptographyProvider>("CryptographyProviderMock", _cryptographyProviderMock.Object);
            LocaleController.RegisterInstance(_localeControllerMock.Object);
        }
Example #14
0
        public void BindLanguageList()
        {
            try
            {
                string          mode                = languageMode == "Native" ? "NativeName" : "LanguageName";
                List <Language> lstAllCultures      = LocaleController.GetCultures();
                List <Language> lstAvailableLocales = LocalizationSqlDataProvider.GetAvailableLocales();
                List <Language> filterLocales       = FilterLocales(lstAllCultures, lstAvailableLocales);
                ddlLanuage.DataSource = filterLocales;
                // .OrderBy(item => mode);
                //ddlLanuage.DataTextField = mode;
                //ddlLanuage.DataValueField = "LanguageCode";
                ddlLanuage.DataBind();

                //List<ListItem> listCopy = new List<ListItem>();
                //foreach (ListItem item in ddlLanuage.Items)
                //    listCopy.Add(item);
                //ddlLanuage.Items.Clear();
                //foreach (ListItem item in listCopy.OrderBy(item => item.Text))
                //    ddlLanuage.Items.Add(item);
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
Example #15
0
    public void LoadModuleTitles()
    {
        List <LocalModuleInfo> lstModuleTitles = LocaleController.GetLocalModuleTitle(GetPortalID, this.ddlAvailableLocales.SelectedValue.ToString());

        gdvLocalModuleTitle.DataSource = lstModuleTitles;
        gdvLocalModuleTitle.DataBind();
    }
Example #16
0
        public void BindLanguageList()
        {
            List <Language> lstAvailableLocales = LocaleController.AddNativeNamesToList(LocalizationSqlDataProvider.GetAvailableLocales());

            ddlLanuage.DataSource = lstAvailableLocales;
            ddlLanuage.DataBind();
            ddlLanuage.SelectedValue = GetCurrentCulture();
        }
Example #17
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                Controller = new BBStoreController();

                LocaleController            lc  = new LocaleController();
                Dictionary <string, Locale> loc = lc.GetLocales(PortalId);

                ModuleController objModules = new ModuleController();

                // If this is the first visit to the page
                if (Page.IsPostBack == false)
                {
                    UnitInfo unit = null;

                    if (Request["unitid"] != null)
                    {
                        UnitId = Convert.ToInt32(Request["unitid"]);
                    }

                    // if unit exists
                    if (UnitId > 0)
                    {
                        unit = Controller.GetUnit(UnitId);
                    }

                    List <ILanguageEditorInfo> dbLangs = new List <ILanguageEditorInfo>();
                    if (unit == null)
                    {
                        txtDecimals.Text = "0";
                        foreach (KeyValuePair <string, Locale> keyValuePair in loc)
                        {
                            UnitLangInfo unitLang = new UnitLangInfo();
                            unitLang.Language = keyValuePair.Key;
                            dbLangs.Add(unitLang);
                        }
                    }
                    else
                    {
                        txtDecimals.Text = unit.Decimals.ToString();
                        foreach (UnitLangInfo unitLang in Controller.GetUnitLangs(UnitId))
                        {
                            dbLangs.Add(unitLang);
                        }
                    }
                    lngUnits.Langs = dbLangs;
                }
            }

            catch (Exception exc)
            {
                //Module failed to load
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Example #18
0
        public void TestDutchLocale()
        {
            // Arrange
            LocaleController controller = new LocaleController();

            // Act
            ViewResult result = controller.Change("de") as ViewResult;

            // Assert
            Assert.AreEqual("12,345,678.00", result.ViewBag.NumberFormat);
        }
        protected void PublishPages(object sender, EventArgs eventArgs)
        {
            var cmdPublishPages = (LinkButton)sender;
            int languageId      = int.Parse(cmdPublishPages.CommandArgument);
            var locale          = new LocaleController().GetLocale(languageId);

            LocaleController.Instance.PublishLanguage(PortalId, locale.Code, true);

            //Redirect to refresh page (and skinObjects)
            Response.Redirect(Globals.NavigateURL(), true);
        }
Example #20
0
    public static List <Language> GetCountryList()
    {
        List <Language> lstLanguage = LocaleController.GetCultures();

        foreach (Language obj in lstLanguage)
        {
            obj.LanguageCode = obj.LanguageCode.Substring(0, obj.LanguageCode.IndexOf("-"));
        }

        return(lstLanguage);
    }
Example #21
0
    public void CheckAndAddLanguageToDatabase()
    {
        List <Language> lstAvailableLocales = LocalizationSqlDataProvider.GetAvailableLocales();
        List <Language> lstAllLocales       = LocaleController.GetCultures();
        int             index = lstAvailableLocales.FindIndex(delegate(Language obj){ return(obj.LanguageCode == GetLocaleFromZipFileName()); });

        if (index < 0)
        {
            int localeIndex = lstAllLocales.FindIndex(delegate(Language obj) { return(obj.LanguageCode == GetLocaleFromZipFileName()); });
            AddToDataBase(lstAllLocales[localeIndex]);
        }
    }
        public void GetLanguageList()
        {
            string          mode = languageMode == "Native" ? "NativeName" : "LanguageName";
            List <Language> lstAvailableLocales = LocaleController.AddNativeNamesToList(LocalizationSqlDataProvider.GetAvailableLocales());

            ddlDefaultLanguage.DataSource     = lstAvailableLocales;
            ddlDefaultLanguage.DataTextField  = mode;
            ddlDefaultLanguage.DataValueField = "LanguageCode";
            ddlDefaultLanguage.DataBind();
            ddlDefaultLanguage.SelectedIndex = ddlDefaultLanguage.Items.IndexOf(ddlDefaultLanguage.Items.FindByValue(ViewState["SelectedLanguageCulture"].ToString()));
            ViewState["RowCount"]            = lstAvailableLocales.Count;
        }
Example #23
0
        private List <string> GetPortalLanguages()
        {
            List <string>               languages = new List <string>();
            LocaleController            lc        = new LocaleController();
            Dictionary <string, Locale> loc       = lc.GetLocales(_moduleContext.PortalId);

            foreach (KeyValuePair <string, Locale> item in loc)
            {
                string cultureCode = item.Value.Culture.Name;
                languages.Add(cultureCode);
            }
            return(languages);
        }
Example #24
0
        public void UpdatePlugg(Plugg p, PluggContent pc)
        {
            //For restore if something goes wrong
            Plugg oldP = GetPlugg(p.PluggId);
            IEnumerable <PluggContent> oldPCs = GetAllContentInPlugg(p.PluggId);

            rep.UpdatePlugg(p); //No repair necessary if this fails

            //For now, remove all PluggContent and recreate in all languages from pc. Fix this when we can deal with translations
            try
            {
                foreach (PluggContent pcDelete in oldPCs)
                {
                    rep.DeletePluggContent(pcDelete);
                }

                pc.PluggId = p.PluggId;
                if (pc.LatexText != null)
                {
                    LatexToMathMLConverter myConverter = new LatexToMathMLConverter(pc.LatexText);
                    myConverter.Convert();
                    pc.LatexTextInHtml = myConverter.HTMLOutput;
                }

                LocaleController lc = new LocaleController();
                var locales         = lc.GetLocales(PortalID);
                foreach (var locale in locales)
                {
                    pc.CultureCode = locale.Key;
                    rep.CreatePluggContent(pc);
                }
            }
            catch (Exception)
            {
                //recreate old Plugg/PluggContent before rethrow
                var pcs = GetAllContentInPlugg(p.PluggId);
                foreach (PluggContent pcDelete in pcs)
                {
                    rep.DeletePluggContent(pcDelete);
                }
                rep.DeletePlugg(p);

                rep.CreatePlugg(oldP);
                foreach (PluggContent oldPC in oldPCs)
                {
                    rep.CreatePluggContent(oldPC);
                }
                throw;
            }
        }
        protected void MarkAllPagesTranslated(object sender, EventArgs eventArgs)
        {
            var cmdTranslateAll = (LinkButton)sender;
            int languageId      = int.Parse(cmdTranslateAll.CommandArgument);
            var locale          = new LocaleController().GetLocale(languageId);

            var nonTranslated = (from t in TabController.Instance.GetTabsByPortal(PortalId).WithCulture(locale.Code, false).Values where !t.IsTranslated && !t.IsDeleted select t);

            foreach (TabInfo page in nonTranslated)
            {
                page.LocalizedVersionGuid = page.DefaultLanguageTab.LocalizedVersionGuid;
                TabController.Instance.UpdateTab(page);
            }
            BindGrid();
        }
Example #26
0
 protected void DisplayVersions()
 {
     try
     {
         using (SqlConnection connection = new SqlConnection(ConnString))
         {
             SqlCommand command = new SqlCommand();
             //Grab a different version if a different language
             LocaleController LangController = new LocaleController();
             string           ThisLocale     = System.Globalization.CultureInfo.CurrentUICulture.Name;
             connection.Open();
             command.CommandText = "SELECT H.[ItemID],H.[Version],H.[LastModifiedOnDate],H.[LastModifiedByUserID],U.[DisplayName] FROM [HtmlText] H inner join [Users] U on H.LastModifiedByUserID = U.UserID WHERE ModuleID = " + ModuleId + " and CONVERT(NVARCHAR(MAX), Summary) = N'" + ThisLocale + "' ORDER BY Version desc";
             command.Connection  = connection;
             SqlDataAdapter sda = new SqlDataAdapter(command);
             DataSet        ds  = new DataSet();
             sda.Fill(ds);
             if (ds.Tables.Count > 0)
             {
                 if (ds.Tables[0].Rows.Count > 0)
                 {
                     dgVersions.DataSource = ds;
                     dgVersions.DataBind();
                     command.ExecuteNonQuery();
                     connection.Close();
                 }
                 else
                 {
                     dgVersions.Visible = false;
                     NoVersions.Visible = true;
                 }
             }
             else
             {
                 dgVersions.Visible = false;
                 NoVersions.Visible = true;
             }
         }
     }
     catch (Exception ex)
     {
         if (PortalSettings.UserInfo.IsSuperUser)
         {
             txtAdminView.Text = ex.Message;
         }
     }
 }
Example #27
0
 public void BindLanguageList()
 {
     try
     {
         string          mode                = languageMode == "Native" ? "NativeName" : "LanguageName";
         List <Language> lstAllCultures      = LocaleController.GetCultures();
         List <Language> lstAvailableLocales = LocalizationSqlDataProvider.GetAvailableLocales();
         List <Language> filterLocales       = FilterLocales(lstAllCultures, lstAvailableLocales);
         ddlLanuage.DataSource = filterLocales;
         ddlLanuage.DataBind();
         ddlLanuage.SelectedValue = GetCurrentCulture();
     }
     catch (Exception ex)
     {
         ProcessException(ex);
     }
 }
Example #28
0
        public void ConfigureTab_Builds_Breadcrumbs_For_Tab_And_Parent()
        {
            //Arrange
            var controller = new PortalSettingsController();
            var settings   = new PortalSettings {
                PortalId = ValidPortalId, CultureCode = Null.NullString
            };
            var validTab = new TabInfo {
                TabID = ValidTabId, PortalID = ValidPortalId, ParentId = ParentTabId
            };
            var parentTab = new TabInfo {
                TabID = ParentTabId, PortalID = ValidPortalId
            };

            settings.ActiveTab         = validTab;
            settings.ActiveTab.SkinSrc = TabSkin;

            var mockLocaleController = new Mock <ILocaleController>();

            mockLocaleController.Setup(c => c.GetLocales(It.IsAny <int>())).Returns(new Dictionary <string, Locale>());
            LocaleController.RegisterInstance(mockLocaleController.Object);

            var mockTabController = new Mock <ITabController>();

            mockTabController.Setup(c => c.GetTabsByPortal(ValidPortalId)).Returns(new TabCollection(new List <TabInfo> {
                validTab, parentTab
            }));
            mockTabController.Setup(c => c.GetTabsByPortal(HostPortalId)).Returns(new TabCollection());
            TabController.SetTestableInstance(mockTabController.Object);

            var mockHostController = new Mock <IHostController>();

            mockHostController.Setup(c => c.GetString("DefaultPortalContainer")).Returns("DefaultPortalContainer");
            HostController.RegisterInstance(mockHostController.Object);

            //Act
            controller.ConfigureActiveTab(settings);

            //Assert
            var actualParent = settings.ActiveTab.BreadCrumbs[0] as TabInfo;
            var actualTab    = settings.ActiveTab.BreadCrumbs[1] as TabInfo;

            Assert.AreEqual(2, settings.ActiveTab.BreadCrumbs.Count);
            Assert.AreEqual(ValidTabId, actualTab.TabID);
            Assert.AreEqual(ParentTabId, actualParent.TabID);
        }
    private void AddLanguage()
    {
        int             PortalID         = GetPortalID;
        List <Language> lstLanguage      = LocalizationSqlDataProvider.GetPortalLanguages(PortalID);
        List <Language> lstLanguageFlags = LocaleController.AddNativeNamesToList(AddFlagPath(LocalizationSqlDataProvider.GetPortalLanguages(PortalID), GetApplicationName));

        if (lstLanguage.Count < 1 || lstLanguageFlags.Count < 1)
        {
            languageSetting.Visible = false;
        }
        else
        {
            var query = from listlang in lstLanguage
                        join listflag in lstLanguageFlags
                        on listlang.LanguageCode equals listflag.LanguageCode
                        select new
            {
                listlang.LanguageCode,
                listflag.FlagPath
            };
            StringBuilder ddlLanguage = new StringBuilder();
            string        cultureCode = GetCurrentCulture();
            ddlLanguage.Append("<ul id=\"languageSelect\" class=\"sfListmenu\"");
            ddlLanguage.Append(">");
            foreach (var item in query)
            {
                if (item.LanguageCode == cultureCode)
                {
                    ddlLanguage.Append("<li value=\"" + item.LanguageCode + "\" class='languageSelected'>");
                    ddlLanguage.Append(item.LanguageCode + "-" + "<img src=\"" + item.FlagPath + "\">");
                    ddlLanguage.Append("</li>");
                }
                else
                {
                    ddlLanguage.Append("<li value=\"" + item.LanguageCode + "\">");
                    ddlLanguage.Append(item.LanguageCode + "-" + "<img src=\"" + item.FlagPath + "\">");
                    ddlLanguage.Append("</li>");
                }
            }
            ddlLanguage.Append("</ul>");
            languageSetting.Text = ddlLanguage.ToString();
        }
    }
Example #30
0
        protected void formViewLang_ItemCreated(object sender, EventArgs e)
        {
            LocaleController            lc  = new LocaleController();
            Dictionary <string, Locale> loc = lc.GetLocales(PortalSettings.Current.PortalId);

            FormViewRow row = formViewLang.HeaderRow;

            if (row != null)
            {
                PlaceHolder phLanguage = row.FindControl("phLanguage") as PlaceHolder;
                int         i          = 0;
                foreach (KeyValuePair <string, Locale> item in loc)
                {
                    HtmlGenericControl div = new HtmlGenericControl("div");
                    div.Style.Add("display", "table-cell");

                    ImageButton imgBtn = new ImageButton();
                    imgBtn.ID       = "imgLanguage" + i.ToString();
                    imgBtn.Click   += Language_Selected;
                    imgBtn.ImageUrl = "~\\images\\Flags\\" + item.Key + ".gif";
                    imgBtn.Style.Add("padding", "3px 10px 5px 10px");

                    imgBtn.Style.Add("border-width", "1px");
                    imgBtn.Style.Add("border-color", "#000000");

                    if (i == formViewLang.PageIndex)
                    {
                        imgBtn.Style.Add("border-style", "solid solid hidden solid");
                        imgBtn.Style.Add("margin", "0 0 1px 0;");
                        imgBtn.Style.Add("background-color", "White");
                    }
                    else
                    {
                        imgBtn.Style.Add("border-style", "solid solid solid solid");
                        imgBtn.Style.Add("margin", "0");
                        imgBtn.Style.Add("background-color", "LightGrey");
                    }
                    div.Controls.Add(imgBtn);
                    phLanguage.Controls.Add(div);
                    i++;
                }
            }
        }
        public HttpResponseMessage GetNonTranslatedPages(string languageCode)
        {
            var request = HttpContext.Current.Request;
           var locale = new LocaleController().GetLocale(languageCode);

            List<PageDto> pages = new List<PageDto>();
            if (!IsDefaultLanguage(locale.Code))
            {
                TabController ctl = new TabController();
                var nonTranslated = (from t in ctl.GetTabsByPortal(PortalSettings.PortalId).WithCulture(locale.Code, false).Values where !t.IsTranslated && !t.IsDeleted select t);
                foreach (TabInfo page in nonTranslated)
                {
                    pages.Add(new PageDto()
                    {
                        Name = page.TabName,
                        ViewUrl = DotNetNuke.Common.Globals.NavigateURL(page.TabID),
                        EditUrl = DotNetNuke.Common.Globals.NavigateURL(page.TabID, "Tab", "action=edit", "returntabid=" + PortalSettings.ActiveTab.TabID)
                    });
                }
            }
            return Request.CreateResponse(HttpStatusCode.OK, pages);
        }
        protected void PublishPages(object sender, EventArgs eventArgs)
        {

            var cmdPublishPages = (LinkButton)sender;
            int languageId = int.Parse(cmdPublishPages.CommandArgument);
            var locale = new LocaleController().GetLocale(languageId);
            LocaleController.Instance.PublishLanguage(PortalId, locale.Code, true);

            //Redirect to refresh page (and skinObjects)
            Response.Redirect(Globals.NavigateURL(), true);
        }
Example #33
0
 /// <summary>
 /// This method will save the text in all Culture Codes
 /// It expects the text to be created in t.CultureCode
 /// It expects the text to be decoded (actual html)
 /// It will call SavePhText(t)
 /// It then translates t into all languages and calls SavePhText on each text
 /// </summary>
 /// <param name="t"></param>
 public void SavePhTextInAllCc(PHText t)
 {
     t.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
     SavePhText(t);  //Save Text in created language
     LocaleController lc = new LocaleController();
     var locales = lc.GetLocales(PortalID);
     PHText translatedText;
     foreach (var locale in locales)
     {
         if (locale.Key != t.CultureCode)
         {
             translatedText = GetCurrentVersionText(locale.Key, t.ItemId, t.ItemType);
             if (translatedText == null)
             {
                 translatedText = new PHText();
                 translatedText.CultureCode = locale.Key;
                 translatedText.ItemId = t.ItemId;
                 translatedText.ItemType = t.ItemType;
             }
             if (t.ItemType == ETextItemType.PluggTitle || t.ItemType == ETextItemType.PluggDescription || t.ItemType == ETextItemType.CourseTitle || t.ItemType == ETextItemType.CourseDescription )
             {
                 string translation = TranslateText(t.CultureCode.Substring(0, 2), locale.Key.Substring(0, 2), t.Text);
                 if (translation != null)
                 {
                     translatedText.Text = translation;
                     translatedText.CultureCodeStatus = ECultureCodeStatus.GoogleTranslated;
                 }
                 else
                 {
                     translatedText.Text = "";
                     translatedText.CultureCodeStatus = ECultureCodeStatus.NotTranslated;
                 }
             }
             else
             {
                 translatedText.Text = "";
                 translatedText.CultureCodeStatus = ECultureCodeStatus.NotTranslated;
             }
             if (translatedText.CreatedByUserId == 0)
                 translatedText.CreatedByUserId = t.CreatedByUserId;
             SavePhText(translatedText);
         }
     }
 }
Example #34
0
        public void BindAll(int tabID)
        {
            TabID = tabID;
            var currentTab = TabController.GetTab(tabID, PortalSettings.PortalId, false);

            //Unique id of default language page
            var uniqueId = currentTab.DefaultLanguageGuid != Null.NullGuid ? currentTab.DefaultLanguageGuid : currentTab.UniqueId;

            // get all non admin pages and not deleted
            var allPages = TabController.GetTabsByPortal(PortalSettings.PortalId).Values.Where(t => t.TabID != PortalSettings.AdminTabId && (Null.IsNull(t.ParentId) || t.ParentId != PortalSettings.AdminTabId));
            allPages = allPages.Where(t => t.IsDeleted == false);
            // get all localized pages of current page
            var tabInfos = allPages as IList<TabInfo> ?? allPages.ToList();
            var localizedPages = tabInfos.Where(t => t.DefaultLanguageGuid == uniqueId || t.UniqueId == uniqueId).OrderBy(t => t.DefaultLanguageGuid).ToList();
            Dictionary<string, TabInfo> localizedTabs = null;

            // we are going to build up a list of locales
            // this is a bit more involved, since we want the default language to be first.
            // also, we do not want to add any locales the user has no access to
            var locales = new List<string>();
            var localeController = new LocaleController();
            var localeDict = localeController.GetLocales(PortalSettings.PortalId);
            if (localeDict.Count > 0)
            {
                if (localizedPages.Count() == 1 && localizedPages.First().CultureCode == "")
                {
                    // locale neutral page
                    locales.Add("");
                }
                else if (localizedPages.Count() == 1 && localizedPages.First().CultureCode != PortalSettings.DefaultLanguage)
                {
                    locales.Add(localizedPages.First().CultureCode);
                    localizedTabs = new Dictionary<string, TabInfo>();
                    localizedTabs.Add(localizedPages.First().CultureCode, localizedPages.First());
                }
                else
                {

                    //force sort order, so first add default language
                    locales.Add(PortalSettings.DefaultLanguage);

                    // build up a list of localized tabs.
                    // depending on whether or not the selected page is in the default langauge
                    // we will add the localized tabs from the current page
                    // or from the defaultlanguage page
                    if (currentTab.CultureCode == PortalSettings.DefaultLanguage)
                    {
                        localizedTabs = currentTab.LocalizedTabs;
                    }
                    else
                    {
                        // selected page is not in default language
                        // add localizedtabs from defaultlanguage page
                        if (currentTab.DefaultLanguageTab != null)
                        {
                            localizedTabs = currentTab.DefaultLanguageTab.LocalizedTabs;
                        }
                    }

                    if (localizedTabs != null)
                    {
                        // only add locales from tabs the user has at least view permissions to. 
                        // we will handle the edit permissions at a later stage
                        locales.AddRange(from localizedTab in localizedTabs where TabPermissionController.CanViewPage(localizedTab.Value) select localizedTab.Value.CultureCode);
                    }


                }
            }
            else
            {
                locales.Add("");
            }

            Data = new DnnPages(locales);

            // filter the list of localized pages to only those that have a culture we want to see
            var viewableLocalizedPages = localizedPages.Where(localizedPage => locales.Find(locale => locale == localizedPage.CultureCode) != null).ToList();
            if (viewableLocalizedPages.Count() > 4)
            {
                mainContainer.Attributes.Add("class", "container RadGrid RadGrid_Default overflow");
            }

            foreach (var tabInfo in viewableLocalizedPages)
            {
                var localTabInfo = tabInfo;
                var dnnPage = Data.Page(localTabInfo.CultureCode);
                if (!TabPermissionController.CanViewPage(tabInfo))
                {
                    Data.RemoveLocale(localTabInfo.CultureCode);
                    Data.Pages.Remove(dnnPage);
                    break;
                }
                dnnPage.TabID = localTabInfo.TabID;
                dnnPage.TabName = localTabInfo.TabName;
                dnnPage.Title = localTabInfo.Title;
                dnnPage.Description = localTabInfo.Description;
                dnnPage.Path = localTabInfo.TabPath.Substring(0, localTabInfo.TabPath.LastIndexOf("//", StringComparison.Ordinal)).Replace("//", "");
                dnnPage.HasChildren = (TabController.GetTabsByPortal(PortalSettings.PortalId).WithParentId(tabInfo.TabID).Count != 0);
                dnnPage.CanAdminPage = TabPermissionController.CanAdminPage(tabInfo);
                dnnPage.CanViewPage = TabPermissionController.CanViewPage(tabInfo);
                dnnPage.LocalResourceFile = LocalResourceFile;

                // calculate position in the form of 1.3.2...
                var SiblingTabs = tabInfos.Where(t => t.ParentId == localTabInfo.ParentId && t.CultureCode == localTabInfo.CultureCode || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList();
                dnnPage.Position = (SiblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture);
                int ParentTabId = localTabInfo.ParentId;
                while (ParentTabId > 0)
                {
                    TabInfo ParentTab = tabInfos.Single(t => t.TabID == ParentTabId);
                    int id = ParentTabId;
                    SiblingTabs = tabInfos.Where(t => t.ParentId == id && t.CultureCode == localTabInfo.CultureCode || t.CultureCode == null).OrderBy(t => t.TabOrder).ToList();
                    dnnPage.Position = (SiblingTabs.IndexOf(localTabInfo) + 1).ToString(CultureInfo.InvariantCulture) + "." + dnnPage.Position;
                    ParentTabId = ParentTab.ParentId;
                }

                dnnPage.DefaultLanguageGuid = localTabInfo.DefaultLanguageGuid;
                dnnPage.IsTranslated = localTabInfo.IsTranslated;
                dnnPage.IsPublished = TabController.IsTabPublished(localTabInfo);
                // generate modules information
                foreach (var moduleInfo in ModuleController.GetTabModules(localTabInfo.TabID).Values.Where(m => !m.IsDeleted))
                {
                    var guid = moduleInfo.DefaultLanguageGuid == Null.NullGuid ? moduleInfo.UniqueId : moduleInfo.DefaultLanguageGuid;

                    var dnnModules = Data.Module(guid); // modules of each language
                    var dnnModule = dnnModules.Module(localTabInfo.CultureCode);
                    // detect error : 2 modules with same uniqueId on the same page
                    dnnModule.LocalResourceFile = LocalResourceFile;
                    if (dnnModule.TabModuleID > 0)
                    {
                        dnnModule.ErrorDuplicateModule = true;
                        ErrorExists = true;
                        continue;
                    }

                    dnnModule.ModuleTitle = moduleInfo.ModuleTitle;
                    dnnModule.DefaultLanguageGuid = moduleInfo.DefaultLanguageGuid;
                    dnnModule.TabId = localTabInfo.TabID;
                    dnnModule.TabModuleID = moduleInfo.TabModuleID;
                    dnnModule.ModuleID = moduleInfo.ModuleID;
                    dnnModule.CanAdminModule = ModulePermissionController.CanAdminModule(moduleInfo);
                    dnnModule.CanViewModule = ModulePermissionController.CanViewModule(moduleInfo);

                    if (moduleInfo.DefaultLanguageGuid != Null.NullGuid)
                    {
                        ModuleInfo defaultLanguageModule = ModuleController.GetModuleByUniqueID(moduleInfo.DefaultLanguageGuid);
                        if (defaultLanguageModule != null)
                        {
                            dnnModule.DefaultModuleID = defaultLanguageModule.ModuleID;
                            if (defaultLanguageModule.ParentTab.UniqueId != moduleInfo.ParentTab.DefaultLanguageGuid)
                                dnnModule.DefaultTabName = defaultLanguageModule.ParentTab.TabName;
                        }
                    }
                    dnnModule.IsTranslated = moduleInfo.IsTranslated;
                    dnnModule.IsLocalized = moduleInfo.IsLocalized;

                    dnnModule.IsShared = TabController.GetTabsByModuleID(moduleInfo.ModuleID).Values.Count(t => t.CultureCode == moduleInfo.CultureCode) > 1;

                    // detect error : the default language module is on an other page
                    dnnModule.ErrorDefaultOnOtherTab = moduleInfo.DefaultLanguageGuid != Null.NullGuid && moduleInfo.DefaultLanguageModule == null;

                    // detect error : different culture on tab and module
                    dnnModule.ErrorCultureOfModuleNotCultureOfTab = moduleInfo.CultureCode != localTabInfo.CultureCode;

                    ErrorExists = ErrorExists || dnnModule.ErrorDefaultOnOtherTab || dnnModule.ErrorCultureOfModuleNotCultureOfTab;
                }
            }

            rDnnModules.DataSource = Data.Modules;
            rDnnModules.DataBind();

        }
    protected void Page_Load(object sender, System.EventArgs e)
    {
        //Populate the HTML
        try
        {
            using (SqlConnection connection = new SqlConnection(ConnString))
            {
                SqlCommand command = new SqlCommand();
                //Grab a different version if a different language
                LocaleController LangController = new LocaleController();
                string ThisLocale = System.Globalization.CultureInfo.CurrentUICulture.Name;

                //Get the last HTML Text
                command.CommandText = "SELECT [ItemID],[Content],[Summary] FROM [HtmlText] WHERE ModuleID = @ModuleID ORDER BY LastModifiedOnDate ";
                command.Parameters.AddWithValue("@ModuleID", ModuleId);
                command.Connection = connection;
                try
                {
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    string defaultLocale = "";
                    bool otherLocal = true;
                    lblUserView.Text = Localization.GetString("txtDefault.Text", LocalResourceFile);

                    //User View
                    while (reader.Read())
                    {
                        if (reader["Summary"].ToString().Trim() == ThisLocale.Trim())
                        {
                            lblUserView.Text = HttpUtility.HtmlDecode(reader["Content"].ToString());
                        }

                        //Store the default locale incase no locale set for the current one
                        if (LangController.GetDefaultLocale(PortalId).Code.Trim() == reader["Summary"].ToString().Trim())
                        {
                            defaultLocale = reader["Content"].ToString();
                        }

                        if (otherLocal & IsEditable)
                        {
                            otherLocal = false;
                            CheckOtherLanguages();
                        }
                    }

                    //Load the default locale if it has data but the other doesn't
                    if ((string.IsNullOrEmpty(lblUserView.Text) | lblUserView.Text == Localization.GetString("txtDefault.Text", LocalResourceFile)) & string.IsNullOrEmpty(defaultLocale) == false)
                    {
                        lblUserView.Text = HttpUtility.HtmlDecode(defaultLocale);
                    }

                    if (ModuleConfiguration.PaneName == "RightPane")
                    {
                        lblUserView.Text = "<p>" + lblUserView.Text + "</p>";
                    }

                }
                finally
                {
                    command.Connection.Close();
                }
            }
        }
        catch (Exception ex)
        {
            if (PortalSettings.UserInfo.IsSuperUser)
                lblUserView.Text = ex.Message;
        }
    }
Example #36
0
        /// <summary>
        /// This method will save the LatexText in all Culture Codes
        /// It expects the text to be created in t.CultureCode
        /// It will call SaveLatexText(t)
        /// It then translates t into all languages and calls SaveLatexText on each text
        /// </summary>
        /// <param name="t"></param>
        public void SaveLatexTextInAllCc(PHLatex t)
        {
            SaveLatexText(t);  //Save LatexText in created language
            LocaleController lc = new LocaleController();
            var locales = lc.GetLocales(PortalID);
            foreach (var locale in locales)
            {
                if (locale.Key != t.CultureCode)
                {
                    t.Text = TranslateText(t.CultureCode.Substring(0, 2), locale.Key.Substring(0, 2), t.Text);

                    t.LatexId = 0;
                    t.CultureCode = locale.Key;
                    t.CultureCodeStatus = ECultureCodeStatus.GoogleTranslated;
                    SaveLatexText(t);
                }
            }
        }
Example #37
0
 /// <summary>
 /// This method will save the text in all Culture Codes
 /// It expects the text to be created in t.CultureCode
 /// It will call SavePhText(t)
 /// It then translates t into all languages and calls SavePhText on each text
 /// </summary>
 /// <param name="t"></param>
 public void SavePhTextInAllCc(PHText t)
 {
     t.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
     SavePhText(t);  //Save Text in created language
     LocaleController lc = new LocaleController();
     var locales = lc.GetLocales(PortalID);
     PHText translatedText;
     foreach (var locale in locales)
     {
         if (locale.Key != t.CultureCode)
         {
             translatedText = GetCurrentVersionText(locale.Key, t.ItemId, t.ItemType);
             translatedText.Text = TranslateText(t.CultureCode.Substring(0, 2), locale.Key.Substring(0, 2), t.Text);
             translatedText.CultureCodeStatus = ECultureCodeStatus.GoogleTranslated;
             SavePhText(translatedText);
         }
     }
 }
        public string GetProperty(string propertyName, string format, CultureInfo formatProvider, UserInfo accessingUser, Scope accessLevel, ref bool propertyNotFound)
        {
            string retVal = "";
            switch (propertyName.ToLower())
            {
                case "all":
                    int moduleId = _moduleContext.ModuleId;
                    int portalId = _moduleContext.PortalId;
                    int tabId = _moduleContext.TabId;
                    ModuleInfo module = new ModuleController().GetModule(moduleId, tabId);

                    dynamic properties = new ExpandoObject();
                    System.IO.FileInfo fi = new System.IO.FileInfo(HttpContext.Current.Server.MapPath("~/" + _moduleContext.Configuration.ModuleControl.ControlSrc.Replace(".html", "") + ".resx"));
                    string physResourceFile = fi.DirectoryName + "/App_LocalResources/" + fi.Name;
                    string relResourceFile = "/DesktopModules/" + module.DesktopModule.FolderName + "/App_LocalResources/" + fi.Name;
                    if (File.Exists(physResourceFile))
                    {
                        using (var rsxr = new ResXResourceReader(physResourceFile))
                        {
                            var res = rsxr.OfType<DictionaryEntry>()
                                .ToDictionary(
                                    entry => entry.Key.ToString().Replace(".", "_"),
                                    entry => Localization.GetString(entry.Key.ToString(), relResourceFile));

                            properties.Resources = res;
                        }
                    }
                    else
                    {
                        properties.Resources = physResourceFile + " not found";
                    }
                    properties.Settings = _moduleContext.Settings;
                    properties.Editable = _moduleContext.EditMode && _moduleContext.IsEditable;
                    properties.Admin = accessingUser.IsInRole(PortalSettings.Current.AdministratorRoleName);
                    properties.ModuleId = moduleId;
                    properties.PortalId = portalId;
                    properties.UserId = accessingUser.UserID;
                    properties.HomeDirectory = PortalSettings.Current.HomeDirectory.Substring(1);
                    properties.RawUrl = HttpContext.Current.Request.RawUrl;

                    List<string> languages = new List<string>();
                    LocaleController lc = new LocaleController();
                    Dictionary<string, Locale> loc = lc.GetLocales(_moduleContext.PortalId);
                    foreach (KeyValuePair<string, Locale> item in loc)
                    {
                        string cultureCode = item.Value.Culture.Name;
                        languages.Add(cultureCode);
                    }
                    properties.Languages = languages;
                    properties.CurrentLanguage = System.Threading.Thread.CurrentThread.CurrentCulture.Name;

                    retVal = JsonConvert.SerializeObject(properties);
                    break;
                case "view":
                    retVal = (string)_moduleContext.Settings["View"];
                    if (String.IsNullOrEmpty(retVal))
                        retVal = "View.html";
                    break;
                case "list":
                    retVal = (string)_moduleContext.Settings["List"];
                    if (String.IsNullOrEmpty(retVal))
                        retVal = "List.html";
                    break;
            }
            return retVal;

        }
        protected void MarkAllPagesTranslated(object sender, EventArgs eventArgs)
        {
            var cmdTranslateAll = (LinkButton)sender;
            int languageId = int.Parse(cmdTranslateAll.CommandArgument);
            var locale = new LocaleController().GetLocale(languageId);

            var nonTranslated = (from t in TabController.Instance.GetTabsByPortal(PortalId).WithCulture(locale.Code, false).Values where !t.IsTranslated && !t.IsDeleted select t);
            foreach (TabInfo page in nonTranslated)
            {
                page.LocalizedVersionGuid = page.DefaultLanguageTab.LocalizedVersionGuid;
                TabController.Instance.UpdateTab(page);
            }
            BindGrid();
        }
        public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modInfo, DateTime beginDate)
        {
            string partition = (string)modInfo.ModuleSettings["Partitioning"];

            int partModuleId = -1;
            int partPortalId = -1;

            switch (partition)
            {
                case "1":
                    partModuleId = modInfo.ModuleID;
                    break;
                case "2":
                    partPortalId = modInfo.PortalID;
                    break;
                case "3":
                    partPortalId = modInfo.PortalID;
                    partModuleId = modInfo.ModuleID;
                    break;
            }

            var searchDocuments = new List<SearchDocument>();

            LocaleController lc = new LocaleController();
            Dictionary<string, Locale> loc = lc.GetLocales(modInfo.PortalID);
            foreach (KeyValuePair<string, Locale> item in loc)
            {
                string cultureCode = item.Value.Culture.Name;
                List<StoryInfo> stories = DbController.Instance.GetStories(partModuleId, partPortalId, "STORY", cultureCode, false).ToList();
                

                foreach (StoryInfo story in stories)
                {
                    DateTime lastmodified = ((DateTime)story.LastModifiedOnDate).ToUniversalTime();

                    if (lastmodified > beginDate.ToUniversalTime() && lastmodified < DateTime.UtcNow)
                    {
                        var strContent = HtmlUtils.Clean(story.Story, false);

                        // Get the description string
                        var description = strContent.Length <= 500 ? strContent : HtmlUtils.Shorten(strContent, 500, "...");

                        var searchDoc = new SearchDocument
                        {
                            UniqueKey = story.StoryId.ToString(),
                            PortalId = modInfo.PortalID,
                            ModuleId = modInfo.ModuleID,
                            ModuleDefId = modInfo.ModuleDefID,
                            Title = story.Title,
                            Description = description,
                            Body = strContent,
                            ModifiedTimeUtc = lastmodified,
                            AuthorUserId = (story.CreatedByUserID ?? -1),
                            CultureCode = cultureCode,
                            IsActive = (story.StartDate == null || story.StartDate < DateTime.Now) && (story.EndDate == null || story.EndDate + new TimeSpan(1, 0, 0, 0) >= DateTime.Now),
                            SearchTypeId = 1,
                            QueryString = "#view/"+story.StoryId.ToString()
                        };

                        if (modInfo.Terms != null && modInfo.Terms.Count > 0)
                        {
                            searchDoc.Tags = CollectHierarchicalTags(modInfo.Terms);
                        }

                        searchDocuments.Add(searchDoc);
                    }
                }

            }
            return searchDocuments;
        }
Example #41
0
        public void UpdatePlugg(Plugg p, PluggContent pc)
        {
            //For restore if something goes wrong
            Plugg oldP = GetPlugg(p.PluggId);
            IEnumerable<PluggContent> oldPCs = GetAllContentInPlugg(p.PluggId);

            rep.UpdatePlugg(p); //No repair necessary if this fails

            //For now, remove all PluggContent and recreate in all languages from pc. Fix this when we can deal with translations
            try
            {
                foreach (PluggContent pcDelete in oldPCs)
                {
                    rep.DeletePluggContent(pcDelete);
                }

                pc.PluggId = p.PluggId;
                if (pc.LatexText != null)
                {
                    LatexToMathMLConverter myConverter = new LatexToMathMLConverter(pc.LatexText);
                    myConverter.Convert();
                    pc.LatexTextInHtml = myConverter.HTMLOutput;
                }

                LocaleController lc = new LocaleController();
                var locales = lc.GetLocales(PortalID);
                foreach (var locale in locales)
                {
                    pc.CultureCode = locale.Key;
                    rep.CreatePluggContent(pc);
                }
            }
            catch (Exception)
            {
                //recreate old Plugg/PluggContent before rethrow
                var pcs = GetAllContentInPlugg(p.PluggId);
                foreach (PluggContent pcDelete in pcs)
                {
                    rep.DeletePluggContent(pcDelete);
                }
                rep.DeletePlugg(p);

                rep.CreatePlugg(oldP);
                foreach (PluggContent oldPC in oldPCs)
                    rep.CreatePluggContent(oldPC);
                throw;
            }
        }
Example #42
0
 protected void DisplayVersions()
 {
     try
     {
         using (SqlConnection connection = new SqlConnection(ConnString))
         {
             SqlCommand command = new SqlCommand();
             //Grab a different version if a different language
             LocaleController LangController = new LocaleController();
             string ThisLocale = System.Globalization.CultureInfo.CurrentUICulture.Name;
             connection.Open();
             command.CommandText = "SELECT H.[ItemID],H.[Version],H.[LastModifiedOnDate],H.[LastModifiedByUserID],U.[DisplayName] FROM [HtmlText] H inner join [Users] U on H.LastModifiedByUserID = U.UserID WHERE ModuleID = " + ModuleId + " and CONVERT(NVARCHAR(MAX), Summary) = N'" + ThisLocale + "' ORDER BY Version desc";
             command.Connection = connection;
             SqlDataAdapter sda = new SqlDataAdapter(command);
             DataSet ds = new DataSet();
             sda.Fill(ds);
             if (ds.Tables.Count > 0)
             {
                 if (ds.Tables[0].Rows.Count > 0)
                 {
                     dgVersions.DataSource = ds;
                     dgVersions.DataBind();
                     command.ExecuteNonQuery();
                     connection.Close();
                 }
                 else
                 {
                     dgVersions.Visible = false;
                     NoVersions.Visible = true;
                 }
             }
             else
             {
                 dgVersions.Visible = false;
                 NoVersions.Visible = true;
             }
         }
     }
     catch (Exception ex)
     {
         if (PortalSettings.UserInfo.IsSuperUser)
             txtAdminView.Text = ex.Message;
     }
 }
Example #43
0
    protected void Page_Load(object sender, System.EventArgs e)
    {
        //Populate the HTML
        try
        {
            litPreview.Text = Localization.GetString("NoPreview.Text", LocalResourceFile);
            using (SqlConnection connection = new SqlConnection(ConnString))
            {
                SqlCommand command = new SqlCommand();
                //Grab a different version if a different language
                LocaleController LangController = new LocaleController();
                string ThisLocale = System.Globalization.CultureInfo.CurrentUICulture.Name;

                //Get the last HTML Text
                command.CommandText = "SELECT [ItemID],[Content],[Summary] FROM [HtmlText] WHERE ModuleID = @ModuleID ORDER BY LastModifiedOnDate ";
                command.Parameters.AddWithValue("@ModuleID", ModuleId);
                command.Connection = connection;
                try
                {
                    command.Connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    bool LocaleNotFound = true;
                    if (reader.HasRows)
                    {
                        //Populate the field
                        while (reader.Read())
                        {
                            if (reader["Summary"].ToString().Trim() == ThisLocale.Trim())
                            {
                                LocaleNotFound = false;
                                txtAdminView.Text = HttpUtility.HtmlDecode(reader["Content"].ToString());
                            }
                        }
                        if (LocaleNotFound)
                        {
                           FirstEntry.Text = "True";
                        }
                    }
                    else
                    {
                        FirstEntry.Text = "True";
                    }
                    if (!Page.IsPostBack)
                    {
                        DisplayVersions();
                    }
                }
                finally
                {
                    command.Connection.Close();
                }
            }
        }
        catch (Exception ex)
        {
            if (PortalSettings.UserInfo.IsSuperUser)
                txtAdminView.Text = ex.Message;
        }
    }
Example #44
0
    protected void BtnSaveContent_Click(object sender, System.EventArgs e)
    {
        try
        {
            if (FirstEntry.Text == "True")
            {
                //Populate the HTML if first entry
                try
                {
                    using (SqlConnection connection = new SqlConnection(ConnString))
                    {
                        SqlCommand command = new SqlCommand();
                        //Grab a different version if a different language
                        LocaleController LangController = new LocaleController();
                        string ThisLocale = System.Globalization.CultureInfo.CurrentUICulture.Name;
                        command.CommandText = "insert into dbo.HtmlText ( ModuleID, Content, Summary, Version, StateID, IsPublished, CreatedByUserID, CreatedOnDate, LastModifiedByUserID, LastModifiedOnDate ) values ( " + ModuleId + ", '" + txtAdminView.Text + "', '" + ThisLocale + "', 1, 1, 1, " + UserId + ", getdate(), " + UserId + ", getdate() )";
                        command.Connection = connection;
                        try
                        {
                            command.Connection.Open();
                            command.ExecuteNonQuery();
                            txtAdminView.Text = "";
                        }
                        finally
                        {
                            command.Connection.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (PortalSettings.UserInfo.IsSuperUser)
                        txtAdminView.Text = ex.Message;
                }
            }
            else
            {
                int VersionNumber = 0;
                using (SqlConnection connection = new SqlConnection(ConnString))
                {
                    SqlCommand command = new SqlCommand();
                    //Grab a different version if a different language
                    LocaleController LangController = new LocaleController();
                    string ThisLocale = System.Globalization.CultureInfo.CurrentUICulture.Name;
                    //Get the last Version
                    command.CommandText = "select max(Version) from dbo.HtmlText where ModuleID = " + ModuleId + " and CONVERT(NVARCHAR(MAX), Summary) = N'" + ThisLocale + "'";
                    command.Connection = connection;
                    try
                    {
                        command.Connection.Open();
                        VersionNumber = Convert.ToInt32(command.ExecuteScalar());
                        if (VersionNumber >= 1)
                        {
                            VersionNumber = VersionNumber + 1;
                        }
                        else
                        {
                            VersionNumber = 1;
                        }
                    }
                    finally
                    {
                        command.Connection.Close();
                    }
                }

                using (SqlConnection connection = new SqlConnection(ConnString))
                {
                    SqlCommand command = new SqlCommand();
                    //Grab a different version if a different language
                    LocaleController LangController = new LocaleController();
                    string ThisLocale = System.Globalization.CultureInfo.CurrentUICulture.Name;
                    //Get the last HTML Text
                    command.CommandText = "insert into dbo.HtmlText ( ModuleID, Content, Summary, Version, StateID, IsPublished, CreatedByUserID, CreatedOnDate, LastModifiedByUserID, LastModifiedOnDate ) values ( " + ModuleId + ", '" + txtAdminView.Text + "', '" + ThisLocale + "', " + VersionNumber + ", 1, 1, " + UserId + ", getdate(), " + UserId + ", getdate() )";
                    command.Connection = connection;
                    try
                    {
                        command.Connection.Open();
                        command.ExecuteNonQuery();
                        txtAdminView.Text = "";
                    }
                    finally
                    {
                        command.Connection.Close();
                    }
                }

                using (SqlConnection connection = new SqlConnection(ConnString))
                {
                    string ThisLocale = System.Globalization.CultureInfo.CurrentUICulture.Name;
                    SqlCommand command = new SqlCommand();
                    command.CommandText = "delete HtmlText from HtmlText T1 inner join ( select ROW_NUMBER() OVER (order by [Version] desc) RowNum, [Version] from HtmlText where ModuleID = " + ModuleId + " AND CONVERT(NVARCHAR(MAX), Summary) = N'" + ThisLocale + "') T2 on T1.[Version] = T2.[Version] where T2.RowNum > 5 AND ModuleID =" + ModuleId;
                    command.Connection = connection;
                    try
                    {
                        command.Connection.Open();
                        command.ExecuteNonQuery();
                    }
                    finally
                    {
                        command.Connection.Close();
                    }
                }
            }
            Response.Redirect(PortalSettings.ActiveTab.FullUrl, true);
        }
        catch (Exception ex)
        {
            if (PortalSettings.UserInfo.IsSuperUser)
                txtAdminView.Text = ex.Message;
            Exceptions.LogException(ex);
        }
    }
Example #45
0
        public void SavePlugg(PluggContainer p)
        {
            try
            {
                bool isNew = p.ThePlugg.PluggId == 0;

                //Temporary - remove soon
                p.ThePlugg.Title = "Title no longer here";
                p.ThePlugg.CreatedByUserId = 1;
                p.ThePlugg.ModifiedByUserId = 1;

                if (isNew)
                    rep.CreatePlugg(p.ThePlugg);
                else
                    rep.UpdatePlugg(p.ThePlugg);

                //Todo: Update..
                p.TheTitle.ItemId = p.ThePlugg.PluggId;
                p.TheTitle.ItemType = ETextItemType.PluggTitle;
                p.TheTitle.CcStatus = ECCStatus.InCreationLanguage;
                p.TheTitle.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                p.TheTitle.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                SavePhText(p.TheTitle);

                //Todo: Update..
                if (p.TheHtmlText != null)
                {
                    p.TheHtmlText.ItemId = p.ThePlugg.PluggId;
                    p.TheHtmlText.ItemType = ETextItemType.PluggHtml;
                    p.TheHtmlText.CcStatus = ECCStatus.InCreationLanguage;
                    p.TheHtmlText.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                    p.TheHtmlText.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                    SavePhText(p.TheHtmlText);
                }

                //Todo: Update..
                if (p.TheLatex != null)
                {
                    p.TheLatex.ItemId = p.ThePlugg.PluggId;
                    p.TheLatex.ItemType = ELatexType.Plugg;
                    p.TheLatex.CcStatus = ECCStatus.InCreationLanguage;
                    p.TheLatex.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                    p.TheLatex.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                    LatexToMathMLConverter myConverter = new LatexToMathMLConverter(p.TheLatex.Text);
                    myConverter.Convert();
                    p.TheLatex.HtmlText = myConverter.HTMLOutput;
                    SaveLatexText(p.TheLatex);
                }

                LocaleController lc = new LocaleController();
                var locales = lc.GetLocales(PortalID);
                foreach (var locale in locales)
                {
                    if (locale.Key != p.ThePlugg.CreatedInCultureCode)
                    {
                        GoogleTranslate(p.TheTitle, locale.Key);
                        if (p.TheHtmlText != null)
                            GoogleTranslate(p.TheHtmlText, locale.Key);
                        if (p.TheLatex != null)
                            GoogleTranslate(p.TheLatex, locale.Key);
                    }
                }

                //Create PluggPage
                DNNHelper d = new DNNHelper();
                string pageUrl = p.ThePlugg.PluggId.ToString();
                string pageName = pageUrl + ": " + p.TheTitle.Text;
                TabInfo newTab = d.AddPluggPage(pageName, pageUrl);
                p.ThePlugg.TabId = newTab.TabID;
                rep.UpdatePlugg(p.ThePlugg);
            }
            catch (Exception)
            {
                //Todo: Update
                DeletePlugg(p.ThePlugg);
                throw;
            }
        }
Example #46
0
 /// <summary>
 /// This method will save the LatexText in all Culture Codes
 /// It expects the text to be created in t.CultureCode
 /// It will call SaveLatexText(t)
 /// It then translates t into all languages and calls SaveLatexText on each text
 /// </summary>
 /// <param name="t"></param>
 public void SaveLatexTextInAllCc(PHLatex t)
 {
     t.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
     SaveLatexText(t);  //Save LatexText in created language
     LocaleController lc = new LocaleController();
     var locales = lc.GetLocales(PortalID);
     PHLatex translatedText;
     foreach (var locale in locales)
     {
         if (locale.Key != t.CultureCode)
         {
             translatedText = GetCurrentVersionLatexText(locale.Key, t.ItemId, t.ItemType);
             if (translatedText == null)
             {
                 translatedText = new PHLatex();
                 translatedText.CultureCode = locale.Key;
                 translatedText.ItemId = t.ItemId;
                 translatedText.ItemType = t.ItemType;
             }
             translatedText.Text = t.Text;
             translatedText.HtmlText = ""; // TranslateText(t.CultureCode.Substring(0, 2), locale.Key.Substring(0, 2), t.HtmlText);
             if (translatedText.CreatedByUserId == 0)
                 translatedText.CreatedByUserId = t.CreatedByUserId;
             translatedText.CultureCodeStatus = ECultureCodeStatus.NotTranslated;
             SaveLatexText(translatedText);
         }
     }
 }