/// <summary> 呼叫highlight.exe 產生高亮後的html </summary>
        /// <returns>回傳 Html 所在的路徑</returns>
        public string GenerateHighLightCode(HighLightParameter parameter)
        {
            var result = ConfigurationManager.GetSection("HighLightSection");
            _section = result as HighLightSection;

            InitParameter(parameter);

            string tempPath = Path.GetTempPath();
            string inputFileName = Path.Combine(tempPath, FileName);
            string outputFileName = Path.Combine(tempPath, FileName) + ".html";

            //System.Diagnostics.Debug.WriteLine(inputFileName);
            //System.Diagnostics.Debug.WriteLine(Content);
            //System.Diagnostics.Debug.WriteLine(_section);
            //System.Diagnostics.Debug.WriteLine(_section.FolderName);
            //System.Diagnostics.Debug.WriteLine(ProcessHelper.GetAssemblyLocationDirectory);
            File.WriteAllText(inputFileName, Content, Encoding.UTF8);
            
            var workingDirectory = Path.Combine(ProcessHelper.GetAssemblyLocationDirectory, _section.FolderName);

            ProcessHelper helper = new ProcessHelper(workingDirectory, _section.ProcessName);
            helper.Arguments = GenerateArguments(inputFileName, outputFileName);
            helper.IsWaitForInputIdle = false;
            helper.WindowStyle = ProcessWindowStyle.Hidden;

            helper.ProcessStart();

            if (!File.Exists(outputFileName))
                throw new FileNotFoundException("找不到outputFile");

            File.Delete(inputFileName);
            return outputFileName;
        }
Esempio n. 2
0
 /// <summary> 初始化參數 </summary>
 private void InitParameter(HighLightParameter parameter)
 {
     Content        = parameter.Content;
     CodeType       = parameter.CodeType;
     HighLightStyle = parameter.HighLightStyle;
     ShowLineNumber = parameter.ShowLineNumber;
     FileName       = parameter.FileName;
 }
 /// <summary> 初始化參數 </summary>
 private void InitParameter(HighLightParameter parameter)
 {
     Content = parameter.Content;
     CodeType = parameter.CodeType;
     HighLightStyle = parameter.HighLightStyle;
     ShowLineNumber = parameter.ShowLineNumber;
     FileName = parameter.FileName;
 }
Esempio n. 4
0
        /// <summary> 呼叫highlight.exe 產生高亮後的html </summary>
        /// <returns>回傳 Html 所在的路徑</returns>
        public string GenerateHighLightCode(HighLightParameter parameter)
        {
            var result = ConfigurationManager.GetSection("HighLightSection");

            _section = result as HighLightSection;

            InitParameter(parameter);

            string tempPath       = Path.GetTempPath();
            string inputFileName  = Path.Combine(tempPath, FileName);
            string outputFileName = Path.Combine(tempPath, FileName) + ".html";

            //System.Diagnostics.Debug.WriteLine(inputFileName);
            //System.Diagnostics.Debug.WriteLine(Content);
            //System.Diagnostics.Debug.WriteLine(_section);
            //System.Diagnostics.Debug.WriteLine(_section.FolderName);
            //System.Diagnostics.Debug.WriteLine(ProcessHelper.GetAssemblyLocationDirectory);
            File.WriteAllText(inputFileName, Content, Encoding.UTF8);

            var workingDirectory = Path.Combine(ProcessHelper.GetAssemblyLocationDirectory, _section.FolderName);

            ProcessHelper helper = new ProcessHelper(workingDirectory, _section.ProcessName);

            helper.Arguments          = GenerateArguments(inputFileName, outputFileName);
            helper.IsWaitForInputIdle = false;
            helper.WindowStyle        = ProcessWindowStyle.Hidden;

            helper.ProcessStart();

            if (!File.Exists(outputFileName))
            {
                throw new FileNotFoundException("找不到outputFile");
            }

            File.Delete(inputFileName);
            return(outputFileName);
        }
Esempio n. 5
0
        /// <summary>
        /// Generate HighLight File
        /// </summary>
        private void btnCodeHighLight_Click(object sender, EventArgs e)
        {
            IGenerateHighLight generate = new GenerateHighLight();
            
            string outputFileName = String.Empty;

            HighLightParameter parameter = new HighLightParameter()
            {
                FileName = _fileName,
                Content = CodeContent,
                CodeType = _codeType,
                HighLightStyle = CodeStyle,
                ShowLineNumber = IsShowLineNumber
            };

            try
            {
                outputFileName = generate.GenerateHighLightCode(parameter);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                this.Dispose();
                this.Close();
                return;
            }

            if (IsClipboard && !String.IsNullOrEmpty(outputFileName))
                InsertToClipboard(outputFileName);

            SaveSetting();

            this.Dispose();
            this.Close();
        }