public async Task <string> CancelOrderAsync(string reason) { // This line creates a [SignalRequest] instance that somewhat // magically initializes the [SignalRequest.Args] dictionary // with the names and values of the parameters passed to this // method. // // Note that the <string> generic parameter here specifies the // result type for this signal method. var signalRequest = new SignalRequest <string>(); // Enqueue the signal request such that workflow method above // can process it as part of the workflow logic. await queue.EnqueueAsync(signalRequest); // Throwing this exception indicates to the Cadence client // that the signal result will be sent as a reply from // the workflow code via the [SignalRequest] rather than // via a result returned by this signal method. // // We understand that this is a bit odd, but this is an // experimental feature after all. The Cadence team is // working on a new feature to handle these scenarios // cleanly. throw new WaitForSignalReplyException(); }
public async Task <string> SignalResultAsync(string name) { var signalRequest = new SignalRequest <string>(); await resultQueue.EnqueueAsync(signalRequest); throw new WaitForSignalReplyException(); }
public async Task SignalVoidAsync(string name) { var signalRequest = new SignalRequest(); await voidQueue.EnqueueAsync(signalRequest); throw new WaitForSignalReplyException(); }
public async Task SendAsync(SignalRequest request) { if (connection.State != ConnectionState.Connected) { await connection.Start(); } await hub.Invoke("Send", request); }
public void Send(SignalRequest request) { if (connection.State != ConnectionState.Connected) { connection.Start().Wait(); } hub.Invoke("Send", request).Wait(); }
// Methods :: Private :: HandleSignalRequest private void HandleSignalRequest(SignalRequest rq) { lock (this) { if (rq.Song.Dead) { return; } // Song if (rq.SongAdded) { EmitSongAdded(rq.Song); } else if (rq.SongChanged) { EmitSongChanged(rq.Song); } else if (rq.SongRemoved) { EmitSongRemoved(rq.Song); rq.Song.Deregister(); } // Albums if (rq.AddedAlbum != null) { EmitAlbumAdded(rq.AddedAlbum); } if (rq.RemovedAlbum != null) { EmitAlbumRemoved(rq.RemovedAlbum); rq.RemovedAlbum.Deregister(); } if (rq.AddChangedAlbum != null) { EmitAlbumChanged(rq.AddChangedAlbum); if (rq.AlbumSongsChanged) { foreach (Song s in rq.AddChangedAlbum.Songs) { EmitSongChanged(s); } } } if (rq.RemoveChangedAlbum != null) { EmitAlbumChanged(rq.RemoveChangedAlbum); } } }
// Delegate Functions // Delegate Functions :: MainLoopIdle (ThreadBase) protected override bool MainLoopIdle() { if (queue.Count == 0) { return(!thread_done); } SignalRequest rq = (SignalRequest)queue.Dequeue(); Global.DB.HandleSignalRequest(rq); return(true); }
private void StartAddToAlbum(SignalRequest rq, Song s) { bool from_db = (s != null); Song song = (from_db) ? s : rq.Song; if (!song.HasAlbum) { return; } string key = song.AlbumKey; Album album = (Album)Albums [key]; bool changed = false; bool added = false; bool songs_changed = false; if (album == null) { album = new Album(song, !from_db); Albums.Add(key, album); added = true; } else { album.Add(song, !from_db, out changed, out songs_changed); } if (from_db) { return; } if (added) { rq.AddedAlbum = album; } else if (changed) { rq.AddChangedAlbum = album; } rq.AlbumSongsChanged = songs_changed; }
// Methods :: Private :: StartRemoveSong private SignalRequest StartRemoveSong(Song song) { lock (this) { if (song.Dead) { throw new InvalidOperationException(); } SignalRequest rq = new SignalRequest(song); db.Delete(song.Filename); Songs.Remove(rq.Song.Filename); StartRemoveFromAlbum(rq); rq.SongRemoved = true; return(rq); } }
public Pipeline createPipeline(Pipeline pipeline) { JavaScriptSerializer javascript = new JavaScriptSerializer(); PipelineRequest pipelineRequest = new PipelineRequest(); List <Signal> signalList = new List <Signal>(); List <SignalRequest> signalRequestList = new List <SignalRequest>(); int len_input_list = pipeline.inputList.Count; signalList = pipeline.inputList; for (int i = 0; i < len_input_list; i++) { SignalRequest signalRequest = new SignalRequest(); signalRequest.name = (signalList[i].name); signalRequest.eventType = (signalList[i].eventType); signalRequest.valueType = (signalList[i].valueType); signalRequestList.Add(signalRequest); } int len_assessment_list = pipeline.assessmentList.Count; List <Assessment> assessmentList = pipeline.assessmentList; List <AssessmentRequest> assessmentRequestList = new List <AssessmentRequest>(); for (int i = 0; i < len_assessment_list; i++) { AssessmentRequest assessmentRequest = new AssessmentRequest(); assessmentRequest.name = (assessmentList[i].name); assessmentRequest.inputList = (assessmentList[i].inputList); assessmentRequest.aprioriConditionList = (assessmentList[i].aprioriConditionList); assessmentRequestList.Add(assessmentRequest); } pipelineRequest.name = pipeline.name; pipelineRequest.interval = pipeline.interval; pipelineRequest.input = pipeline.input; pipelineRequest.inputList = signalRequestList; pipelineRequest.assessmentList = assessmentRequestList; string data = javascript.Serialize(pipelineRequest); string pipeline_json = http.post("/pipeline", data); return(javascript.Deserialize <Pipeline>(pipeline_json)); }
// Methods :: Private :: StartSyncSong private SignalRequest StartSyncSong(Song song, Metadata metadata) { lock (this) { if (song.Dead) { throw new InvalidOperationException(); } SignalRequest rq = new SignalRequest(song); StartRemoveFromAlbum(rq); song.Sync(metadata); StartAddToAlbum(rq); SaveSongInternal(song, true); rq.SongChanged = true; return(rq); } }
// Delegate Functions :: MainLoopIdle protected override bool MainLoopIdle() { if (queue.Count == 0) { if (thread_done) { pw.Done(); return(false); } return(true); } SignalRequest rq = (SignalRequest)queue.Dequeue(); canceled_box.Value = pw.Report(current_folder.Name, Path.GetFileName(rq.Song.Filename)); Global.DB.HandleSignalRequest(rq); return(true); }
// Methods :: Private // Methods :: Private :: StartAddSong private SignalRequest StartAddSong(Song song) { lock (this) { SignalRequest rq = new SignalRequest(song); try { Songs.Add(song.Filename, song); } catch (ArgumentException) { // already exists throw new InvalidOperationException(); } StartAddToAlbum(rq); // Store after the album cover has been stored, // in case of unexpected exit SaveSongInternal(song, false); rq.SongAdded = true; return(rq); } }
public async Task SendNewInitiator(SignalRequest peer) { Console.WriteLine($"\nSendNewInitiator: ${peer.Sender}\n"); await Clients.Client(peer.Receiver).ReceiveNewInitiator(peer); }
// Delegate Functions :: ThreadFunc (ThreadBase) protected override void ThreadFunc() { Hashtable snapshot; lock (Global.DB) snapshot = (Hashtable)Global.DB.Songs.Clone(); // Check for removed songs and changes foreach (string file in snapshot.Keys) { FileInfo finfo = new FileInfo(file); Song song = (Song)snapshot [file]; SignalRequest rq = null; if (!finfo.Exists) { rq = Global.DB.StartRemoveSong(song); } else { long ticks = FileUtils.MTimeToTicks(song.MTime); if (ticks < finfo.LastWriteTimeUtc.Ticks) { try { Metadata metadata = new Metadata(song.Filename); rq = Global.DB.StartSyncSong(song, metadata); } catch { try { rq = Global.DB.StartRemoveSong(song); } catch (InvalidOperationException) { } } } } if (rq == null) { continue; } queue.Enqueue(rq); } // Check for new songs foreach (string folder in Global.DB.WatchedFolders) { DirectoryInfo dinfo = new DirectoryInfo(folder); if (!dinfo.Exists) { continue; } BooleanBox canceled = new BooleanBox(false); Global.DB.HandleDirectory(dinfo, queue, canceled); } thread_done = true; }
// Methods :: Private :: StartAddToAlbum private void StartAddToAlbum(SignalRequest rq) { StartAddToAlbum(rq, null); }