internal override void LogTag(object sender, TagReadEventArgs data) { TagInfo tag = data.TagInfo; binaryWriter.Write(tag.ID.Value); binaryWriter.Write(tag.Time); binaryWriter.Write(tag.SignalStrenth); binaryWriter.Write(tag.Antenna); binaryWriter.Write(tag.Frequency); }
/// <summary> /// A <typeparamref name="TagReadEventArgs.TagMessageDelegate"/> method that is used to /// handle the events and write to the text file. /// </summary> /// <param name="sender">The object that sent the event (also the object that was /// subscribed to).</param> /// <param name="tagInfo">The <typeparamref name="TagReadEventArgs"/> for the current reading.</param> internal override void LogTag(object sender, TagReadEventArgs e) { TagInfo tagInfo = e.TagInfo; ITagEventPublisher network = sender as ITagEventPublisher; if (network != null) { textWriter.WriteLine(" Tag ID: {0} Antenna: {1} Signal Strength: {2} Frequency: {3} Time: {4}", tagInfo.ID.Value, tagInfo.Antenna, tagInfo.SignalStrenth, tagInfo.Frequency, tagInfo.Time); } }
internal override void LogTag(object sender, TagReadEventArgs e) { string tagName = e.TagInfo.ID.Value; if (tagCounts.ContainsKey(tagName)) { tagCounts[tagName] = tagCounts[tagName] + 1; } else { tagCounts.Add(tagName, 1); } }
public void Start(bool useTiming) { try { // Create an instance of StreamReader to read from a file. // The using statement also closes the StreamReader. using (StreamReader sr = new StreamReader(fileName)) { String line; // Read the first line and determine the start time. if (useTiming && (line = sr.ReadLine()) != null) { } // Read lines from the file until the end of // the file is reached. bool firstTag = true; long startTime = 0; while ((line = sr.ReadLine()) != null) { //Console.WriteLine(line); TagInfo tagInfo = lineProcessor.Process(line); TagReadEventArgs e = new TagReadEventArgs(TagEventType.Read, tagInfo); // Read the first line and determine the start time. if (useTiming) { if (firstTag) { firstTag = false; startTime = e.TagInfo.Time; } else { int sleepTime = (int)(e.TagInfo.Time - startTime); System.Threading.Thread.Sleep(sleepTime); } } foreach (NetworkListener listener in listeners) { listener.TestReceivePacket(e); } } } } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } }
public void UpdateRaceStandingsGrid(TagReadEventArgs e) { standingsAreDirty = true; }
public void UpdatePassingsGrid(TagReadEventArgs e, int addIndex = -1) { PassingsInfo pi = null; bool tagClash = false; CompetitorRace cr = null; List<CompetitorRace> crs = FindCompetitorRaceByTag(e.TagInfo.ID); if (crs.Count == 1) cr = crs[0]; else if(crs.Count > 1) tagClash = true; EventEntry eve = null; if (cr == null && !tagClash) { eve = isCompetitorInEventThreadSafe(e.TagInfo.ID); //the following may happen - for example, event entry has IDs of removed competitor; //then we should go as if there is not corresponding event entry if (eve != null) { if (DataManager.Instance.GetCompetitorByID(eve.competitorID) == null) eve = null; } } if (cr != null) { pi = new PassingsInfo(e.TagInfo, cr.competitorID, cr.firstName, cr.lastName, cr.bikeNumber); pi.CompetitorRace = cr; if (addIndex == -1 || addIndex >= cr.passings.Count) cr.passings.Add(pi); else cr.passings.Insert(addIndex, pi); } else if (eve != null) { CompetitorRace crNew = new CompetitorRace(eve.competitorID); //can competitor be null? probably not, as EventEntry is not null crNew.competitor = DataManager.Instance.GetCompetitorByID(eve.competitorID); crNew.EventEntry = eve; crNew.lastName = (crNew.competitor != null) ? crNew.competitor.LastName : ""; crNew.firstName = (crNew.competitor != null) ? crNew.competitor.FirstName : ""; crNew.competitorID = eve.competitorID; crNew.tagID = eve.tagNumber; crNew.tagID2 = eve.tagNumber2; crNew.bikeNumber = eve.bikeNumber; crNew.raceParent = this.GetCurrentSession(); if (currentRace != null)//should never happen { currentRace.competitorRaceList.Add(crNew); crNew.raceParent = currentRace; } pi = new PassingsInfo(e.TagInfo, crNew.competitorID, crNew.firstName, crNew.lastName, crNew.bikeNumber); pi.CompetitorRace = cr;//crNew??? if (addIndex == -1 || addIndex >= cr.passings.Count || addIndex >= crNew.passings.Count)// crNew.passings.Add(pi); else crNew.passings.Insert(addIndex, pi); } else { //have to create a new CompetitorRace: cr = new CompetitorRace(); cr.isNull = true; //make its competitor's ID negative: //this will prevent possible clash with real //competitors' IDs cr.competitorID = -1 * DataManager.getNextID(); cr.tagID = e.TagInfo.ID; cr.tagID2 = e.TagInfo.ID; cr.firstName = ""; cr.lastName = "Unassigned"; if (currentRace != null)//should never happen { //currentRace.competitorRaceList is the currentRaceList currentRace.competitorRaceList.Add(cr); cr.raceParent = currentRace; } pi = new PassingsInfo(e.TagInfo, cr.competitorID, cr.firstName, cr.lastName, cr.bikeNumber); pi.CompetitorRace = cr; if (addIndex == -1 || addIndex >= cr.passings.Count) cr.passings.Add(pi); else cr.passings.Insert(addIndex, pi); } if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate { if (addIndex == -1 || addIndex >= cr.passings.Count || addIndex >= (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Count) (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Add(pi); else (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Insert(addIndex, pi); if (passingsDataGrid.RowCount > 0 && !passingsGridScrolled) { passingsDataGrid.Rows[passingsDataGrid.RowCount - 1].Selected = true; passingsDataGrid.CurrentCell = passingsDataGrid.Rows[passingsDataGrid.RowCount - 1].Cells[0]; } }); } else { if (addIndex == -1 || addIndex >= cr.passings.Count || addIndex >= (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Count) (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Add(pi); else (passingsDataGrid.DataSource as BindingList<PassingsInfo>).Insert(addIndex, pi); if (passingsDataGrid.RowCount > 0 && !passingsGridScrolled) { passingsDataGrid.Rows[passingsDataGrid.RowCount - 1].Selected = true; passingsDataGrid.CurrentCell = passingsDataGrid.Rows[passingsDataGrid.RowCount - 1].Cells[0]; } } if (tagClash) { //TODO: after the user has selected the Competitor, this should remain for the whole //run; need some kind of Dictionary for that; it should be looked up first in //the method findCRbyTag; //also, don't forget to reset everything for a new run; for instance, tagClashFormList if (!tagClashFormList.Contains(pi.ID)) { List<CompetitorRace> crsNew = new List<CompetitorRace>(); foreach (CompetitorRace cRace in crs) { if (cRace.competitorID >= 0)//don't need "Unassigned" CRs crsNew.Add(cRace); } if (crsNew.Count > 1) { tagClashFormList.Add(pi.ID); TagClashForm clashForm = new TagClashForm(); clashForm.SetCompetitors(crsNew, pi, tagClashFormList, currentRace, passingsDataGrid, disambiuationCRDict); clashForm.Show(this); } } } //check if pi.lapTime is smaller than min lap time, make it "DELETED" if true if (pi != null && pi.CompetitorRace != null) { if (pi.CompetitorRace.passings != null && pi.CompetitorRace.passings.Count > 1) { PassingsInfo piPrevious = null; //look for any previous valid passings for (int i = pi.CompetitorRace.passings.Count - 2; i >= 0; i--) { if (!pi.CompetitorRace.passings[i].Deleted.Equals("DELETED")) { piPrevious = pi.CompetitorRace.passings[i]; break; } } if (piPrevious != null) { long latestTime = pi.Time; long nextToLatestTime = piPrevious.Time; double lapTime = (latestTime - nextToLatestTime) / 1000.0; if (lapTime < DataManager.Instance.MinimumLapTime) { pi.Deleted = "DELETED"; pi.LapTime = GetTimeString(lapTime); } } } } }
private void LogPassings(TagReadEventArgs e) { if (binaryLogger == null) { try { CreateBinLogger(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); DataManager.Log(ex.StackTrace); } } #if !V15 if (DataManager.Instance.ValidTags.ContainsKey(e.TagInfo.ID.Value)) { DataManager.Instance.MarkTagAsUsed(e.TagInfo.ID); #endif passingsQueue.Put(e.TagInfo); this.SuspendLayout(); if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate { UpdatePassingsGrid(e); }); } else { UpdatePassingsGrid(e); } if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate { UpdateRaceStandingsGrid(e); }); } else { UpdateRaceStandingsGrid(e); } this.ResumeLayout(); } #if !V15 }
private void LogReadings(TagReadEventArgs e) { readingsQueue.Put(e.TagInfo); }
private void addPassingButton_Click(object sender, EventArgs e) { long existingTime = 1; int index = -1; if (passingsDataGrid.SelectedRows.Count != 0) { index = passingsDataGrid.SelectedRows[0].Index; PassingsInfo pi = (passingsDataGrid.DataSource as BindingList<PassingsInfo>)[index]; existingTime = pi.Time + 1;//- 1; } Form addPassingDialog = new Form(); addPassingDialog.Text = "Add a new passing"; //addPassingDialog.Width = 300; //addPassingDialog.Height = 150; Button okButton = new Button(); Button cancelButton = new Button(); TextBox tagTextBox = new TextBox(); Label tagLabel = new Label(); tagLabel.Text = "TagID"; okButton.Text = "OK"; cancelButton.Text = "Cancel"; okButton.DialogResult = System.Windows.Forms.DialogResult.OK; cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; addPassingDialog.Width = 400; addPassingDialog.Height = 135; okButton.SetBounds(30, 70, 125, 22); cancelButton.SetBounds(160, 70, 120, 22); tagLabel.SetBounds(30, 20, 50, 22); tagTextBox.SetBounds(85, 20, 196, 22); addPassingDialog.Controls.Add(okButton); addPassingDialog.Controls.Add(cancelButton); addPassingDialog.Controls.Add(tagTextBox); addPassingDialog.Controls.Add(tagLabel); addPassingDialog.CancelButton = cancelButton; if (addPassingDialog.ShowDialog() == DialogResult.OK) { TagId tagID = new TagId(tagTextBox.Text); TagInfo ti = new TagInfo(tagID, 0, 0, 0, existingTime); TagReadEventArgs newTagArgs = new TagReadEventArgs(TagEventType.NewTagDetected, ti); if (index != -1) index += 1; UpdatePassingsGrid(newTagArgs, index); UpdateRaceStandingsGrid(newTagArgs); } addPassingDialog.Dispose(); }
internal override void LogTag(object sender, TagReadEventArgs tagInfo) { logCommand(tagInfo); }
internal void LogTag(object sender, TagReadEventArgs tagInfo) { NetworkListener network = sender as NetworkListener; if (network != null) tagRecords.Add(tagInfo); }
/// <summary> /// A dummy test stub that when passed a <typeparamref name="TagReadEventArgs"/> fires /// the TagDetected event. It also checks for any new tags and fires the TagAdded event /// if one is found. /// </summary> /// <param name="tagInfo">The <typeparamref name="TagReadEventArgs"/> with the reading information /// to propogate.</param> internal void TestReceivePacket(TagReadEventArgs e) { TagInfo tagInfo = e.TagInfo; if (!registeredTags.Contains(tagInfo.ID)) { registeredTags.Add(tagInfo.ID); TagAdded(this, tagInfo.ID); } TagDetected(this, e); }
private void LogTagController(object sender, TagReadEventArgs tagInfo) { Count++; LogTag(sender, tagInfo); }
/// <summary> /// A <typeparamref name="TagReadEventArgs.TagMessageDelegate"/> method that is used to /// handle the events. /// </summary> /// <param name="sender">The object that sent the event (also the object that was /// subscribed to).</param> /// <param name="tagInfo">The <typeparamref name="TagReadEventArgs"/> for the current reading.</param> internal abstract void LogTag(object sender, TagReadEventArgs tagInfo);
private void addPassingButton_Click(object sender, EventArgs e) { if(raceInformationControl.GetCurrentRace() == null) { MessageBox.Show("Please select a race in the Race Info tab first!"); return; } long existingTime = 1; int index = -1; if (passingsDataGrid.SelectedRows.Count != 0) { index = passingsDataGrid.SelectedRows[0].Index; PassingsInfo pi = (passingsDataGrid.DataSource as BindingList<PassingsInfo>)[index]; existingTime = pi.Time + 1;//- 1; } CompetitorRace selectedCR = null; if (competitorRaceDataGrid.SelectedRows != null && competitorRaceDataGrid.SelectedRows.Count > 0) { int crIndex = competitorRaceDataGrid.SelectedRows[0].Index; selectedCR = (competitorRaceDataGrid.DataSource as SortableBindingList<CompetitorRace>)[crIndex]; } Form addPassingDialog = new Form(); addPassingDialog.Text = "Add a new passing"; Button okButton = new Button(); Button cancelButton = new Button(); TextBox tagTextBox = new TextBox(); Label tagLabel = new Label(); tagLabel.Text = "TagID"; okButton.Text = "OK"; cancelButton.Text = "Cancel"; okButton.DialogResult = System.Windows.Forms.DialogResult.OK; cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; addPassingDialog.Width = 400; addPassingDialog.Height = 135; okButton.SetBounds(30, 70, 125, 22); cancelButton.SetBounds(160, 70, 120, 22); tagLabel.SetBounds(30, 20, 50, 22); tagTextBox.SetBounds(85, 20, 196, 22); addPassingDialog.Controls.Add(okButton); addPassingDialog.Controls.Add(cancelButton); addPassingDialog.Controls.Add(tagTextBox); addPassingDialog.Controls.Add(tagLabel); addPassingDialog.CancelButton = cancelButton; if (addPassingDialog.ShowDialog() == DialogResult.OK) { TagId tagID = new TagId(tagTextBox.Text); TagInfo ti = new TagInfo(tagID, 0, 0, 0, existingTime); TagReadEventArgs newTagArgs = new TagReadEventArgs(TagEventType.NewTagDetected, ti); if (index != -1) index += 1; raceInformationControl.UpdatePassingsGrid(newTagArgs, index); raceInformationControl.UpdateRaceStandingsGrid(newTagArgs); SelectCompetitorRace(selectedCR); } addPassingDialog.Dispose(); }
private void ProcessPassingTimes(List<TagInfo> passingTimes) { // Create TagInfo with the new calculated passing time. TagInfo tagInfo = passingStrategy.HandlePassing(passingTimes); TagReadEventArgs tagEvent = new TagReadEventArgs(TagEventType.PassDetermined, tagInfo); TagDetected(this, tagEvent); }
/// <summary> /// Register a new Tag to listen for. /// </summary> /// <param name="tagId">The <typeparamref name="TagId"/> of the new Tag.</param> /// <remarks>If the tag already exists or is registered, no error is generated, /// but it may be logged.</remarks> //public void AddTag(TagId tagId) //{ //} /// <summary> /// A Handler to listen for a new Tag event. /// </summary> /// <param name="sender">The object instance that fired the event.</param> /// <param name="tagId">The <typeparamref name="TagId"/> of the new Tag.</param> /// <remarks>If the tag already exists or is registered, no error is generated, /// but it may be logged.</remarks> //internal void AddTagHandler(object sender, TagId tagId) //{ // AddTag(tagId); //} /// <summary> /// A handler for the TagDetected events. /// </summary> /// <param name="sender">The object instance that fired the event.</param> /// <param name="tagId">The <typeparamref name="TagId"/> of the detected Tag.</param> /// <remarks>If the Tag has not been registered, then the detection will be ignored.</remarks> internal void TagDetectedHandler(object sender, TagReadEventArgs e) { TagInfo tagInfo = e.TagInfo; // TODO: Should we make sure the Tag is registered here? readingsQueue.Put(tagInfo); }
// Wrap the tag into a TagReadEventArgs and fire it. private void SendTag(TagInfo tagInfo) { TagReadEventArgs e = new TagReadEventArgs(TagEventType.Read, tagInfo); TagDetected(this, e); }