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


C# Pubnub.publish方法代码示例

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


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

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

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

示例3: 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));
        }
开发者ID:stjom,项目名称:pubnub-api,代码行数:30,代码来源:WhenAMessageIsPublished.cs

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

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

示例6: 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();
        }
开发者ID:inncapsule,项目名称:CSharpUrlEncodingFix,代码行数:25,代码来源:Pubnub_Example.cs

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

示例8: 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");
                }
             }
        }
       }
开发者ID:jhey,项目名称:pubnub-api,代码行数:59,代码来源:WhenDetailedHistoryIsRequested.cs

示例9: IfSSLNotProvidedThenDefaultShouldBeFalse

 public void IfSSLNotProvidedThenDefaultShouldBeFalse()
 {
     Pubnub pubnub = new Pubnub(
         "demo",
         "demo",
         ""
     );
     string channel = "hello_world";
     string message = "Pubnub API Usage Example";
     Common cm = new Common();
     Assert.AreEqual(true, pubnub.publish(channel, message, cm.DisplayReturnMessage));
 }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:12,代码来源:WhenAMessageIsPublished.cs

示例10: NullShouldBeTreatedAsEmpty

 public void NullShouldBeTreatedAsEmpty()
 {
     Pubnub pubnub = new Pubnub(
         null,
         "demo",
         null,
         null,
         false
     );
     string channel = "mychannel";
     string message = "Pubnub API Usage Example";
     Common cm = new Common();
     Assert.AreEqual(false, pubnub.publish(channel, message, cm.DisplayReturnMessage));
 }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:14,代码来源:WhenAMessageIsPublished.cs

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

示例12: 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 = "WhenSubscribedToAChannel";
			unitTest.TestCaseName = "ThenSubscribeShouldReturnReceivedMessage";
			
			pubnub.PubnubUnitTest = unitTest;
			
			pubnub.subscribe (channel, cm.DisplayReturnMessage); 
			Thread.Sleep(3000);
			string msg = "Test Message";
			
			pubnub.publish (channel, msg, cm.DisplayReturnMessageDummy);
			//cm.deliveryStatus = false;
			while (!cm.deliveryStatus);
			if (cm.objResponse != null) {
				IList<object> fields = cm.objResponse as IList<object>;
				
				if (fields [0] != null)
				{
					var myObjectArray = (from item in fields select item as object).ToArray ();
					Console.WriteLine ("Resp:" + myObjectArray[0].ToString ());
					Assert.AreEqual(msg, myObjectArray[0].ToString());
				}
				else
				{
					Assert.Fail("No response");
				}
			}
			else
			{
				Assert.Fail("No response");
			}
		}
开发者ID:stjom,项目名称:pubnub-api,代码行数:47,代码来源:WhenSubscribedToAChannel.cs

示例13: ThenItShouldReturnHistoryMessages

        public void ThenItShouldReturnHistoryMessages ()
        {
            Pubnub pubnub = new Pubnub (
                "demo",
                "demo",
                "",
                "",
                false
            );
            string channel = "hello_world";
            bool responseStatus = false;
            //publish a test message.
            Common cm = new Common();
            cm.deliveryStatus = false;
            cm.objResponse = null;
            pubnub.publish (channel, "Test message", cm.DisplayReturnMessage);

            List<object> lstHistory = null;

            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) {
                if (e.PropertyName == "History")
                {
                    lstHistory = ((Pubnub)sender).History;
           
                    responseStatus = true;
                }
            };

            pubnub.history(channel, 1);

            /*while (!responseStatus) ;

            string strResponse = "";
            if (lstHistory.Equals (null)) {
                Assert.Fail("Null response");
            }
            else
            {
                foreach(object lst in lstHistory)
                {
                    strResponse = lst.ToString();
                    Console.WriteLine("resp:" + strResponse);
                    Assert.IsNotEmpty(strResponse);
                }
            }*/
        }
开发者ID:stjom,项目名称:pubnub-api,代码行数:46,代码来源:WhenGetRequestHistoryMessages.cs

示例14: TestUnencryptedHistory

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

            string message = "Pubnub API Usage Example - Publish";
            //pubnub.CIPHER_KEY = "enigma";

            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "History")
                {
                    Console.WriteLine("\n*********** History Messages *********** ");
                    cm.deliveryStatus = true;
                }
            };
            cm.deliveryStatus = false;
            pubnub.publish(channel, message, cm.DisplayReturnMessage);
            while (!cm.deliveryStatus) ;

            cm.deliveryStatus = false;
            pubnub.history(channel, 1);
            while (!cm.deliveryStatus) ;
            if (pubnub.History[0].Equals (null)) {
                Assert.Fail("Null response");
            }
            else
            {
                Assert.True(message.Equals(pubnub.History[0].ToString()));
            }
        }
开发者ID:stjom,项目名称:pubnub-api,代码行数:39,代码来源:WhenGetRequestHistoryMessages.cs

示例15: Publish_Example

        static void Publish_Example()
        {
            Pubnub pubnub = new Pubnub(
                    "demo",
                    "demo",
                    "",
                    false);
            string channel = "hello_world";
            string message = "Pubnub API Usage Example - Publish";

            pubnub.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                if (e.PropertyName == "Publish")
                {
                    Console.WriteLine("\n*********** Publish Messages *********** ");
                    Console.WriteLine(
                        "Publish Success: " + ((Pubnub)sender).Publish[0].ToString() +
                        "\nPublish Info: " + ((Pubnub)sender).Publish[1].ToString()
                        );
                }
            };
            pubnub.publish(channel, message);
        }
开发者ID:Vlanta,项目名称:c-sharp,代码行数:23,代码来源:Pubnub_Example.cs


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