本文整理汇总了C#中PubNub_Messaging.Pubnub类的典型用法代码示例。如果您正苦于以下问题:C# Pubnub类的具体用法?C# Pubnub怎么用?C# Pubnub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pubnub类属于PubNub_Messaging命名空间,在下文中一共展示了Pubnub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThenItShouldReturnTimeStamp
public void ThenItShouldReturnTimeStamp()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"",
false
);
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenGetRequestServerTime";
unitTest.TestCaseName = "ThenItShouldReturnTimeStamp";
pubnub.PubnubUnitTest = unitTest;
string strResponse = "";
Common cm = new Common();
cm.deliveryStatus = false;
cm.objResponse = null;
pubnub.time(cm.DisplayReturnMessage);
//cm.objResponse = null;
while (!cm.deliveryStatus) ;
IList<object> fields = cm.objResponse as IList<object>;
strResponse = fields[0].ToString();
Console.WriteLine("Resp:" + strResponse);
Assert.AreNotEqual("0",strResponse);
}
示例2: ThenUnencryptPublishShouldReturnSuccessCodeAndInfo
public void ThenUnencryptPublishShouldReturnSuccessCodeAndInfo()
{
ThreadPool.QueueUserWorkItem((s) =>
{
isUnencryptPublished = false;
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
string channel = "my/channel";
string message = messageForUnencryptPublish;
pubnub.publish<string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback);
manualEvent1.WaitOne(310 * 1000);
if (!isUnencryptPublished)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Assert.IsTrue(isUnencryptPublished, "Unencrypt Publish Failed");
TestComplete();
});
}
else
{
pubnub.detailedHistory<string>(channel, -1, unEncryptPublishTimetoken, -1, false, CaptureUnencryptDetailedHistoryCallback);
mreUnencryptDH.WaitOne(310 * 1000);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Assert.IsTrue(isUnencryptDH, "Unable to match the successful unencrypt Publish");
TestComplete();
});
}
});
}
示例3: ThenPresenceShouldReturnReceivedMessage
public void ThenPresenceShouldReturnReceivedMessage()
{
receivedFlag1 = false;
ThreadPool.QueueUserWorkItem((s) =>
{
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
string channel = "my/channel";
pubnub.presence<string>(channel, ThenPresenceShouldReturnMessage);
//since presence expects from stimulus from sub/unsub...
pubnub.subscribe<string>(channel, DummyMethodForSubscribe);
manualEvent1.WaitOne(2000);
pubnub.unsubscribe<string>(channel, DummyMethodForUnSubscribe);
manualEvent3.WaitOne(2000);
manualEvent2.WaitOne(310 * 1000);
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
Assert.IsTrue(receivedFlag1, "Presence message not received");
TestComplete();
});
});
}
示例4: Main
public static void Main()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
false
);
string channel = "my/channel";
string message = "Pubnub API Usage Example";
pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);
Console.WriteLine("UUID -> " + pubnub.generateGUID());
pubnub.publish(channel, message);
pubnub.history(channel, 10);
pubnub.time();
pubnub.subscribe(channel);
Console.ReadKey();
}
示例5: PublishDemo
internal static void PublishDemo()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"",
false);
string channel = "my_channel";
Console.WriteLine("Publish_Example");
bool exitFlag = false;
while (!exitFlag)
{
Console.WriteLine("Enter the message for publish. To exit loop, enter QUIT");
string userinput = Console.ReadLine();
if (userinput.ToLower() == "quit")
{
exitFlag = true;
}
else
{
pubnub.publish(channel, userinput, DisplayReturnMessage);
}
}
}
示例6: HereNow_Example
static void HereNow_Example()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
false);
//string channel = "hello_world";
string channel = "hello_world";
pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Here_Now")
{
Console.WriteLine("\n********** Here Now Messages *********** ");
Dictionary<string, object> _message = (Dictionary<string, object>)(((Pubnub)sender).Here_Now[0]);
foreach (object uuid in (object[])_message["uuids"])
{
Console.WriteLine("UUID: " + uuid.ToString());
}
Console.WriteLine("Occupancy: " + _message["occupancy"].ToString());
}
};
pubnub.here_now(channel);
}
示例7: DetailedHistoryCountDemo
/*public static void Main()
{
DetailedHistoryCountDemo();
Console.ReadLine();
}*/
internal static void DetailedHistoryCountDemo()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"",
false);
string channel = "my_channel";
//Console.WriteLine("Detailed History Count Demo");
//pubnub.detailedHistory(channel, 100, DisplayDetailedHistory);
//Console.WriteLine("Detailed History Count and reverse Demo");
//pubnub.detailedHistory(channel, -1, -1, 100, true, DisplayDetailedHistory);
//Console.WriteLine("Detailed History with start and end");
//pubnub.detailedHistory(channel, 13499635513028988, 13499836911845528, 200, true, DisplayDetailedHistory);
//Console.WriteLine("Detailed History with start");
//pubnub.detailedHistory(channel, 13499635513028988, -1, 100, true, DisplayDetailedHistory);
Console.WriteLine("Detailed History with end");
pubnub.detailedHistory(channel, -1, 13499836911845528, 100, true, DisplayDetailedHistory);
}
示例8: NullMessage
public void NullMessage()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"",
false
);
string channel = "hello_world";
string message = null;
Common cm = new Common();
cm.deliveryStatus = false;
cm.objResponse = null;
pubnub.publish(channel, message, cm.DisplayReturnMessage);
//wait till the response is received from the server
while (!cm.deliveryStatus) ;
IList<object> fields = cm.objResponse as IList<object>;
string strSent = fields[1].ToString();
string strOne = fields[0].ToString();
Assert.True(("Sent").Equals(strSent));
Assert.True(("1").Equals(strOne));
}
示例9: SubscribeDemo
internal static void SubscribeDemo()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"",
false);
string channel = "my_channel";
Console.WriteLine("Subscribe_Example");
pubnub.subscribe(channel, DisplayReturnMessage);
bool userexit = false;
while (!userexit)
{
Console.WriteLine("For Unsubscribe");
Console.WriteLine("Enter Y for UNSUBSCRIBE or ENTER X to EXIT subscribe loop");
string userinput = Console.ReadLine();
if (userinput.ToLower() == "y")
{
pubnub.unsubscribe(channel, DisplayReturnMessage);
userexit = true;
}
else if (userinput.ToLower() == "x")
{
userexit = true;
}
}
}
示例10: ThenItShouldReturnSuccessCodeAndInfo
public void ThenItShouldReturnSuccessCodeAndInfo()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"",
false
);
string channel = "hello_world";
string message = "Pubnub API Usage Example";
Common cm = new Common();
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAMessageIsPublished";
unitTest.TestCaseName = "ThenItShouldReturnSuccessCodeAndInfo";
pubnub.PubnubUnitTest = unitTest;
cm.deliveryStatus = false;
cm.objResponse = null;
pubnub.publish(channel, message, cm.DisplayReturnMessage);
//wait till the response is received from the server
while (!cm.deliveryStatus) ;
IList<object> fields = cm.objResponse as IList<object>;
string strSent = fields[1].ToString();
string strOne = fields[0].ToString();
Assert.True(("Sent").Equals(strSent));
Assert.True(("1").Equals(strOne));
}
示例11: DetailedHistory_Decrypted_Example
public static void DetailedHistory_Decrypted_Example()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"enigma",
false);
string channel = "testchannel";
//pubnub.CIPHER_KEY = "enigma";
string msg = "Test Message";
deliveryStatus = false;
pubnub.publish(channel, msg, DisplayReturnMessage);
while (!deliveryStatus) ;
deliveryStatus = false;
pubnub.detailedHistory(channel, 1, DisplayReturnMessage);
while (!deliveryStatus) ;
Console.WriteLine("\n*********** DetailedHistory Messages Received*********** ");
if (objResponse.Equals(null))
{
Console.WriteLine("Null response");
}
else
{
IList<object> fields = objResponse as IList<object>;
Console.WriteLine("fields[0]: " + fields[0]);
Console.WriteLine("fields[1]: " + fields[1]);
//Assert.AreEqual(fields[0], msg);
}
}
示例12: ThenUnencryptPublishShouldReturnSuccessCodeAndInfo
public void ThenUnencryptPublishShouldReturnSuccessCodeAndInfo()
{
isUnencryptPublished = false;
Pubnub pubnub = new Pubnub("demo","demo","","",false);
string channel = "my/channel";
string message = messageForUnencryptPublish;
EnqueueCallback(() => pubnub.publish<string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback));
EnqueueConditional(() => isCheck);
EnqueueCallback(() =>
{
if (!isUnencryptPublished)
{
Assert.IsTrue(isUnencryptPublished, "Unencrypt Publish Failed");
}
else
{
EnqueueCallback(() => pubnub.detailedHistory<string>(channel, -1, unEncryptPublishTimetoken, -1, false, CaptureUnencryptDetailedHistoryCallback));
EnqueueConditional(() => isUnencryptCheck);
EnqueueCallback(() => Assert.IsTrue(isUnencryptDH, "Unable to match the successful unencrypt Publish"));
}
});
EnqueueTestComplete();
}
示例13: PresenceDemo
internal static void PresenceDemo()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"",
false);
string channel = "my_channel";
Console.WriteLine("Presence_Example");
pubnub.presence(channel, DisplayReturnMessage);
bool pre_unsub = false;
while (!pre_unsub)
{
Console.WriteLine("Enter y for Presence-Unsub; x to EXIT presence loop");
string userchoice = Console.ReadLine();
if (userchoice.ToLower() == "y")
{
Console.WriteLine("PresenceUnsubscribe_Example");
pubnub.presence_unsubscribe(channel, DisplayReturnMessage);
pre_unsub = true;
}
else if (userchoice.ToLower() == "x")
{
pre_unsub = true;
}
}
}
示例14: ItShouldReturnDetailedHistory
public void ItShouldReturnDetailedHistory()
{
Pubnub pubnub = new Pubnub(
"demo",
"demo",
"",
"",
false
);
string channel = "hello_world";
Common cm = new Common();
cm.deliveryStatus = false;
cm.objResponse = null;
//publish a test message.
pubnub.publish(channel, "Test message", cm.DisplayReturnMessage);
while (!cm.deliveryStatus)
;
cm.deliveryStatus = false;
cm.objResponse = null;
pubnub.detailedHistory(channel, 1, cm.DisplayReturnMessage);
while (!cm.deliveryStatus)
;
string strResponse = "";
if (cm.objResponse.Equals(null))
{
Assert.Fail("Null response");
} else
{
IList<object> fields = cm.objResponse as IList<object>;
foreach (object item in fields)
{
strResponse = item.ToString();
Console.WriteLine(strResponse);
Assert.IsNotNull(strResponse);
}
if (fields [0] != null)
{
var myObjectArray = (from item in fields select item as object).ToArray();
IList<object> enumerable = myObjectArray [0] as IList<object>;
if ((enumerable != null) && (enumerable.Count > 0))
{
foreach (object element in enumerable)
{
Console.WriteLine("Resp:" + element.ToString());
}
}
else
{
Assert.Fail("No response");
}
}
}
}
示例15: ThenItShouldReturnTimeStamp
public void ThenItShouldReturnTimeStamp()
{
Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
EnqueueCallback(() => pubnub.time<string>(ReturnTimeStampCallback));
EnqueueConditional(() => isTimeStamp);
EnqueueCallback(() => Assert.IsTrue(timeReceived, "time() Failed"));
EnqueueTestComplete();
}