static void Main(string[] args) { string decorationLine = new string('-', Console.WindowWidth); Console.Write(decorationLine); Console.WriteLine("***PubNub simple chat application***"); Console.Write(decorationLine); Process.Start("..\\..\\RecieverPage.html"); Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-d9aadadf-abba-443c-a767-62023d43411a", // PUBLISH_KEY "sub-c-102d0358-073f-11e3-916b-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-YmI4NDcxNzQtOWZhYi00MTRmLWI4ODktMDI2ZjViMjQyYzdj", // SECRET_KEY false // SSL_ON/OFF ); string channel = "PublishApp"; // Publish a sample message to Pubnub List<object> publishResult = pubnub.Publish(channel, "Hello PubNub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) Task task = new Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return true; } ) ); task.Start(); // Read messages from the console and publish them to PubNub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
public static void Main() { // Start the HTML5 Pubnub client Process.Start(@"..\..\index.html"); System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-35648aec-f497-4d5b-ab3e-8d621ba3794c", // PUBLISH_KEY "sub-c-fb346fbe-8d19-11e5-a7e4-0619f8945a4f", // SUBSCRIBE_KEY "sec-c-M2JmNWIwODMtNDNhYi00MjBlLWI2ZTYtZjExNjA1OTU4ZDBj", // SECRET_KEY true // SSL_ON? ); string channel = "simple chat channel"; // Publish a sample message to Pubnub List<object> publishResult = pubnub.Publish(channel, "Hello there!"); Console.WriteLine( "Publish Success: " + publishResult[0] + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime); // Subscribe for receiving messages (in a background task to avoid blocking) var task = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate (object message) { Console.WriteLine("Received Message -> '" + message + "'"); return true; } ) ); task.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); var message = Console.ReadLine(); pubnub.Publish(channel, message); Console.WriteLine("Message {0} sent.", message); } }
public static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\Receiver.html"); Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-ebd958d0-e2fd-4aab-a2fc-7d31e8995644", "sub-c-44a39b0c-886a-11e5-84ee-0619f8945a4f", "sec-c-MWVkYjQxY2EtYTEzYi00OTBmLWJmNzktYmM5OWI2OWE4YzU4", true ); string channel = "Chat"; // Publish a sample message to Pubnub List <object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) Task t = new Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return(true); } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\PubNub-HTML5-Client.html"); System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-25499a0d-31e9-468c-b4e4-e1940acb2e46", // PUBLISH_KEY "sub-c-73f3014a-8793-11e5-8e17-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-NzBlZGI4OGYtZjkzNS00MjQ1LWI2NzItMTZlODNlOTdjNDEz", // SECRET_KEY true // SSL_ON? ); string channel = "demo-channel"; // Publish a sample message to Pubnub List <object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return(true); } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\PubNub-HTML5-Client.html"); System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-4fd56e1f-976d-440d-8bd1-fa892d69270f", // PUBLISH_KEY "sub-c-8a8f356e-3fd6-11e4-b33e-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-YzQyOTFlNjItMzgwNS00NzZkLTgwYzMtNDMxYmNmOTkxODE5", // SECRET_KEY true // SSL_ON? ); string channel = "feedbacks-channel"; // Publish a sample message to Pubnub List <object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Urgent Problem -> '" + message + "'"); return(true); } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter urgent problem message: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Problem message {0} sent.", msg); } }
static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\PubNub-HTML5-Client.html"); System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-4c88dcfd-2722-4d3f-a561-109481fa9adc", // PUBLISH_KEY "sub-c-c452f2d8-89de-11e5-83e3-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-YTg4ODdkZWUtMzRhOC00NmU1LWFkZDctNGJjN2Y3NzZmMDdh", // SECRET_KEY true // SSL_ON? ); string channel = "AAA"; // Publish a sample message to Pubnub List <object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return(true); } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\PubNub-HTML5-Client.html"); System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-c8e12013-c187-4311-97f6-37f19f472922", // PUBLISH_KEY "sub-c-a8243ee0-8b88-11e5-9320-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-NmU5MGU5YjMtYWQxNC00MmRhLTg2NTctNWI0OWM0NjVjNjUz" ); string channel = "test-channel"; // Publish a sample message to Pubnub List<object> publishResult = pubnub.Publish(channel, "Hello"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) //System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( // () => // pubnub.Subscribe( // channel, // delegate (object message) // { // Console.WriteLine("Received Message -> '" + message + "'"); // return true; // } // ) //); //t.Start(); // Read messages from the console and publish them to Pubnub string ipAddress = new WebClient().DownloadString("http://icanhazip.com").Trim(); while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = string.Format("{0}: {1}", ipAddress, Console.ReadLine()); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\PubNub-HTML5-Client.html"); System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-02dee9ae-9627-4fb7-a486-a5cdf9df9749", // PUBLISH_KEY "sub-c-04a5c868-0374-11e3-bde1-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-NTUzNGMyMjgtNDhkZS00ZTMwLWEyYTEtNGY5ZjYyOGU5ODY2", // SECRET_KEY true // SSL_ON? ); string channel = "nakov-channel"; // Publish a sample message to Pubnub List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return true; } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\PubNub-HTML5-Client.html"); System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-4fd56e1f-976d-440d-8bd1-fa892d69270f", // PUBLISH_KEY "sub-c-8a8f356e-3fd6-11e4-b33e-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-YzQyOTFlNjItMzgwNS00NzZkLTgwYzMtNDMxYmNmOTkxODE5", // SECRET_KEY true // SSL_ON? ); string channel = "feedbacks-channel"; // Publish a sample message to Pubnub List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Urgent Problem -> '" + message + "'"); return true; } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter urgent problem message: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Problem message {0} sent.", msg); } }
static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\PubNub-HTML5-Client.html"); //System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-a40489bf-98a7-40ff-87df-4af2f371d50a", // PUBLISH_KEY "sub-c-68236eaa-8bb6-11e5-8b47-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-ZmVhNTE4NTgtYWRmYi00NGNjLWIzNjgtZjI1YTU2M2ZkMDU2", // SECRET_KEY true // SSL_ON? ); string channel = "demo-channel"; // Publish a sample message to Pubnub List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate (object message) { Console.WriteLine("Received Message -> '" + message + "'"); return true; } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
public static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\Receiver.html"); Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-ebd958d0-e2fd-4aab-a2fc-7d31e8995644", "sub-c-44a39b0c-886a-11e5-84ee-0619f8945a4f", "sec-c-MWVkYjQxY2EtYTEzYi00OTBmLWJmNzktYmM5OWI2OWE4YzU4", true ); string channel = "Chat"; // Publish a sample message to Pubnub List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) Task t = new Task( () => pubnub.Subscribe( channel, delegate (object message) { Console.WriteLine("Received Message -> '" + message + "'"); return true; } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\PubNub-HTML5-Client.html"); System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-25499a0d-31e9-468c-b4e4-e1940acb2e46", // PUBLISH_KEY "sub-c-73f3014a-8793-11e5-8e17-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-NzBlZGI4OGYtZjkzNS00MjQ1LWI2NzItMTZlODNlOTdjNDEz", // SECRET_KEY true // SSL_ON? ); string channel = "demo-channel"; // Publish a sample message to Pubnub List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return true; } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
/* 02. Implement a very simple chat application based on some message queue service: Users can send message into a common channel. Messages are displayed in the format {IP : message_text}. Use PubNub. Your application can be console, GUI or Web-based.*/ static void Main() { Process.Start("..\\..\\PubNubChatDemo.html"); System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-e485b33f-6d32-4410-9cb8-98c61a4a48df", // PUBLISH_KEY "sub-c-44c8865e-0817-11e3-ab8d-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-NWQwNjFmY2EtNzljMy00MGU2LTk4YjYtMWQwZThmM2U1Mjcw", // SECRET_KEY false // SSL_ON? ); string channel = "secret-ninja-channel"; // Publish a sample message to Pubnub List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return true; } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
static void Main(string[] args) { PubnubAPI pubnub = new PubnubAPI( "pub-c-2902e1f0-71b1-44ff-a438-11d120ed8bcf", // PUBLISH_KEY "sub-c-92dac9b8-0747-11e3-9163-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-M2RjZmI0OTUtOGU1MC00Mzg1LThjMTQtYjQ4ZmU1YWQ4NzU5", // SECRET_KEY true // SSL_ON? ); Console.WriteLine("Enter chanel name: "); string chanel = Console.ReadLine(); Console.WriteLine("Enter message: "); string msg = Console.ReadLine(); pubnub.Publish(chanel, msg); System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( "chat", delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return true; } ) ); t.Start(); }
public static string CheckIn(int userId, int placeId) { var context = new FoursquareContext(); var user = context.Users.FirstOrDefault(u => u.Id == userId); var place = context.Places.FirstOrDefault(p => p.Id == placeId); if (user == null || place == null) { throw new ServerErrorException("User or place does not exist.", "INV_NICK_LEN"); } user.Latitude = place.Latitude; user.Longitude = place.Longitude; context.SaveChanges(); PubnubAPI pubnub = new PubnubAPI( "pub-c-b428e4fd-a82e-4cc7-a0d2-d4f832fd1d2b", // PUBLISH_KEY "sub-c-20f993fa-04b4-11e3-a005-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-ZGEzODJjZDEtOWE1ZC00YTE4LTg2NTctNzdiYTc4NjBlODVh", // SECRET_KEY true // SSL_ON? ); string channel = place.Id + "" + place.Name; List<object> publishResult = pubnub.Publish(channel, string.Format("User {0} checked at {1}.", user.Username, place.Name)); return channel; }
public static Channel GetChannel(this SessionState _sessionState, string name, string password, PubnubAPI pubnub) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password)) { return(null); } Channel result = AppCache.ChannelList.Where(c => c.Name == name && c.Password == password).FirstOrDefault(); if (result == null) { //try to get channel from mongodb result = _sessionState.GetChannels().Where(c => c.Name == name).FirstOrDefault();// && c.PublicData.Password == password).FirstOrDefault(); if (result == null) { //save new channel result = new Channel(); result.Name = name; result.Password = password; result.CreatedDateTime = DateTime.Now; _sessionState.SaveChannel(result); //add channel in cache AppCache.ChannelList.AddSafeName(result); if (pubnub != null) { List <object> publishAllChannel = pubnub.Publish("SCAllChannel", result.Name); } } else if (result.Password != password) { result = null; } } return(result); }
static void Main() { PubnubAPI pubnub = new PubnubAPI( "pub-c-1776bd27-f356-4f36-9b86-b0cb4798a8e3", // PUBLISH_KEY "sub-c-9c0ac472-e7b9-11e3-a91c-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-OWY4ZDA0NmYtNmEzNi00NDA4LWI4YmYtNTIyOTU2MTMzZWUz", // SECRET_KEY true // SSL_ON? ); string channel = "IcoPubnub"; // Publish a sample message to Pubnub List <object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return(true); } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { string msg = Console.ReadLine(); pubnub.Publish(channel, msg); } }
static void Main(string[] args) { PubnubAPI pubnub = new PubnubAPI( "pub-c-143cd1af-de82-4ecc-bfe9-db2904f2d5a4", // PUBLISH_KEY "sub-c-859122ec-07e8-11e3-ba95-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-MjBjMTA5NjEtZTI1Mi00ZjgxLWJmZDMtMjU2NTExMjA3Mzkw", // SECRET_KEY true // SSL_ON? ); string channel = "stan-channel"; // Publish a sample message to Pubnub List<object> publishResult = pubnub.Publish(channel, "Hello Pubnub!"); Console.WriteLine( "Publish Success: " + publishResult[0].ToString() + "\n" + "Publish Info: " + publishResult[1] ); // Show PubNub server time object serverTime = pubnub.Time(); Console.WriteLine("Server Time: " + serverTime.ToString()); // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return true; } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
public static void SendNotification(string message) { PubnubAPI pubnub = new PubnubAPI( PublishKey, // PUBLISH_KEY SubscribeKey, // SUBSCRIBE_KEY SecretKey, // SECRET_KEY true // SSL_ON? ); pubnub.Publish(Channel, message); }
public HttpResponseMessage AddMessage(ChannelAddMessageModel channelModel) { var responseMsg = this.PerformOperation(() => { ChannelsRepository.AddMessage(channelModel.Name, channelModel.Nickname, channelModel.Message); }); pubnub.Publish(channelModel.Name, channelModel.Message); return(responseMsg); }
public HttpResponseMessage AddMessage(ChannelAddMessageModel channelModel) { var responseMsg = this.PerformOperation(() => { var index = channelModel.Message.IndexOf(':'); var message = channelModel.Message.Substring(index + 2); ChannelsRepository.AddMessage(channelModel.Name, channelModel.Nickname, message); }); pubnub.Publish(channelModel.Name, channelModel.Message); return(responseMsg); }
private static void SendMessage(PubnubAPI chatService, string chatRoom) { while (Console.KeyAvailable) { ConsoleKeyInfo pressedKey = Console.ReadKey(true); if (pressedKey.Key == ConsoleKey.S) { Console.WriteLine("Please enter your message:"); string outMsg = Console.ReadLine(); chatService.Publish(chatRoom, String.Format("{0} : {1}", name, outMsg)); Console.WriteLine("Message sent."); } } }
public void StartCooking(StepModel step, string sessionKey) { PubnubAPI pubnub = new PubnubAPI( "pub-c-40427e1d-7b94-4f2c-bde6-6c93636f2a6f", // PUBLISH_KEY "sub-c-db9871f4-05e0-11e3-8dc9-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-M2FlN2E1ZTMtNGRkMi00MTg4LTgxYmQtM2E1OWUxMjJlMWMx", // SECRET_KEY true // SSL_ON? ); string channel = "startCooking-channel"; System.Threading.Thread.Sleep(step.Time * 60 * 1000); pubnub.Publish(channel, "Step " + step.Number + " has finished."); }
// POST api/Comments?userId=1 public HttpResponseMessage PostComment(int userId, Comment comment) { if (ModelState.IsValid && comment.AuthorId == userId) { this.dbRepository.Add(comment); // Pusblish to channel List <object> publishResult = pubnub.Publish(this.pubnubChanel, comment.Content); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, comment); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = comment.CommentId })); return(response); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public static void Main() { PubnubAPI pubnub = new PubnubAPI( PubNubConstants.PublishKey, PubNubConstants.SubscribeKey, PubNubConstants.SecretKey, true); string channel = PubNubConstants.ChannelName; while (true) { Console.WriteLine("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message {0} sent.", msg); } }
private void PublishToPubNub(string name, Message msg) { if (msg != null) { List <dynamic> pubnubMessage = new List <dynamic>(); Dictionary <string, string> actionDict = new Dictionary <string, string>(); actionDict.Add("Action", "add"); actionDict.Add("Channel", name); pubnubMessage.Add(actionDict); msg.PrivateData = null; if (msg.PublicData.Type == MessageTypes.File) { _sessionState.AuthClient(); msg.PublicData.Value = _sessionState.Client.GetMediaLinkAsync(msg.PublicData.Value).Result.Url; } pubnubMessage.Add(msg); List <object> publishResult = pubnub.Publish("NewMsgIn" + name, pubnubMessage); } }
static void Main() { if (pubNubPublishKey.IndexOf('*') > 0 || pubNubSubscribeKey.IndexOf('*') > 0 || pubNubSecretKey.IndexOf('*') > 0) { Console.WriteLine("Please setup your PubNub Keys into the code"); return; } PubnubAPI pubnub = new PubnubAPI(pubNubPublishKey, pubNubSubscribeKey, pubNubSecretKey, true /* SSL on */); Console.WriteLine("Welcome to the SimpleChat Service\n\n"); // Subscribe for receiving messages (in a background task to avoid blocking) Task receiver = new Task(() => pubnub.Subscribe( pubNubChannel, delegate(object message) { Console.WriteLine("Message Received: " + message); return true; } ) ); receiver.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Msg> "); string message = Console.ReadLine().Trim(); if (message.Length == 0) { return; } pubnub.Publish(pubNubChannel, message); Console.WriteLine("Message sent."); } }
static void Main() { // Start the HTML5 Pubnub client Process.Start("..\\..\\PubNub-HTML5-Client.html"); System.Threading.Thread.Sleep(2000); PubnubAPI pubnub = new PubnubAPI( "pub-c-96036ed5-b848-4f13-96ed-116460e341f2", // PUBLISH_KEY "sub-c-3cb2c784-0670-11e3-a3d6-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-MWE3N2U3ZjgtYmI5OC00MGRmLTkwNGMtYjRkMjk4NTkyMTg5", // SECRET_KEY true // SSL_ON? ); string channel = "simple-chat"; // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { Console.WriteLine("Received Message -> '" + message + "'"); return true; } ) ); t.Start(); // Read messages from the console and publish them to Pubnub while (true) { Console.Write("Enter a message to be sent to Pubnub: "); string msg = Console.ReadLine(); pubnub.Publish(channel, msg); Console.WriteLine("Message sent."); System.Threading.Thread.Sleep(1000); } }
private void PublishToPubNub(string name, ServiceData sd, bool isRemove) { Message msg = sd.Result as Message; if (msg != null) { List <dynamic> pubnubMessage = new List <dynamic>(); Dictionary <string, string> actionDict = new Dictionary <string, string>(); if (isRemove) { actionDict.Add("Action", "del"); } else { actionDict.Add("Action", "add"); } actionDict.Add("Channel", name); pubnubMessage.Add(actionDict); msg.PrivateData = null; pubnubMessage.Add(msg); List <object> publishResult = pubnub.Publish("NewMsgIn" + name, pubnubMessage); } }
public static Channel GetChannel(this boSessionState _sessionState, string name, string password, PubnubAPI pubnub) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password)) { return(null); } Channel result = AppCache.ChannelList.Where(c => c.Name == name && c.PublicData.Password == password).FirstOrDefault(); if (result == null) { //try to get channel from mongodb result = _sessionState.GetChannels().Where(c => c.Name == name).FirstOrDefault();// && c.PublicData.Password == password).FirstOrDefault(); if (result == null) { //save new channel result = new Channel(); result.Name = name; result.PublicData = new ChannelResource() { Password = password, CreatedDateTime = DateTime.Now }; result.PrivateData = AppCache.AESProvider.EncryptToString(JsonConvert.SerializeObject(result.PublicData)); _sessionState.SaveChannel(result); //add channel in cache AppCache.ChannelList.AddSafeName(result); if (pubnub != null) { List <object> publishAllChannel = pubnub.Publish("SCAllChannel", result.Name); } } else if (result.PublicData.Password != password) { result = null; } } return(result); }
public IHttpActionResult BuyCart() { var cart = this.data.Carts.Find(this.GetCartId()); if (cart == null) { return(BadRequest(CartNotFoundExceptionMassage + "card")); } var newOrder = new Order { Products = cart.Products, TimeOfOrder = DateTime.Now, UserId = cart.UserId, }; this.data.Orders.Add(newOrder); this.data.Orders.SaveChanges(); string orderAsJson = JsonConvert.SerializeObject(newOrder); pubnub.Publish("admin", orderAsJson); return(Ok(newOrder)); }
public static Channel GetChannel(this SessionState _sessionState, string name, string password, PubnubAPI pubnub) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password)) return null; Channel result = AppCache.ChannelList.Where(c => c.Name == name && c.Password == password).FirstOrDefault(); if (result == null) { //try to get channel from mongodb result = _sessionState.GetChannels().Where(c => c.Name == name).FirstOrDefault();// && c.PublicData.Password == password).FirstOrDefault(); if (result == null) { //save new channel result = new Channel(); result.Name = name; result.Password = password; result.CreatedDateTime = DateTime.Now; _sessionState.SaveChannel(result); //add channel in cache AppCache.ChannelList.AddSafeName(result); if (pubnub != null) { List<object> publishAllChannel = pubnub.Publish("SCAllChannel", result.Name); } } else if(result.Password != password) result = null; } return result; }
public void PublishMessage(string message) { pubnub.Publish(this.channel, message); }
static void Main(string[] args) { PubnubAPI pubnub = new PubnubAPI( "pub-c-ed80e48c-24dd-4955-958b-7eecd8de0600", // PUBLISH_KEY "sub-c-8f7881d6-082b-11e3-ab8d-02ee2ddab7fe", // SUBSCRIBE_KEY "sec-c-ZGJiMThiNTAtMDljOC00MzY4LWE4OTAtZWZlZTQ0YjIwYzZi", // SECRET_KEY true // SSL_ON? ); string channel = "hw-chat-channel"; string machineIp = GetLocalIp(); Console.WriteLine("Welcome to the Web Api Homework channel"); Console.WriteLine("Please enter your message."); Console.WriteLine("For exit enter \"exit\""); Console.WriteLine("To stop showing your own messages enter \"mine-off\" / \"mine-on\""); Console.Write(">"); bool turnOfOwnMessages = false; // Subscribe for receiving messages (in a background task to avoid blocking) System.Threading.Tasks.Task t = new System.Threading.Tasks.Task( () => pubnub.Subscribe( channel, delegate(object message) { MessageDetails recievedMessage = JsonConvert.DeserializeObject <MessageDetails>(message.ToString()); if ((turnOfOwnMessages && recievedMessage.Ip != machineIp) || !turnOfOwnMessages) { Console.WriteLine("Received Message (IP:{0}) -> '{1}'", recievedMessage.Ip, recievedMessage.Message); } return(true); } ) ); t.Start(); string newMessage = Console.ReadLine(); string newMessageToLower = newMessage.ToLower(); string messageDetails; while (newMessageToLower != "exit") { if (newMessageToLower == "mine-off") { turnOfOwnMessages = true; Console.WriteLine("Your own messages will no-longer be displayed!"); } else if (newMessageToLower == "mine-on") { turnOfOwnMessages = false; Console.WriteLine("Your own messages will be displayed also!"); } else { messageDetails = GetMessageDetails(newMessage, machineIp); pubnub.Publish(channel, messageDetails); } newMessage = Console.ReadLine(); newMessageToLower = newMessage.ToLower(); } }
public static Channel GetChannel(this boSessionState _sessionState, string name, string password, PubnubAPI pubnub) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password)) return null; Channel result = AppCache.ChannelList.Where(c => c.Name == name && c.PublicData.Password == password).FirstOrDefault(); if (result == null) { //try to get channel from mongodb result = _sessionState.GetChannels().Where(c => c.Name == name).FirstOrDefault();// && c.PublicData.Password == password).FirstOrDefault(); if (result == null) { //save new channel result = new Channel(); result.Name = name; result.PublicData = new ChannelResource() { Password = password, CreatedDateTime = DateTime.Now }; result.PrivateData = AppCache.AESProvider.EncryptToString(JsonConvert.SerializeObject(result.PublicData)); _sessionState.SaveChannel(result); //add channel in cache AppCache.ChannelList.AddSafeName(result); if (pubnub != null) { List<object> publishAllChannel = pubnub.Publish("SCAllChannel", result.Name); } } else if(result.PublicData.Password != password) result = null; } return result; }