void scanner_RawFrameIn(object sender, Scanner.RawFrameEventArgs e) { if (SequenceRecording && e.FrameID % SequenceInterval == 0) { string path = WorkingDirectory + '\\' + SequenceLabel + '_' + SequenceCounter.ToString("D5"); switch (e.FrameType) { case Scanner.FrameTypes.Depth: SetSequenceCounter(SequenceCounter + 1); path += ".rwd"; break; case Scanner.FrameTypes.Color: path += ".rwc"; break; } SequenceTasks.Enqueue(new SequenceTask() { Data = e.Data, FileName = path }); for (int i = 0; i < SaveAREs.Length; i++) { SaveAREs[i].Set(); } } }
private bool SetupQuestPhases(string phaseLine) { string[] mainParts = phaseLine.Split(':'); if (mainParts.Length != 2 || mainParts[0] != "Quests") { return(false); } _ambassador.SequenceCounters = new List <SequenceCounter>(); string[] itemParts = mainParts[1].Split('|'); foreach (string current in itemParts) { string[] sequenceParts = current.Split(','); string[] phaseParts = sequenceParts[0].Split('>'); int phaseProgress = Convert.ToInt32(phaseParts[1]); string[] detailParts = sequenceParts[1].Split('>'); SequenceCounter newCounter = new SequenceCounter { Name = phaseParts[0], Phase = phaseProgress, QuestTitle = detailParts[0], QuestDetails = detailParts[1] }; _ambassador.SequenceCounters.Add(newCounter); } return(true); }
public async Task ExecuteAsync(GenerateNextNumberCommand command, IExecutionContext executionContext) { using (var scope = TransactionScopeManager.Create(DbContext)) { // Lock this counter to avoid concurrent requests both getting a read of the same counter value // - It may though fail the very first time when the counter doesn't exist yet. I'll live with that. string tableName = DbConstants.DefaultAppSchema + ".SequenceCounter"; await DbContext.Database.ExecuteSqlRawAsync($"SELECT TOP 1 * FROM {tableName} WITH(HOLDLOCK,UPDLOCK) WHERE [Name] = {{0}} ", command.CounterName); SequenceCounter counter = await DbContext.Counters.FindAsync(command.CounterName); if (counter == null) { counter = new SequenceCounter { Name = command.CounterName, Counter = 1 }; await DbContext.Counters.AddAsync(counter); } else { counter.Counter++; } command.OutputValue = counter.Counter; await DbContext.SaveChangesAsync(); await scope.CompleteAsync(); } }
public void DualCounterTest() { string filePath = "c:\\temp\\test"; DocCounter docCounter = new DocCounter(filePath); SequenceCounter sequenceCounter = new SequenceCounter(filePath); docCounter.Reset(); sequenceCounter.Reset(); long docCount = docCounter.Get(); Assert.AreEqual(0, docCount); docCount = docCounter.Next(); Assert.AreEqual(1, docCount); long sequenceCount = sequenceCounter.Get(); Assert.AreEqual(0, sequenceCount); sequenceCount = sequenceCounter.Next(); Assert.AreEqual(1, sequenceCount); docCounter.Close(); docCounter = new DocCounter(filePath); docCount = docCounter.Get(); Assert.AreEqual(1, docCount); }
public bool CheckThreadProgress(string name, int progress) { SequenceCounter arg = new SequenceCounter { Name = name, Phase = progress }; return(CheckThreadProgress(arg)); }
public void Test_increment_IncrementsTheCounter() { SequenceCounter counter = new SequenceCounter(); Assert.Equal("0", counter.AsString()); counter.Increment(); Assert.Equal("1", counter.AsString()); counter.Increment(); Assert.Equal("2", counter.AsString()); }
internal void EndParallelSequence(bool endAllParallelSequencesAndContinueNumbering) { if (endAllParallelSequencesAndContinueNumbering) { int sequence = _counter.Sequence; _counter = _counter.Parent; _counter.Sequence = sequence; } else { _counter = _counter.Parent; } }
public void Test_counter_WhenThereIsOneParent() { SequenceCounter parent = new SequenceCounter(); parent.Increment(); Assert.AreEqual("1", parent.AsString()); SequenceCounter child = new SequenceCounter(parent); child.Increment(); Assert.AreEqual("1.1", child.AsString()); child.Increment(); Assert.AreEqual("1.2", child.AsString()); }
public bool CheckThreadProgress(SequenceCounter requiredCounter) { SequenceCounter counter = SequenceCounters.FirstOrDefault(c => c.Name == requiredCounter.Name); if(counter == default(SequenceCounter)) { if(DebugMode) Debug.LogWarning("Could not find quest thread " + name + "; definently NOT on that quest!"); return false; } bool correctProgress = counter.Phase == requiredCounter.Phase; if(DebugMode) Debug.Log("The player " + (correctProgress ? "has" : "does not have") + " the right progress for quest " + name); return correctProgress; }
internal SequenceCounter Clone() { SequenceCounter counter; if (Parent == null) { counter = new SequenceCounter(); } else { counter = new SequenceCounter(Parent.Clone()); } counter.Sequence = Sequence; return(counter); }
internal NetTraffic(long creationTime) { this.payloadLoss = new SequenceCounter(true); this.payloadDrop = new SequenceCounter(false); this.outgoingPing = new PingCounter(); this.pingWindow = new int[NetConfig.PING_SMOOTHING_WINDOW]; this.creationTime = creationTime; this.lastPayloadSeq = ushort.MaxValue; // "-1" this.notificationAck = 0; this.pingWindowIndex = 0; this.lastPacketRecvTime = creationTime; this.lastPayloadRecvTime = creationTime; this.lastNotificationRecvTime = creationTime; this.lastPongRecvTime = creationTime; for (int i = 0; i < this.pingWindow.Length; i++) this.pingWindow[i] = -1; }
public void Test_counter_WhenThereAreTwoParents() { SequenceCounter parent = new SequenceCounter(); parent.Increment(); Assert.AreEqual("1", parent.AsString()); SequenceCounter child = new SequenceCounter(parent); child.Increment(); Assert.AreEqual("1.1", child.AsString()); SequenceCounter grandchild = new SequenceCounter(child); grandchild.Increment(); Assert.AreEqual("1.1.1", grandchild.AsString()); grandchild.Increment(); Assert.AreEqual("1.1.2", grandchild.AsString()); }
private void ResetPhases() { _ambassador.SequenceCounters = new List <SequenceCounter>(); SequenceCounter main = new SequenceCounter { Name = "Main", Phase = 0, QuestTitle = "Main Quest", QuestDetails = "Talk to King Aylea XXXIII" }; SequenceCounter side = new SequenceCounter { Name = "Goldensage", Phase = 0, QuestTitle = "Side Quest", QuestDetails = "Talk to everyone to find the side quest." }; _ambassador.SequenceCounters.Add(main); _ambassador.SequenceCounters.Add(side); }
public int GetNextCounterId(string sequenceKey) { int i = 1; SequenceCounter model = DapperUtil.Query <SequenceCounter>("ComBeziCommon_SequenceCounter_Read", new { SequenceKey = sequenceKey }).FirstOrDefault(); if (model == null) { SequenceCounter sc = new SequenceCounter(); sc.SequenceKey = sequenceKey; sc.CounterId = i; DapperUtil.Insert <SequenceCounter>(sc, false);//true 返回插入数据的主键,false则不返回 } else { i = model.CounterId; model.CounterId = i + 1; model.SequenceKey = sequenceKey; DapperUtil.Update(model); } return(i); }
internal NetTraffic(long creationTime) { payloadLoss = new SequenceCounter(true); payloadDrop = new SequenceCounter(false); outgoingPing = new PingCounter(); pingWindow = new int[NetConfig.PING_SMOOTHING_WINDOW]; this.creationTime = creationTime; lastPayloadSeq = ushort.MaxValue; // "-1" notificationAck = 0; pingWindowIndex = 0; lastPacketRecvTime = creationTime; lastPayloadRecvTime = creationTime; lastNotificationRecvTime = creationTime; lastPongRecvTime = creationTime; for (int i = 0; i < pingWindow.Length; i++) { pingWindow[i] = -1; } }
public void SequenceCounterTest() { string filePath = "c:\\temp\\test"; SequenceCounter counter = new SequenceCounter(filePath); counter.Reset(); long count = counter.Get(); Assert.AreEqual(0, count); count = counter.Next(); Assert.AreEqual(1, count); count = counter.Next(); Assert.AreEqual(2, count); counter.Close(); counter = null; counter = new SequenceCounter(filePath); count = counter.Get(); Assert.AreEqual(2, count); }
public bool CheckThreadProgress(SequenceCounter requiredCounter) { SequenceCounter counter = SequenceCounters.FirstOrDefault(c => c.Name == requiredCounter.Name); if (counter == default(SequenceCounter)) { if (DebugMode) { Debug.LogWarning("Could not find quest thread " + name + "; definently NOT on that quest!"); } return(false); } bool correctProgress = counter.Phase == requiredCounter.Phase; if (DebugMode) { Debug.Log("The player " + (correctProgress ? "has" : "does not have") + " the right progress for quest " + name); } return(correctProgress); }
public void UpdateThread(string name, int progress, string questName = "", string questDetail = "") { SequenceCounter counter = SequenceCounters.FirstOrDefault(c => c.Name == name); if (counter == default(SequenceCounter)) { if (DebugMode) { Debug.LogWarning("Could not find Quest Thread " + name); } return; } if (DebugMode) { Debug.Log("Updating Quest Thread " + name + " to progress Lv." + progress); } counter.Phase = progress; counter.QuestTitle = questName; counter.QuestDetails = questDetail; }
private string FormatPhaseLine() { StringBuilder builder = new StringBuilder("Quests:"); // Format of line: // Quests:A>n,T>d|B>n,T>d|C>n,T>d for (int i = 0; i < _ambassador.SequenceCounters.Count; i++) { SequenceCounter current = _ambassador.SequenceCounters[i]; if (DebugMode) { Debug.Log("Serializing Sequence Counter #" + i + Environment.NewLine + current.ToString()); } builder.Append(current.Name); builder.Append(">"); builder.Append(current.Phase); builder.Append(","); builder.Append(current.QuestTitle); builder.Append(">"); builder.Append(current.QuestDetails); if (i < _ambassador.SequenceCounters.Count - 1) { builder.Append("|"); } } if (DebugMode) { Debug.Log("Resulting phsae line:" + builder.ToString()); } return(builder.ToString()); }
internal void StartChildSequence() { _counter = new SequenceCounter(_counter); }
public bool CheckThreadProgress(string name, int progress) { SequenceCounter arg = new SequenceCounter{ Name = name, Phase = progress }; return CheckThreadProgress(arg); }
internal ParallelSequenceCounter(SequenceCounter parent) : base(parent) { Sequence = Parent.Sequence; }
public bool EligibleForUse(SequenceCounter phase) { return(phase.Name == RequiredPhase.Name && phase.Phase == RequiredPhase.Phase); }
internal SequenceCounter(SequenceCounter parent) { Parent = parent; }
public bool EligibleForUse(SequenceCounter phase) { return phase.Name == RequiredPhase.Name && phase.Phase == RequiredPhase.Phase; }
internal void EndParallelSequence() { _counter = ((ParallelSequenceCounter)_counter).Root; }
internal void StartParallelSequence() { _counter = new ParallelSequenceCounter(_counter); }
internal ParallelSequenceCounter(SequenceCounter parent) : base(parent) { Root = parent.Clone(); Sequence = Parent.Sequence; }
internal void EndChildSequence() { _counter = _counter.Parent; }