public ThingBrowser(string thingPropertiesURI) { DataRiver = DataRiver.GetInstance(); // Add listener for discovery of Things CustomDispatcher = new Dispatcher(); NewThingListener = new NewThingDiscoveredListener(DataRiver); DataRiver.AddListener(NewThingListener, CustomDispatcher); Thing = CreateThing(DataRiver, thingPropertiesURI); Stop = false; Console.CancelKeyPress += this.CtrlCHandler; Console.WriteLine("ThingBrowser started"); }
public int Run(ulong runningTime, string barcodeFilePath) { StartTimestamp = DateTime.Now; int barcodeIndex = 0; DateTime barcodeTimestamp = StartTimestamp.AddMilliseconds(-BarcodeIntervalMS); // Get barcodes List <string> barcodes = ReadBarCodes(barcodeFilePath); if (barcodes.Count == 0) { Console.WriteLine("Error: no barcodes found"); return(1); } // Add listener for new Things var cameraDiscoveredListener = new CameraThingDiscoveredListener(this); DataRiver.AddListener(cameraDiscoveredListener); // Add listener for lost Things var cameraLostListener = new CameraThingLostListener(this); DataRiver.AddListener(cameraLostListener); // Check for related camera already in the discovered things registry System.Threading.Thread.Sleep(CameraInitialDelayMS); CheckRegistryForRelatedCameras(); do { var now = DateTime.Now; // Check if next barcode should be read if (barcodeIndex < barcodes.Count && ((now.Subtract(barcodeTimestamp).TotalSeconds * 1000) > BarcodeIntervalMS)) { string barcode = barcodes[barcodeIndex]; barcodeIndex++; // Randomly skip some of the barcodes if (StaticRandom.Rand(0, 100) > BarcodeSkipPercentage) { ParameterizedThreadStart pts = new ParameterizedThreadStart(BarcodeTask); Thread t = new Thread(pts); Threads.Add(t); t.Start(barcode); } // Update timestamp barcodeTimestamp = now; } // Sleep for some time System.Threading.Thread.Sleep(CameraDelayMS); } while (!Stop && SecondsExecuting(StartTimestamp) < runningTime); // Remove listeners DataRiver.RemoveListener(cameraLostListener); DataRiver.RemoveListener(cameraDiscoveredListener); return(0); }