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


C# Pubnub.Publish方法代码示例

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


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

示例1: Main

        public static void Main()
        {
            // Start the HTML5 Pubnub client
            Process.Start("..\\..\\PubNub-HTML5-Client.html");

            Thread.Sleep(2000);

            Pubnub pubnub = new Pubnub(
                "pub-c-dfec8b59-9beb-4446-8230-236e56a93b34",               // PUBLISH_KEY
                "sub-c-1e7a2bac-8c71-11e5-84ee-0619f8945a4f",               // SUBSCRIBE_KEY
                "sec-c-MzI4MDA3ZWQtZDE5ZC00ODkxLTlmYTItYWZiZjE0MDY5Zjdi",   // SECRET_KEY
                "",
                true
            );

            string channel = "test-channel";

            // Publish a sample message to Pubnub
            pubnub.Publish<string>(
                channel,
                "Hello Pubnub!",
                DisplayReturnMessage,
                DisplayErrorMessage);

            // Subscribe for receiving messages (in a background task to avoid blocking)
            Task t = new Task(
                () =>
                pubnub.Subscribe<string>(
                    channel,
                    DisplaySubscribeReturnMessage,
                    DisplaySubscribeConnectStatusMessage,
                    DisplayErrorMessage
                )
            );
            t.Start();

            // Read messages from the console and publish them to Pubnub
            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                string msg = Console.ReadLine();
                pubnub.Publish<string>(
                    channel,
                    msg,
                    DisplayReturnMessage,
                    DisplayErrorMessage);
                Console.WriteLine("Message {0} sent.", msg);
            }
        }
开发者ID:MarinaGeorgieva,项目名称:TelerikAcademy,代码行数:49,代码来源:Startup.cs

示例2: ThenPublishMpnsToastShouldReturnSuccess

        public void ThenPublishMpnsToastShouldReturnSuccess()
        {
            receivedSuccessMessage = false;
            pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);
            string channel = "hello_my_channel";

            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenPushIsRequested";
            unitTest.TestCaseName = "ThenPublishMpnsToastShouldReturnSuccess";
            pubnub.PubnubUnitTest = unitTest;

            mrePublish = new ManualResetEvent(false);

            MpnsToastNotification toast = new MpnsToastNotification();
            toast.text1 = "hardcode message";
            Dictionary<string, object> dicToast = new Dictionary<string, object>();
            dicToast.Add("pn_mpns", toast);

            pubnub.EnableDebugForPushPublish = true;
            pubnub.Publish<string>(channel, dicToast, PublishCallbackResult, DummyErrorCallback);
            mrePublish.WaitOne(60 * 1000, false);

            pubnub.EndPendingRequests(); 
            pubnub.PubnubUnitTest = null;
            pubnub = null;
            Assert.True(receivedSuccessMessage, "Toast Publish Failed");
        }
开发者ID:RecursosOnline,项目名称:c-sharp,代码行数:27,代码来源:WhenPushIsRequested.cs

示例3: ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2

        public void ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2 ()
        {
            Pubnub pubnub = new Pubnub (
                Common.PublishKey,
                Common.SubscribeKey,
                              "",
                              "enigma",
                              false
                          );
            string channel = "hello_world";
            object message = new PubnubDemoObject ();

            Common common = new Common ();
          
            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2");
          
            common.DeliveryStatus = false;
            common.Response = null;
          
            pubnub.Publish (channel, message, common.DisplayReturnMessage, common.DisplayReturnMessage);
            //wait till the response is received from the server
            common.WaitForResponse ();
            if (common.Response != null) {
                IList<object> fields = common.Response as IList<object>;
                string sent = fields [1].ToString ();
                string one = fields [0].ToString ();
                Assert.True (("Sent").Equals (sent));
                Assert.True (("1").Equals (one));
            } else {
                Assert.Fail ("Null response");
            }
        }
开发者ID:jugalkishor-sujal,项目名称:c-sharp,代码行数:32,代码来源:WhenAMessageIsPublished.cs

示例4: 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 = "hello_my_channel";
            string message = messageForUnencryptPublish;

            pubnub.Publish<string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback, DummyErrorCallback);
            mreUnencryptedPublish.WaitOne(310*1000);

            if (!isUnencryptPublished)
            {
                Assert.IsTrue(isUnencryptPublished, "Unencrypt Publish Failed");
            }
            else
            {
                pubnub.DetailedHistory<string>(channel, -1, unEncryptPublishTimetoken, -1, false, CaptureUnencryptDetailedHistoryCallback, DummyErrorCallback);
                mreUnencryptDetailedHistory.WaitOne(310 * 1000);
                Assert.IsTrue(isUnencryptDetailedHistory, "Unable to match the successful unencrypt Publish");
            }
        }
开发者ID:kaido42,项目名称:c-sharp,代码行数:25,代码来源:WhenAMessageIsPublished.cs

示例5: ThenItShouldReturnSuccessCodeAndInfo

		public void ThenItShouldReturnSuccessCodeAndInfo()
		{
			Pubnub pubnub = new Pubnub(
				"demo",
				"demo",
				"",
				"",
				false
				);
			string channel = "hello_world";
			string message = "Pubnub API Usage Example";
			
			Common common = new Common();
			
			pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfo");
			
			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.True (("Sent").Equals(sent));
			Assert.True(("1").Equals(one));
		}
开发者ID:Vlanta,项目名称:c-sharp,代码行数:28,代码来源:WhenAMessageIsPublished.cs

示例6: History

 public void History()
 {
     var channel = "csharp_history_test";
     var pn = new Pubnub("demo", "demo", string.Empty);
     pn.Publish(channel, new { name = "test" });
     Assert.IsTrue(pn.History("csharp_history_test", 10).Count > 0);
 }
开发者ID:martindevans,项目名称:pubnub,代码行数:7,代码来源:History.cs

示例7: Main

        static public void Main()
        {
            Pubnub pubnub = new Pubnub(
                                       publishKey: "pub-c-d8635a25-b556-4267-84c4-a9db379cd66a",
                                       subscribeKey: "sub-c-e809ad42-8bd8-11e5-bf00-02ee2ddab7fe");

            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(
                () =>
                pubnub.Subscribe<string>(
                channel: channel,
                userCallback: DisplaySubscribeReturnMessage,
                connectCallback: DisplaySubscribeConnectStatusMessage,
                errorCallback: DisplayErrorMessage)
            );
            t.Start();

            while (true)
            {
                Console.Write("Enter a message to be sent to Pubnub: ");
                string msg = Console.ReadLine();
                pubnub.Publish<string>(
                    channel: channel,
                    message: msg,
                    userCallback: DisplayReturnMessage,
                    errorCallback: DisplayErrorMessage);
                Console.WriteLine("Message {0} sent.", msg);
            }
        }
开发者ID:NikitoG,项目名称:TelerikAcademyHomeworks,代码行数:28,代码来源:PubnubExample.cs

示例8: ThenSubscribeShouldReturnReceivedMessage

        public void ThenSubscribeShouldReturnReceivedMessage()
        {
            receivedMessage = false;
            Pubnub pubnub = new Pubnub(PubnubCommon.PublishKey, PubnubCommon.SubscribeKey, "", "", false);

            PubnubUnitTest unitTest = new PubnubUnitTest();
            unitTest.TestClassName = "WhenSubscribedToAChannel";
            unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage";

            pubnub.PubnubUnitTest = unitTest;

            string channel = "hello_my_channel";

            pubnub.Subscribe<string>(channel, ReceivedMessageCallbackWhenSubscribed, SubscribeDummyMethodForConnectCallback, DummyErrorCallback);
            Thread.Sleep(1000);
            pubnub.Publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback, DummyErrorCallback);
            manualResetEventsWaitTimeout = (unitTest.EnableStubTest) ? 1000 : 310 * 1000;
            mePublish.WaitOne(manualResetEventsWaitTimeout);

            meSubscribeNoConnect.WaitOne(manualResetEventsWaitTimeout);
            pubnub.Unsubscribe<string>(channel, dummyUnsubscribeCallback, SubscribeDummyMethodForConnectCallback, UnsubscribeDummyMethodForDisconnectCallback, DummyErrorCallback);

            meUnsubscribe.WaitOne(manualResetEventsWaitTimeout);
            
            pubnub.EndPendingRequests();

            Assert.IsTrue(receivedMessage,"WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed");
        }
开发者ID:Evgeniy20,项目名称:c-sharp,代码行数:28,代码来源:WhenSubscribedToAChannel.cs

示例9: NullMessage

        public void NullMessage()
        {
            Pubnub pubnub = new Pubnub(
                Common.PublishKey,
                Common.SubscribeKey,
                                "",
                                "",
                                false
                            );
            string channel = "hello_world";
            string message = null;

            Common common = new Common();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.Publish(channel, message, common.DisplayReturnMessage, common.DisplayReturnMessage);
            //wait till the response is received from the server
            common.WaitForResponse();
            if (common.Response != null)
                {
                    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);
                } else
                {
                    Assert.Fail("Null response");
                }
        }
开发者ID:jugalkishor-sujal,项目名称:c-sharp,代码行数:31,代码来源:WhenAMessageIsPublished.cs

示例10: ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2

 public void ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2()
 {
   Pubnub pubnub = new Pubnub(
     "demo",
     "demo",
     "",
     "enigma",
     false
     );
   string channel = "hello_world";
   object message = new PubnubDemoObject();
   
   Common common = new Common();
   
   pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenAMessageIsPublished", "ThenItShouldReturnSuccessCodeAndInfoForEncryptedComplexMessage2");
   
   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);
 }
开发者ID:Vlanta,项目名称:c-sharp,代码行数:28,代码来源:WhenAMessageIsPublished.cs

示例11: ThenSubscribeShouldReturnReceivedMessage

        public void ThenSubscribeShouldReturnReceivedMessage()
        {
            receivedMessage = false;
            ThreadPool.QueueUserWorkItem((s) =>
                {
                    Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);

                    string channel = "my/channel";

                    PubnubUnitTest unitTest = new PubnubUnitTest();
                    unitTest.TestClassName = "WhenSubscribedToAChannel";
                    unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage";
                    pubnub.PubnubUnitTest = unitTest;

                    pubnub.Subscribe<string>(channel, ReceivedMessageCallback);

                    pubnub.Publish<string>(channel, "Test for WhenSubscribedToAChannel ThenItShouldReturnReceivedMessage", dummyPublishCallback);
                    mePublish.WaitOne(310 * 1000);

                    meSubscribeNoConnect.WaitOne(310 * 1000);
                    
                    pubnub.Unsubscribe<string>(channel, dummyUnsubCallback);
                    meUnsubscribe.WaitOne(310 * 1000);
                    Thread.Sleep(100);
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            Assert.IsTrue(receivedMessage, "WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed");
                            TestComplete();
                        });
                });
        }
开发者ID:hellogurus,项目名称:pubnub-api,代码行数:31,代码来源:WhenSubscribedToAChannel.cs

示例12: ItShouldReturnDetailedHistory

        public void ItShouldReturnDetailedHistory ()
        {
            GC.Collect ();
            Pubnub pubnub = new Pubnub (
                          Common.PublishKey,
                          Common.SubscribeKey,
                          "",
                          "",
                          false
                      );
            string channel = "hello_world_de1";
            string message = "Test Message";
      
            Common common = new Common ();
            common.DeliveryStatus = false;
            common.Response = null;

            pubnub.PubnubUnitTest = common.CreateUnitTestInstance ("WhenDetailedHistoryIsRequested", "ItShouldReturnDetailedHistory");
      
            //publish a test message. 
            pubnub.Publish (channel, message, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
      
            common.WaitForResponse ();

            common.DeliveryStatus = false;
            common.Response = null;
            Thread.Sleep (1000);
            pubnub.DetailedHistory (channel, 1, common.DisplayReturnMessage, common.DisplayReturnMessageDummy);
            common.WaitForResponse ();

            ParseResponse (common.Response, 0, 0, message);
            pubnub.EndPendingRequests ();
        }
开发者ID:seeva92,项目名称:c-sharp,代码行数:33,代码来源:WhenDetailedHistoryIsRequested.cs

示例13: ItShouldReturnDetailedHistory

		public void ItShouldReturnDetailedHistory()
		{
			Pubnub pubnub = new Pubnub(
				"demo",
				"demo",
				"",
				"",
				false
				);
			string channel = "hello_world";
			string message = "Test message";
			
			Common common = new Common();
			common.DeliveryStatus = false;
			common.Response = null;
			
			//publish a test message. 
			pubnub.Publish(channel, message, common.DisplayReturnMessage);
			
			while (!common.DeliveryStatus); 
			
			pubnub.PubnubUnitTest = common.CreateUnitTestInstance("WhenDetailedHistoryIsRequested" ,"ItShouldReturnDetailedHistory");
			
			common.DeliveryStatus = false;
			common.Response = null;
			pubnub.DetailedHistory(channel, 1, common.DisplayReturnMessage);
			while (!common.DeliveryStatus);
			
			ParseResponse(common.Response, 0, 0, message);
		}
开发者ID:primohit,项目名称:pubnub-api,代码行数:30,代码来源:WhenDetailedHistoryIsRequested.cs

示例14: Notify

        public string Notify(string user, object message)
        {

            var pubnub = new Pubnub(PubKey, SubKey);
            pubnub.Publish(user, message, SuccessCB, ErrorCB);
            return this.response;
        }
开发者ID:WebAndClauld-Teamwork---Team-Mango,项目名称:RecepiesApi,代码行数:7,代码来源:Notifier.cs

示例15: 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);
        }
开发者ID:Vlanta,项目名称:c-sharp,代码行数:25,代码来源:WhenAMessageIsPublished.cs


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