本文整理汇总了C#中Pubnub.Subscribe方法的典型用法代码示例。如果您正苦于以下问题:C# Pubnub.Subscribe方法的具体用法?C# Pubnub.Subscribe怎么用?C# Pubnub.Subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pubnub
的用法示例。
在下文中一共展示了Pubnub.Subscribe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThenSubscribeShouldReturnReceivedMessage
public void ThenSubscribeShouldReturnReceivedMessage()
{
receivedMessage = false;
Pubnub pubnub = new Pubnub("demo","demo","","",false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenSubscribedToAChannel";
unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage";
pubnub.PubnubUnitTest = unitTest;
string channel = "my/channel";
pubnub.Subscribe<string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeDummyMethodForConnectCallback);
pubnub.Publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback);
mePublish.WaitOne(310 * 1000);
meSubscribeNoConnect.WaitOne(310 * 1000);
pubnub.Unsubscribe<string>(channel, dummyUnsubscribeCallback, SubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback);
meUnsubscribe.WaitOne(310 * 1000);
pubnub.EndPendingRequests();
UUnitAssert.True(receivedMessage,"WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed");
}
示例2: ThenPresenceShouldReturnReceivedMessage
public void ThenPresenceShouldReturnReceivedMessage()
{
receivedPresenceMessage = false;
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAClientIsPresented";
unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage";
pubnub.PubnubUnitTest = unitTest;
string channel = "hello_my_channel";
pubnub.Presence<string>(channel, ThenPresenceShouldReturnMessage, PresenceDummyMethodForConnectCallback, DummyErrorCallback);
Thread.Sleep(1000);
//since presence expects from stimulus from sub/unsub...
pubnub.Subscribe<string>(channel, DummyMethodForSubscribe, SubscribeDummyMethodForConnectCallback, DummyErrorCallback);
Thread.Sleep(1000);
subscribeManualEvent.WaitOne(2000);
pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribe, UnsubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback, DummyErrorCallback);
Thread.Sleep(1000);
unsubscribeManualEvent.WaitOne(2000);
presenceManualEvent.WaitOne(310 * 1000);
pubnub.EndPendingRequests();
Assert.IsTrue(receivedPresenceMessage, "Presence message not received");
}
示例3: Main
static public void Main()
{
Pubnub pubnub = new Pubnub(
publishKey: "pub-c-d8635a25-b556-4267-84c4-a9db379cd66a",
subscribeKey: "sub-c-e809ad42-8bd8-11e5-bf00-02ee2ddab7fe");
System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(
() =>
pubnub.Subscribe<string>(
channel: channel,
userCallback: DisplaySubscribeReturnMessage,
connectCallback: DisplaySubscribeConnectStatusMessage,
errorCallback: DisplayErrorMessage)
);
t.Start();
while (true)
{
Console.Write("Enter a message to be sent to Pubnub: ");
string msg = Console.ReadLine();
pubnub.Publish<string>(
channel: channel,
message: msg,
userCallback: DisplayReturnMessage,
errorCallback: DisplayErrorMessage);
Console.WriteLine("Message {0} sent.", msg);
}
}
示例4: ThenPresenceShouldReturnReceivedMessage
public void ThenPresenceShouldReturnReceivedMessage()
{
receivedPresenceMessage = false;
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAClientIsPresented";
unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage";
pubnub.PubnubUnitTest = unitTest;
string channel = "my/channel";
pubnub.Presence<string>(channel, ThenPresenceShouldReturnMessage);
//since presence expects from stimulus from sub/unsub...
pubnub.Subscribe<string>(channel, DummyMethodForSubscribe);
subscribeManualEvent.WaitOne(2000);
pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribe);
unsubscribeManualEvent.WaitOne(2000);
presenceManualEvent.WaitOne(310 * 1000);
pubnub.PresenceUnsubscribe<string>(channel, DummyMethodForPreUnSub);
presenceUnsubscribeEvent.WaitOne();
Assert.IsTrue(receivedPresenceMessage, "Presence message not received");
}
示例5: ThenShouldReturnUnsubscribedMessageSSL
public void ThenShouldReturnUnsubscribedMessageSSL ()
{
Pubnub pubnub = new Pubnub (Common.PublishKey,
Common.SubscribeKey, "", "", true);
Common common = new Common ();
common.DeliveryStatus = false;
common.Response = null;
pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenUnsubscribedToAChannel", "ThenShouldReturnUnsubscribedMessage");
string channel = "hello_world2";
pubnub.Subscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
common.WaitForResponse ();
common.DeliveryStatus = false;
common.Response = null;
pubnub.Unsubscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
common.WaitForResponse ();
if (common.Response.ToString ().Contains ("Unsubscribed from")) {
Console.WriteLine ("Response:" + common.Response);
Assert.Pass ();
} else {
Assert.Fail ();
}
pubnub.EndPendingRequests ();
}
示例6: ThenSubscribeShouldReturnReceivedMessage
public void ThenSubscribeShouldReturnReceivedMessage()
{
receivedMessage = false;
ThreadPool.QueueUserWorkItem((s) =>
{
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
string channel = "my/channel";
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenSubscribedToAChannel";
unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage";
pubnub.PubnubUnitTest = unitTest;
pubnub.Subscribe<string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeDummyMethodForConnectCallback);
//Thread.Sleep(500);
pubnub.Publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback);
mePublish.WaitOne(310 * 1000);
//Thread.Sleep(500);
meSubscribeNoConnect.WaitOne(310 * 1000);
pubnub.Unsubscribe<string>(channel, dummyUnsubscribeCallback, SubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback);
Thread.Sleep(500);
meUnsubscribe.WaitOne(310 * 1000);
Thread.Sleep(1000);
pubnub.EndPendingRequests();
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Assert.IsTrue(receivedMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed");
TestComplete();
});
});
}
示例7: ThenShouldReturnUnsubscribedMessage
public void ThenShouldReturnUnsubscribedMessage()
{
receivedChannelConnectedMessage = false;
receivedUnsubscribedMessage = false;
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenUnsubscribedToAChannel";
unitTest.TestCaseName = "ThenShouldReturnUnsubscribedMessage";
pubnub.PubnubUnitTest = unitTest;
string channel = "my/channel";
pubnub.Subscribe<string>(channel, DummyMethodChannelSubscribeUserCallback, DummyMethodChannelSubscribeConnectCallback);
meChannelSubscribed.WaitOne();
if (receivedChannelConnectedMessage)
{
pubnub.Unsubscribe<string>(channel, DummyMethodUnsubscribeChannelUserCallback, DummyMethodUnsubscribeChannelConnectCallback, DummyMethodUnsubscribeChannelDisconnectCallback);
meChannelUnsubscribed.WaitOne();
}
pubnub.EndPendingRequests();
UUnitAssert.True(receivedUnsubscribedMessage, "WhenUnsubscribedToAChannel --> ThenShouldReturnUnsubscribedMessage Failed");
}
示例8: SubscribePublishAndParse
void SubscribePublishAndParse (string message, Pubnub pubnub, Common common, string channel)
{
Random r = new Random ();
channel = "hello_world_sub" + r.Next (1000);
pubnub.Subscribe<string> (channel, common.DisplayReturnMessage, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
Thread.Sleep (5000);
pubnub.Publish (channel, message, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy);
common.WaitForResponse ();
if (common.Response != null) {
object[] deserializedMessage = Common.Deserialize<object[]> (common.Response.ToString ());
if (deserializedMessage != null) {
Assert.True (message.Equals (deserializedMessage [0].ToString ()));
} else {
Assert.Fail ("Test not successful");
}
} else {
Assert.Fail ("No response");
}
common.DeliveryStatus = false;
common.Response = null;
pubnub.Unsubscribe<string> (channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
common.WaitForResponse (20);
pubnub.EndPendingRequests ();
}
示例9: ThenPresenceShouldReturnCustomUUID
public void ThenPresenceShouldReturnCustomUUID()
{
receivedCustomUUID = false;
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAClientIsPresented";
unitTest.TestCaseName = "ThenPresenceShouldReturnCustomUUID";
pubnub.PubnubUnitTest = unitTest;
string channel = "my/channel";
pubnub.Presence<string>(channel, ThenPresenceWithCustomUUIDShouldReturnMessage);
//since presence expects from stimulus from sub/unsub...
pubnub.SessionUUID = customUUID;
pubnub.Subscribe<string>(channel, DummyMethodForSubscribeUUID);
subscribeUUIDManualEvent.WaitOne(2000);
pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribeUUID);
unsubscribeUUIDManualEvent.WaitOne(2000);
presenceUUIDManualEvent.WaitOne(310 * 1000);
pubnub.PresenceUnsubscribe<string>(channel, DummyMethodForPreUnSubUUID);
presenceUnsubscribeUUIDEvent.WaitOne();
Assert.IsTrue(receivedCustomUUID, "Custom UUID not received");
}
示例10: ThenSubscribeShouldReturnReceivedMessage
public void ThenSubscribeShouldReturnReceivedMessage()
{
receivedMessage = false;
Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenSubscribedToAChannel";
unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage";
pubnub.PubnubUnitTest = unitTest;
string channel = "hello_my_channel";
pubnub.Subscribe<string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeDummyMethodForConnectCallback, DummyErrorCallback);
Thread.Sleep(1000);
pubnub.Publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback, DummyErrorCallback);
manualResetEventsWaitTimeout = (unitTest.EnableStubTest) ? 1000 : 310 * 1000;
mePublish.WaitOne(manualResetEventsWaitTimeout);
meSubscribeNoConnect.WaitOne(manualResetEventsWaitTimeout);
pubnub.Unsubscribe<string>(channel, dummyUnsubscribeCallback, SubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback, DummyErrorCallback);
meUnsubscribe.WaitOne(manualResetEventsWaitTimeout);
pubnub.EndPendingRequests();
Assert.IsTrue(receivedMessage,"WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed");
}
示例11: ThenPresenceShouldReturnReceivedMessage
public void ThenPresenceShouldReturnReceivedMessage()
{
receivedPresenceMessage = false;
ThreadPool.QueueUserWorkItem((s) =>
{
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
string channel = "my/channel";
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAClientIsPresented";
unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage";
pubnub.PubnubUnitTest = unitTest;
pubnub.Presence<string>(channel, ThenPresenceShouldReturnMessage);
//since presence expects from stimulus from sub/unsub...
pubnub.Subscribe<string>(channel, DummyMethodForSubscribe);
subscribeManualEvent.WaitOne(2000);
pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribe);
unsubscribeManualEvent.WaitOne(2000);
pubnub.PresenceUnsubscribe<string>(channel, DummyMethodForPreUnSub);
presenceUnsubscribeEvent.WaitOne(2000);
presenceManualEvent.WaitOne(310 * 1000);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Assert.IsTrue(receivedPresenceMessage, "Presence message not received");
TestComplete();
});
});
}
示例12: ThenShouldReturnUnsubscribedMessage
public void ThenShouldReturnUnsubscribedMessage()
{
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
Common common = new Common();
common.DeliveryStatus = false;
common.Response = null;
pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenUnsubscribedToAChannel", "ThenShouldReturnUnsubscribedMessage");
string channel = "hello_world";
pubnub.Subscribe<string>(channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
common.WaitForResponse();
common.DeliveryStatus = false;
common.Response = null;
pubnub.Unsubscribe<string>(channel, common.DisplayReturnMessageDummy, common.DisplayReturnMessageDummy, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
common.WaitForResponse();
if (common.Response.ToString().Contains ("Unsubscribed from")) {
Console.WriteLine("Response:" + common.Response);
Assert.NotNull(common.Response);
}
else
{
Assert.Fail("ThenShouldReturnUnsubscribedMessage failed");
}
}
示例13: ThenPresenceShouldReturnCustomUUID
public void ThenPresenceShouldReturnCustomUUID()
{
Debug.Log("Running ThenPresenceShouldReturnCustomUUID()");
receivedCustomUUID = false;
Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAClientIsPresented";
unitTest.TestCaseName = "ThenPresenceShouldReturnCustomUUID";
pubnub.PubnubUnitTest = unitTest;
string channel = "hello_my_channel";
pubnub.Presence<string>(channel, ThenPresenceWithCustomUUIDShouldReturnMessage, PresenceUUIDDummyMethodForConnectCallback, DummyErrorCallback);
Thread.Sleep(1000);
//since presence expects from stimulus from sub/unsub...
pubnub.SessionUUID = customUUID;
pubnub.Subscribe<string>(channel, DummyMethodForSubscribeUUID, SubscribeUUIDDummyMethodForConnectCallback, DummyErrorCallback);
Thread.Sleep(1000);
subscribeUUIDManualEvent.WaitOne(310 * 1000);
presenceUUIDManualEvent.WaitOne(310 * 1000);
pubnub.EndPendingRequests();
UUnitAssert.True(receivedCustomUUID, "Custom UUID not received");
}
示例14: ThenSubscribeShouldReturnConnectStatus
public void ThenSubscribeShouldReturnConnectStatus()
{
receivedConnectMessage = false;
ThreadPool.QueueUserWorkItem((s) =>
{
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenSubscribedToAChannel";
unitTest.TestCaseName = "ThenSubscribeShouldReturnConnectStatus";
pubnub.PubnubUnitTest = unitTest;
string channel = "my/channel";
pubnub.Subscribe<string>(channel, ReceivedMessageCallbackYesConnect, ConnectStatusCallback);
meSubscribeYesConnect.WaitOne(310 * 1000);
Thread.Sleep(200);
pubnub.Unsubscribe<string>(channel, dummyUnsubCallback);
meUnsubscribe.WaitOne(310 * 1000);
Thread.Sleep(200);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Assert.IsTrue(receivedConnectMessage, "WhenSubscribedToAChannel --> ThenSubscribeShouldReturnConnectStatus Failed");
TestComplete();
});
});
}
示例15: Init
public void Init()
{
pubnub = new Pubnub(publishKey: "pub-c-413b0e07-fbf4-4075-b4f5-7b5a28184c27",
subscribeKey: "sub-c-17646960-ab37-11e5-ae71-02ee2ddab7fe");
pubnub.Subscribe("Zones", DisplaySubscribeReturnMessage,
DisplaySubscribeConnectStatusMessage,DisplayErrorMessage);
}