private void WriteHTMLForDataForItem(VideoSectionItem item, StringBuilder sb, ContentFile file) { if (item.ChildrenItems != null && item.ChildrenItems.Count > 0) { sb.Append("<div class=\"expandCollapseDivWrapper\">"); sb.AppendFormat("<div wrapperId={0} class=\"expandCollapseDiv\">+</div>", item.Number); sb.AppendFormat("<div onclick=\"runVideo('{0}','{1}')\" class=\"chapterDivWithExpandCollapse\">", AppUtil.GetXmlUrlForItem(item,file.FileName),item.Number); sb.Append(AppUtil.FilterChapterName(item.Chapter)); sb.Append("</div>"); sb.AppendFormat("<div style=\"float:right;\">{0}</div>", GetMinuteSecond(item.Duration)); sb.Append("<div class=\"clearBoth\"></div>"); sb.Append("</div>"); sb.AppendFormat("<div childrenId={0} class=\"chapterDivWithoutExpandCollapse\">", item.Number); foreach (VideoSectionItem childItem in item.ChildrenItems) { WriteHTMLForDataForItem(childItem, sb, file); } sb.Append("</div>"); } else { sb.AppendFormat("<div onclick=\"runVideo('{0}','{1}')\" class=\"singleItem\">", AppUtil.GetXmlUrlForItem(item, file.FileName),item.Number); sb.Append(AppUtil.FilterChapterName(item.Chapter)); sb.AppendFormat("<div style=\"float:right;\">{0}</div>", GetMinuteSecond(item.Duration)); sb.Append("</div>"); } }
private void CreateItemNode(VideoSectionItem item) { _XmlWriter.WriteRaw(String.Format(@"<item> <title>{0}</title> <media:content url='{1}' type='{2}' start='{3}' /> <description>{4}</description> <link>{5}/</link> </item>", AppUtil.FilterChapterName(item.Chapter), GetVideoUrl(item.FileName) , item.FileType, GetStartPoint(item.StartTime) //, GetDurationInSeconds(item.Duration) , AppUtil.Encode(item.Description), item.Link)); }
private bool isChild(VideoSectionItem item, string hyphenForLevel) { if (item.Chapter.Trim().StartsWith(hyphenForLevel)) { string chapterNameWithoutHyphen = item.Chapter.Trim().Substring(hyphenForLevel.Length); if (!chapterNameWithoutHyphen.Trim().StartsWith("-")) { return true; } return false; } return false; }
private int getLevelForItem(VideoSectionItem item) { int level = 0; string chapterName = item.Chapter.Trim(); int i = 0; while (i < chapterName.Length) { if (chapterName[i] != '-') { break; } level++; i++; } return level; }
public void GenerateXmlfileForItem(VideoSectionItem videoSectionItem, int level, string upperLevelChapterName, string xmlDir) { ///TODO: Save Video File Information to the Database. }
private void WriteXml(string upperLevelChapterName, string rootFolderName, VideoSectionItem videoSectionItem, int level) { string xmlDir = Path.Combine(AppUtil.GetUploadFolderForXml(), rootFolderName); //GenerateXmlfileForItem(item, level, uppderLevelChapterName, dir); _StringWriter = new StringWriter(); _XmlWriter = new XmlTextWriter(_StringWriter); _XmlWriter.Formatting = Formatting.Indented; _XmlWriter.WriteRaw("<rss version='2.0' xmlns:media='http://search.yahoo.com/mrss/'>"); _XmlWriter.WriteRaw("<channel>"); ///TODO: For now title is hard coded. It should be replaced. _XmlWriter.WriteRaw("<title>Test playlist with differents video</title>"); CreateItemNode(videoSectionItem); _XmlWriter.WriteRaw("</channel>"); _XmlWriter.WriteRaw("</rss>"); _XmlWriter.Flush(); _StringWriter.Flush(); String xmlFileName = SaveXml(_StringWriter.ToString(), videoSectionItem, xmlDir); _XmlWriter.Close(); }
private String SaveXml(String xmlContent, VideoSectionItem item, string xmlDir) { //xmlDir = Path.Combine(xmlDir, Path.GetFileNameWithoutExtension((string)HttpContext.Current.Session["CURRENT_FILE"])); String fileName = string.Empty; Directory.CreateDirectory(xmlDir); try { fileName = String.Format("{0}.xml", AppUtil.GetFilteredDiskFileName(item.Chapter)); string xmlFileName = Path.Combine(xmlDir, AppUtil.GetFilteredDiskFileName(fileName)); File.AppendAllText(xmlFileName, xmlContent); } catch (Exception ex) { throw ex; } return fileName; }
private List<VideoSectionItem> ConvertToVideoSectionItemList(DataTable dataTable) { List<VideoSectionItem> videoSectionItems = new List<VideoSectionItem>(); foreach (DataRow dr in dataTable.Rows) { VideoSectionItem item = new VideoSectionItem(); item.Number = Convert.ToInt32(dr[AppConstants.ExcelColumns.NUMBER]); item.FileName = dr[AppConstants.ExcelColumns.FILE_NAME].ToString(); item.Chapter = dr[AppConstants.ExcelColumns.CHAPTER_NAME].ToString(); DateTime startTime = Convert.ToDateTime(dr[AppConstants.ExcelColumns.START_POINT]); item.StartTime = startTime.Second.ToString(); item.Duration = dr[AppConstants.ExcelColumns.DURATION].ToString(); item.ThumbNail = dr[AppConstants.ExcelColumns.THUMBNAIL].ToString(); item.FileType = dr[AppConstants.ExcelColumns.VIDEO_TYPE].ToString(); item.Description = dr[AppConstants.ExcelColumns.DESCRIPTION].ToString(); item.Link = dr[AppConstants.ExcelColumns.LINK].ToString(); videoSectionItems.Add(item); } return videoSectionItems; }
private void LoadChildrenForItem(VideoSectionItem item, int maxLevel, List<VideoSectionItem> itemList) { int itemLevel = getLevelForItem(item); if (itemLevel == maxLevel) { return; } else { item.ChildrenItems = PopulateSectionItemsForLevel(itemList, item); if (item.ChildrenItems != null) { for (int i = 0; i < item.ChildrenItems.Count; i++) { VideoSectionItem childItem = item.ChildrenItems[i]; LoadChildrenForItem(childItem, maxLevel, itemList); } } } }
private List<VideoSectionItem> PopulateSectionItemsForLevel(List<VideoSectionItem> videoSectionItems, VideoSectionItem currentItem) { int level = getLevelForItem(currentItem); int childLevel = level + 1; string hyphenForLevel = string.Empty; for (int i = 0; i < childLevel; i++) { hyphenForLevel += "-"; } List<VideoSectionItem> childItems = new List<VideoSectionItem>(); for (int j = 0; j < videoSectionItems.Count; j++) { VideoSectionItem item = videoSectionItems[j]; if (item.Number == currentItem.Number) { childItems = new List<VideoSectionItem>(); for (j = j + 1; j < videoSectionItems.Count; j++) { item = videoSectionItems[j]; int levelForItem = getLevelForItem(item); if (levelForItem == level) { currentItem.ChildrenItems = childItems; break; } if (isChild(item, hyphenForLevel)) { childItems.Add(item); } } } } return childItems; }
public static string GetXmlUrlForItem(VideoSectionItem item,string fileName) { string path = string.Format("{0}/{1}/{2}.xml", ConfigReader.XmlUrl, Path.GetFileNameWithoutExtension(fileName), GetFilteredDiskFileName(item.Chapter)); return path; }