public HalfLifeDemoAnalyser(HalfLifeDemo demo, IAnalysisWindow analysisWindowInterface, IProgressWindow progressWindowInterface) { this.demo = demo; this.analysisWindowInterface = analysisWindowInterface; this.progressWindowInterface = progressWindowInterface; newRoundEventId = GameManager.NewRoundEventId(demo); gameState = new HalfLifeGameState(); NewRound(); titleTable = new Hashtable(); // TextMsg AddTitle("#Target_Bombed", "Target Succesfully Bombed!"); AddTitle("#VIP_Escaped", "The VIP has escaped!"); AddTitle("#VIP_Assassinated", "VIP has been assassinated!"); AddTitle("#Terrorists_Escaped", "The terrorists have escaped!"); AddTitle("#CTs_PreventEscape", "The CTs have prevented most of the terrorists from escaping!"); AddTitle("#Escaping_Terrorists_Neutralized", "Escaping terrorists have all been neutralized!"); AddTitle("#Bomb_Defused", "The bomb has been defused!"); AddTitle("#CTs_Win", "Counter-Terrorists Win!"); AddTitle("#Terrorists_Win", "Terrorists Win!"); AddTitle("#Round_Draw", "Round Draw!"); AddTitle("#All_Hostages_Rescued", "All Hostages have been rescued!"); AddTitle("#Target_Saved", "Target has been saved!"); AddTitle("#Hostages_Not_Rescued", "Hostages have not been rescued!"); AddTitle("#Terrorists_Not_Escaped", "Terrorists have not escaped!"); AddTitle("#VIP_Not_Escaped", "VIP has not escaped!"); AddTitle("#Terrorist_Escaped", "A terrorist has escaped!"); AddTitle("#Bomb_Planted", "The bomb has been planted!"); AddTitle("#Game_will_restart_in", "The game will restart in %s1 %s2"); AddTitle("#Game_bomb_drop", "%s1 dropped the bomb"); AddTitle("#Game_bomb_pickup", "%s1 picked up the bomb"); AddTitle("#Game_connected", "%s1 connected"); AddTitle("#Game_disconnected", "%s1 has left the game"); AddTitle("#Game_join_ct", "%s1 is joining the Counter-Terrorist force"); AddTitle("#Game_join_ct_auto", "%s1 is joining the Counter-Terrorist force (auto)"); AddTitle("#Game_join_terrorist", "%s1 is joining the Terrorist force"); AddTitle("#Game_join_terrorist_auto", "%s1 is joining the Terrorist force (auto)"); AddTitle("#Game_kicked", "Kicked %s1"); AddTitle("#Game_teammate_attack", "%s1 attacked a teammate"); // SayText AddTitle("#Cstrike_Name_Change", "* %s1 changed name to %s2"); AddTitle("#Cstrike_Chat_CT", "(Counter-Terrorist) "); AddTitle("#Cstrike_Chat_T", "(Terrorist) "); AddTitle("#Cstrike_Chat_CT_Dead", "*DEAD*(Counter-Terrorist) "); AddTitle("#Cstrike_Chat_T_Dead", "*DEAD*(Terrorist) "); AddTitle("#Cstrike_Chat_Spec", "(Spectator) "); AddTitle("#Cstrike_Chat_All", ""); AddTitle("#Cstrike_Chat_AllDead", "*DEAD* "); AddTitle("#Cstrike_Chat_AllSpec", "*SPEC* "); }
public HalfLifeDemoWriter(HalfLifeDemo demo, IHalfLifeDemoWriter demoWriterInterface, IProgressWindow progressWindowInterface, Int32 firstFrameToWriteIndex) { this.demo = demo; this.demoWriterInterface = demoWriterInterface; this.progressWindowInterface = progressWindowInterface; this.firstFrameToWriteIndex = firstFrameToWriteIndex; }
private void Flow(IProgressWindow prgWin) { prgWin.AppendLog("获取信息中", 10); IUpdateInfo info = InfoGetter.Get(); prgWin.AppendLog("获取信息完毕,正在解析", 20); prgWin.SetUpdateContent(info.UpdateContent); IEnumerable <IFile> needUpdateFile = Differ.Diff(info.Files, GetLocalFiles()); if (needUpdateFile.Count() == 0) { prgWin.AppendLog("无需更新!", 100); Thread.Sleep(4000); prgWin.Finish(); return; } int downloadingFile = 0; Downloader.DownloadedAFile += (s, e) => { downloadingFile++; prgWin.SetProgress(20 + (100 / needUpdateFile.Count() * downloadingFile * 80)); prgWin.AppendLog($"正在下载并更新{downloadingFile}/{needUpdateFile.Count()}"); }; Downloader.Download(needUpdateFile); prgWin.AppendLog("结束,三秒后退出", 100); Thread.Sleep(3000); prgWin.Finish(); }
/// <summary> /// Starts writing the demo in a new thread /// </summary> public Thread Write(IProgressWindow writeProgressWindowInterface) { this.writeProgressWindowInterface = writeProgressWindowInterface; return(new Thread(new ParameterizedThreadStart(WritingThread)) { Name = "Writing Demo" }); }
public static void LogVersion(IProgressWindow logger, System.Reflection.Assembly executingAssembly) { string company, product; Version version; GetVersion(executingAssembly, out company, out product, out version); var shortVer = string.Format("{0} {1}.{2} running...", product, version.Major, version.Minor); var longVer = string.Format("{0} {1} running...", product, version.ToString()); logger.Log(shortVer, longVer); }
public void Start(IProgressWindow prgWin) { try { Flow(prgWin); } catch (Exception ex) { prgWin.AppendLog("下载失败" + ex.ToString()); Debug.WriteLine(ex); } }
public void RegisterViewsFirstRun() { int count = 0, illegallyNamedCount = 0; IResourceList contacts = Core.ResourceStore.GetAllResources("Contact"); IProgressWindow wnd = Core.ProgressWindow; if (wnd != null) { wnd.UpdateProgress(0, "Upgrading Contact Names information.", null); } ContactManager.UnlinkIdenticalContactNames(contacts, wnd, ref count, ref illegallyNamedCount); Trace.WriteLine("ContactsUpgrade3ViewsConstructor (RegisterViewsFirstRun) -- " + count + " completely unnecessary contact names removed, of that - " + illegallyNamedCount + " illegally named Conact Names"); }
//static DispatcherTimer timer = new DispatcherTimer(); private static bool pleaseWaitImplementation(bool canBeCanceled, int?progressMax, MyRunMethod method, IProgressWindow _pleaseWaitDlg) { bool res = true; Debug.WriteLine("PleaseWait.Run start"); //Cancel = false; // Start my lengthy Process // Display the Please Wait Dialog here if (_pleaseWaitDlg == null) { //_pleaseWaitDlg = new PleaseWaitWindow(canBeCanceled, progressMax); _pleaseWaitDlg = MainWindow.Instance; } Thread lengthyProcessThread = new Thread(threadRunner); lengthyProcessThread.SetApartmentState(ApartmentState.STA); lengthyProcessThread.IsBackground = true; // so not to have stray running threads if the main form is closed PleaseWaitContext pleaseWaitContext = new PleaseWaitContext(method, _pleaseWaitDlg); lengthyProcessThread.Start(pleaseWaitContext); IProgressWindow temporaryWindow = _pleaseWaitDlg; MethodParameters par = new MethodParameters(temporaryWindow); //timer.Interval = TimeSpan.FromSeconds(.5); //timer.Tick += delegate //{ // timer.Stop(); // if (/*!pendingClosing &&*/ !par.Finished) // { // temporaryWindow.ShowProgress(); // } //}; temporaryWindow.Parameters = par; //timer.Start(); temporaryWindow.ShowProgress(canBeCanceled, progressMax); Debug.WriteLine("Creating thread: " + lengthyProcessThread.ManagedThreadId); //if please wait thread throws exception then rethrow it if (pleaseWaitContext.ReturnException != null) { res = false; ExceptionHandler.Default.Process(pleaseWaitContext.ReturnException); //throw new RethrowedException(pleaseWaitContext.ReturnException);) throw pleaseWaitContext.ReturnException; } return(res); }
public static void DoWithRetry(IProgressWindow logger, Action action, int numberOfRetries, TimeSpan?retryDelay) { var retryDelayInSecondsSchedule = retryDelay.HasValue ? new[] { retryDelay.Value }.Cycle() : new[] { 10, 30, 60, 5 * 60, 10 * 60, 15 * 60, 60 * 60, 2 * 60 * 60, }.Concat(new[] { 2 * 60 * 60 }.Cycle()) .Select(x => TimeSpan.FromSeconds(x)); foreach (var delay in retryDelayInSecondsSchedule.Take(numberOfRetries)) { try { action(); return; } catch (SimpleException <DoNotRetry> ex) { if (ex.InnerException != null) { throw ex.InnerException; } throw new ErrorMessageException(ex.Message); } catch (ErrorMessageException ex) { logger.Log("Error: " + ex.Message); logger.Log("Waiting to retry... (" + delay.ToPrettyFormat() + ")"); System.Threading.Thread.Sleep(delay); } catch (Exception ex) { logger.Log(VaultServerException.WrapException(ex).ToString()); logger.Log("Waiting to retry... (" + delay.ToPrettyFormat() + ")"); System.Threading.Thread.Sleep(delay); } } action(); }
/// <summary> /// Invokes <see cref="IPlugin.Startup"/> for each of the loaded plugins, on the Resource thread, sync. /// </summary> public void StartupPlugins() { IProgressWindow window = Core.ProgressWindow; for (int a = 0; a < _plugins.Count; a++) { IPlugin plugin = _plugins[a]; Trace.WriteLine("Starting plugin " + plugin.GetType().Name); if (window != null) { window.UpdateProgress((a + 1) * 100 / _plugins.Count, Stringtable.StartingPluginsProgressMessage, null); } // Run on another thread string sStartupError = null; bool bCancelStartup = false; IPlugin pluginConst = plugin; // Precaution: don't access modified closure Core.ResourceAP.RunJob(string.Format(Stringtable.JobStartingPlugin, plugin.GetType().Name), delegate { try { pluginConst.Startup(); } catch (CancelStartupException) { Trace.WriteLine(string.Format("Starting Plugin “{0}”: CancelStartupException.", pluginConst.GetType().AssemblyQualifiedName), "Plugin.Loader"); bCancelStartup = true; } catch (Exception ex) { sStartupError = ex.Message; } }); // Process results on home thread if (bCancelStartup) { throw new CancelStartupException(); } if (sStartupError != null) { Trace.WriteLine(string.Format("Error Starting Plugin “{0}”. {1}", plugin.GetType().AssemblyQualifiedName, sStartupError)); } } }
//static PleaseWaitWindow _pleaseWaitDlg; /// <summary> /// Runs the specified long operation (in delegate) in separate thread and display please wait modal window. /// </summary> /// <param name="method">The method to run in background.</param> /// <param name="canBeCanceled">if set to <c>true</c> operation can be canceled (PleaseWait window display Cancel button).</param> public static bool Run(MyRunMethod method, bool canBeCanceled = false, IProgressWindow progressWindow = null, int?progressMax = null, bool useDefaultExceptionHandling = true) { bool res = true; if (useDefaultExceptionHandling) { UIHelper.RunWithExceptionHandling(delegate { res = pleaseWaitImplementation(canBeCanceled, progressMax, method, progressWindow); }); } else { res = pleaseWaitImplementation(canBeCanceled, progressMax, method, progressWindow); } return(res); }
public async void Start(IProgressWindow prgWin) { try { UpdateInfo uInfo = null; prgWin.SetTip("正在获取更新信息", 10); await Task.Run(() => uInfo = UpdateInfo.Parse(webClient.DownloadString(api))); prgWin.SetTip("获取完成", 15); prgWin.SetUpdateContent($"{uInfo.Title}{Environment.NewLine}{uInfo.UpdateContent}"); if (Directory.Exists(updateTmpDir)) { Directory.Delete(updateTmpDir, true); } if (!Directory.Exists(updateTmpDir)) { Directory.CreateDirectory(updateTmpDir); } prgWin.SetTip("正在下载更新", 30); await Task.Run(() => webClient.DownloadFile(uInfo.DownloadUrl, Path.Combine(updateTmpDir, tmpFilePath))); prgWin.SetTip("正在应用更新", 80); await Task.Run(() => { using (var zip = new ZipFile("..\\update\\tmp.zip")) { zip.ExtractAll(Path.Combine(updateTmpDir)); } }); Process.Start(new ProcessStartInfo("cmd.exe") { Arguments = "/c " + uInfo.Bat, WorkingDirectory = "..\\", }).Start(); prgWin.Finish(); } catch (Exception ex) { Trace.Fail(ex.ToString()); } }
/// <summary> /// Calls <see cref="IPlugin.Shutdown"/> on each of the plugins, on the calling thread. /// </summary> /// <param name="bShowProgress">Whether to report to the progress window.</param> public void ShutdownPlugins(bool bShowProgress) { IProgressWindow window = Core.ProgressWindow; foreach (IPlugin plugin in _plugins) { if ((bShowProgress) && (window != null)) { window.UpdateProgress(0, string.Format(Stringtable.StoppingPluginProgressMessage, plugin.GetType().Name), null); } try { plugin.Shutdown(); } catch (Exception ex) { Core.ReportException(ex, false); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { uiGameLog.Document = new FlowDocument(); uiGameLog.Document.FontSize = 14; uiGameLog.Document.FontFamily = new FontFamily("Times New Roman"); WindowState = Config.Settings.AnalysisWindowState; // show progress window/start parsing thread ProgressWindow progressWindow = new ProgressWindow() { Owner = this }; progressWindow.Thread = new Thread(new ThreadStart(Parse)) { Name = "Demo Parsing Thread" }; progressWindowInterface = (IProgressWindow)progressWindow; if (progressWindow.ShowDialog() == false) { Close(); } }
/// <summary> /// Initializes a new instance of the <see cref="PleaseWaitContext"/> class. /// </summary> /// <param name="dlg">PleaseWaitWindow used in this context</param> public ProgressOperationContext(IProgressWindow dlg) { this.dlg = dlg; }
private static void UpdateResources() { string[] lastTypes = ObjectStore.ReadString("UnknownFiles", "LastConf").Split(';'); string[] types = (Core.FileResourceManager as FileResourceManager).GetResourceTypes(); if (types.Length == lastTypes.Length) { bool needUpdate = false; Array.Sort(types); Array.Sort(lastTypes); for (int i = 0; i < types.Length; ++i) { if (types[i] != lastTypes[i]) { needUpdate = true; break; } } // plugin configuration not changed if (!needUpdate) { return; } } IResourceList unknownRcs = Core.ResourceStore.GetAllResources(_unknowFileResourceType); IProgressWindow progressWindow = Core.ProgressWindow; for (int i = 0, percents = 0; i < unknownRcs.Count && Core.State != CoreState.ShuttingDown; ++i) { if (progressWindow != null) { progressWindow.UpdateProgress(percents / unknownRcs.Count, "Updating unknown resources", null); percents += 100; } IResource unknown = unknownRcs[i]; IResource source = FileResourceManager.GetSource(unknown); if (source != null) { string resourceType = Core.FileResourceManager.GetResourceTypeByExtension( IOTools.GetExtension(unknown.GetPropText(Core.Props.Name))); if (resourceType != null) { unknown.ChangeType(resourceType); } } } foreach (IResourceType resType in Core.ResourceStore.ResourceTypes) { if (resType.HasFlag(ResourceTypeFlags.FileFormat) && !resType.OwnerPluginLoaded) { IResourceList formatFiles = Core.ResourceStore.GetAllResources(resType.Name); foreach (IResource formatFile in formatFiles) { formatFile.ChangeType(_unknowFileResourceType); } } } StringBuilder confString = new StringBuilder(); foreach (string restype in types) { confString.Append(restype); confString.Append(";"); } ObjectStore.WriteString("UnknownFiles", "LastConf", confString.ToString().TrimEnd(';')); }
/// <summary> /// Initializes a new instance of the <see cref="MethodParameters"/> class. /// </summary> /// <param name="pleaseWaitDlg">The _please wait window instance.</param> public MethodParameters(IProgressWindow pleaseWaitDlg) { this.pleaseWaitDlg = pleaseWaitDlg; }
internal void SetProgressWindow(IProgressWindow progressWindow) { _progressWindow = progressWindow; }
/// <summary> /// Starts writing the demo in a new thread /// </summary> public Thread Write(IProgressWindow writeProgressWindowInterface) { this.writeProgressWindowInterface = writeProgressWindowInterface; return new Thread(new ParameterizedThreadStart(WritingThread)) { Name = "Writing Demo" }; }
/// <summary> /// Initializes a new instance of the <see cref="PleaseWaitContext"/> class. /// </summary> /// <param name="method">The method to run in background.</param> /// <param name="dlg">PleaseWaitWindow used in this context</param> public PleaseWaitContext(MyRunMethod method, IProgressWindow dlg) : base(dlg) { this.method = method; }