private string ResolvePowerpoint(FileSystemInfo file) { //"if success -> return "true", else return error message string var filePath = file.FullName; var objPpt = new PowerPointHandler(filePath); try { objPpt.PptMain(filePath); } catch (Exception e) { return(e.Message); } finally { Common.WriteSglText(filePath); } return("true"); throw new NotImplementedException(); }
private void ThreadLaunch(Timeline timeline, TimelineHandler handler) { try { _log.Trace($"Attempting new thread for: {handler.HandlerType}"); Thread t = null; ThreadJob threadJob = new ThreadJob { Id = Guid.NewGuid().ToString(), Handler = handler }; switch (handler.HandlerType) { case HandlerType.NpcSystem: NpcSystem npc = new NpcSystem(handler); break; case HandlerType.Command: t = new Thread(() => { Cmd o = new Cmd(handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); threadJob.ProcessName = ProcessManager.ProcessNames.Command; break; case HandlerType.Word: _log.Trace("Launching thread for word"); if (_isWordInstalled) { var pids = ProcessManager.GetPids(ProcessManager.ProcessNames.Word).ToList(); if (pids.Count > timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.Word)) { return; } t = new Thread(() => { WordHandler o = new WordHandler(timeline, handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); threadJob.ProcessName = ProcessManager.ProcessNames.Word; } break; case HandlerType.Excel: _log.Trace("Launching thread for excel"); if (_isExcelInstalled) { var pids = ProcessManager.GetPids(ProcessManager.ProcessNames.Excel).ToList(); if (pids.Count > timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.Excel)) { return; } t = new Thread(() => { ExcelHandler o = new ExcelHandler(timeline, handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); threadJob.ProcessName = ProcessManager.ProcessNames.Excel; } break; case HandlerType.Clicks: _log.Trace("Launching thread to handle clicks"); t = new Thread(() => { Clicks o = new Clicks(handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); break; case HandlerType.Reboot: _log.Trace("Launching thread to handle reboot"); t = new Thread(() => { Reboot o = new Reboot(handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); break; case HandlerType.PowerPoint: _log.Trace("Launching thread for powerpoint"); if (_isPowerPointInstalled) { var pids = ProcessManager.GetPids(ProcessManager.ProcessNames.PowerPoint).ToList(); if (pids.Count > timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.PowerPoint)) { return; } t = new Thread(() => { PowerPointHandler o = new PowerPointHandler(timeline, handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); threadJob.ProcessName = ProcessManager.ProcessNames.PowerPoint; } break; case HandlerType.Outlook: _log.Trace("Launching thread for outlook - note we're not checking if outlook installed, just going for it"); //if (this.IsOutlookInstalled) //{ t = new Thread(() => { Outlook o = new Outlook(handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); threadJob.ProcessName = ProcessManager.ProcessNames.Outlook; //} break; case HandlerType.BrowserIE: //IE demands COM apartmentstate be STA so diff thread creation required t = new Thread(() => { BrowserIE o = new BrowserIE(handler); }); t.SetApartmentState(ApartmentState.STA); t.IsBackground = true; t.Name = threadJob.Id; t.Start(); break; case HandlerType.Notepad: //TODO t = new Thread(() => { Notepad o = new Notepad(handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); break; case HandlerType.BrowserChrome: t = new Thread(() => { BrowserChrome o = new BrowserChrome(handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); threadJob.ProcessName = ProcessManager.ProcessNames.Chrome; break; case HandlerType.BrowserFirefox: t = new Thread(() => { BrowserFirefox o = new BrowserFirefox(handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); threadJob.ProcessName = ProcessManager.ProcessNames.Firefox; break; case HandlerType.Watcher: t = new Thread(() => { Watcher o = new Watcher(handler); }) { IsBackground = true, Name = threadJob.Id }; t.Start(); //threadJob.ProcessName = ProcessManager.ProcessNames.Watcher; break; } if (threadJob.ProcessName != null) { _threadJobs.Add(threadJob); } if (t != null) { _threads.Add(t); } } catch (Exception e) { _log.Error(e); } }
private static void Main(string[] args) { Console.WriteLine(DateTime.Now + " " + "Developed by Moravia Publishing & Media automation team. All rights reserved." + "\n"); Console.WriteLine("Please input the root directory of loc templates folders >> "); Console.WriteLine("========================================"); Input: var dirInput = Console.ReadLine(); Console.WriteLine("========================================"); Console.WriteLine("In progress of processing, please hold on and wait for a while :) "); Console.WriteLine("========================================"); // Check if input path is empty if (string.IsNullOrEmpty(dirInput) && string.IsNullOrWhiteSpace(dirInput)) { Console.WriteLine("Empty or invalid directory, please double check and re-enter it!"); goto Input; } // Transfer input directory string to DirectoryInfo if (!File.Exists(dirInput) && Directory.Exists(dirInput)) { if (!dirInput.EndsWith("\\")) { dirInput = dirInput + "\\"; } var dirInfo = new DirectoryInfo(dirInput); // Get all subfolder names and add into LocalLanguage List try { ListLangFolders(dirInfo); } catch (Exception ex) { Console.WriteLine("Error when create folders list: " + ex.Message); return; } foreach (var lang in ListLang) { try { var langDirInfo = new DirectoryInfo(dirInput + lang + "\\"); SortLocFiles(langDirInfo); } catch (IOException e) { Console.WriteLine("Fail to sort files: " + e.Message); return; } } } else if (File.Exists(dirInput)) { var fileInfo = new FileInfo(dirInput); switch (fileInfo.Extension) { case ".dotx": case ".docx": case ".dotm": ListWord.Add(fileInfo.FullName); break; case ".xltx": case ".xlsx": case ".xltm": ListExcel.Add(fileInfo.FullName); break; case ".potx": case ".pptx": case ".potm": ListPpt.Add(fileInfo.FullName); break; } } KillProcess(); // PowerPointHandler if (ListPpt.Count > 0) { foreach (var f in ListPpt) { if (f.Contains("~$")) { continue; } Console.Write("\r\n" + "Processing: "); Common.WriteLine("\r\n" + f + "\r\n"); var objPpt = new PowerPointHandler(f); objPpt.PptMain(f); Common.WriteSglText(f); } } // WordHandler if (ListWord.Count > 0) { foreach (var f in ListWord) { if (f.Contains("~$")) { continue; } Console.Write("\r\n" + "Processing: "); Common.WriteLine("\r\n" + f + "\r\n"); var objWordHandler = new WordHandler(f); objWordHandler.WordMain(f); Common.WriteSglText(f); } } // Process ExcelHandler files if (ListExcel.Count > 0) { foreach (var f in ListExcel) { if (f.Contains("~$")) { continue; } Console.Write("\r\n" + "Processing: "); Common.WriteLine("\r\n" + f + "\r\n"); var objExcelHandler = new ExcelHandler(f); objExcelHandler.ExcelMain(f); Common.WriteSglText(f); } } // Write all Console content to text Common.WriteAllText(dirInput); // End Console.WriteLine("========================================"); Console.WriteLine("All files process complete! You are good to go!"); Console.ReadLine(); }