internal void DumpSchedulerStatus(bool alwaysOutput = true) { if (!logger.IsVerbose && !alwaysOutput) { return; } PrintStatistics(); var sb = new StringBuilder(); sb.AppendLine("Dump of current OrleansTaskScheduler status:"); sb.AppendFormat("CPUs={0} RunQueue={1}, WorkItems={2} {3}", Environment.ProcessorCount, RunQueue.Length, workgroupDirectory.Count, applicationTurnsStopped ? "STOPPING" : "").AppendLine(); sb.AppendLine("RunQueue:"); RunQueue.DumpStatus(sb); Pool.DumpStatus(sb); foreach (var workgroup in workgroupDirectory.Values) { sb.AppendLine(workgroup.DumpStatus()); } logger.LogWithoutBulkingAndTruncating(Logger.Severity.Info, ErrorCode.SchedulerStatus, sb.ToString()); }
public void TestCrossRunMatch2() { RunQueue queue = new RunQueue(2); Run r1 = new Run("1234co"), r2 = new Run("co5678"); int callInc = 0; queue.Enqueue(r1); queue.Enqueue(r2); RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel(); model.ScanQueuedRuns(queue, "coco", delegate(Run run, int index, int length) { Assert.IsTrue(callInc < 2); if (callInc == 0) { Assert.AreEqual(r1, run); Assert.AreEqual(4, index); Assert.AreEqual(2, length); } else if (callInc == 1) { Assert.AreEqual(r2, run); Assert.AreEqual(0, index); Assert.AreEqual(2, length); } callInc++; } ); Assert.AreEqual(2, callInc); }
public void TestScanRunQueueMultipleTimes2() { //harder one int callInc = 0; RunQueue rq2 = new RunQueue(5); FillRunQueue(rq2, GetTestRuns2()); RunQueue rq2_clone = rq2.Clone(); RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel(); model.ScanQueuedRuns(rq2, "3", delegate(Run run, int index, int length) { Assert.IsTrue(callInc < 1); if (callInc == 0) { Assert.AreEqual(rq2_clone[1].Run, run); Assert.AreEqual(0, index); Assert.AreEqual(1, length); } callInc++; } ); //add new item and search again, this time we don't want to hit 3 again rq2.Enqueue(new Run("3")); model.ScanQueuedRuns(rq2, "3", delegate(Run run, int index, int length) { Assert.AreEqual("3", run.Text); } ); }
protected override void QueueTask(Task task) { var contextObj = task.AsyncState; #if DEBUG if (logger.IsVerbose2) { logger.Verbose2("QueueTask: Id={0} with Status={1} AsyncState={2} when TaskScheduler.Current={3}", task.Id, task.Status, task.AsyncState, Current); } #endif var context = contextObj as ISchedulingContext; var workItemGroup = GetWorkItemGroup(context); if (applicationTurnsStopped && (workItemGroup != null) && !workItemGroup.IsSystem) { // Drop the task on the floor if it's an application work item and application turns are stopped logger.Warn(ErrorCode.SchedulerAppTurnsStopped, string.Format("Dropping Task {0} because applicaiton turns are stopped", task)); return; } if (workItemGroup == null) { var todo = new TaskWorkItem(this, task, context); RunQueue.Add(todo); } else { var error = String.Format("QueueTask was called on OrleansTaskScheduler for task {0} on Context {1}." + " Should only call OrleansTaskScheduler.QueueTask with tasks on the null context.", task.Id, context); logger.Error(ErrorCode.SchedulerQueueTaskWrongCall, error); throw new InvalidOperationException(error); } }
public static void ProcessRun(AddHighlight addHighlightDelegate, Run run, RunQueue runQueue, string searchText) { if (run != null && !string.IsNullOrEmpty(run.Text)) { runQueue.Enqueue(run); ScanQueuedRuns(runQueue, searchText, addHighlightDelegate); } }
public static void FillRunQueue(RunQueue rq, List <Run> lr) { for (int i = 0; i < lr.Count; i++) { rq.Enqueue(lr[i]); Assert.AreEqual(i + 1, rq.Count); Assert.AreEqual(lr[i].Text, rq[i].Text); } }
public void MakeInvalid() { RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel(); model.FindOptions.UseRegularExpressions = true; Query q = new Query(".*["); RunQueue rq = new RunQueue(1); rq.Enqueue(new System.Windows.Documents.Run("hello this is it")); model.ScanQueuedRuns(rq, q, null); Assert.IsFalse(q.Valid); Assert.AreEqual("Regular expression error, parsing \".*[\" - Unterminated [] set.", q.ReasonInvalid); }
public MainWindow() { InitializeComponent(); InitializeSingleTaskExecutor(); _cooldown = new EventCooldown( TimeSpan.FromSeconds(2), Action, TimeSpan.FromSeconds(5)); var i = 32; _runQueue = new RunQueue(() => DoNothing(i)); }
public static void ScanQueuedRuns(RunQueue runQueue, string searchText, AddHighlight addHighlightDelegate) { System.Text.StringBuilder queuedText = new System.Text.StringBuilder(100); queuedText.Length = 0; for (int i = 0; i < runQueue.Count && (i == 0 || queuedText.Length < 100); i++)//look at the text in queue up until 100 chars of the 2nd run { queuedText.Append(runQueue[i].HitAvailableText); } int currentIndex = 0; string text = queuedText.ToString(); int index; while ((index = text.IndexOf(searchText, currentIndex, StringComparison.CurrentCultureIgnoreCase)) > -1)//find a hit for searchText in the plain text version. { //we have a hit, we need to find the runs it was in and highlight int indexOffset; int remainingChars = 0; int hitLength = 0; string searchSegment = searchText; bool moreToFind = true; while (moreToFind) { Run runAtPos = runQueue.HitPosition(index, searchSegment.Length, out indexOffset, out remainingChars); //remainingChars is # of chars in the run after the hit position - so if the hit spreads over 2 or more runs //then remainingChars will be less than the searchSegment. if (remainingChars < searchSegment.Length) { //partial match, find parts with rest moreToFind = true; searchSegment = searchText.Substring(remainingChars); hitLength = remainingChars; index = text.IndexOf(searchSegment, index + hitLength, StringComparison.CurrentCultureIgnoreCase); } else { moreToFind = false; hitLength = searchSegment.Length; } addHighlightDelegate(runAtPos, indexOffset, hitLength); currentIndex = index + hitLength; } } }
public void TestScanRunQueueMultipleTimes3() { //harder one int callInc = 0; RunQueue rq2 = new RunQueue(5); FillRunQueue(rq2, GetTestRuns2()); rq2.Enqueue(new Run("3 3")); rq2.Enqueue(new Run("232")); RunQueue rq2_clone = rq2.Clone(); RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel(); model.ScanQueuedRuns(rq2, "3", delegate(Run run, int index, int length) { Assert.IsTrue(callInc < 4); if (callInc == 0) { Assert.AreEqual(rq2_clone[1].Run, run); Assert.AreEqual(0, index); Assert.AreEqual(1, length); } else if (callInc == 1) { Assert.AreEqual(rq2_clone[3].Run, run); Assert.AreEqual(0, index); Assert.AreEqual(1, length); } else if (callInc == 2) { Assert.AreEqual(rq2_clone[3].Run, run); Assert.AreEqual(2, index); Assert.AreEqual(1, length); } else if (callInc == 3) { Assert.AreEqual(rq2_clone[4].Run, run); Assert.AreEqual(1, index); Assert.AreEqual(1, length); } callInc++; } ); }
public void TestRunQueue() { RunQueue rq = new RunQueue(5); FillRunQueue(rq, GetTestRuns()); //now wrap rq.Enqueue(new Run("bbbb")); Assert.AreEqual(5, rq.Count); rq.Enqueue(new Run("cccc")); Assert.AreEqual(5, rq.Count); Assert.AreEqual("5555 6666", rq[0].Text); Assert.AreEqual("7777 8888", rq[1].Text); Assert.AreEqual("9999 aaaa", rq[2].Text); Assert.AreEqual("bbbb", rq[3].Text); Assert.AreEqual("cccc", rq[4].Text); }
public void StopApplicationTurns() { #if DEBUG if (logger.IsVerbose) { logger.Verbose("StopApplicationTurns"); } #endif RunQueue.RunDownApplication(); applicationTurnsStopped = true; foreach (var group in workgroupDirectory.Values) { if (!group.IsSystem) { group.Stop(); } } }
public static void HandleConsoleInput(String Input) { pLastManualConsoleInput = Input; SortedDictionary <int, Color> Cols = new SortedDictionary <int, Color>(); Cols.Add(0, Color.LightGreen); WriteLine(Input, Cols); String[] Commands = Input.Split(' '); try { switch (Commands[0].ToUpper()) { //Run ScriptProcessor commands as a forced script shift (by default, shift conditions are unchanged). case "INSERT": ScriptProcessor.ScriptSniffer FoundSniffer = ScriptProcessor.SnifferSearch(); if (FoundSniffer != null) { FoundSniffer.ForceInsertScriptElement((Input.Remove(0, Input.IndexOf(' ') + 1)).Split(' '), false); } else { WriteLine("Cannot insert new script shift as a script is not running."); } break; //Activate a single script element. case "ACTIVATE": ScriptProcessor.ActivateScriptElement(Input.Remove(0, Input.IndexOf(' ') + 1)); break; //Freshly load a new script. case "LOAD": WriteLine("Attempting to load script " + Commands[1].ToUpper() + "."); ButtonScripts.StartScript(Commands[1].ToUpper()); break; //Executes a function statement per the EntityFactory's inbuilt function parser. case "DO": RunQueue.Add(EntityFactory.AssembleVoidDelegate("do=" + Input.Remove(0, Input.IndexOf(' ') + 1))); break; //Executes a method specifier (instance return) per the EntityFactory's inbuilt function parser. case "RUN": RunQueue.Add(EntityFactory.AssembleVoidDelegate(Input.Remove(0, Input.IndexOf(' ') + 1))); break; //Fork to a new script from your current state. Equivalent to "do B|[Script name]". case "FORK": ScriptProcessor.ActivateScriptElement("B|" + Commands[1].ToUpper()); break; //Close the program. case "QUIT": WriteLine("Closing the VNF client..."); ExitOut = true; break; default: WriteLine("Unrecognized command."); break; } } catch (Exception e) { WriteLine(e.GetType().Name + ": " + e.Message); } }
public void Stop() { RunQueue.RunDown(); Pool.Stop(); }
public void IgnoreWhitespaceSplitRuns() { List <Run> runs = new List <Run>(); runs.Add(new Run(" a b")); runs.Add(new Run(" c")); runs.Add(new Run(" stella was here a b ")); runs.Add(new Run("but not here")); runs.Add(new Run("ok she's back a b")); //harder one int callInc = 0; RunQueue rq2 = new RunQueue(5); QueueTests.FillRunQueue(rq2, runs); RunQueue rq2_clone = rq2.Clone(); RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel(); model.FindOptions.IgnoreWhitespaceCharacters = true; model.ScanQueuedRuns(rq2, "abc", delegate(Run run, int index, int length) { Assert.IsTrue(callInc < 2); if (callInc == 0) { Assert.AreEqual(rq2_clone[0].Run, run); Assert.AreEqual(2, index); Assert.AreEqual(3, length); } if (callInc == 1) { Assert.AreEqual(rq2_clone[1].Run, run); Assert.AreEqual(0, index); Assert.AreEqual(2, length); } callInc++; } ); callInc = 0; model.ScanQueuedRuns(rq2, "a b c", delegate(Run run, int index, int length) { Assert.IsTrue(callInc < 2); if (callInc == 0) { Assert.AreEqual(rq2_clone[0].Run, run); Assert.AreEqual(2, index); Assert.AreEqual(3, length); } if (callInc == 1) { Assert.AreEqual(rq2_clone[1].Run, run); Assert.AreEqual(0, index); Assert.AreEqual(2, length); } callInc++; } ); }
public static void ScanQueuedRuns(RunQueue runQueue, string searchText, AddHighlight addHighlightDelegate) { System.Text.StringBuilder queuedText = new System.Text.StringBuilder(100); queuedText.Length = 0; for (int i = 0; i < runQueue.Count && (i==0 || queuedText.Length < 100); i++)//look at the text in queue up until 100 chars of the 2nd run { queuedText.Append(runQueue[i].HitAvailableText); } int currentIndex = 0; string text = queuedText.ToString(); int index; while ((index = text.IndexOf(searchText, currentIndex, StringComparison.CurrentCultureIgnoreCase)) >-1)//find a hit for searchText in the plain text version. { //we have a hit, we need to find the runs it was in and highlight int indexOffset; int remainingChars=0; int hitLength=0; string searchSegment = searchText; bool moreToFind = true; while (moreToFind) { Run runAtPos = runQueue.HitPosition(index, searchSegment.Length, out indexOffset, out remainingChars); //remainingChars is # of chars in the run after the hit position - so if the hit spreads over 2 or more runs //then remainingChars will be less than the searchSegment. if (remainingChars < searchSegment.Length) { //partial match, find parts with rest moreToFind = true; searchSegment = searchText.Substring(remainingChars); hitLength = remainingChars; index = text.IndexOf(searchSegment, index + hitLength, StringComparison.CurrentCultureIgnoreCase); } else { moreToFind = false; hitLength = searchSegment.Length; } addHighlightDelegate(runAtPos, indexOffset, hitLength); currentIndex = index + hitLength; } } }
public static void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate,RunQueue runQueue, string searchText) { while (runQueue.Count > 0) { runQueue.Dequeue(); ScanQueuedRuns(runQueue, searchText, addHighlightDelegate); } }
private void DetermineLevels(BidiChain chain) { StatusStack stack = new StatusStack(); RunQueue runQueue = new RunQueue(); IsolatingRun isolatingRun = new IsolatingRun() { Text = _text, ParagraphLevel = _baseLevel }; BidiLink roller = chain.RollerLink; BidiLink firstLink = null; BidiLink lastLink = null; BidiLink priorLink = roller; byte priorLevel = _baseLevel; CharType sor = CharType.Nil; CharType eor = CharType.Nil; // Rule X1 int overIsolate = 0; int overEmbedding = 0; int validIsolate = 0; stack.Push(_baseLevel, CharType.ON, false); for (BidiLink link = roller.Next; link != roller; link = link.Next) { bool forceFinish = false; bool bnEquivalent = false; CharType type = link.type; switch (type) { /* Rule X2, X3, X4, X5, X5a, X5b, X5c */ case CharType.RLE: case CharType.LRE: case CharType.RLO: case CharType.LRO: case CharType.RLI: case CharType.LRI: case CharType.FSI: bool isIsolate = (type == CharType.RLI || type == CharType.LRI || type == CharType.FSI); bool isRTL = (type == CharType.RLE || type == CharType.RLO || type == CharType.RLI); if (type == CharType.FSI) { isRTL = (DetermineBaseLevel(link, roller, (byte)0, true) == 1); } if (isIsolate) { link.level = stack.EmbeddingLevel; } else { bnEquivalent = true; } byte newLevel = (isRTL ? stack.OddLevel : stack.EvenLevel); if (newLevel <= Level.MaxValue && overIsolate == 0 && overEmbedding == 0) { if (isIsolate) { ++validIsolate; } CharType overrideStatus = (type == CharType.LRO ? CharType.L : type == CharType.RLO ? CharType.R : CharType.ON); stack.Push(newLevel, overrideStatus, isIsolate); } else { if (isIsolate) { ++overIsolate; } else { if (overIsolate == 0) { ++overEmbedding; } } } break; /* Rule X6 */ default: link.level = stack.EmbeddingLevel; if (stack.OverrideStatus != CharType.ON) { link.type = stack.OverrideStatus; if (priorLink.type == link.type && priorLink.level == link.level) { // Properties of this link are same as previous link, // therefore merge it and continue the loop. priorLink.MergeNext(); continue; } } break; /* Rule X6a */ case CharType.PDI: if (overIsolate != 0) { --overIsolate; } else if (validIsolate == 0) { // Do nothing } else { overEmbedding = 0; while (!stack.IsolateStatus) { stack.Pop(); } stack.Pop(); --validIsolate; } link.level = stack.EmbeddingLevel; break; /* Rule X7 */ case CharType.PDF: bnEquivalent = true; if (overIsolate != 0) { // Do nothing } else if (overEmbedding != 0) { --overEmbedding; } else if (!stack.IsolateStatus && stack.Count >= 2) { stack.Pop(); } break; // Rule X8 case CharType.B: // These values are reset for clarity, in this implementation B // can only occur as the last code in the array. stack.Clear(); overIsolate = 0; overEmbedding = 0; validIsolate = 0; link.level = _baseLevel; break; case CharType.BN: bnEquivalent = true; break; case CharType.Nil: forceFinish = true; link.level = _baseLevel; break; } // Rule X9 if (bnEquivalent) { // The type of this link is BN equivalent, so abandon it and // continue the loop. priorLink.AbandonNext(); continue; } if (sor == CharType.Nil) { sor = Level.MakeExtremeType(_baseLevel, link.level); firstLink = link; priorLevel = link.level; } else if (priorLevel != link.level || forceFinish) { // Save the current level i.e. level of the next run. byte currentLevel = link.level; // Since the level has changed at this link, therefore, the run // must end at the prior link. lastLink = priorLink; // Now we have both the prior level and the current level i.e. // unchanged levels of both the current run and the next run. // So, identify eos of the current run. // Note: // sor of the run has already been determined at this stage. eor = Level.MakeExtremeType(priorLevel, currentLevel); runQueue.Enqueue(new LevelRun(firstLink, lastLink, sor, eor)); if (runQueue.ShouldDequeue || forceFinish) { // Rule X10 while (!runQueue.IsEmpty) { LevelRun peek = runQueue.Peek(); if (!peek.IsAttachedTerminator) { isolatingRun.BaseLevelRun = peek; isolatingRun.Resolve(); } // Dequeue the run. runQueue.Dequeue(); } } // The sor of next run (if any) will be technically equal to eor of // this run. sor = eor; // The next run (if any) will start from this link. firstLink = link; priorLevel = currentLevel; } priorLink = link; } SaveLevels(chain); }
public void TestScanRunQueue() { RunQueue rq = new RunQueue(5); FillRunQueue(rq, GetTestRuns()); RunQueue rq_clone = rq.Clone(); RapidFindReplaceControlViewModel model = new RapidFindReplaceControlViewModel(); //easy one model.ScanQueuedRuns(rq, new Keyoti.RapidFindReplace.WPF.Query("1111"), delegate(Run run, int index, int length){ Assert.AreEqual(rq_clone[0].Run, run); Assert.AreEqual(0, index); Assert.AreEqual(4, length); } ); //easy one model.ScanQueuedRuns(rq, "4444", delegate(Run run, int index, int length) { Assert.AreEqual(rq_clone[1].Run, run); Assert.AreEqual(5, index); Assert.AreEqual(4, length); } ); //harder one int callInc = 0; model.ScanQueuedRuns(rq, "44445555", delegate(Run run, int index, int length) { if (callInc == 0) { Assert.AreEqual(rq_clone[1].Run, run); Assert.AreEqual(5, index); Assert.AreEqual(4, length); } else if (callInc == 1) { Assert.AreEqual(rq_clone[2].Run, run); Assert.AreEqual(0, index); Assert.AreEqual(4, length); } callInc++; } ); //harder one callInc = 0; RunQueue rq2 = new RunQueue(5); FillRunQueue(rq2, GetTestRuns2()); RunQueue rq2_clone = rq2.Clone(); model.ScanQueuedRuns(rq2, "22223", delegate(Run run, int index, int length) { if (callInc == 0) { Assert.AreEqual(rq2_clone[0].Run, run); Assert.AreEqual(2, index); Assert.AreEqual(4, length); } else if (callInc == 1) { Assert.AreEqual(rq2_clone[1].Run, run); Assert.AreEqual(0, index); Assert.AreEqual(1, length); } Assert.IsTrue(callInc < 2); callInc++; } ); }
public static void ProcessRemainingQueuedRuns(AddHighlight addHighlightDelegate, RunQueue runQueue, string searchText) { while (runQueue.Count > 0) { runQueue.Dequeue(); ScanQueuedRuns(runQueue, searchText, addHighlightDelegate); } }