public virtual void Export() { ContentTheme theme = new ContentTheme(); theme.Name = ctx.Post("Name"); theme.Description = strUtil.CutString(ctx.Post("Description"), 200); if (strUtil.IsNullOrEmpty(theme.Name)) { echoError("请填写主题名称"); return; } List <ContentSection> sectionList = sectionService.GetByApp(ctx.app.Id); // 1、获取app信息 ContentApp app = ctx.app.obj as ContentApp; XApp xapp = exportApp(app); xapp.SectionList = new List <XSection>(); // 2、循环导出section string[] rowList = app.RowList; // 循环行 for (int iRow = 1; iRow < (rowList.Length + 1); iRow++) { int columnCount = cvt.ToInt(rowList[iRow - 1]); if (columnCount <= 0) { continue; } // 循环列 for (int iColumn = 1; iColumn < (columnCount + 1); iColumn++) { List <ContentSection> sections = sectionService.GetByRowColumn(sectionList, iRow, iColumn); // 循环section for (int iSection = 1; iSection < sections.Count + 1; iSection++) { XSection xSection = getSection(sections[iSection - 1], iRow, iColumn, iSection); xapp.SectionList.Add(xSection); } } } // 处理 #sectionId 的css问题,==> 转化成 #portarContainer .row-iRow .col-iColumn .section-iSection processCssId(xapp, sectionList); // 3、保存为 json 格式 exportToDisk(xapp, theme); echoToParentPart(lang("opok")); }
protected override void initTheme() { if (ContentTheme.IdHasError(base.themeId)) { logger.Error("theme id error, id=" + base.themeId); return; } this.xapp = ContentTheme.GetByThemeId(base.themeId); if (this.xapp == null) { throw new Exception("没有有效的主题数据, themeId=" + base.themeId); } }
/// <summary> /// 将安装包保存到磁盘 /// </summary> /// <param name="xapp"></param> private void exportToDisk(XApp xapp, ContentTheme theme) { String jsonString = Json.ToString(xapp); String fileName = Guid.NewGuid().ToString() + ".config"; String savedPath = ContentTheme.GetFileAbsDir(); if (Directory.Exists(savedPath) == false) { Directory.CreateDirectory(savedPath); } file.Write(Path.Combine(savedPath, fileName), jsonString); theme.FileName = fileName; theme.insert(); }
protected override void initTheme() { if (base.themeId <= 0) { return; } ContentTheme x = cdb.findById <ContentTheme>(base.themeId); if (x == null) { return; } String jsonStr = file.Read(x.GetFileAbsPath()); xapp = Json.Deserialize <XApp>(jsonStr); if (xapp == null) { throw new Exception("没有有效的主题数据, name=" + x.Name + ", path=" + x.GetFileAbsPath()); } }
/// <summary> /// 将安装包保存到磁盘 /// </summary> /// <param name="xapp"></param> private void exportToDisk(XApp xapp, ContentTheme theme) { String jsonString = Json.ToString(xapp); theme.Insert(jsonString); }