/// <summary> /// 獲取指定文件夾下所有文件的文件名列表 /// </summary> /// <returns>文件名列表</returns> public List <string> GetWorkPageFiles() { var htmlWork = ConfigurationUtil.GetKeyValue("HtmlWork"); // 如果目錄不存在 if (!Directory.Exists(htmlWork)) { return(new List <string>()); } List <string> fileNames = new List <string>(); string filter = DateTime.Now.ToString("yyyyMMdd", CultureInfo.CurrentCulture); DirectoryInfo root = new DirectoryInfo(htmlWork); // 獲取文件列表 root.GetFiles().ToList().ForEach(d => { if (d.Name.IndexOf(filter, StringComparison.CurrentCultureIgnoreCase) >= 0) { fileNames.Add(d.Name); } }); if (fileNames.Count > 0) { fileNames.Insert(0, string.Empty); } return(fileNames); }
/// <summary> /// /// </summary> /// <param name="config"></param> public static void Register(HttpConfiguration config) { var allowedMethods = ConfigurationUtil.GetKeyValue("cors:allowedMethods"); var allowedOrigin = ConfigurationUtil.GetKeyValue("cors:allowedOrigin"); var allowedHeaders = ConfigurationUtil.GetKeyValue("cors:allowedHeaders"); // 跨域設置 var geduCors = new EnableCorsAttribute(allowedOrigin, allowedHeaders, allowedMethods) { SupportsCredentials = true }; config.EnableCors(geduCors); // 路由設置 config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }
/// <summary> /// 執行命令行 /// </summary> /// <param name="getArguments">參數</param> /// <param name="waitForExit">等待時間後關閉</param> private static void CallCommondProcess(Func <string> getArguments, int waitForExit = 2000) { Process cmdProcess = new Process(); // 命令 cmdProcess.StartInfo.FileName = ConfigurationUtil.GetKeyValue("Preview"); // 顯示DOC界面 cmdProcess.StartInfo.CreateNoWindow = true; // 啟動Exited事件 cmdProcess.EnableRaisingEvents = true; // 註冊進程結束事件 //cmdProcess.Exited += new EventHandler((s, v) => //{ // 註冊進程結束事件 //Environment.Exit(0); //}); // 參數設定 cmdProcess.StartInfo.Arguments = getArguments(); cmdProcess.Start(); cmdProcess.WaitForExit(waitForExit); }
/// <summary> /// 出題按鍵點擊事件 /// </summary> /// <param name="sender">事件發生者</param> /// <param name="e">事件處理</param> private void SureClick(object sender, EventArgs e) { TopMost = true; // 打開歷屆題型 if (cmbWorkPages.SelectedIndex > 0) { // 使用IE打開已作成的靜態頁面 CallCommondProcess(() => { return("\"" + Path.GetFullPath(ConfigurationUtil.GetKeyValue("HtmlWork") + cmbWorkPages.SelectedValue.ToString()) + "\""); }); Environment.Exit(0); return; } // 選題情況 if (!Process.ChooseCheck()) { MessageBox.Show(this, MessageUtil.GetMessage(() => MsgResources.I0009A)); return; } LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0002A)); // 出題按鍵點擊事件 FileInfo exerciseFile = Process.Compile(); // 使用IE打開已作成的靜態頁面 CallCommondProcess(() => { if (ConfigurationUtil.GetUseIIS()) { return("\"" + ConfigurationUtil.GetIISUrl() + exerciseFile.Name + "\""); } return("\"" + Path.GetFullPath(exerciseFile.FullName) + "\""); }, 3000); Environment.Exit(0); }
/// <summary> /// /// </summary> /// <returns></returns> public FileInfo Compile() { // HTML模板存放路徑 string sourceFileName = System.Web.Hosting.HostingEnvironment.MapPath(ConfigurationUtil.HtmlTemplatePath); // 靜態頁面作成后存放的路徑(文件名:日期時間形式) string destFileName = System.Web.Hosting.HostingEnvironment.MapPath(ConfigurationUtil.GetKeyValue("HtmlWork") + string.Format(CultureInfo.CurrentCulture, "{0}.html", DateTime.Now.ToString("yyyyMMddHHmmssfff", CultureInfo.CurrentCulture))); // 文件移動 File.Copy(sourceFileName, destFileName); StringBuilder htmlTemplate = new StringBuilder(); // 讀取HTML模板內容 htmlTemplate.Append(File.ReadAllText(destFileName, Encoding.UTF8)); // 取得HTML和JS的替換內容 GetHtmlReplaceContentMaps(); // 遍歷已選擇的題型 foreach (KeyValuePair <string, ConcurrentDictionary <SubstituteType, string> > d in _htmlMaps) { LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0001A, d.Key)); // 替換HTML模板中的預留內容(HTML、JS注入操作) foreach (KeyValuePair <SubstituteType, string> m in d.Value) { LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0002A, m.Key)); switch (m.Key) { // 樣式庫引用注入 case SubstituteType.Stylesheet: Stylesheet.AppendLine(m.Value); break; // 腳本引用注入 case SubstituteType.Script: Script.AppendLine(m.Value); break; // 打印前設置事件注入 case SubstituteType.PrintSettingEvent: PrintSettingEvent.AppendLine(m.Value); break; // 打印后設置事件注入 case SubstituteType.PrintAfterSettingEvent: PrintAfterSettingEvent.AppendLine(m.Value); break; // 準備事件注入 case SubstituteType.ReadyEvent: ReadyEvent.AppendLine(m.Value); break; // 交卷事件注入 case SubstituteType.TheirPapersEvent: TictheirPapersEvent.AppendLine(m.Value); break; // 答題訂正事件注入 case SubstituteType.MakeCorrectionsEvent: MakeCorrectionsEvent.AppendLine(m.Value); break; // 題型正文注入 case SubstituteType.Content: Content.AppendLine(m.Value); break; default: break; } } } // 樣式庫注入 htmlTemplate.Replace("<!--STYLESHEET-->", Stylesheet.ToString()); // 腳本注入 htmlTemplate.Replace("<!--SCRIPT-->", Script.ToString()); // 打印前設置事件注入 htmlTemplate.Replace("// PRINTSETTING", PrintSettingEvent.ToString()); // 打印后設置事件注入 htmlTemplate.Replace("// PRINTAFTERSETTING", PrintAfterSettingEvent.ToString()); // 題型準備事件注入 htmlTemplate.Replace("// READY", ReadyEvent.ToString()); // 題型訂正事件注入 htmlTemplate.Replace("// MAKECORRECTIONS", MakeCorrectionsEvent.ToString()); // 題型交卷事件注入 htmlTemplate.Replace("// TICTHEIRPAPERS", TictheirPapersEvent.ToString()); // 題型正文注入 htmlTemplate.Replace("<!--CONTENT-->", Content.Insert(0, IsEncryptScript).AppendLine().ToString()); LogUtil.LogDebug(MessageUtil.GetMessage(() => MsgResources.I0003L)); // 保存至靜態頁面 File.WriteAllText(destFileName, htmlTemplate.ToString(), Encoding.UTF8); return(new FileInfo(destFileName)); }
/// <summary> /// /// </summary> public WaitResponseAttribute() { _waitTime = Convert.ToInt32(ConfigurationUtil.GetKeyValue("responsewaittime")); }