本文整理汇总了C#中Pubnub.SetUserState方法的典型用法代码示例。如果您正苦于以下问题:C# Pubnub.SetUserState方法的具体用法?C# Pubnub.SetUserState怎么用?C# Pubnub.SetUserState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pubnub
的用法示例。
在下文中一共展示了Pubnub.SetUserState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//.........这里部分代码省略.........
break;
case "23":
Console.WriteLine("Enter channel name");
Console.WriteLine("NOTE: If you want to consider only Channel Group, just hit ENTER");
string userStateChannel = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(string.Format("Channel = {0}", userStateChannel));
Console.ResetColor();
Console.WriteLine("Enter channel group name");
Console.WriteLine("NOTE: If you want to consider only Channel, just hit ENTER");
string userStateChannelGroup = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(string.Format("ChannelGroup = {0}", userStateChannelGroup));
Console.ResetColor();
Console.WriteLine("User State will be accepted as dictionary key:value pair");
Console.WriteLine("Enter key. ");
string keyUserState = Console.ReadLine();
if (string.IsNullOrEmpty(keyUserState.Trim()))
{
Console.WriteLine("dictionary key:value pair entry completed.");
break;
}
Console.WriteLine("Enter value");
string valueUserState = Console.ReadLine();
int valueInt;
double valueDouble;
//string currentUserState = "";
if (Int32.TryParse(valueUserState, out valueInt))
{
pubnub.SetUserState<string>(userStateChannel, userStateChannelGroup, new KeyValuePair<string, object>(keyUserState, valueInt), DisplayReturnMessage, DisplayErrorMessage);
}
else if (Double.TryParse(valueUserState, out valueDouble))
{
pubnub.SetUserState<string>(userStateChannel, userStateChannelGroup, new KeyValuePair<string, object>(keyUserState, valueDouble), DisplayReturnMessage, DisplayErrorMessage);
}
else
{
pubnub.SetUserState<string>(userStateChannel, userStateChannelGroup, new KeyValuePair<string, object>(keyUserState, valueUserState), DisplayReturnMessage, DisplayErrorMessage);
}
break;
case "24":
Console.WriteLine("Enter channel name");
Console.WriteLine("NOTE: If you want to consider only Channel Group, just hit ENTER");
string deleteChannelUserState = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(string.Format("Channel = {0}", deleteChannelUserState));
Console.ResetColor();
Console.WriteLine("Enter channel group name");
Console.WriteLine("NOTE: If you want to consider only Channel, just hit ENTER");
string deleteChannelGroupUserState = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine(string.Format("ChannelGroup = {0}", deleteChannelGroupUserState));
Console.ResetColor();
Console.WriteLine("Enter key of the User State Key-Value pair to be deleted");
string deleteKeyUserState = Console.ReadLine();
pubnub.SetUserState<string>(deleteChannelUserState, deleteChannelGroupUserState, new KeyValuePair<string, object>(deleteKeyUserState, null), DisplayReturnMessage, DisplayErrorMessage);
break;
case "25":
示例2: IfSetAndDeleteUserStateThenItShouldReturnInfo
public void IfSetAndDeleteUserStateThenItShouldReturnInfo()
{
receivedUserStateMessage = false;
currentTestCase = "IfSetAndDeleteUserStateThenItShouldReturnInfo";
pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
pubnub.SessionUUID = customUUID;
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAClientIsPresented";
unitTest.TestCaseName = "IfSetAndDeleteUserStateThenItShouldReturnInfo";
pubnub.PubnubUnitTest = unitTest;
manualResetEventsWaitTimeout = (unitTest.EnableStubTest) ? 1000 : 310 * 1000;
string channel = "hello_my_channel";
jsonUserState = "{\"k\":\"v\"}";
KeyValuePair<string, object> kvp = new KeyValuePair<string, object>("k", "v");
userStateManualEvent = new ManualResetEvent(false);
pubnub.SetUserState<string>(channel, kvp, SetUserStateDummyMethodCallback, DummyErrorCallback);
userStateManualEvent.WaitOne(manualResetEventsWaitTimeout);
Thread.Sleep(2000);
receivedUserStateMessage = false;
KeyValuePair<string, object> kvp2 = new KeyValuePair<string, object>("k2", "v2");
userStateManualEvent = new ManualResetEvent(false);
pubnub.SetUserState<string>(channel, kvp2, SetUserStateDummyMethodCallback, DummyErrorCallback);
userStateManualEvent.WaitOne(manualResetEventsWaitTimeout);
Thread.Sleep(2000);
receivedUserStateMessage = false;
userStateManualEvent = new ManualResetEvent(false);
pubnub.GetUserState<string>(channel, "", GetUserStateRegularCallback, DummyErrorCallback);
userStateManualEvent.WaitOne(manualResetEventsWaitTimeout);
Thread.Sleep(2000);
receivedUserStateMessage = false;
KeyValuePair<string, object> kvp22 = new KeyValuePair<string, object>("k2", null);
userStateManualEvent = new ManualResetEvent(false);
pubnub.SetUserState<string>(channel, kvp22, SetUserStateDummyMethodCallback, DummyErrorCallback);
userStateManualEvent.WaitOne(manualResetEventsWaitTimeout);
Thread.Sleep(2000);
receivedUserStateMessage = false;
userStateManualEvent = new ManualResetEvent(false);
pubnub.GetUserState<string>(channel, "", GetUserStateRegularCallback, DummyErrorCallback);
userStateManualEvent.WaitOne(manualResetEventsWaitTimeout);
pubnub.EndPendingRequests();
pubnub.PubnubUnitTest = null;
pubnub = null;
Assert.IsTrue(receivedUserStateMessage, "IfSetAndDeleteUserStateThenItShouldReturnInfo message not received");
}
示例3: IfGlobalHereNowIsCalledThenItShouldReturnInfoWithUserState
public void IfGlobalHereNowIsCalledThenItShouldReturnInfoWithUserState()
{
receivedGlobalHereNowMessage = false;
currentTestCase = "IfGlobalHereNowIsCalledThenItShouldReturnInfoWithUserState";
pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
pubnub.SessionUUID = customUUID;
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAClientIsPresented";
unitTest.TestCaseName = "IfGlobalHereNowIsCalledThenItShouldReturnInfoWithUserState";
pubnub.PubnubUnitTest = unitTest;
string channel = "hello_my_channel";
manualResetEventsWaitTimeout = (unitTest.EnableStubTest) ? 1000 : 310 * 1000;
subscribeManualEvent = new ManualResetEvent(false);
pubnub.Subscribe<string>(channel, DummyMethodForSubscribe, SubscribeDummyMethodForConnectCallback, DummyErrorCallback);
Thread.Sleep(1000);
subscribeManualEvent.WaitOne(manualResetEventsWaitTimeout);
userStateManualEvent = new ManualResetEvent(false);
jsonUserState = "{\"testkey\":\"testval\"}";
pubnub.SetUserState<string>(channel, jsonUserState, SetUserStateDummyMethodCallback, DummyErrorCallback);
userStateManualEvent.WaitOne(manualResetEventsWaitTimeout);
globalHereNowManualEvent = new ManualResetEvent(false);
pubnub.GlobalHereNow<string>(true, true, ThenGlobalHereNowShouldReturnMessage, DummyErrorCallback);
globalHereNowManualEvent.WaitOne();
unsubscribeManualEvent = new ManualResetEvent(false);
pubnub.Unsubscribe<string>(channel, DummyMethodForUnSubscribe, UnsubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback, DummyErrorCallback);
Thread.Sleep(1000);
unsubscribeManualEvent.WaitOne(manualResetEventsWaitTimeout);
pubnub.EndPendingRequests();
pubnub.PubnubUnitTest = null;
pubnub = null;
Assert.IsTrue(receivedGlobalHereNowMessage, "global_here_now message not received for user state");
}
示例4: IfSetAndGetUserStateThenItShouldReturnInfo
public void IfSetAndGetUserStateThenItShouldReturnInfo()
{
receivedUserStateMessage = false;
currentTestCase = "IfSetAndGetUserStateThenItShouldReturnInfo";
pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
pubnub.SessionUUID = customUUID;
PubnubUnitTest unitTest = new PubnubUnitTest();
unitTest.TestClassName = "WhenAClientIsPresented";
unitTest.TestCaseName = "IfSetAndGetUserStateThenItShouldReturnInfo";
pubnub.PubnubUnitTest = unitTest;
manualResetEventsWaitTimeout = (unitTest.EnableStubTest) ? 1000 : 310 * 1000;
string channel = "hello_my_channel";
jsonUserState = "{\"testkey\":\"testval\"}";
userStateManualEvent = new ManualResetEvent(false);
pubnub.SetUserState<string>(channel,"", customUUID, jsonUserState, SetUserStateDummyMethodCallback, DummyErrorCallback);
userStateManualEvent.WaitOne(manualResetEventsWaitTimeout);
if (receivedUserStateMessage)
{
Thread.Sleep(2000);
receivedUserStateMessage = false;
userStateManualEvent = new ManualResetEvent(false);
pubnub.GetUserState<string>(channel, "", customUUID, GetUserStateRegularCallback, DummyErrorCallback);
userStateManualEvent.WaitOne(manualResetEventsWaitTimeout);
}
pubnub.EndPendingRequests();
pubnub.PubnubUnitTest = null;
pubnub = null;
Assert.IsTrue(receivedUserStateMessage, "IfSetAndGetUserStateThenItShouldReturnInfo failed");
}
示例5: Main
//.........这里部分代码省略.........
Console.ForegroundColor = ConsoleColor.Blue;
if (!string.IsNullOrEmpty (currentUserStateView)) {
Console.WriteLine ("Current User State = {0}", currentUserStateView);
} else {
Console.Write ("No User State Exists");
}
Console.ResetColor ();
break;
case "26":
Console.WriteLine ("Enter channel name");
string setUserStateChannel = Console.ReadLine ();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine (string.Format ("Channel = {0}", setUserStateChannel));
Console.ResetColor ();
//Console.WriteLine ("NOTE: Hopefully you added local user state.");
Console.WriteLine ("If you want to consider already created local user state, press ENTER");
Console.WriteLine ("Else enter user state in json format (Eg. {\"key1\":\"value1\",\"key2\":\"value2\"}");
string manualJsonUserState = Console.ReadLine ();
string jsonUserState = "";
if (string.IsNullOrEmpty (manualJsonUserState)) {
jsonUserState = pubnub.GetLocalUserState (setUserStateChannel);
} else {
jsonUserState = manualJsonUserState;
}
if (jsonUserState == "" || jsonUserState == "{}") {
Console.WriteLine ("Invalid User State");
break;
}
Console.WriteLine ("Enter UUID. (Optional. Press ENTER to skip it)");
string uuid = Console.ReadLine ();
if (string.IsNullOrEmpty (uuid)) {
pubnub.SetUserState<string> (setUserStateChannel, jsonUserState, DisplayReturnMessage, DisplayErrorMessage);
} else {
pubnub.SetUserState<string> (setUserStateChannel, uuid, jsonUserState, DisplayReturnMessage, DisplayErrorMessage);
}
break;
case "27":
Console.WriteLine ("Enter channel name");
string getUserStateChannel2 = Console.ReadLine ();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine (string.Format ("Channel = {0}", getUserStateChannel2));
Console.ResetColor ();
Console.WriteLine ("Enter UUID. (Optional. Press ENTER to skip it)");
string uuid2 = Console.ReadLine ();
if (string.IsNullOrEmpty (uuid2)) {
pubnub.GetUserState<string> (getUserStateChannel2, DisplayReturnMessage, DisplayErrorMessage);
} else {
pubnub.GetUserState<string> (getUserStateChannel2, uuid2, DisplayReturnMessage, DisplayErrorMessage);
}
break;
case "28":
Console.WriteLine ("Enter uuid for WhereNow. To consider SessionUUID, just press ENTER");
string whereNowUuid = Console.ReadLine ();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine (string.Format ("uuid = {0}", whereNowUuid));
Console.ResetColor ();
Console.WriteLine ();
Console.WriteLine ("Running Where_Now()");
pubnub.WhereNow<string> (whereNowUuid, DisplayReturnMessage, DisplayErrorMessage);
break;
case "29":