private void ProcessLot(
            DataReader <ChocolateLotState> lotStateReader,
            DataWriter <ChocolateLotState> lotStateWriter)
        {
            using var samples = lotStateReader.Take();
            foreach (var sample in samples.ValidData)
            {
                if (sample.GetInt32Value("next_station") ==
                    types.StationKind.GetMember("TEMPERING_CONTROLLER").Ordinal)
                {
                    uint lotId = sample.GetUInt32Value("lot_id");
                    Console.WriteLine($"Processing lot #{lotId}");

                    // Send an update that the tempering station is processing lot
                    var updatedState = lotStateWriter.CreateData();
                    updatedState.SetValue("lot_id", lotId);
                    updatedState.SetAnyValue("lot_status", "PROCESSING");
                    updatedState.SetAnyValue("next_station", "INVALID_CONTROLLER");
                    updatedState.SetAnyValue("station", "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
                    var instanceHandle = lotStateWriter.LookupInstance(updatedState);
                    lotStateWriter.DisposeInstance(instanceHandle);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Publishes the data
        /// </summary>
        public void Run(int sampleCount)
        {
            var sample = new HelloWorld();

            for (int count = 0; count < sampleCount && continueRunning; count++)
            {
                // Modify the data to be sent here
                sample.message = $"Hello {count}";

                Console.WriteLine($"Writing HelloWorld, count {count}");

                InstanceHandle instanceHandle = writer.RegisterInstance(sample);
                writer.Write(sample, instanceHandle);

                Thread.Sleep(1000);

                if (count % 2 == 0)
                {
                    Console.WriteLine("Unregistering the instance");
                    writer.UnregisterInstance(instanceHandle);
                }
                else if (count % 3 == 0)
                {
                    Console.WriteLine("Disposing the instance");
                    writer.DisposeInstance(instanceHandle);
                }

                var status = writer.DataWriterCacheStatus;
                Console.WriteLine("Instance statistics: ");
                Console.WriteLine($"  * Alive instance count:        {status.AliveInstanceCount}");
                Console.WriteLine($"  * Unregistered instance count: {status.UnregisteredInstanceCount}");
                Console.WriteLine($"  * Disposed instance count:     {status.DisposedInstanceCount}");
            }
        }
        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);

                    // Since this is the last step in processing,
                    // notify the monitoring application that the lot is complete
                    // using a dispose
                    var instanceHandle = lotStateWriter.LookupInstance(updatedState);
                    lotStateWriter.DisposeInstance(instanceHandle);
                }
            }
        }