private void OnTimer(object sender, EventArgs e) { // any lines to copy in int addedLines = 0; lock (fixGui.Lines) { lock (fixFile.Lines) { while (fixGui.Lines.Count < fixFile.Lines.Count) { LineTag lt = fixFile.Lines[fixGui.Lines.Count]; Line ln = new Line(lt); fixGui.Lines.Add(ln); addedLines++; } } } if (addedLines > 0) { l.Info("Added {0} lines", addedLines); } string state = fixFile.GetStatus(); if (this.Title != state) { this.Title = state; } }
// addTrail - if the message relates to an order, add to the list of // messages for that order private void addTrail(LineTag tag) { // extract relevant order is's (Cloid,OrigCloid) List <String> idents = new List <string>(); if (tag.fields.ContainsKey("11")) // new { idents.Add(tag.fields["11"]); } if (tag.fields.ContainsKey("41")) { idents.Add(tag.fields["41"]); // orig } // if none, nothing to do if (idents.Count == 0) { return; } // See if we can find an existing order trail using orderid's quickIndex // is used to map an order id to an order trail OrderTrail ot = null; foreach (String s in idents) { if (quickIndex.ContainsKey(s)) { // yes - remember it ot = quickIndex[s]; break; } } // no - must be new if (ot == null) { ot = new OrderTrail(); } // add any missing keys to quickindex and point to the order trail foreach (String s in idents) { if (!quickIndex.ContainsKey(s)) { quickIndex[s] = ot; } } // add the new line to the order trail ot.lines.Add(tag); // and point to the order trail from the line tag.orderTrail = ot; }
// Called from main GUI, passes us a line, hide all lines not relevant to the order // and unhide relevant ones using the order trail public void SetOrderFilter(LineTag fl) { // Hide all lines lock (lines) { foreach (LineTag l in lines) { l.hide = true; } } // unhide lines in the order trail foreach (LineTag l in fl.orderTrail.lines) { l.hide = false; } }
// the file reader thread private void readFixFile() { ignoreHB = true; // ignore heartbeats state = "Loading"; // Open file & enter main loop. when running is set to false we will stop StreamReader reader = new StreamReader(new FileStream(fixFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); while (running) { string line = ""; // read all available lines, when we get to the end we will just repeat // until there is more to read while (running && (line = reader.ReadLine()) != null) { lineNumber++; // create a tag for this line, initially it just holds the lines text curTag = new LineTag(line); // parse it splitting it into tag/value pairs, if it parses ok, add it to lines if (parseFix()) { add(curTag); } else { curTag = null; } } // reached end of data, set new state & wait for more to appear state = "Following"; l.Debug("End of block in {0}, size now {1} lines.", fixFile, lastLine); System.Threading.Thread.Sleep(50); // teeny sleep so we dont hog processor } l.Info("MON thread stopped"); running = true; }
// add - adds a line to the line list private void add(LineTag tag) { // extract order type and save seperatly if (tag.fields.ContainsKey("35")) { tag.type = tag.fields["35"]; } // if its a heartbeat and set to ignore them, just return here if (tag.type == "0" && ignoreHB) { return; } // add the line to the lines list. We need to lock the list as it is shared by GUI thread lock (lines) { lines.Add(tag); lastLine++; } // add to order trail addTrail(tag); }
public Line(LineTag tag) { this.tag = tag; }