/// <summary> /// Executes the command publication. /// </summary> /// <param name="command">The command.</param> private void executeCommandPublication(Command command) { PublicationArgs args = ((PublicationArgs)command.Args); if (args.Text == "" && args.Publication == null) { } else if ((args.Publication == null) && (args.Text != "")) { } }
static void Main(string[] args) { parseParse(File.ReadAllText(@"C:\shuffly\Shuffly-Brain\papa.txt")); string channel = "/consolepublisher"; Console.WriteLine("Initializing..."); Client client = new Client(new ClientArgs { // replace with your domain key DomainKey = "035d9877-9eaf-45ef-936f-80087fb3a221", // replace with your domain name DomainName = "localhost", Synchronous = true }); Publisher publisher = new Publisher(new PublisherArgs { // replace with your domain key DomainKey = "035d9877-9eaf-45ef-936f-80087fb3a221", // replace with your domain name DomainName = "localhost", Synchronous = true }); client.Connect(new ConnectArgs { OnSuccess = (successArgs) => { Console.WriteLine("The client connected and has ID " + successArgs.ClientId + "."); }, OnFailure = (failureArgs) => { Console.WriteLine("The client could not connect... " + failureArgs.Exception.Message); }, OnStreamFailure = (streamFailureArgs) => { Console.WriteLine("The client could not stream... " + streamFailureArgs.Exception.Message); Console.WriteLine("The client " + (streamFailureArgs.WillReconnect ? "will" : "will not") + " automatically reconnect." + Environment.NewLine); } }); // client is configured as "synchronous", so this // won't execute until the connect method is complete if (client.State != ClientState.Connected) { Console.WriteLine(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); return; } Console.WriteLine("Connected"); client.Subscribe(new SubscribeArgs { Channel = channel, OnSuccess = (successArgs) => { Console.WriteLine("The client " + (successArgs.IsResubscribe ? "re-" : "") + "subscribed to " + channel + "."); }, OnFailure = (failureArgs) => { Console.WriteLine("The client could not subscribe to " + channel + "... " + failureArgs.Exception.Message); }, OnReceive = (receiveArgs) => { Payload payload = JSON.Deserialize<Payload>(receiveArgs.DataJson); Tuple<SpokeQuestion, string, GameBoard> vf = null; switch (payload.Type) { case SpokeMessageType.AskQuestion: return; case SpokeMessageType.JoinGame: playersInGame.Add(receiveArgs.PublishingClient.Id, payload.PlayerName); if (playersInGame.Count == 2) { vf = RunGame.StartGame("sevens", playersInGame); stackTrace = vf.Item2; } else return; break; case SpokeMessageType.AnswerQuestion: vf = RunGame.ResumeGame("sevens", stackTrace, payload.AnswerIndex, playersInGame); stackTrace = vf.Item2; Console.WriteLine(vf.Item1); break; default: throw new ArgumentOutOfRangeException(); } PublicationArgs fc; foreach (KeyValuePair<string, string> user in playersInGame) { fc = new PublicationArgs { Publication = new Publication { Channel = channel + "/gamedata/" + user.Value, DataJson = JSON.Serialize(vf.Item3) }, OnComplete = (completeArgs) => { if (completeArgs.Publication.Successful == true) { Console.WriteLine("The publisher published to " + channel + "."); } else { Console.WriteLine("The publisher could not publish to " + channel + "... " + completeArgs.Publication.Error); } }, OnException = (exceptionArgs) => { Console.WriteLine("The publisher threw an exception... " + exceptionArgs.Exception.Message); } }; publisher.Publish(fc); } SpokeQuestion q = vf.Item1; fc = new PublicationArgs { Publication = new Publication { Channel = channel + "/" + q.User, DataJson = JSON.Serialize(new Payload(q.Question, q.Answers)) }, OnComplete = (completeArgs) => { if (completeArgs.Publication.Successful == true) { Console.WriteLine("The publisher published to " + channel + "."); } else { Console.WriteLine("The publisher could not publish to " + channel + "... " + completeArgs.Publication.Error); } }, OnException = (exceptionArgs) => { Console.WriteLine("The publisher threw an exception... " + exceptionArgs.Exception.Message); } }; publisher.Publish(fc); // Console.WriteLine("The client received data... (text: " + payload.Text + ", time: " + payload.Time + ")"); } }); Console.WriteLine(); Console.WriteLine("Press Enter to publish text from the publisher. Press Escape to quit."); while (true) { ConsoleKeyInfo consoleKeyInfo = Console.ReadKey(); if (consoleKeyInfo.Key == ConsoleKey.Escape) { return; } if (consoleKeyInfo.Key == ConsoleKey.Enter) { } } }