public void DoWork() { _stop = false; Stopped = false; while (!_stop) { while (!_queuedRequests.IsEmpty) { string text; _queuedRequests.TryPop(out text); if (string.IsNullOrEmpty(text)) { continue; } if (_definitions.ContainsKey(text)) { continue; //already done it.... } try { IList <ParseError> errors; var statements = ScriptDom.GetStatements(text, out errors); if (statements.Count > 0) { var glyphDefinitions = GetGlyphDefinitions(statements, text); _definitions[text] = glyphDefinitions; } } catch (Exception e) { //hmmmmm } var rePop = new string[5]; var clearPop = new string[100]; if (_queuedRequests.Count > 10) { var count = _queuedRequests.TryPopRange(rePop); while (_queuedRequests.Count > 10) { _queuedRequests.TryPopRange(clearPop); } _queuedRequests.PushRange(rePop, 0, count - 1); } } _event.WaitOne(); } Stopped = true; }
private static double AddChildItems(string name, CodeStatement <TSqlStatement> sqlModule, CodeCoverageStore store, double parentStatements, string file, TreeViewItem child, ref double parentCoveredStatements, ref double childStatements, ref double childCoveredStatements) { if (string.IsNullOrEmpty(name)) { return(parentStatements); } //need to enumerate the statement tree to find statements (flatten tree - have probably already done it?? maybe can just use a visitor - see count lines of code surely?) var script = File.ReadAllText(sqlModule.FileName); if (script.Length < sqlModule.Length) { //bad tings.... return(parentStatements); } IList <ParseError> errors; var statementNodes = ScriptDom.GetStatements(script.Substring(sqlModule.StartLocation, sqlModule.Length), out errors); if (errors != null && errors.Count > 1) { //more bad tings return(parentStatements); } var coveredStatements = store.GetCoveredStatements(name, sqlModule.FileName); var beginEndBlocks = statementNodes.Count(p => p.GetType() == typeof(BeginEndBlockStatement)); var statementCount = statementNodes.Count - 1 - beginEndBlocks; parentStatements += statementCount; parentCoveredStatements += coveredStatements?.Count ?? 0; childStatements += statementCount; childCoveredStatements += coveredStatements?.Count ?? 0; //if the file has changed we can't get anything useful from it... if (coveredStatements != null && coveredStatements.Count > 0 && !coveredStatements.Any(p => p.TimeStamp < File.GetLastWriteTimeUtc(file))) { var coveragePercent = ((double)coveredStatements.Count / (double)statementCount) * 100; var label = new LabelWithProgressIndicator(string.Format("{0} - {1}% ({2} / {3})", name, coveragePercent, coveredStatements.Count, statementCount), coveragePercent, file); label.Configure(); child.Items.Add(label); } else { var label = new LabelWithProgressIndicator(name + " - 0 %", 0, file); label.Configure(); child.Items.Add(label); } return(parentStatements); }