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


C# Pubnub.publish方法代码示例

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


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

示例1: ThenSubscribeShouldReturnReceivedMessage

        public void ThenSubscribeShouldReturnReceivedMessage()
        {
            receivedMessage = false;
            Pubnub pubnub = new Pubnub("demo","demo","","",false);

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

            pubnub.PubnubUnitTest = unitTest;


            string channel = "my/channel";

            pubnub.subscribe<string>(channel, ReceivedMessageCallbackNoConnect);
            //Thread.Sleep(5000);

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

            meSubNoConnect.WaitOne(310 * 1000);
            pubnub.unsubscribe<string>(channel, dummyUnsubCallback);
            
            meUnsub.WaitOne(310 * 1000);
            Assert.IsTrue(receivedMessage,"WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed");
        }
开发者ID:sevco777,项目名称:pubnub-api,代码行数:26,代码来源:WhenSubscribedToAChannel.cs

示例2: Receive_from_standIn

        public void Receive_from_standIn()
        {
            var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt");
            using (var sut = new PubnubHostTransceiver(cre, "hostchannel"))
            {

                var are = new AutoResetEvent(false);
                HostInput result = null;
                sut.ReceivedFromStandIn += _ =>
                                               {
                                                   result = _;
                                                   are.Set();
                                               };

                var standIn = new Pubnub(cre.PublishingKey, cre.SubscriptionKey, cre.SecretKey);
                var hi = new HostInput{CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "portname", StandInEndpointAddress = "endpoint"};
                standIn.publish("hostchannel", hi.Serialize(), _ => { });

                Assert.IsTrue(are.WaitOne(5000));

                Assert.AreEqual(hi.CorrelationId, result.CorrelationId);
                Assert.AreEqual(hi.Data, result.Data);
                Assert.AreEqual(hi.Portname, result.Portname);
                Assert.AreEqual(hi.StandInEndpointAddress, result.StandInEndpointAddress);
            }
        }
开发者ID:kennychou0529,项目名称:NPantaRhei,代码行数:26,代码来源:test_PubnubHostTransceiver.cs

示例3: 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 = "my/channel";
            string message = messageForUnencryptPublish;

            pubnub.publish<string>(channel, message, ReturnSuccessUnencryptPublishCodeCallback);
            manualEvent1.WaitOne(310*1000);

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

示例4: Receive_from_host

        public void Receive_from_host()
        {
            var cre = PubnubCredentials.LoadFrom("pubnub credentials.txt");

            using (var sut = new PubnubStandInTransceiver(cre, "hostchannel"))
            {
                var are = new AutoResetEvent(false);
                HostOutput result = null;
                sut.ReceivedFromHost += _ =>
                                            {
                                                result = _;
                                                are.Set();
                                            };

                var sender = new Pubnub(cre.PublishingKey, cre.SubscriptionKey);
                var ho = new HostOutput {CorrelationId = Guid.NewGuid(), Data = "hello".Serialize(), Portname = "portname"};
                sender.publish(sut.StandInEndpointAddress, ho.Serialize(), _ => { });

                Assert.IsTrue(are.WaitOne(5000));

                Assert.AreEqual(ho.CorrelationId, result.CorrelationId);
                Assert.AreEqual(ho.Data, result.Data);
                Assert.AreEqual(ho.Portname, result.Portname);
            }
        }
开发者ID:kennychou0529,项目名称:NPantaRhei,代码行数:25,代码来源:test_PubnubStandInTransceiver.cs

示例5: IfSSLNotProvidedThenDefaultShouldBeFalse

        public void IfSSLNotProvidedThenDefaultShouldBeFalse()
        {
            isPublished3 = false;
            Pubnub pubnub = new Pubnub("demo", "demo", "");
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            pubnub.publish<string>(channel, message, ReturnNoSSLDefaultFalseCallback);
            manualEvent3.WaitOne(310 * 1000);
            Assert.IsTrue(isPublished3, "Publish Failed with no SSL");
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:11,代码来源:WhenAMessageIsPublished.cs

示例6: IfSSLNotProvidedThenDefaultShouldBeFalse

        public void IfSSLNotProvidedThenDefaultShouldBeFalse()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                ""
            );
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

            Assert.AreEqual(true, pubnub.publish(channel, message));
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:14,代码来源:WhenAMessageIsPublished.cs

示例7: ThenItShouldReturnSuccessCodeAndInfo

        public void ThenItShouldReturnSuccessCodeAndInfo()
        {
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                false
            );
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

            pubnub.publish(channel, message);
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:15,代码来源:WhenAMessageIsPublished.cs

示例8: 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:jasonsperske,项目名称:pubnub-api,代码行数:15,代码来源:WhenSubscribedToAChannel.cs

示例9: ThenPublishKeyShouldNotBeEmptyAfterOverriden

        public void ThenPublishKeyShouldNotBeEmptyAfterOverriden()
        {
            Pubnub pubnub = new Pubnub(
                "",
                "demo",
                "",
                false
            );
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            pubnub.PropertyChanged += new PropertyChangedEventHandler(Pubnub_PropertyChanged);

            Assert.AreEqual(false, pubnub.publish(channel, message));
        }
开发者ID:Vlanta,项目名称:c-sharp,代码行数:15,代码来源:WhenAMessageIsPublished.cs

示例10: IfSSLNotProvidedThenDefaultShouldBeFalse

        public void IfSSLNotProvidedThenDefaultShouldBeFalse()
        {
            publishedMessage = false;
            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                ""
            );
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            pubnub.publish(channel, message, ThenDoCallback);
            manualEvent.WaitOne();
            Assert.IsTrue(publishedMessage);
        }
开发者ID:orcuna,项目名称:pubnub-api,代码行数:15,代码来源:WhenAMessageIsPublished.cs

示例11: ThenSubscribeShouldReturnReceivedMessage

        public void ThenSubscribeShouldReturnReceivedMessage()
        {
            receivedMessage = false;
            Pubnub pubnub = new Pubnub("demo","demo","","",false);

            string channel = "my/channel";

            pubnub.subscribe<string>(channel, ReceivedMessageCallback);
            Thread.Sleep(5000);

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

            manualEvent1.WaitOne(310*1000);
            Assert.IsTrue(receivedMessage,"WhenSubscribedToAChannel --> ThenItShouldReturnReceivedMessage Failed");
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:16,代码来源:WhenSubscribedToAChannel.cs

示例12: ThenItShouldReturnSuccessCodeAndInfo

        public void ThenItShouldReturnSuccessCodeAndInfo()
        {
            publishedMessage = false;

            Pubnub pubnub = new Pubnub(
                "demo",
                "demo",
                "",
                "",
                false
            );
            string channel = "my/channel";
            string message = "Pubnub API Usage Example";

            pubnub.publish(channel, message,ThenDoCallback);
            manualEvent.WaitOne();
            Assert.IsTrue(publishedMessage);
        }
开发者ID:orcuna,项目名称:pubnub-api,代码行数:18,代码来源:WhenAMessageIsPublished.cs

示例13: Run

        public void Run()
        {
            var are = new AutoResetEvent(false);

            var pubnubServer = new Pubnub("demo", "demo");
            pubnubServer.subscribe("testchannel", (ReadOnlyCollection<object> _) =>
                                                      {
                                                          var v = _[0] as JValue;
                                                          var a = Convert.FromBase64String((string)v.Value);
                                                          Console.WriteLine("received: {0}", a);
                                                          are.Set();
                                                      });

            var pubnubClient = new Pubnub("demo", "demo");
            pubnubClient.publish("testchannel", new byte[]{1,2,3}, _ => Console.WriteLine("published"));

            Assert.IsTrue(are.WaitOne(5000));
        }
开发者ID:kennychou0529,项目名称:NPantaRhei,代码行数:18,代码来源:explore_PubNub.cs

示例14: DetailedHistoryStartWithReverseTrue

        public void DetailedHistoryStartWithReverseTrue()
        {
            expectedCountAtStartTimeWithReverseTrue = 0;
            msgStartReverseTrue = false;
            Pubnub pubnub = new Pubnub("demo", "demo", "", "", false);
            string channel = "my/channel";
            startTimeWithReverseTrue = Pubnub.translateDateTimeToPubnubUnixNanoSeconds(DateTime.UtcNow);
            for (int index = 0; index < 10; index++)
            {
                pubnub.publish<string>(channel,
                    string.Format("DetailedHistoryStartTimeWithReverseTrue {0} {1}", startTimeWithReverseTrue, index),
                    DetailedHistorySamplePublishCallback);
                mrePublishStartReverseTrue.WaitOne(5000);
            }

            Thread.Sleep(5000);

            pubnub.detailedHistory<string>(channel, startTimeWithReverseTrue, DetailedHistoryStartWithReverseTrueCallback, true);
            mreMsgStartReverseTrue.WaitOne(310 * 1000);
            Assert.IsTrue(msgStartReverseTrue, "Detailed History with Start and Reverse True Failed");
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:21,代码来源:WhenDetailedHistoryIsRequested.cs

示例15: ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo

        public void ThenEncryptObjectPublishShouldReturnSuccessCodeAndInfo()
        {
            isEncryptObjectPublished = false;
            Pubnub pubnub = new Pubnub("demo", "demo", "", "enigma", false);
            string channel = "my/channel";
            object message = new SecretCustomClass();
            messageObjectForEncryptPublish = JsonConvert.SerializeObject(message);

            pubnub.publish<string>(channel, message, ReturnSuccessEncryptObjectPublishCodeCallback);
            mreEncryptObjectPub.WaitOne(310 * 1000);

            if (!isEncryptObjectPublished)
            {
                Assert.IsTrue(isEncryptObjectPublished, "Encrypt Object Publish Failed");
            }
            else
            {
                pubnub.detailedHistory<string>(channel, -1, encryptObjectPublishTimetoken, -1, false, CaptureEncryptObjectDetailedHistoryCallback);
                mreEncryptObjectDH.WaitOne(310 * 1000);
                Assert.IsTrue(isEncryptObjectDH, "Unable to match the successful encrypt object Publish");
            }
        }
开发者ID:netcon-source,项目名称:pubnub-api,代码行数:22,代码来源:WhenAMessageIsPublished.cs


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