public static design_time GetTemplateDesignTime(template_Type templ, out lm_scorm root) { root = null; //if (templ.ToString().IndexOf("passive") == 0) return null; string fn = string.Format("~/Framework/Templates/{0}.htm.aspx.lmdata", templ); root = LMDataReader.ReadVirtual(fn); return root.DesignTime; //if (!(root.Items[0] is design_time)) return null; //return (design_time)root.Items[0]; }
public override void finishTreeBeforeLocalize(lm_scorm root) { base.finishTree(root); LMLiteral lit = (LMLiteral)Item; if (lit == null || string.IsNullOrEmpty(lit.text)) return; //matice tvorici krizovku string txt = lit.text.Replace('\r', ' ').Trim(); string[] lines = txt.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); table = new table(); table.Items = new object[lines.Length]; for (int i = 0; i < lines.Length; i++) table.Items[i] = new row(); int max = 0; int count = 0; for (int i = 0; i < lines.Length; i++) { string str = lines[i].Trim(); if (string.IsNullOrEmpty(str)) throw new Exception(string.Format("Empty row not allowed {0}", ErrorId)); string[] cells = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (max == 0) max = cells.Length; else if (max != cells.Length) throw new Exception(string.Format("All rows have to have the same number of cells {0}", ErrorId)); row rw = (row)table.Items[i]; rw.Items = new object[max]; for (int j = 0; j < max; j++) rw.Items[j] = createCheckItem(cells[j], count++); } table.border = true; table.grid = tableGrid.thin; table.flow = flow_type.left; table.finishTreeBeforeLocalize(root); //table.padding = colPadding.right; }
public override void finishTreeBeforeLocalize(lm_scorm root) { base.finishTree(root); LMLiteral lit = (LMLiteral)Item; if (lit == null || string.IsNullOrEmpty(lit.text)) return; //matice tvorici krizovku string txt = lit.text.Replace('\r', ' '); string[] lines = txt.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); List<List<string>> data = new List<List<string>>(); int max = 0; string headerStr; int count = 0; for (int i = 0; i < lines.Length; i++) { string str = lines[i].Trim(); if (string.IsNullOrEmpty(str)) continue; List<string> line = new List<string>(); string[] cells = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); line.AddRange(cells); if (header(row_header, i, out headerStr) != null) line.Insert(0, headerStr); data.Add(line); max = Math.Max(max, line.Count); } //doplneni radku na stejnou delku for (int i = 0; i < data.Count; i++) if (data[i].Count < max) for (int j = data[i].Count; j < max; j++) data[i].Add("-"); //col_Header? if (col_header != crossWordHeader_Type.no) { List<string> line = new List<string>(); if (row_header != crossWordHeader_Type.no) line.Add("@"); for (int i = 0; i < (row_header != crossWordHeader_Type.no ? max - 1 : max); i++) line.Add(header(col_header, i, out headerStr)); data.Insert(0, line); } //vyplneni Lines = new cross_line[data.Count]; for (int i = 0; i < data.Count; i++) Lines[i] = new cross_line(this, data[i], ref count); }
public static void setActRoot(lm_scorm root) { EaUrlInfo.Instance.root = root; //HttpContext.Current.Items[actRootKey] = root; }
public bool TitleOK(lm_scorm root) { foreach (string tit in AllTitles(root.PageInfo.ProdInfo.Lang)) if (root.title == "$trans;" + tit) return true; return false; }
public override void finishTree(lm_scorm root) { base.finishTree(root); //maximalni delka classifications se stejnou group int max = 0; foreach (classification cl in LMScormObj.GetAll(root, delegate(object obj) { return (obj is classification) && ((classification)obj).group == group; })) max = Math.Max(cl.Items.Length, max); //prenes GapFills LMScormObj[] newGf = new LMScormObj[max + 1]; for (int i = 0; i < Items.Length; i++) newGf[i + 1] = Items[i]; for (int i = Items.Length; i < max; i++) { gap_fill gf = new gap_fill(); gf.isFake = true; gf.id = id + i.ToString(); newGf[i + 1] = gf; } //prvni radek tabulky: if (htmlTitleObj != null) newGf[0] = htmlTitleObj; else { html ht = new html(); newGf[0] = ht; ht.localItems = localtitle; } table = new table(); table.Items = newGf; table.border = true; table.col_header = true; table.grid = tableGrid.thin; table.finishTreeBeforeLocalize(root); }
public override void finishTree(lm_scorm root) { base.finishTree(root); doFinishTree(localItems); }
public override void finishTreeBeforeLocalize(lm_scorm root) { base.finishTreeBeforeLocalize(root); isHtml = Items != null && Items.Length > 0 && Items[0] is tr; if (!isHtml) noHtmlFinishTree(root); if (row_header) //nastaveni isTh priznaku k prvnim celum foreach (tr row in Items) ((td)row.Items[0]).isTh = true; if (col != null || row_header) { colGroup = new control("colgroup"); if (col == null) colGroup.Items = new object[] { new col() }; else colGroup.Items = col; col = null; if (row_header) { col firstCl = (col)colGroup.Items[0]; firstCl.hlite = false; firstCl.isHeader = true; } } if (col_header && Items.Length > 0) { thead = new control("thead"); thead.Items = new object[1] { Items[0] }; tr row = (tr)Items[0]; row.hlite = false; row.isHeader = true; if (Items.Length == 1) Items = null; else { object[] newTr = new object[Items.Length - 1]; Array.Copy(Items, 1, newTr, 0, newTr.Length); Items = newTr; } } if (Items != null) { tbody = new control("tbody"); tbody.Items = Items; Items = null; } }
public override void finishTree(lm_scorm root) { base.finishTree(root); if (Items == null || Items.Length == 0) return; if (type == check_itemType.no) type = check_itemType.checkBox; int cnt = 0; _items = new selection_item[Items.Length]; for (int i = 0; i < _items.Length; i++) { check_item chi = Items[i]; _items[i] = new selection_item(chi); chi.type = type; if (type == check_itemType.radioButton && chi.correct) cnt++; } if (type == check_itemType.radioButton && cnt != 1) throw new Exception(string.Format("Just one selection.check_item with correct=true allowed {0}", ErrorId)); }
public static string pageTitle(lm_scorm root, SiteMapNode nd) { if (root != null && root.SiteNode != null) nd = root.SiteNode; if (nd != null && !string.IsNullOrEmpty(nd.Title)) return nd.Title; if (root != null) return string.Format("[{0}].[{1}]", root.PageInfo.SpaceId, root.PageInfo.GlobalId); return "System Page"; }
public override void finishTree(lm_scorm root) { base.finishTree(root); foreach (design_time dsgn in LMScormObj.GetAll(this, delegate(object o) { return o is design_time; })) { DesignTime = dsgn; break; } }
/*public static bool dumpResx(TextWriter wr, List<string> keys, List<string> values) { if (keys.Count <= 0) return false; for (int i = 0; i < keys.Count; i++) wr.AddResource(keys[i], values[i]); return true; }*/ /// <summary> /// Vytvoreni ResX z LMData. /// </summary> public static bool LMData2ResX(lm_scorm root, processStringsEvent onProcessString) { List<string> keys = new List<string>(); List<string> values = new List<string>(); TranslateInfo buf = new TranslateInfo(); foreach (TranslateInfo info in toTranslate(root, buf)) switch (info.Typ) { case LocalizeType.string2string: string valStr = (string)info.Value; if (string.IsNullOrEmpty(valStr) || !valStr.StartsWith(localizeStringPrefix)) continue; keys.Add(ResxFilesManager.resxId(info.Obj.varName, info.Field.Name.Substring(localizePrefix.Length))); //string.Format("Ui{0}_{1}", info.Obj.UniqueId, info.Field.Name.Substring(localizePrefix.Length))); values.Add(valStr.Substring(localizeStringPrefix.Length)); break; case LocalizeType.items2string: case LocalizeType.items2items: object[] objs = (object[])info.Value; foreach (LMScormObj item in objs) if (item is trans) { string txt; if (!tryTransText((trans)item, out txt)) continue; keys.Add(ResxFilesManager.resxId(item.varName, null)); values.Add(txt); } break; } return onProcessString(keys, values); //return createResx(fileName, keys, values); }
/// <summary> /// Pro jeden LMData objekt (soubor) vraci seznam properties k lokalizaci /// </summary> static IEnumerable<TranslateInfo> toTranslate(lm_scorm root, TranslateInfo buf) { foreach (LMScormObj obj in LMScormObj.GetAll(root)) { foreach (FieldInfo fi in obj.GetType().GetFields()) { object[] attrs = fi.GetCustomAttributes(typeof(LMScormLibDOM.LocalizedProperty), true); if (attrs == null || attrs.Length == 0) continue; LocalizedProperty attr = (LocalizedProperty)attrs[0]; if (!fi.Name.StartsWith(localizePrefix)) throw new Exception(); string nm = fi.Name.Substring(localizePrefix.Length); PropertyInfo prop = obj.GetType().GetProperty(nm); if (prop == null) if (attr.canMiss) continue; else throw new Exception(); object val = prop.GetValue(obj, null); if (val == null) continue; buf.Fill(attr.Type, obj, fi, val); yield return buf; } } }
/// <summary> /// lokalizace objektu (LMData souboru) /// </summary> public static void Localize(lm_scorm root) { if (HttpContext.Current == null) return; adjustThreadCulture(); StringBuilder buf = new StringBuilder(); ResxFilesManager resx = new ResxFilesManager(root.PageInfo.FileName); if (resx == null) return; object[] objs; foreach (TranslateInfo info in toTranslate(root, new TranslateInfo())) switch (info.Typ) { case LocalizeType.string2string: //Lokalizovatelna String property, vysledkem lokalizace je lokalizovatelny LMLiteral string valStr = (string)info.Value; if (string.IsNullOrEmpty(valStr)) break; if (!valStr.StartsWith(localizeStringPrefix)) info.setValue(createLiteral(valStr)); else info.setValue(resx.propertyTolocalizedLiteral(info, valStr.Substring(localizeStringPrefix.Length))); break; case LocalizeType.items2string: //HTML: vysledkem lokalizace je jeden lokalizovatelny LMLiteral objs = (object[])info.Value; if (objs.Length == 0) break; if (objs.Length == 1 && objs[0] is LMLiteral) info.setValue(objs[0]); else { bool first = true; foreach (object res in localizeObjectList(objs, buf, resx)) { if (!first || !(res is LMLiteral)) throw new Exception(); first = true; info.setValue(res); } } break; case LocalizeType.items2items: //HTML a LMScormObj: vysledkem lokalizace je seznam lokalizovatelnych LMLiteral a LMScormObj objs = (object[])info.Value; if (objs.Length == 0) break; bool noLocalize = true; foreach (LMScormObj item in objs) if (item is trans || item is img) { noLocalize = false; break; } if (noLocalize) info.setValue(objs); else { List<LMScormObj> items = new List<LMScormObj>(); foreach (LMScormObj res in localizeObjectList(objs, buf, resx)) items.Add(res); LMScormObj[] resObjs = new LMScormObj[items.Count]; items.CopyTo(resObjs); info.setValue(resObjs); } break; } }
protected override void CreateChildControls() { Data = lm_scorm.getActRoot(); Ctrl.ExpandChildControls(this, this, Data); }
public override void finishTreeBeforeLocalize(lm_scorm root) { if (correct != null) correct = LMScormLib.OtherLib.NormalizeString(correct.Trim()); if (init_value != null) init_value = LMScormLib.OtherLib.NormalizeString(init_value.Trim()); }
void noHtmlFinishTree(lm_scorm root) { if (Items == null || Items.Length == 0) return; //kontrola: kdyz jedna rowStart, tak vsechny rowStart: int rowCount = 0; foreach (LMScormObj obj in Items) if (obj is row) rowCount++; if (rowCount > 0 && rowCount != Items.Length) throw new Exception(string.Format("All rows or none rows expected in table {0}", ErrorId)); //kontrola: kdyz rowStart, tak stejny pocet prvku if (rowCount > 0) { int cnt = -1; foreach (row rw in Items) if (cnt == -1) cnt = rw.Items == null ? 0 : rw.Items.Length; else if (cnt != (rw.Items == null ? 0 : rw.Items.Length)) throw new Exception(string.Format("Number of row child element must be equal in table {0}", ErrorId)); } bool addCol = start_with != tableStart_with.no; //pridani extra sloupce //pridani prvniho colStart: if (addCol && col != null) { col[] oldCol = col; col = new col[oldCol.Length + 1]; Array.Copy(oldCol, 0, col, 1, oldCol.Length); col[0] = new col(); } //pridani rows a dummy cell if (rowCount == 0) { object[] oldItems = Items; Items = new object[oldItems.Length]; for (int i = 0; i < oldItems.Length; i++) { tr rw = new tr(); Items[i] = rw; td cl = new td(); cl.Items = new object[] { oldItems[i] }; if (addCol) { td addCl = new td(); addCl.setCellContent(i, start_with, rw, this); rw.items = new object[] { addCl, cl }; } else rw.items = new object[] { cl }; } } else //pridani cells for (int rwi = 0; rwi < Items.Length; rwi++) { //zamena ROW by TR row oldRw = (row)Items[rwi]; tr rw = rowToTr(oldRw); Items[rwi] = rw; object[] oldItems = oldRw.Items; rw.items = new object[addCol ? oldItems.Length + 1 : oldItems.Length]; for (int i = 0; i < rw.Items.Length; i++) { td cl = new td(); rw.Items[i] = cl; if (addCol && i == 0) cl.setCellContent(rwi, start_with, rw, this); else { cl.Items = new object[] { oldItems[addCol ? i - 1 : i] }; } } } //dosazeni myCol do celu: if (col != null) foreach (tr rw in Items) { for (int i = 0; i < col.Length; i++) { if (rw.Items.Length <= i) continue; ((td)rw.Items[i]).myCol = col[i]; } } }