protected void btnSave_Click(object sender, EventArgs e) { BaseHandler bh = new BaseHandler(); PHLatex t = bh.GetCurrentVersionLatexText(CultureCode, ItemId, ItemType); if (t == null) { t = new PHLatex(); t.CreatedByUserId = UserId; t.CultureCode = CultureCode; t.ItemId = ItemId; t.ItemType = ItemType; } t.ModifiedByUserId = UserId; if (Case == EControlCase.Edit) { t.Text = tbEnterLatex.Text; t.HtmlText = ""; bh.SaveLatexTextInAllCc(t); Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(TabId, "", "edit=0", AttachQS)); } else if (Case == EControlCase.Translate) { PHLatex translatedFrom = bh.GetCurrentVersionLatexText(CreatedInCultureCode, ItemId, ItemType); if (translatedFrom != null) { t.Text = translatedFrom.Text; t.HtmlText = System.Net.WebUtility.HtmlDecode(teTranslate.Text); t.CultureCodeStatus = ECultureCodeStatus.HumanTranslated; bh.SaveLatexText(t); Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(TabId, "", "translate=0", AttachQS)); } } }
public void DeleteLatexText(PHLatex p) { using (IDataContext db = DataContext.Instance()) { var rep = db.GetRepository <PHLatex>(); rep.Delete(p); } }
public void CreateLatexText(PHLatex p) { using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository<PHLatex>(); rep.Insert(p); } }
public void CreateLatexText(PHLatex p) { using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository <PHLatex>(); rep.Insert(p); } }
/// <summary> /// Must set Text, ItemId, ItemType, CultureCode, CultureCodeStatus and CreatedByUserId or it will not save anything /// If text is versioned, it creates a new version /// If text is not versioned, it creates new text or updates text depending on TextId. /// </summary> /// <param name="t"></param> public void SaveLatexText(PHLatex t) { if (t.Text == null || t.ItemId == 0 || t.ItemType == ELatexItemType.NotSet || t.CultureCode == null || t.CultureCodeStatus == ECultureCodeStatus.NotSet || t.CreatedByUserId == 0) { return; //Nothing to save } if (t.ModifiedByUserId == 0) { t.ModifiedByUserId = t.CreatedByUserId; } t.ModifiedOnDate = DateTime.Now; t.CurrentVersion = true; if (t.HtmlText == null || t.HtmlText == "") { LatexToMathMLConverter myConverter = new LatexToMathMLConverter(t.Text); myConverter.Convert(); t.HtmlText = myConverter.HTMLOutput; } bool isVersioned = (t.ItemType == ELatexItemType.PluggComponentLatex || t.ItemType == ELatexItemType.CourseLatexText); if (isVersioned) { var prevText = rep.GetCurrentVersionLatexText(t.CultureCode, t.ItemId, t.ItemType); if (prevText == null) { t.Version = 1; } else { t.Version = prevText.Version++; prevText.CurrentVersion = false; rep.UpdateLatexText(prevText); } t.CreatedOnDate = DateTime.Now; rep.CreateLatexText(t); } else { t.Version = 0; if (t.LatexId == 0) { t.CreatedOnDate = DateTime.Now; rep.CreateLatexText(t); } else { rep.UpdateLatexText(t); } } }
/// <summary> /// Will get the latest version of LatexText in language cultureCode for itemType/itemId /// If the text does not exist, it creates a LatexText where LatexId=0 /// </summary> /// <param name="cultureCode"></param> /// <param name="itemId"></param> /// <param name="itemType"></param> /// <returns></returns> public PHLatex GetCurrentVersionLatexText(string cultureCode, int itemId, ELatexItemType itemType) { PHLatex txt = rep.GetCurrentVersionLatexText(cultureCode, itemId, itemType); if (txt == null) { txt = new PHLatex(); txt.Text = "(No text)"; txt.HtmlText = "(No text)"; txt.CultureCode = cultureCode; txt.ItemId = itemId; txt.ItemType = itemType; } return(txt); }
public PHLatex GetCurrentVersionLatexText(string cultureCode, int itemId, ELatexItemType itemType) { IEnumerable <PHLatex> txt; PHLatex theText = null; using (IDataContext ctx = DataContext.Instance()) { var rep = ctx.GetRepository <PHLatex>(); txt = rep.Find("WHERE CultureCode = @0 AND ItemId = @1 AND ItemType = @2 AND CurrentVersion = 'True'", cultureCode, itemId, (int)itemType); } if (txt.Any()) { theText = txt.First(); //Can only be at most one. PetaPoco does not handle composite key } return(theText); }
/// <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); } } }
/// <summary> /// Must set Text, ItemId, ItemType, CultureCode, CultureCodeStatus and CreatedByUserId or it will not save anything /// If text is versioned, it creates a new version /// If text is not versioned, it creates new text or updates text depending on TextId. /// </summary> /// <param name="t"></param> public void SaveLatexText(PHLatex t) { if (t.Text == null || t.ItemId == 0 || t.ItemType == ELatexItemType.NotSet || t.CultureCode == null || t.CultureCodeStatus == ECultureCodeStatus.NotSet || t.CreatedByUserId == 0) return; //Nothing to save if (t.ModifiedByUserId == 0) t.ModifiedByUserId = t.CreatedByUserId; t.ModifiedOnDate = DateTime.Now; t.CurrentVersion = true; if (t.HtmlText==null || t.HtmlText == "") { LatexToMathMLConverter myConverter = new LatexToMathMLConverter(t.Text); myConverter.Convert(); t.HtmlText = myConverter.HTMLOutput; } bool isVersioned = (t.ItemType == ELatexItemType.PluggComponentLatex || t.ItemType == ELatexItemType.CourseLatexText); if (isVersioned) { var prevText = rep.GetCurrentVersionLatexText(t.CultureCode, t.ItemId, t.ItemType); if (prevText == null) { t.Version = 1; } else { t.Version = prevText.Version++; prevText.CurrentVersion = false; rep.UpdateLatexText(prevText); } t.CreatedOnDate = DateTime.Now; rep.CreateLatexText(t); } else { t.Version = 0; if (t.LatexId == 0) { t.CreatedOnDate = DateTime.Now; rep.CreateLatexText(t); } else rep.UpdateLatexText(t); } }
/// <summary> /// Will get the latest version of LatexText in language cultureCode for itemType/itemId /// If the text does not exist, it creates a LatexText where LatexId=0 /// </summary> /// <param name="cultureCode"></param> /// <param name="itemId"></param> /// <param name="itemType"></param> /// <returns></returns> public PHLatex GetCurrentVersionLatexText(string cultureCode, int itemId, ELatexItemType itemType) { PHLatex txt = rep.GetCurrentVersionLatexText(cultureCode, itemId, itemType); if (txt == null) { txt = new PHLatex(); txt.Text = "(No text)"; txt.HtmlText = "(No text)"; txt.CultureCode = cultureCode; txt.ItemId = itemId; txt.ItemType = itemType; } return txt; }
public string GetCreatedInCultureCode(PHLatex t) { if (t.ItemType == ELatexItemType.PluggComponentLatex) { PluggComponent pc = rep.GetPluggComponent(t.ItemId); Plugg p = rep.GetPlugg(pc.PluggId); return p.CreatedInCultureCode; } if (t.ItemType == ELatexItemType.CourseLatexText) { Course c = rep.GetCourse(t.ItemId); return c.CreatedInCultureCode; } return null; }
///<summary> /// Load TheLatexCourseText in the CultureCode language from DB. You must set CourseId and CultureCode to get TheHtmlCourseText ///</summary> public void LoadTheLatexCourseText() { if (TheCourse == null || TheCourse.CourseId == 0 || CultureCode == null) throw new Exception("Cannot load TheHtmlCourseText. Need CourseId and CultureCode"); BaseHandler bh = new BaseHandler(); TheLatexCourseText = bh.GetCurrentVersionLatexText(CultureCode, TheCourse.CourseId, ELatexItemType.CourseLatexText); }
private string CreateDivLat(PHLatex lat, string ltdivid, int IntCompOrder) { string LatHTMLstring = ""; if (lat == null) LatHTMLstring = "<div><div id=" + ltdivid + " class='Main'>" + "Component " + IntCompOrder + ": " + BtnLatexTxt + " "; else LatHTMLstring = "<div><div id=" + ltdivid + " class='Main'> " + "Component " + IntCompOrder + ": " + BtnLatexTxt + " " + lat.Text + ""; divTitle.Controls.Add(new LiteralControl(LatHTMLstring)); return LatHTMLstring; }
private void CallLatFun(int ltorderid, PluggComponent comp, PHLatex lat, string p) { hdnlabel.Value = Convert.ToString(comp.PluggComponentId); if (comp.ComponentType == EComponentType.Latex) { pnlRRT.Visible = true; pnllabel.Visible = false; pnlletex.Visible = false; richtextbox.Visible = false; pnlYoutube.Visible = false; richrichtext.Text = lat.Text; } pnlPluggCom.Visible = false; }
public void SavePlugg(PluggContainer p, List <object> cs) { if (p.ThePlugg.CreatedInCultureCode != null && p.CultureCode != p.ThePlugg.CreatedInCultureCode) { throw new Exception("Cannot use SavePlugg unless you are saving it in the creation language."); } p.ThePlugg.CreatedInCultureCode = p.CultureCode; try { bool isNew = p.ThePlugg.PluggId == 0; //Temporary - to avoid login - remove soon p.ThePlugg.CreatedByUserId = 1; p.ThePlugg.ModifiedByUserId = 1; //Save Plugg entity p.ThePlugg.ModifiedOnDate = DateTime.Now; if (isNew) { p.ThePlugg.CreatedOnDate = DateTime.Now; rep.CreatePlugg(p.ThePlugg); } else { rep.UpdatePlugg(p.ThePlugg); } //Save Title if (p.TheTitle == null || p.TheTitle.Text == null) { throw new Exception("Cannot Save Plugg. TheTitle cannot be null"); } if (p.TheTitle.TextId == 0) { p.TheTitle.ItemId = p.ThePlugg.PluggId; p.TheTitle.ItemType = ETextItemType.PluggTitle; p.TheTitle.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage; p.TheTitle.CreatedByUserId = p.ThePlugg.CreatedByUserId; p.TheTitle.ModifiedByUserId = p.ThePlugg.ModifiedByUserId; } SavePhTextInAllCc(p.TheTitle); //Save or Update if (p.TheDescription != null && p.TheDescription.Text != null) { if (p.TheDescription.TextId == 0) { p.TheDescription.ItemId = p.ThePlugg.PluggId; p.TheDescription.ItemType = ETextItemType.PluggDescription; p.TheDescription.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage; p.TheDescription.CreatedByUserId = p.ThePlugg.CreatedByUserId; p.TheDescription.ModifiedByUserId = p.ThePlugg.ModifiedByUserId; } SavePhTextInAllCc(p.TheDescription); } int cmpOrder = 1; PluggComponent pc = new PluggComponent(); pc.PluggId = p.ThePlugg.PluggId; foreach (object cmp in cs) { pc.ComponentOrder = cmpOrder; switch (cmp.GetType().Name) { case "PHText": PHText theText = (PHText)cmp; switch (theText.ItemType) { case ETextItemType.PluggComponentRichRichText: pc.ComponentType = EComponentType.RichRichText; break; case ETextItemType.PluggComponentRichText: pc.ComponentType = EComponentType.RichText; break; case ETextItemType.PluggComponentLabel: pc.ComponentType = EComponentType.Label; break; } rep.CreatePluggComponent(pc); theText.ItemId = pc.PluggComponentId; theText.CultureCode = p.ThePlugg.CreatedInCultureCode; theText.CreatedByUserId = p.ThePlugg.CreatedByUserId; SavePhTextInAllCc(theText); break; case "PHLatex": PHLatex theLatex = (PHLatex)cmp; pc.ComponentType = EComponentType.Latex; rep.CreatePluggComponent(pc); theLatex.ItemId = pc.PluggComponentId; theLatex.CultureCode = p.ThePlugg.CreatedInCultureCode; theLatex.CreatedByUserId = p.ThePlugg.CreatedByUserId; SaveLatexTextInAllCc(theLatex); break; case "YouTube": pc.ComponentType = EComponentType.YouTube; rep.CreatePluggComponent(pc); YouTube theVideo = (YouTube)cmp; theVideo.CreatedByUserId = p.ThePlugg.CreatedByUserId; theVideo.PluggComponentId = pc.PluggComponentId; SaveYouTube(theVideo); break; } cmpOrder++; } //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; } }
public void UpdateLatexText(PHLatex p) { using (IDataContext db = DataContext.Instance()) { var rep = db.GetRepository<PHLatex>(); rep.Update(p); } }
protected void btnSaveTitle_Click(object sender, EventArgs e) { BaseHandler bh = new BaseHandler(); PluggContainer pc = new PluggContainer(new Localization().CurrentCulture); pc.ThePlugg.CreatedByUserId = this.UserId; pc.ThePlugg.ModifiedByUserId = this.UserId; pc.ThePlugg.PluggId = 0; pc.ThePlugg.WhoCanEdit = (EWhoCanEdit)Enum.Parse(typeof(EWhoCanEdit), rdEditPlug.SelectedValue); pc.SetTitle(txtTitle.Text); pc.SetDescription(txtDescription.Text); List<object> cmpData = new List<object>(); foreach (string StrCmpData in hdcmpData.Value.Split(new string[] { "$#%#$%" }, StringSplitOptions.RemoveEmptyEntries)) { string[] straCmpData = StrCmpData.Split(new string[] { "$$$&$$$" }, StringSplitOptions.RemoveEmptyEntries); switch (straCmpData[0]) { case "RichRichText": PHText RichRichText = new PHText(); RichRichText.Text = straCmpData[1]; RichRichText.ItemType = ETextItemType.PluggComponentRichRichText; cmpData.Add(RichRichText); break; case "RichText": PHText RichText = new PHText(); RichText.Text = straCmpData[1]; RichText.ItemType = ETextItemType.PluggComponentRichText; cmpData.Add(RichText); break; case "Label": PHText Label = new PHText(); Label.Text = straCmpData[1]; Label.ItemType = ETextItemType.PluggComponentLabel; cmpData.Add(Label); break; case "Latex": PHLatex Latex = new PHLatex(straCmpData[1], new Localization().CurrentCulture,ELatexItemType.PluggComponentLatex); cmpData.Add(Latex); break; case "YouTube": Plugghest.Base2.YouTube objYouTube = new Plugghest.Base2.YouTube(); string[] strYoutubeval = straCmpData[1].Split(new string[] { "&&&$$&&&" }, StringSplitOptions.RemoveEmptyEntries); objYouTube.YouTubeAuthor = strYoutubeval[3]; objYouTube.YouTubeCode = strYoutubeval[2]; objYouTube.YouTubeComment = strYoutubeval[5]; objYouTube.YouTubeCreatedOn = Convert.ToDateTime(strYoutubeval[4]); objYouTube.YouTubeDuration = Convert.ToInt32(strYoutubeval[1]); objYouTube.YouTubeTitle = strYoutubeval[0]; cmpData.Add(objYouTube); break; } } bh.SavePlugg(pc, cmpData); }
///<summary> /// Creates a LatexCourseText Object (a PHLatex). /// Sets its Text to text, /// its CultureCode to the CultureCode of the CourseContainer, /// its ELatexItemType to CourseLatexText. /// its ItemId to TheCourse.CourseId /// To save it (itemId must be different from zero) use BaseHandler.SaveLatexText(PHLatex t) or SaveLatexTextInAllCc /// Note that BaseHandler.CreateCourse(CourseContainer c) will NOT create LatexCourseText ///</summary> public void SetTheLatexCourseText(string text) { TheLatexCourseText = new PHLatex(text, CultureCode, ELatexItemType.CourseLatexText); TheLatexCourseText.ItemId = TheCourse.CourseId; }
/// <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); } } }