private void ProcessLot( StationKind currentStation, DataReader <ChocolateLotState> lotStateReader, DataWriter <ChocolateLotState> lotStateWriter) { using var samples = lotStateReader.Take(); foreach (var sample in samples.ValidData()) { // No need to check that this is the next station: content filter // ensures that the reader only receives lots with // next_station == this station Console.WriteLine($"Processing lot #{sample.lot_id}"); // Send an update that the tempering station is processing lot var updatedState = new ChocolateLotState(sample) { lot_status = LotStatusKind.PROCESSING, next_station = StationKind.INVALID_CONTROLLER, station = currentStation }; lotStateWriter.Write(updatedState); // "Processing" the lot. Thread.Sleep(5000); // Send an update that this station is done processing lot updatedState.lot_status = LotStatusKind.COMPLETED; updatedState.station = currentStation; updatedState.next_station = GetNextStation(currentStation); lotStateWriter.Write(updatedState); } }
private static int MonitorLotState(DataReader <ChocolateLotState> reader) { int samplesRead = 0; using var samples = reader.Take(); foreach (var sample in samples) { Console.WriteLine("Received lot update: "); if (sample.Info.ValidData) { Console.WriteLine(sample.Data); samplesRead++; } else { // Detect that a lot is complete by checking for // the disposed state. if (sample.Info.State.Instance == InstanceState.NotAliveDisposed) { // Create a sample to fill in the key values associated // with the instance var keyHolder = new ChocolateLotState(); reader.GetKeyValue(keyHolder, sample.Info.InstanceHandle); Console.WriteLine($"[lot_id: {keyHolder.lot_id} is completed]"); } } } return(samplesRead); }
private static void ProcessLot( DataReader <ChocolateLotState> lotStateReader, DataWriter <ChocolateLotState> lotStateWriter) { using var samples = lotStateReader.Take(); foreach (var sample in samples.ValidData()) { // Exercise #1.3: Remove the check that the Tempering Application is // the next_station. This will now be filtered automatically. if (sample.next_station == StationKind.TEMPERING_CONTROLLER) { Console.WriteLine("Processing lot " + sample.lot_id); // Send an update that the tempering station is processing lot var updatedState = new ChocolateLotState(sample) { lot_status = LotStatusKind.PROCESSING, next_station = StationKind.INVALID_CONTROLLER, station = StationKind.TEMPERING_CONTROLLER }; lotStateWriter.Write(updatedState); // "Processing" the lot. Thread.Sleep(5000); // Since this is the last step in processing, // notify the monitoring application that the lot is complete // using a dispose lotStateWriter.DisposeInstance( lotStateWriter.LookupInstance(updatedState)); Console.WriteLine("Lot completed"); } } }
private void ProcessLot( DataReader <ChocolateLotState> lotStateReader, DataWriter <ChocolateLotState> lotStateWriter) { // Take all samples. Samples are loaned to application, loan is // returned when LoanedSamples is Disposed. ValidData iterates only over // samples such that sample.Info.ValidData is true. using var samples = lotStateReader.Take(); foreach (var sample in samples.ValidData()) { if (sample.next_station == StationKind.TEMPERING_CONTROLLER) { Console.WriteLine("Processing lot #" + sample.lot_id); // Send an update that the tempering station is processing lot var updatedState = new ChocolateLotState(sample) { lot_status = LotStatusKind.PROCESSING, next_station = StationKind.INVALID_CONTROLLER, station = StationKind.TEMPERING_CONTROLLER }; lotStateWriter.Write(updatedState); // "Processing" the lot. Thread.Sleep(5000); // Exercise #3.1: Since this is the last step in processing, // notify the monitoring application that the lot is complete // using a dispose } } }
private void PublishStartLot( DataWriter <ChocolateLotState> writer, uint lotsToProcess) { var sample = new ChocolateLotState(); for (uint count = 0; !shutdownRequested && count < lotsToProcess; count++) { sample.lot_id = count % 100; sample.lot_status = LotStatusKind.WAITING; sample.next_station = StationKind.TEMPERING_CONTROLLER; Console.WriteLine("Starting lot:"); Console.WriteLine($"[lot_id: {sample.lot_id} next_station: {sample.next_station}]"); writer.Write(sample); Thread.Sleep(8000); } }