private PageViewConfig GetPageViewConfig() { string asmdir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string exedir = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(asmdir)); string pageviewcfgfile = System.IO.Path.Combine(exedir, @"Config\PageViewConfig.xml"); if (!System.IO.File.Exists(pageviewcfgfile)) { return(null); } PageViewConfig config = ConfigSerializer <PageViewConfig> .ReadFile(pageviewcfgfile); return(config); }
public CoreUI() { InitializeComponent(); // silver vs2008 toolstrip look TanColorTable colorTable = new TanColorTable(); colorTable.UseSystemColors = true; toolStrip.Renderer = new ToolStripProfessionalRenderer(colorTable); // fill panels AccountsPanel = new AccountsPanel(this); AccountsPanel.Dock = DockStyle.Fill; splitLeftRight.Panel1.Controls.Add(AccountsPanel); LogPanel = new LogPanel(); LogPanel.Dock = DockStyle.Fill; splitTopBottom.Panel1.Controls.Add(LogPanel); mAttackPanel = new AttackPanel(this); mAttackPanel.Dock = DockStyle.Fill; tabs.TabPages[TABINDEX_ATTACK].Controls.Add(mAttackPanel); /* * MainPanel = new MainPanel(this); * MainPanel.Dock = DockStyle.Fill; * splitLeftRight2.Panel1.Controls.Add(MainPanel); */ mFiltersPanel = new FiltersPanel(this); mFiltersPanel.Dock = DockStyle.Fill; tabs.TabPages[TABINDEX_FILTERS].Controls.Add(mFiltersPanel); RoomsPanel = new RoomsPanel(this); RoomsPanel.Dock = DockStyle.Fill; tabs.TabPages[TABINDEX_ROOMS].Controls.Add(RoomsPanel); MobsPanel = new MobsPanel(this); MobsPanel.Dock = DockStyle.Fill; tabs.TabPages[TABINDEX_MOBS].Controls.Add(MobsPanel); RaidsPanel = new RaidsPanel(this); RaidsPanel.Dock = DockStyle.Fill; tabs.TabPages[TABINDEX_RAIDS].Controls.Add(RaidsPanel); SpawnsPanel = new SpawnsPanel(this); SpawnsPanel.Dock = DockStyle.Fill; tabs.TabPages[TABINDEX_SPAWNS].Controls.Add(SpawnsPanel); mTrainPanel = new TrainPanel(this); mTrainPanel.Dock = DockStyle.Fill; tabs.TabPages[TABINDEX_TRAINER].Controls.Add(mTrainPanel); mTalkPanel = new TalkPanel(this); mTalkPanel.Dock = DockStyle.Fill; tabs.TabPages[TABINDEX_TALK].Controls.Add(mTalkPanel); ChatPanel = new ChatUI(this); ChatPanel.Dock = DockStyle.Fill; tabs.TabPages[TABINDEX_CHAT].Controls.Add(ChatPanel); Instance = this; Settings = ConfigSerializer.ReadFile("config.xml"); this.Text = "Typpo's DC Tool - [www.typpo.us] - v" + Version.Id; foreach (string s in Server.NamesList) { ListViewGroup grp = new ListViewGroup(s); AccountsPanel.Groups.Add(grp); } }
static void Main(string[] args) { int nResult = 0; bool bOK = false; string executePath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string stmcRootPath = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(executePath)); string configPath = System.IO.Path.Combine(stmcRootPath, @"Config\SyncConfig.xml"); string pdfPath = System.IO.Path.Combine(stmcRootPath, @"Business\PDF"); string pdfImgPath = System.IO.Path.Combine(stmcRootPath, @"Business\PDFImages"); string tempPath = System.IO.Path.Combine(pdfPath, "TEMP"); SyncConfig config = null; // variables for Pdf2Image use string cfgpath = System.IO.Path.Combine(stmcRootPath, @"Config\Pdf2ImgConfig.xml"); g_log.TraceInfo("********"); g_log.TraceInfo("PdfSync is starting..."); for ( ; ;) { // 檢查configuration file存不存在,不存在則無法執行,Abort! if (!System.IO.File.Exists(configPath)) { g_log.TraceError("ERROR: SyncConfig.xml is not found in path: {0}", System.IO.Path.GetDirectoryName(configPath)); nResult = -1; break; } g_log.TraceInfo("SyncConfig.xml has been found in path: {0}", System.IO.Path.GetDirectoryName(configPath)); try { // 連接AP server,模擬取得文件版控,目前 dummy access。 config = ConfigSerializer <SyncConfig> .ReadFile(configPath); g_log.TraceInfo("SyncConfig deserialized succeed."); bOK = RestfulAPIRequest(ref config); if (!bOK) { nResult = -2; break; } // 存取成功後,更新最後存取時間回configuration file。 config.LastUpdated = DateTime.Now; ConfigSerializer <SyncConfig> .WriteFile(configPath, config); g_log.TraceInfo("SyncConfig.xml has been rewrite and saved."); } catch (Exception ex) { g_log.TraceFatal("FATAL: SyncConfig deserialized failed with error: {0}", ex.Message); g_log.TraceError("Error stack trace : {0}", ex.StackTrace); g_log.TraceInfo("PdfSync process will be end with error..."); nResult = -2; break; } // 建立TEMP目錄存放下載的文件 g_log.TraceInfo("Create temporary folder to store downloaded pdf files..."); if (!System.IO.Directory.Exists(tempPath)) { // 目錄不存在,創建一個目錄。 System.IO.Directory.CreateDirectory(tempPath); } else { // 目錄已存在,將目錄內所有檔案刪除。 Array.ForEach(System.IO.Directory.GetFiles(tempPath), System.IO.File.Delete); } // 先下載文件到TEMP目錄 g_log.TraceInfo("Start to download pdf files..."); string PreviousName = null; // Business\PDF\*.pdf string LocalName = null; System.IO.FileInfo fi; bool IsNeedUpdate = false; // 預設文件未更版 WebClient wc = new WebClient(); // 先以下列方式避開客戶不明原因無信任自家的憑證。 // 由於客戶為內網環境,所以尚可先用此方式處理,但仍需請客戶排解其根本問題。 if (PassCertificateValidation()) { ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; } foreach (var ps in config.SyncPdfs) { g_log.TraceInfo("Download PDF file with url: {0}", ps.Url); try { LocalName = System.IO.Path.Combine(tempPath, ps.LocalName); wc.DownloadFile(ps.Url, LocalName); fi = new System.IO.FileInfo(LocalName); if (fi.Length <= 0) { // 下載下來的文件,檔案是空檔即為無效的。後面流程就中止,維持上次的文件運作。 g_log.TraceError("Document ({0}) is empty.", LocalName); nResult = -3; break; } else { // 檢查下載的文件和上次的文件是否相同,如果已經有一份不相同了,全部都要更版。 PreviousName = System.IO.Path.Combine(pdfPath, ps.LocalName); if (!IsFileEqual(LocalName, PreviousName)) { g_log.TraceInfo("{0}...Different!", ps.LocalName); IsNeedUpdate = true; } else { g_log.TraceInfo("{0}...Same file. Ignore.", ps.LocalName); } } } catch (WebException e) { if (((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.NotFound) { // configuration裡設定的文件,缺一不可。後面流程中止,維持上次的文件運作。 g_log.TraceError("Document not found - {0}", ps.Url); nResult = -3; break; } } g_log.TraceInfo("PDF file saved to file: {0}", ps.LocalName); } if (nResult != 0) // error occurred, abort { break; } if (!IsNeedUpdate) // 所有文件未更版,無須後續Pdf2Image { g_log.TraceInfo("All PDFs unchanged, no need to update."); } else { g_log.TraceInfo("Backup current pdf files..."); // 建立或清空BAK目錄,以存放目前的PDF文件 string bakPath = System.IO.Path.Combine(pdfPath, "BAK"); if (!System.IO.Directory.Exists(bakPath)) { System.IO.Directory.CreateDirectory(bakPath); } else { Array.ForEach(System.IO.Directory.GetFiles(bakPath), System.IO.File.Delete); } // 將PDF目錄下的所有文件複製到BAK目錄保留。 Array.ForEach(System.IO.Directory.GetFiles(pdfPath), (filepath) => { string fileName = System.IO.Path.GetFileName(filepath); System.IO.File.Copy(filepath, System.IO.Path.Combine(bakPath, fileName)); g_log.TraceInfo("PDF file: {0} is backup.", fileName); }); Array.ForEach(System.IO.Directory.GetFiles(pdfPath), System.IO.File.Delete); // 將TEMP目錄下新下載的文件複製到PDF目錄。 Array.ForEach(System.IO.Directory.GetFiles(tempPath), (filepath) => { string fileName = System.IO.Path.GetFileName(filepath); System.IO.File.Copy(filepath, System.IO.Path.Combine(pdfPath, fileName)); g_log.TraceInfo("PDF file: {0} is updated.", fileName); }); // 清空PDFImages目錄。 // 如此一來,令後面流程依pdf產生圖檔。 g_log.TraceInfo("Delete all files in PDFImages directory..."); Array.ForEach(System.IO.Directory.GetFiles(pdfImgPath), System.IO.File.Delete); } // // POC string pathToXmlFile = System.IO.Path.Combine(pdfImgPath, "PdfImageFiles.xml"); bool regenImages = false; if (!System.IO.File.Exists(pathToXmlFile)) { g_log.TraceWarn("Miss {0}", pathToXmlFile); regenImages = true; } else { g_log.TraceInfo("PdfImageFiles.xml is existed and begin to check images existence..."); PdfImageFiles pdfImageList = ConfigSerializer <PdfImageFiles> .ReadFile(pathToXmlFile); foreach (var p in pdfImageList.ImagePageInfos) { if (!System.IO.File.Exists(p.FilePath)) { g_log.TraceWarn("Miss {0}", p.FilePath); regenImages = true; break; } } } if (!regenImages) { g_log.TraceInfo("All images is ready, no need to regenerate."); break; } g_log.TraceInfo("Clean '{0}' directory...", pdfImgPath); Array.ForEach(System.IO.Directory.GetFiles(pdfImgPath), System.IO.File.Delete); g_log.TraceInfo("Start to convert PDF to images..."); Pdf2ImageConverter conv = new Pdf2ImageConverter(); List <string> totalImgFiles = new List <string>(); conv.Settings.Load(cfgpath); g_log.TraceInfo("Extension: {0}", conv.Settings.Extension); //string testPDF = System.IO.Path.Combine(pdfPath, "2.pdf"); //List<string> imgFiles = conv.ConvertPdfPageToImage(testPDF, "", pdfImgPath); Array.ForEach(System.IO.Directory.GetFiles(pdfPath), (filepath) => { g_log.TraceInfo("Converting {0} ...", filepath); List <string> imgFiles = conv.ConvertPdfPageToImage(filepath, "", pdfImgPath); g_log.TraceInfo("PDF file: {0} converted. ({1}-page)", filepath, imgFiles.Count); if (imgFiles.Count > 0) { totalImgFiles.AddRange(imgFiles); } }); conv.Dispose(); PdfImageFiles pdfImageFiles = new PdfImageFiles(); foreach (string path in totalImgFiles) { pdfImageFiles.ImagePageInfos.Add(new ImagePageInfo() { FilePath = path }); } ConfigSerializer <PdfImageFiles> .WriteFile(System.IO.Path.Combine(pdfImgPath, "PdfImageFiles.xml"), pdfImageFiles); g_log.TraceInfo("Completed to convert PDF to images."); break; // normal termination of flow } // 移除TEMP目錄 if (System.IO.Directory.Exists(tempPath)) { Array.ForEach(System.IO.Directory.GetFiles(tempPath), System.IO.File.Delete); System.IO.Directory.Delete(tempPath); } if (nResult == 0) // no error occurred { g_log.TraceInfo("PdfSync process finished and exit."); } else { g_log.TraceError("ERROR: PdfSync process abort with error: {0}...", nResult); } }