/// <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>
        /// 彈出 HighLightCode 的表單
        /// Show HighLightCode Form
        /// </summary>
        public void ShowCodeForm(IRibbonControl control)
        {
            string outFileName = Guid.NewGuid().ToString();

            try
            {
                ProcessHelper processHelper = new ProcessHelper("NoteHighLightForm.exe",new string[]{control.Tag, outFileName});
                processHelper.IsWaitForInputIdle = true;
                processHelper.ProcessStart();
            }
            catch (Exception ex)
            {
                MessageBox.Show("執行NoteHighLightForm.exe發生錯誤,錯誤訊息為:" + ex.Message);
                return;
            }

            string fileName = Path.Combine(Path.GetTempPath(), outFileName + ".html");

            if (File.Exists(fileName))
                InsertHighLightCodeToCurrentSide(fileName);
        }