本文整理汇总了C#中Pubnub.publish方法的典型用法代码示例。如果您正苦于以下问题:C# Pubnub.publish方法的具体用法?C# Pubnub.publish怎么用?C# Pubnub.publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pubnub
的用法示例。
在下文中一共展示了Pubnub.publish方法的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, ReceivedMessageCallbackNoConnect);
//Thread.Sleep(5000);
pubnub.publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback);
mePublish.WaitOne(310 * 1000);
meSubNoConnect.WaitOne(310 * 1000);
pubnub.unsubscribe<string>(channel, dummyUnsubCallback);
meUnsub.WaitOne(310 * 1000);
Assert.IsTrue(receivedMessage,"WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed");
}
示例2: Receive_from_standIn
public void Receive_from_standIn()
{
var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt");
using (var sut = new PubnubHostTransceiver(cre, "hostchannel"))
{
var are = new AutoResetEvent(false);
HostInput result = null;
sut.ReceivedFromStandIn += _ =>
{
result = _;
are.Set();
};
var standIn = new Pubnub(cre.PublishingKey, cre.SubscriptionKey, cre.SecretKey);
var hi = new HostInput{CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "portname", StandInEndpointAddress = "endpoint"};
standIn.publish("hostchannel", hi.Serialize(), _ => { });
Assert.IsTrue(are.WaitOne(5000));
Assert.AreEqual(hi.CorrelationId, result.CorrelationId);
Assert.AreEqual(hi.Data, result.Data);
Assert.AreEqual(hi.Portname, result.Portname);
Assert.AreEqual(hi.StandInEndpointAddress, result.StandInEndpointAddress);
}
}
示例3: ThenUnencryptPublishShouldReturnSuccessCodeAndInfo
public void ThenUnencryptPublishShouldReturnSuccessCodeAndInfo()
{
isUnencryptPublished = false;
Pubnub pubnub = new Pubnub("demo","demo","","",false);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAMessageIsPublished";
unitTest.TestCaseName = "ThenUnencryptPublishShouldReturnSuccessCodeAndInfo";
pubnub.PubnubUnitTest = unitTest;
string channel = "my/channel";
string message = messageForUnencryptPublish;
pubnub.publish<string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback);
manualEvent1.WaitOne(310*1000);
if (!isUnencryptPublished)
{
Assert.IsTrue(isUnencryptPublished, "Unencrypt Publish Failed");
}
else
{
pubnub.detailedHistory<string>(channel, -1, unEncryptPublishTimetoken, -1, false, CaptureUnencryptDetailedHistoryCallback);
mreUnencryptDH.WaitOne(310 * 1000);
Assert.IsTrue(isUnencryptDH, "Unable to match the successful unencrypt Publish");
}
}
示例4: 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);
}
}
示例5: IfSSLNotProvidedThenDefaultShouldBeFalse
public void IfSSLNotProvidedThenDefaultShouldBeFalse()
{
isPublished3 = false;
Pubnub pubnub = new Pubnub("demo", "demo", "");
string channel = "my/channel";
string message = "Pubnub API Usage Example";
pubnub.publish<string>(channel, message, ReturnNoSSLDefaultFalseCallback);
manualEvent3.WaitOne(310 * 1000);
Assert.IsTrue(isPublished3, "Publish Failed with no SSL");
}
示例6: IfSSLNotProvidedThenDefaultShouldBeFalse
public void IfSSLNotProvidedThenDefaultShouldBeFalse()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
""
);
string channel = "my/channel";
string message = "Pubnub API Usage Example";
pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);
Assert.AreEqual(true, pubnub.publish(channel, message));
}
示例7: ThenItShouldReturnSuccessCodeAndInfo
public void ThenItShouldReturnSuccessCodeAndInfo()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
false
);
string channel = "my/channel";
string message = "Pubnub API Usage Example";
pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);
pubnub.publish(channel, message);
}
示例8: ThenSubscribeShouldReturnReceivedMessage
public void ThenSubscribeShouldReturnReceivedMessage()
{
receivedMessage = false;
Pubnub pubnub = new Pubnub("demo","demo","","",false);
string channel = "test";
EnqueueCallback(() => pubnub.subscribe<string>(channel, ReceivedMessageCallback));
EnqueueCallback(() => pubnub.publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback));
EnqueueConditional(() => isPublished);
EnqueueConditional(() => isReceived);
EnqueueCallback(() => Assert.IsTrue(receivedMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed"));
EnqueueTestComplete();
}
示例9: ThenPublishKeyShouldNotBeEmptyAfterOverriden
public void ThenPublishKeyShouldNotBeEmptyAfterOverriden()
{
Pubnub pubnub = new Pubnub(
"",
"demo",
"",
false
);
string channel = "my/channel";
string message = "Pubnub API Usage Example";
pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);
Assert.AreEqual(false, pubnub.publish(channel, message));
}
示例10: IfSSLNotProvidedThenDefaultShouldBeFalse
public void IfSSLNotProvidedThenDefaultShouldBeFalse()
{
publishedMessage = false;
Pubnub pubnub = new Pubnub(
"demo",
"demo",
""
);
string channel = "my/channel";
string message = "Pubnub API Usage Example";
pubnub.publish(channel, message, ThenDoCallback);
manualEvent.WaitOne();
Assert.IsTrue(publishedMessage);
}
示例11: ThenSubscribeShouldReturnReceivedMessage
public void ThenSubscribeShouldReturnReceivedMessage()
{
receivedMessage = false;
Pubnub pubnub = new Pubnub("demo","demo","","",false);
string channel = "my/channel";
pubnub.subscribe<string>(channel, ReceivedMessageCallback);
Thread.Sleep(5000);
pubnub.publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback);
manualEvent2.WaitOne(310 * 1000);
manualEvent1.WaitOne(310*1000);
Assert.IsTrue(receivedMessage,"WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed");
}
示例12: ThenItShouldReturnSuccessCodeAndInfo
public void ThenItShouldReturnSuccessCodeAndInfo()
{
publishedMessage = false;
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"",
false
);
string channel = "my/channel";
string message = "Pubnub API Usage Example";
pubnub.publish(channel, message,ThenDoCallback);
manualEvent.WaitOne();
Assert.IsTrue(publishedMessage);
}
示例13: Run
public void Run()
{
var are = new AutoResetEvent(false);
var pubnubServer = new Pubnub("demo", "demo");
pubnubServer.subscribe("testchannel", (ReadOnlyCollection<object> _) =>
{
var v = _[0] as JValue;
var a = Convert.FromBase64String((string)v.Value);
Console.WriteLine("received: {0}", a);
are.Set();
});
var pubnubClient = new Pubnub("demo", "demo");
pubnubClient.publish("testchannel", new byte[]{1,2,3}, _ => Console.WriteLine("published"));
Assert.IsTrue(are.WaitOne(5000));
}
示例14: DetailedHistoryStartWithReverseTrue
public void DetailedHistoryStartWithReverseTrue()
{
expectedCountAtStartTimeWithReverseTrue = 0;
msgStartReverseTrue = false;
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
string channel = "my/channel";
startTimeWithReverseTrue = Pubnub.translateDateTimeToPubnubUnixNanoSeconds(DateTime.UtcNow);
for (int index = 0; index < 10; index++)
{
pubnub.publish<string>(channel,
string.Format("DetailedHistoryStartTimeWithReverseTrue {0} {1}", startTimeWithReverseTrue, index),
DetailedHistorySamplePublishCallback);
mrePublishStartReverseTrue.WaitOne(5000);
}
Thread.Sleep(5000);
pubnub.detailedHistory<string>(channel, startTimeWithReverseTrue, DetailedHistoryStartWithReverseTrueCallback, true);
mreMsgStartReverseTrue.WaitOne(310 * 1000);
Assert.IsTrue(msgStartReverseTrue, "Detailed History with Start and Reverse True Failed");
}
示例15: ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo
public void ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo()
{
isEncryptObjectPublished = false;
Pubnub pubnub = new Pubnub("demo", "demo", "", "enigma", false);
string channel = "my/channel";
object message = new SecretCustomClass();
messageObjectForEncryptPublish = JsonConvert.SerializeObject(message);
pubnub.publish<string>(channel, message, ReturnSuccessEncryptObjectPublishCodeCallback);
mreEncryptObjectPub.WaitOne(310 * 1000);
if (!isEncryptObjectPublished)
{
Assert.IsTrue(isEncryptObjectPublished, "Encrypt Object Publish Failed");
}
else
{
pubnub.detailedHistory<string>(channel, -1, encryptObjectPublishTimetoken, -1, false, CaptureEncryptObjectDetailedHistoryCallback);
mreEncryptObjectDH.WaitOne(310 * 1000);
Assert.IsTrue(isEncryptObjectDH, "Unable to match the successful encrypt object Publish");
}
}