public void It_should_return_a_200_response() { IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherOptions() { HostName = Config.HttpHost }); var events = new Event[] { new Event { Channel = "my-channel-1", EventName = "my_event", Data = new { hello = "world" } }, new Event { Channel = "my-channel-2", EventName = "my_other_event", Data = new { hello = "other worlds" } }, }; ITriggerResult result = pusher.Trigger(events); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public async Task It_should_expose_a_single_event_id_when_publishing_to_a_single_channel() { ITriggerResult result = await _pusher.TriggerAsync("ch1", "my_event", new { hello = "world" }); Assert.IsTrue(result.EventIds.ContainsKey("ch1")); Assert.AreEqual(1, result.EventIds.Count); }
public void It_should_return_a_202_response() { IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret); ITriggerResult result = pusher.Trigger(new string[] { "my-channel-1", "my-channel-2" }, "my_event", new { hello = "world" }); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public void it_can_trigger_an_event_with_a_percent_in_the_message() { var eventJSON = File.ReadAllText("AcceptanceTests/percent-message.json"); var message = new JavaScriptSerializer().Deserialize(eventJSON, typeof(object)); ITriggerResult result = _pusher.Trigger("my-channel", "my_event", message); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public async void it_can_trigger_an_event_with_a_percent_in_the_message_async() { var eventJSON = File.ReadAllText("AcceptanceTests/percent-message.json"); var message = JsonConvert.DeserializeObject(eventJSON); ITriggerResult result = await _pusher.TriggerAsync("my-channel", "my_event", message); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public async Task it_can_trigger_an_event_with_a_percent_in_the_message_async() { string fileName = Path.Combine(Assembly.GetExecutingAssembly().Location, @"../../../../AcceptanceTests/percent-message.json"); var eventJSON = File.ReadAllText(fileName); var message = JsonConvert.DeserializeObject(eventJSON); ITriggerResult result = await _pusher.TriggerAsync("my-channel", "my_event", message); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public void It_should_return_a_202_response() { IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherOptions() { Encrypted = true }); ITriggerResult result = pusher.Trigger("my-channel", "my_event", new { hello = "world" }); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public async Task It_should_expose_a_multiple_event_ids_when_publishing_to_multiple_channels() { var channels = new string[] { "ch1", "ch2", "ch3" }; ITriggerResult result = await _pusher.TriggerAsync(channels, "my_event", new { hello = "world" }); Assert.IsTrue(result.EventIds.ContainsKey("ch1")); Assert.IsTrue(result.EventIds.ContainsKey("ch2")); Assert.IsTrue(result.EventIds.ContainsKey("ch3")); Assert.AreEqual(channels.Length, result.EventIds.Count); }
public async Task it_should_expose_the_event_id_async() { var waiting = new AutoResetEvent(false); ITriggerResult asyncResult = await _pusher.TriggerAsync("my-channel", "my_event", new { hello = "world" }); waiting.Set(); Assert.IsFalse(string.IsNullOrEmpty(asyncResult.EventIds["my-channel"])); }
public async Task <ActionResult> Pushermessage(string message) { var options = new PusherOptions(); options.Cluster = "mt1"; var pusher = new Pusher("932166", "e19424c57e2df62ff676", "3ebdf5f715c1973b537a", options); ITriggerResult result = await pusher.TriggerAsync("my_channel", "my_event", new { message = message, name = "Anonymous" }); return(new HttpStatusCodeResult((int)HttpStatusCode.OK)); }
public void CanTriggerEventWithPercentInMessage() { var eventJSON = File.ReadAllText("AcceptanceTests/percent-message.json"); var message = new JavaScriptSerializer().Deserialize(eventJSON, typeof(object)); IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret); ITriggerResult result = pusher.Trigger("my-channel", "my_event", message); Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); }
public async Task <ActionResult> Pushermessage(String message) { var options = new PusherOptions(); options.Cluster = "XXX_CLUSTER"; var pusher = new Pusher("XXX_APP_ID", "XXX_APP_KEY", "XXX_APP_SECRET", options); ITriggerResult result = await pusher.TriggerAsync("asp_channel", "asp_event", new { message = message, name = "Anonymous" }); return(new HttpStatusCodeResult((int)HttpStatusCode.OK)); }
public JObject QrCodeLogout(JObject jobj, string sConnString, int userId) { JObject jresponse = new JObject(); string qrCode = string.Empty; int retVal = 0; string message = string.Empty; try { string pusherAppId = System.Configuration.ConfigurationManager.AppSettings["pusherAppId"].ToString(); string pusherAppKey = System.Configuration.ConfigurationManager.AppSettings["pusherAppKey"].ToString(); string pusherAppsecret = System.Configuration.ConfigurationManager.AppSettings["pusherAppsecret"].ToString(); if (jobj.SelectToken("QrCode") != null) { GT.DataAccessLayer.V_1_5.Login loginObj = new DataAccessLayer.V_1_5.Login(sConnString); retVal = loginObj.QrCodeLogOut(userId, out message); if (retVal == 1) { qrCode = Convert.ToString(jobj.SelectToken("QrCode")); Pusher pusherObj = new Pusher(pusherAppId, pusherAppKey, pusherAppsecret); ITriggerResult pusherResponse = null; pusherResponse = pusherObj.Trigger(qrCode, "Logout", new { QrCode = qrCode, IsLoggedOut = 1 }); jresponse = new JObject(new JProperty("Success", true), new JProperty("Message", "Success")); if (HttpContext.Current.Request.Cookies["SessionId"] != null || HttpContext.Current.Request.Cookies["UserData"] != null) { HttpContext.Current.Request.Cookies["SessionId"].Expires = DateTime.Now.AddDays(-1); HttpContext.Current.Request.Cookies["UserData"].Expires = DateTime.Now.AddDays(-1); } } else { jresponse = new JObject(new JProperty("Success", false), new JProperty("Message", "Log Out Failed")); } } else { jresponse = new JObject(new JProperty("Success", false), new JProperty("Message", "Invalid QrCode")); } } catch (Exception ex) { Logger.ExceptionLog("Exception in QrCodeLogout : " + ex.ToString()); jresponse = new JObject(new JProperty("Success", false), new JProperty("Message", "Something Went Wrong")); } return(jresponse); }
public async Task It_should_return_a_200_response_async() { IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret, new PusherOptions() { HostName = Config.HttpHost }); ITriggerResult asyncResult = await pusher.TriggerAsync(new string[] { "my-channel-1", "my-channel-2" }, "my_event", new { hello = "world" }); Assert.AreEqual(HttpStatusCode.OK, asyncResult.StatusCode); }
public async Task <ActionResult> Answer(Answer data) { db.Answer.Add(data); db.SaveChanges(); var options = new PusherOptions(); options.Cluster = "mt1"; var pusher = new Pusher("903489", "1bfe83e4cfdaea4bd143", "250fe69cbb1c4721ffa6", options); ITriggerResult result = await pusher.TriggerAsync("asp_channel", "asp_event", data); return(Content("ok")); }
public JObject QR_Code_Check(string sConnString, JObject jObj, int userID) { JObject responseJobj = new JObject(); string qrCode = Convert.ToString(jObj.SelectToken("QrCode")); string deviceId = Convert.ToString(jObj.SelectToken("DeviceUniqueId")); string deviceToken = Convert.ToString(jObj.SelectToken("DeviceToken")); int osId = Convert.ToInt32(jObj.SelectToken("OsId")); int retVal = 0; string retMsg = ""; string qrCodeAccessToken = ""; DataSet ds = new DataSet(); string pusherAppId = System.Configuration.ConfigurationManager.AppSettings["PusherAppId"].ToString(); string pusherAppKey = System.Configuration.ConfigurationManager.AppSettings["PusherAppKey"].ToString(); string pusherAppsecret = System.Configuration.ConfigurationManager.AppSettings["PusherAppsecret"].ToString(); Logger.TraceLog(pusherAppId + pusherAppKey + pusherAppsecret); DataAccessLayer.V_1_5.Login loginObj = new DataAccessLayer.V_1_5.Login(sConnString); ds = loginObj.QRCodeChecking(userID, qrCode, deviceId, deviceToken, osId, out retVal, out retMsg); if (retVal == 1) { if (ds.Tables.Count != 0) { if (ds.Tables[0].Rows.Count != 0) { qrCodeAccessToken = ds.Tables[0].Rows[0]["QrCodeAccessToken"].ToString(); } } Pusher pusherObj = new Pusher(pusherAppId, pusherAppKey, pusherAppsecret); ITriggerResult PusherResponse = null; PusherResponse = pusherObj.Trigger(qrCode, "Login", new { IsloggedIn = 0, QrCode = qrCode, QrCodeAccessToken = qrCodeAccessToken, DeviceUniqueId = deviceId, DeviceToken = deviceToken, OsId = osId }); Logger.TraceLog("PusherResponse" + PusherResponse.Body); responseJobj = new JObject(new JProperty("Success", true), new JProperty("Message", "Succes")); } else { responseJobj = new JObject(new JProperty("Success", false), new JProperty("Message", retMsg)); } return(responseJobj); }
public async Task <ActionResult> Comment(Comment data) { db.Comment.Add(data); db.SaveChanges(); var options = new PusherOptions(); options.Cluster = "mt1"; var pusher = new Pusher("321765", "ec75c89294f1617ae16e", "1d93c1bc7b6c6d0cd03f", options); ITriggerResult result = await pusher.TriggerAsync("asp_channel", "asp_event", data); return(Content("ok")); }
public async Task <ActionResult> Comment(Comment data) { db.Comment.Add(data); db.SaveChanges(); var options = new PusherOptions(); options.Cluster = "ap1"; var pusher = new Pusher("810929", "093c221464e0b9370411", "ddfeb0fbf4c35863680d", options); ITriggerResult result = await pusher.TriggerAsync("asp_channel", "asp_event", data); return(Content("ok")); }
public async Task <ActionResult> Comment(Comments data) { _context.Comments.Add(data); _context.SaveChanges(); var options = new PusherOptions(); options.Cluster = "XXX_APP_CLUSTER"; var pusher = new Pusher("XXX_APP_ID", "XXX_APP_KEY", "XXX_APP_SECRET", options); ITriggerResult result = await pusher.TriggerAsync("asp_channel", "asp_event", data); return(Content("ok")); }
public async Task <ActionResult> Comment(Comment data) { db.Comments.Add(data); db.SaveChanges(); var options = new PusherOptions(); options.Cluster = "ap1"; var pusher = new Pusher("1185884", "9711cf863b669984e1f2", "73a4067f2b75a0bfe4eb", options); ITriggerResult result = await pusher.TriggerAsync("asp_channel", "asp_event", data); return(Content("ok")); }
public async Task <ActionResult> Comment(Comment data) { CommentDAO cmtDao = new CommentDAO(); cmtDao.AddComment(data); var options = new PusherOptions(); options.Cluster = "ap1"; var pusher = new Pusher("1072058", "b50b10f861de3e38c121", "50c05543df2a7eab8101", options); ITriggerResult result = await pusher.TriggerAsync("asp_channel", "asp_event", data); return(Content("ok")); }
public void It_should_be_received_by_a_client() { string channelName = "my_channel"; string eventName = "my_event"; bool eventReceived = false; AutoResetEvent reset = new AutoResetEvent(false); var client = new PusherClient.Pusher(Config.AppKey); client.Connected += new PusherClient.ConnectedEventHandler(delegate(object sender) { Debug.WriteLine("connected"); reset.Set(); }); Debug.WriteLine("connecting"); client.Connect(); Debug.WriteLine("waiting to connect"); reset.WaitOne(TimeSpan.FromSeconds(5)); Debug.WriteLine("subscribing"); var channel = client.Subscribe(channelName); channel.Subscribed += new PusherClient.SubscriptionEventHandler(delegate(object s) { Debug.WriteLine("subscribed"); reset.Set(); }); Debug.WriteLine("binding"); channel.Bind(eventName, delegate(dynamic data) { Debug.WriteLine("event received"); eventReceived = true; reset.Set(); }); Debug.WriteLine("waiting to subscribe"); reset.WaitOne(TimeSpan.FromSeconds(5)); Debug.WriteLine("triggering"); IPusher pusher = new Pusher(Config.AppId, Config.AppKey, Config.AppSecret); ITriggerResult result = pusher.Trigger(channelName, eventName, new { hello = "world" }); Debug.WriteLine("waiting for event to be received"); reset.WaitOne(TimeSpan.FromSeconds(5)); Assert.IsTrue(eventReceived); }
public IPubSubResult Publish <T>(T message) where T : class, IPubSubMessage { Requires.NotNull(message, nameof(message)); Requires.NotNullOrEmpty(message.Channel, nameof(message.Channel)); Requires.NotNullOrEmpty(message.Event, nameof(message.Event)); Requires.NotNull(message.Payload, nameof(message.Payload)); ITriggerResult triggerResult = _pusher.Trigger(message.Channel, message.Event, message.Payload); return(new PusherResult { Body = triggerResult.Body, StatusCode = triggerResult.StatusCode }); }
public void url_resource_is_in_expected_format() { ITriggerResult result = _pusher.Trigger( channelName, eventName, eventData ); _subClient.Received().Execute( Arg.Is <IRestRequest>( x => CheckRequestHasExpectedUrl(x) ) ); }
public void post_payload_contains_channelName_eventName_and_eventData() { ITriggerResult result = _pusher.Trigger( channelName, eventName, eventData ); _subClient.Received().Execute( Arg.Is <IRestRequest>( x => CheckRequestContainsPayload(x, channelName, eventName, eventData) ) ); }
public void It_should_return_a_200_response_async() { var waiting = new AutoResetEvent(false); ITriggerResult asyncResult = null; _pusher.TriggerAsync("my-channel", "my_event", new { hello = "world" }, (ITriggerResult result) => { asyncResult = result; waiting.Set(); }); waiting.WaitOne(5000); Assert.AreEqual(HttpStatusCode.OK, asyncResult.StatusCode); }
public void it_should_expose_the_event_id_async() { var waiting = new AutoResetEvent(false); ITriggerResult asyncResult = null; _pusher.TriggerAsync("my-channel", "my_event", new { hello = "world" }, (ITriggerResult result) => { asyncResult = result; waiting.Set(); }); waiting.WaitOne(5000); Assert.IsTrue(string.IsNullOrEmpty(asyncResult.EventIds["my-channel"]) == false); }
private void SendMessage(string key, string channelName, string eventName, string messageBody) { try { bool keyExists = _messageDictionary.ContainsKey(key); bool messageBodyIsNew = keyExists && _messageDictionary[key] != messageBody; if (!keyExists || messageBodyIsNew) { #if DEBUG //Logger.Info($"sending {eventName} {key} "); #endif Task <ITriggerResult> task = _pusherServer.TriggerAsync(channelName, eventName, messageBody); ITriggerResult result = task.Result; HttpStatusCode statusCode = result.StatusCode; string body = result.Body; if (statusCode != HttpStatusCode.OK) { string message = $"SendMessage() failed to return OK status code, statusCode = {statusCode}, body = {body}"; Logger.Error(message); throw new Exception(message); } if (!Utils.IsValidJson(body)) { Logger.Error($"SendMessage(): Pusher body is not valid JSON, body = {body}"); } // ERROR 2019-09-18 17:47:40,781 [22] SendMessage() exception = System.IndexOutOfRangeException: Index was outside the bounds of the array. // at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) // at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value) // at SportsIq.Pusher.PusherUtil.SendMessage(String key, String channelName, String eventName, String messageBody) in D:\workspace\SIQ\SportsIqNew\SportsIq.Pusher\PusherUtil.cs:line 103 if (!keyExists) { _messageDictionary.Add(key, messageBody); } } } catch (Exception exception) { Logger.Error($"SendMessage() exception = {exception}"); } }
public async Task <ActionResult> Comment(Review data) { db.Review.Add(data); db.SaveChanges(); var options = new PusherOptions(); options.Cluster = "ap1"; var pusher = new Pusher( "517985", "d6da99d6e03f6878b567", "eaa3506a81d07a10b73c", options); ITriggerResult result = await pusher.TriggerAsync( "my-channel", "my-event", data); return(Content("ok")); }
public async Task UpdateHomePageTime(string username, TZone tzone) { string stuff = tzone.Local(DateTime.Now.ToUniversalTime()).ToShortTimeString() + " " + tzone.Abbreviation + " - " + tzone.Local(DateTime.Now.ToUniversalTime()).ToLongDateString(); var options = new PusherOptions() { Encrypted = true, Cluster = Globals.PusherCluster }; Pusher pusher = new Pusher(Globals.PusherAppId, Globals.PusherKey, Globals.PusherSecret, options); var data = new { message = stuff }; ITriggerResult x = await pusher.TriggerAsync("notes-data-" + username, "update-time", data); if (x.StatusCode != System.Net.HttpStatusCode.OK) { RecurringJob.RemoveIfExists(username); } }