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); } }
/// <summary> /// 放送局のコンストラクタ /// </summary> /// <param name="id">放送局のID</param> /// <param name="name">放送局の名前</param> /// <param name="stationKind">放送局の種類</param> /// <param name="url">放送局のURL</param> public Station(string id, string name, StationKind stationKind, Uri url) { this.id = id; this.name = name; this.kind = stationKind; if (kind.Equals(StationKind.RssPodcast)) { globalHeadline = new PodcasCo.Stations.RssPodcast.Headline(id + "-global", this); globalHeadline.SetUrl(url); localHeadline = new PodcasCo.Stations.RssPodcast.Headline(id + "-local", this); localHeadline.SetUrl(new Uri(UserSetting.PodcastClipDirectoryPath + @"\" + localHeadline.GetId() + @"\" + PodcasCoInfo.LocalRssFile)); localHeadline.FetchHeadline(); /* * 放送局の名前を得る(URLがNotFoundや、存在してもRSSで無いっぽい場合は例外が投げられるため * 以下の設定保存は実行されない) */ FetchName(); localHeadline.SaveSetting(); globalHeadline.SaveSetting(); } else { // ここには到達しない Trace.Assert(false, "想定外の動作のため、終了します"); } }
/// <summary> /// 放送局のコンストラクタ /// </summary> /// <param name="id">放送局のID</param> /// <param name="name">放送局の名前</param> /// <param name="stationKind">放送局の種類</param> public Station(string id, string name, StationKind stationKind) { this.id = id; this.name = name; this.kind = stationKind; if (kind.Equals(StationKind.RssPodcast)) { globalHeadline = new PodcasCo.Stations.RssPodcast.Headline(id + "-global", this); localHeadline = new PodcasCo.Stations.RssPodcast.Headline(id + "-local", this); localHeadline.FetchHeadline(); } else { // ここには到達しない Trace.Assert(false, "想定外の動作のため、終了します"); } }
private StationKind GetNextStation(StationKind currentStation) => nextStation[currentStation];