本文整理汇总了C#中Pubnub类的典型用法代码示例。如果您正苦于以下问题:C# Pubnub类的具体用法?C# Pubnub怎么用?C# Pubnub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pubnub类属于命名空间,在下文中一共展示了Pubnub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
});
});
}
示例2: ThenChannelLevelShouldReturnSuccess
public void ThenChannelLevelShouldReturnSuccess()
{
currentUnitTestCase = "ThenChannelLevelShouldReturnSuccess";
receivedAuditMessage = false;
ThreadPool.QueueUserWorkItem((s) =>
{
Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAuditIsRequested";
unitTest.TestCaseName = "ThenChannelLevelShouldReturnSuccess";
pubnub.PubnubUnitTest = unitTest;
string channel = "hello_my_channel";
if (PubnubCommon.PAMEnabled)
{
mreAudit = new ManualResetEvent(false);
pubnub.AuditAccess<string>(channel, AccessToChannelLevelCallback, DummyErrorCallback);
mreAudit.WaitOne(60 * 1000);
Assert.IsTrue(receivedAuditMessage, "WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess failed.");
}
else
{
Assert.Inconclusive("PAM Not Enabled for WhenAuditIsRequested -> ThenChannelLevelShouldReturnSuccess");
}
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
TestComplete();
});
});
}
示例3: NullMessage
public void NullMessage()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"",
false
);
string channel = "hello_world";
string message = null;
Common common = new Common();
common.DeliveryStatus = false;
common.Response = null;
pubnub.Publish(channel, message, common.DisplayReturnMessage);
//wait till the response is received from the server
while (!common.DeliveryStatus) ;
IList<object> fields = common.Response as IList<object>;
string sent = fields[1].ToString();
string one = fields[0].ToString();
Assert.AreEqual("Sent", sent);
Assert.AreEqual("1", one);
}
示例4: 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");
}
}
示例5: 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 = "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(2000);
pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribeUUID, UnsubscribeUUIDDummyMethodForConnectCallback, UnsubscribeUUIDDummyMethodForDisconnectCallback, DummyErrorCallback);
Thread.Sleep(1000);
unsubscribeUUIDManualEvent.WaitOne(2000);
presenceUUIDManualEvent.WaitOne(310 * 1000);
pubnub.EndPendingRequests();
Assert.IsTrue(receivedCustomUUID, "Custom UUID not received");
}
示例6: Init
public void Init()
{
if (!PubnubCommon.PAMEnabled)
{
Assert.Inconclusive("WhenAClientIsPresent Grant access failed.");
return;
}
receivedGrantMessage = false;
Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "GrantRequestUnitTest";
unitTest.TestCaseName = "Init";
pubnub.PubnubUnitTest = unitTest;
string channel = "hello_my_channel";
pubnub.GrantAccess<string>(channel, true, true, 20, ThenSubscriberInitializeShouldReturnGrantMessage, DummyErrorCallback);
//Thread.Sleep(1000);
grantManualEvent.WaitOne();
Assert.IsTrue(receivedGrantMessage, "WhenAClientIsPresent Grant access failed.");
}
示例7: Send_to_standIn
public void Send_to_standIn()
{
var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt");
using(var sut = new PubnubHostTransceiver(cre, "hostchannel"))
{
var standIn = new Pubnub(cre.PublishingKey, cre.SubscriptionKey, cre.SecretKey);
try
{
var standInChannel = Guid.NewGuid().ToString();
var are = new AutoResetEvent(false);
ReadOnlyCollection<object> result = null;
standIn.subscribe(standInChannel, (ReadOnlyCollection<object> _) =>
{
result = _;
are.Set();
});
var ho = new HostOutput{CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "portname"};
sut.SendToStandIn(new Tuple<string, HostOutput>(standInChannel, ho));
Assert.IsTrue(are.WaitOne(5000));
var hoReceived = Convert.FromBase64String((string)((JValue)result[0]).Value).Deserialize() as HostOutput;
Assert.AreEqual(ho.CorrelationId, hoReceived.CorrelationId);
Assert.AreEqual(ho.Data, hoReceived.Data);
Assert.AreEqual(ho.Portname, hoReceived.Portname);
}
finally
{
standIn.subscribe("standIn", _ => {});
}
}
}
示例8: Receive_from_host
public void Receive_from_host()
{
var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt");
using (var sut = new PubnubStandInTransceiver(cre, "hostchannel"))
{
var are = new AutoResetEvent(false);
HostOutput result = null;
sut.ReceivedFromHost += _ =>
{
result = _;
are.Set();
};
var sender = new Pubnub(cre.PublishingKey, cre.SubscriptionKey);
var ho = new HostOutput {CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "portname"};
sender.publish(sut.StandInEndpointAddress, ho.Serialize(), _ => { });
Assert.IsTrue(are.WaitOne(5000));
Assert.AreEqual(ho.CorrelationId, result.CorrelationId);
Assert.AreEqual(ho.Data, result.Data);
Assert.AreEqual(ho.Portname, result.Portname);
}
}
示例9: 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();
});
});
}
示例10: 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");
}
示例11: Init
public void Init()
{
if (!PubnubCommon.PAMEnabled)
{
EnqueueTestComplete();
return;
}
receivedGrantMessage = false;
ThreadPool.QueueUserWorkItem((s) =>
{
Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "GrantRequestUnitTest";
unitTest.TestCaseName = "Init3";
pubnub.PubnubUnitTest = unitTest;
EnqueueCallback(() => pubnub.ChannelGroupGrantAccess<string>(channelGroupName, true, true, 20, ThenChannelGroupInitializeShouldReturnGrantMessage, DummySubscribeErrorCallback));
grantManualEvent.WaitOne(310 * 1000);
EnqueueCallback(() => Assert.IsTrue(receivedGrantMessage, "WhenSubscribedToAChannelGroup Grant access failed."));
EnqueueCallback(() =>
{
pubnub.PubnubUnitTest = null;
pubnub = null;
}
);
EnqueueTestComplete();
});
}
示例12: 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");
}
示例13: ThenNoExistChannelShouldReturnNotSubscribed
public void ThenNoExistChannelShouldReturnNotSubscribed()
{
receivedNotSubscribedMessage = false;
mreUnsubscribe = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem((s) =>
{
Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenUnsubscribedToAChannel";
unitTest.TestCaseName = "ThenNoExistChannelShouldReturnNotSubscribed";
pubnub.PubnubUnitTest = unitTest;
string channel = "hello_my_channel";
EnqueueCallback(() => pubnub.Unsubscribe<string>(channel, DummyMethodNoExistChannelUnsubscribeChannelUserCallback, DummyMethodNoExistChannelUnsubscribeChannelConnectCallback, DummyMethodNoExistChannelUnsubscribeChannelDisconnectCallback1, NoExistChannelErrorCallback));
mreUnsubscribe.WaitOne(310 * 1000);
EnqueueCallback(() => pubnub.EndPendingRequests());
EnqueueCallback(() => Assert.IsTrue(receivedNotSubscribedMessage, "WhenUnsubscribedToAChannel --> ThenNoExistChannelShouldReturnNotSubscribed Failed"));
EnqueueTestComplete();
});
}
示例14: Init
public void Init()
{
if (!PubnubCommon.PAMEnabled)
{
EnqueueTestComplete();
return;
}
receivedGrantMessage = false;
Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "GrantRequestUnitTest";
unitTest.TestCaseName = "Init";
pubnub.PubnubUnitTest = unitTest;
string channel = "hello_my_channel";
EnqueueCallback(() => pubnub.GrantAccess<string>(channel, true, true, 20, ThenPublishInitializeShouldReturnGrantMessage, DummyErrorCallback));
//Thread.Sleep(1000);
EnqueueConditional(() => grantInitCallbackInvoked);
EnqueueCallback(() => Assert.IsTrue(receivedGrantMessage, "WhenAClientIsPresent Grant access failed."));
EnqueueTestComplete();
}
示例15: Init
public void Init()
{
if (!PubnubCommon.PAMEnabled)
{
TestComplete();
return;
}
receivedGrantMessage = false;
ThreadPool.QueueUserWorkItem((s) =>
{
Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, PubnubCommon.SecretKey, "", false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "GrantRequestUnitTest";
unitTest.TestCaseName = "Init";
pubnub.PubnubUnitTest = unitTest;
string channel = "hello_my_channel,hello_my_channel1,hello_my_channel2";
mreGrant = new ManualResetEvent(false);
pubnub.GrantAccess<string>(channel, true, true, 20, ThenSubscriberInitializeShouldReturnGrantMessage, DummyErrorCallback);
mreGrant.WaitOne(60 * 1000); //1 minute
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Assert.IsTrue(receivedGrantMessage, "WhenAClientIsPresent Grant access failed.");
TestComplete();
});
});
}