当前位置: 首页>>代码示例>>C#>>正文


C# Pubnub.presence方法代码示例

本文整理汇总了C#中PubNub_Messaging.Pubnub.presence方法的典型用法代码示例。如果您正苦于以下问题:C# Pubnub.presence方法的具体用法?C# Pubnub.presence怎么用?C# Pubnub.presence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PubNub_Messaging.Pubnub的用法示例。


在下文中一共展示了Pubnub.presence方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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();
                       });
                });
        }
开发者ID:hart404,项目名称:pubnub-api,代码行数:25,代码来源:WhenAClientIsPresented.cs

示例2: 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;
                }
            }
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:33,代码来源:Presence_Example.cs

示例3: ThenItShouldReturnReceivedMessage

        public void ThenItShouldReturnReceivedMessage()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );
            string channel = "hello_world";
            Common cm = new Common();
            cm.deliveryStatus = false;
            cm.objResponse = null;

            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenAClientIsPresented";
            unitTest.TestCaseName = "ThenPresenceShouldReturnReceivedMessage";
            pubnub.PubnubUnitTest = unitTest;

            pubnub.presence(channel, cm.DisplayReturnMessage);
            //while (!cm.deliveryStatus) ;
            //cm.objResponse = null;
            pubnub.subscribe(channel, cm.DisplayReturnMessageDummy);
            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("Resp:" + strResponse);
                    //Assert.IsNotEmpty(strResponse);
                }
                Assert.AreEqual("hello_world", fields[2]);
            }
        }
开发者ID:stjom,项目名称:pubnub-api,代码行数:41,代码来源:WhenAClientIsPresented.cs

示例4: Presence_Example

        static void Presence_Example()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    false);
            string channel = "hello_world";

            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "ReturnMessage")
                {
                    Console.WriteLine("\n********** Presence Messages ********** ");
                    MessageFeeder(((Pubnub)sender).ReturnMessage);
                }
            };
            pubnub.presence(channel);
        }
开发者ID:Vlanta,项目名称:c-sharp,代码行数:19,代码来源:Pubnub_Example.cs

示例5: Main


//.........这里部分代码省略.........
            while (!exitFlag)
            {
                string userinput = Console.ReadLine();
                switch (userinput)
                {
                    case "0":
                        exitFlag = true;
                        break;
                    case "1":
                        Console.WriteLine("Running subscribe() (not implementing connectCallback)");
                        pubnub.subscribe<string>(channel, DisplayReturnMessage);
                        //System.Threading.Tasks.Task subtask = System.Threading.Tasks.Task.Factory.StartNew(() => pubnub.subscribe<string>(channel, DisplayReturnMessage));
                        //pubnub.subscribe<object>(channel, DisplayReturnMessage);
                        //pubnub.subscribe(channel, DisplayReturnMessage);
                        break;
                    case "2":
                        Console.WriteLine("Running subscribe() (implementing connectCallback)");
                        pubnub.subscribe<string>(channel, DisplayReturnMessage, DisplayConnectStatusMessage);
                        //System.Threading.Tasks.Task subtask = System.Threading.Tasks.Task.Factory.StartNew(() => pubnub.subscribe<string>(channel, DisplayReturnMessage));
                        //pubnub.subscribe<object>(channel, DisplayReturnMessage);
                        //pubnub.subscribe(channel, DisplayReturnMessage);
                        break;
                    case "3":
                        Console.WriteLine("Running publish()");
                        Console.WriteLine("Enter the message for publish. To exit loop, enter QUIT");
                        string publishMsg = Console.ReadLine();
                        double doubleData;
                        int intData;
                        if (int.TryParse(publishMsg, out intData))
                        {
                            pubnub.publish<string>(channel, intData, DisplayReturnMessage);
                        }
                        else if (double.TryParse(publishMsg, out doubleData))
                        {
                            pubnub.publish<string>(channel, doubleData, DisplayReturnMessage);
                        }
                        else
                        {
                            //check whether any numeric is sent in double quotes
                            if (publishMsg.IndexOf("\"") == 0 && publishMsg.LastIndexOf("\"") == publishMsg.Length - 1)
                            {
                                string strMsg = publishMsg.Substring(1, publishMsg.Length - 2);
                                if (int.TryParse(strMsg, out intData))
                                {
                                    pubnub.publish<string>(channel, strMsg, DisplayReturnMessage);
                                }
                                else if (double.TryParse(strMsg, out doubleData))
                                {
                                    pubnub.publish<string>(channel, strMsg, DisplayReturnMessage);
                                }
                                else
                                {
                                    pubnub.publish<string>(channel, publishMsg, DisplayReturnMessage);
                                }
                            }
                            else
                            {
                                pubnub.publish<string>(channel, publishMsg, DisplayReturnMessage);
                            }
                        }
                        break;
                    case "4":
                        Console.WriteLine("Running presence()");
                        pubnub.presence<string>(channel, DisplayReturnMessage);
                        //System.Threading.Tasks.Task pretask = System.Threading.Tasks.Task.Factory.StartNew(() => pubnub.presence<string>(channel, DisplayReturnMessage));
                        //pubnub.presence<object>(channel, DisplayReturnMessage);
                        break;
                    case "5":
                        Console.WriteLine("Running detailed history()");
                        pubnub.detailedHistory<string>(channel, 100, DisplayReturnMessage);
                        //pubnub.detailedHistory<object>(channel, 100, DisplayReturnMessage);
                        break;
                    case "6":
                        Console.WriteLine("Running Here_Now()");
                        pubnub.here_now<string>(channel, DisplayReturnMessage);
                        //pubnub.here_now<object>(channel, DisplayReturnMessage);
                        break;
                    case "7":
                        Console.WriteLine("Running unsubscribe()");
                        pubnub.unsubscribe<string>(channel, DisplayReturnMessage);
                        //pubnub.unsubscribe<object>(channel, DisplayReturnMessage);
                        break;
                    case "8":
                        Console.WriteLine("Running presence-unsubscribe()");
                        pubnub.presence_unsubscribe<string>(channel, DisplayReturnMessage);
                        break;
                    case "9":
                        Console.WriteLine("Running time()");
                        pubnub.time<string>(DisplayReturnMessage);
                        break;
                    default:
                        Console.WriteLine("INVALID CHOICE.");
                        break;
                }
            }

            Console.WriteLine("\nPress any key to confirm exit.\n\n");
            Console.ReadLine();

        }
开发者ID:sevco777,项目名称:pubnub-api,代码行数:101,代码来源:Pubnub_Example.cs

示例6: Presence_Example

        public static void Presence_Example()
        {
            Pubnub pubnub = new Pubnub (
                   "demo",
                   "demo",
                   "",
                   "",
                   false);
            string channel = "hello_world";

            deliveryStatus = false;

            pubnub.presence (channel, DisplayReturnMessage);
            Pubnub pubnub2 = new Pubnub (
                   "demo",
                   "demo",
                   "",
                   "",
                   false);

            pubnub2.subscribe (channel, DisplayReturnMessage);

            bool bStop = false;
            while (!bStop) {
                if (objResponse != null) {
                    IList<object> fields = objResponse as IList<object>;

                    if (fields [0] != null)
                    {
                         var myObjectArray = (from item in fields select item as object).ToArray ();
                        IEnumerable enumerable = myObjectArray [0] as IEnumerable;
                        if (enumerable != null) {
                            foreach (object element in enumerable)
                            {
                                Console.WriteLine ("Resp:" + element.ToString ());
                                //bStop = true;
                            }
                        }
                    }
                }
            }
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:42,代码来源:PubNub-Example2.cs

示例7: Presence_Example

        static void Presence_Example()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    false);
            string channel = "my/channel";

            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "ReturnMessage")
                {
                    Dictionary<string, object> _message = (Dictionary<string, object>)(((Pubnub)sender).ReturnMessage);
                    Console.WriteLine("Received Message -> '" + _message["text"] + "'");
                }
            };
            pubnub.presence(channel);
        }
开发者ID:inncapsule,项目名称:pubnub-api,代码行数:19,代码来源:Pubnub_Example.cs


注:本文中的PubNub_Messaging.Pubnub.presence方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。