using System; using System.Text; using System.IO; using System.Collections.Generic; using ClearSlideLibrary.Dom; using ClearSlideLibrary.Animations; namespace ClearSlideLibrary.HtmlController { public class HtmlController { private readonly int _numberOfSlides; private readonly int _allSlidesCount; private readonly int _slideIndex; private readonly string _fileName; private readonly string _baseFileName; private readonly string _filePath; private readonly StringBuilder _htmlPart; private readonly PPTSlide _mSlide; private const string JS_DIR_NAME = "temp"; public int SlideWidth { get; set; } public int SlideHeight { get; set; } public HtmlController(string filepath, string filename, PPTSlide aSlide, int slideCounter, int slidesNumber) { _baseFileName = filename; try { if (filename.Length != 0) { if (slidesNumber != 1) { this._fileName = filename +"_" +slideCounter.ToString(); } else { this._fileName = filename; } } this._mSlide = aSlide; _numberOfSlides = 1; _allSlidesCount = slidesNumber; _slideIndex = slideCounter; this._filePath = filepath; this._htmlPart = new StringBuilder(); } catch (ArgumentNullException ex) { Console.WriteLine("The passed value for filename:" + ex.Message); return; } } public void GenerateHtml() { this.GenerateHeader(); this.GenerateBody(); this.WriteTofile(_htmlPart); } private void WriteTofile(StringBuilder content) { string htmlFilePath = this._filePath + "\\" + this._fileName; string outFileName = htmlFilePath + ".html"; FileStream fs = File.Create(outFileName, 1024); Byte[] htmlcontent = new UTF8Encoding(true).GetBytes(content.ToString()); fs.Write(htmlcontent, 0, htmlcontent.Length); fs.Close(); string outputDirWithFileNameAdded = Path.Combine(_filePath, _fileName); CopyJSFiles(_filePath, outputDirWithFileNameAdded); } private void CopyJSFiles(string destinationDirForHtmlFile, string newOutputDir) { string sourceDir = Path.Combine(destinationDirForHtmlFile, JS_DIR_NAME); string destDir = newOutputDir; DirectoryInfo src = new DirectoryInfo(sourceDir); DirectoryInfo dest = new DirectoryInfo(destDir); FileInfo[] files = src.GetFiles(); foreach (FileInfo file in files) { try { if (file.Exists) { file.CopyTo(Path.Combine(dest.FullName, file.Name)); } } catch (IOException iex) { Console.WriteLine(iex.Message); } } } private void GenerateHeader() { string numbers = DynamicHeaderJSPart(); AppendHeader(numbers); } private string DynamicHeaderJSPart() { if (_numberOfSlides == 1) { return "[0,1,1]"; } else { int count = 0; StringBuilder numbers = new StringBuilder(); numbers.Append("["); while (count <= _numberOfSlides - 1) { numbers.Append(count.ToString()); numbers.Append(","); count++; } numbers.Append(count); int length = numbers.ToString().Length; string outputString = numbers.ToString().Remove(length - 1, 1); return outputString + "]"; } } private void AppendHeader(string numbers) { string SC = ".SC {height: " + SlideHeight + "px; width: " + SlideWidth + "px; display: none;}"; string DC = ".DC1 {top: 0px; left: 0px; height: 100%; width: 100%; opacity: 1; }"; string DC0 = ".DC0 {top: 0px; left: 0px; height: 100%; width: 100%; opacity: 0;}"; _htmlPart.Append(""); _htmlPart.Append(""); _htmlPart.Append("" + this._fileName + ""); _htmlPart.Append(""); _htmlPart.Append(""); _htmlPart.Append(""); _htmlPart.Append(""); _htmlPart.Append(""); _htmlPart.Append(""); _htmlPart.Append(""); _htmlPart.Append(""); _htmlPart.Append(""); _htmlPart.Append(""); _htmlPart.Append(""); } private void GenerateBody() { _htmlPart.Append(""); AppendPlayer(); _htmlPart.Append("
"); DynamicBodyPart(); _htmlPart.Append(""); _htmlPart.Append("
"); _htmlPart.Append(""); _htmlPart.Append(""); } private void DynamicBodyPart() { if (_numberOfSlides != 0) { ////foreach (PPTSlide pptSlide in _mSlides) ////{ string dirpath = Path.Combine(_filePath, _fileName); HtmlSlide slide = new HtmlSlide(_mSlide.Id, "SC", this._fileName, dirpath, _mSlide.slideIndex) { ContainerShape = _mSlide.ContainerShape }; _htmlPart.Append(slide.DrawElement()); //} } } private void AppendPlayer() { _htmlPart.Append("
"); _htmlPart.Append("\"click"); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("00:00"); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
 
"); _htmlPart.Append("
"); String nextUrl = _slideIndex >= _allSlidesCount ? "'" + _fileName + ".html'" : "'" + _baseFileName + "_" + (_slideIndex + 1) + ".html?autoStart=true'"; String prevUrl = _slideIndex <= 1 ? "'" + _fileName + ".html'" : "'" + _baseFileName + "_" + (_slideIndex - 1) + ".html?autoStart=true'"; _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
/ 1
"); _htmlPart.Append(""); _htmlPart.Append("
"); _htmlPart.Append("
"); _htmlPart.Append("
"); } } }