public void ReleasedMessageAtQos2RemovesMessageFromStorage() { Func <MqttMessage, bool> pubCallback = null; Func <MqttMessage, bool> pubRelCallback = null; short msgId = 1; var mock = new Mock <IMqttConnectionHandler>(); mock.Setup(x => x.RegisterForMessage(MqttMessageType.Publish, It.IsAny <Func <MqttMessage, bool> >())) .Callback((MqttMessageType mt, Func <MqttMessage, bool> cb) => pubCallback = cb); mock.Setup(x => x.RegisterForMessage(MqttMessageType.PublishRelease, It.IsAny <Func <MqttMessage, bool> >())) .Callback((MqttMessageType mt, Func <MqttMessage, bool> cb) => pubRelCallback = cb); var pm = new PublishingManager(mock.Object); // fake a publish from a remote party and verify we sent a received back. pubCallback(new MqttPublishMessage() .WithMessageIdentifier(msgId) .ToTopic("A/Topic") .WithQos(MqttQos.ExactlyOnce) .PublishData(new byte[] { 0, 1, 2 })); var rcvdMsgs = GetReceivedMessages(pm); Assert.True(rcvdMsgs.ContainsKey(msgId)); // fake the publish release message from remote party and verify that a publishcomplete is sent. pubRelCallback(new MqttPublishReleaseMessage().WithMessageIdentifier(msgId)); Assert.False(rcvdMsgs.ContainsKey(msgId)); }
public static IEnumerable <IDocument> GetNewsDocs(string[] providers, Guid searchIndexGuid, out int hitCount, Guid[] categories = null, string terms = null, int skip = 0, int take = 0, string[] orderToSortResults = null) { ISearchService searchService = ServiceBus.ResolveService <ISearchService>(); ISearchQuery searchQuery = ObjectFactory.Resolve <ISearchQuery>(); var queryBuilder = ObjectFactory.Resolve <IQueryBuilder>(); //Note: Make sure the Index item has been re-generated via sitfinity's backend to get proper results //Guid.Parse("6894B15C-7836-6C70-9642-FF00005F0421") var publishingPoint = PublishingManager.GetManager("SearchPublishingProvider") .GetPublishingPoint(searchIndexGuid) as PublishingPoint; string catalogName = (publishingPoint.PipeSettings.First(p => p.PipeName == "SearchIndex") as SearchIndexPipeSettings).CatalogName; var orderBy = orderToSortResults != null ? orderToSortResults : new string[] { "PublicationDate DESC" }; //searchQuery.IndexName = AppSettingsUtility.GetValue<string>("NewsCatalogName"); searchQuery.IndexName = catalogName; searchQuery.OrderBy = orderBy; searchQuery.Skip = skip; searchQuery.Take = take; searchQuery.SearchGroup = BuildQuery(categories, providers); var resultSet = searchService.Search(searchQuery); hitCount = resultSet.HitCount; log.InfoFormat("search cate:{0}, limit:{1}, hit:{2}", catalogName, take, hitCount); return(resultSet.SetContentLinks()); }
private static bool TryInitialize(ConfigElementList <SearchIndexStartupElement> indexes, out WarmupParameters parameters) { parameters = null; if (!(indexes?.Count > 0)) { return(false); } var publishingManager = PublishingManager.GetManager(PublishingConfig.SearchProviderName); if (publishingManager == null) { return(false); } var searchService = ServiceBus.ResolveService <ISearchService>(); if (searchService == null) { return(false); } parameters = new WarmupParameters { PublishingAdminService = new PublishingAdminService(), PublishingManager = publishingManager, SearchService = searchService, Indexes = ((IList <SearchIndexStartupElement>)indexes).OrderBy(i => i.WithBackgroundIndexing), WorkerDelegate = new SystemManager.RunWithElevatedPrivilegeDelegate(DoWarmup) }; return(true); }
/// <summary> /// Gets the received messages inside a publishing manager. /// </summary> /// <param name="pubMgr"></param> /// <returns></returns> private static Dictionary <int, MqttPublishMessage> GetReceivedMessages(PublishingManager pubMgr) { // we need to crack open the publishing manager and access some privates var fi = typeof(PublishingManager).GetField("receivedMessages", ReflectionBindingConstants.NonPublicField); return((Dictionary <int, MqttPublishMessage>)fi.GetValue(pubMgr)); }
/// <inheritdoc /> public virtual FeedViewModel GetViewModel() { var viewModel = new FeedViewModel(); viewModel.InsertionOption = this.InsertionOption; viewModel.CssClass = this.CssClass; if (this.FeedId != null && this.FeedId != Guid.Empty) { RssPipeSettings pipe = PublishingManager.GetManager().GetPipeSettings <RssPipeSettings>().Where(p => p.Id == this.FeedId).FirstOrDefault(); if (pipe != null) { string url = RouteHelper.ResolveUrl(String.Concat("~/", Config.Get <PublishingConfig>().FeedsBaseURl, "/", pipe.UrlName), UrlResolveOptions.Absolute); string title = (!string.IsNullOrEmpty(this.TextToDisplay)) ? HttpUtility.HtmlEncode(this.TextToDisplay) : string.Empty; if (this.InsertionOption == FeedInsertionOption.AddressBarOnly || this.InsertionOption == FeedInsertionOption.PageAndAddressBar) { viewModel.HeadLink = string.Format( CultureInfo.CurrentCulture, @"<link rel=""alternate"" type=""application/rss+xml"" title=""{0}"" href=""{1}""/>", title, url); } if (this.InsertionOption == FeedInsertionOption.PageOnly || this.InsertionOption == FeedInsertionOption.PageAndAddressBar) { viewModel.Title = title; viewModel.Url = url; viewModel.Tooltip = this.Tooltip; viewModel.OpenInNewWindow = this.OpenInNewWindow; } } } return(viewModel); }
private string GetCatalogueName(Guid searchIndexPipeId) { var searchManager = PublishingManager.GetManager(PublishingConfig.SearchProviderName); var pipeSettings = searchManager.GetPipeSettings <SearchIndexPipeSettings>(); var pipe = pipeSettings.SingleOrDefault(p => p.Id == searchIndexPipeId); if (pipe != null) { if (!SystemManager.CurrentContext.IsMultisiteMode) { return(pipe.CatalogName); } else { var siteId = SystemManager.CurrentContext.CurrentSite.Id; IList <Guid> sites; if (pipe.PublishingPoint.IsSharedWithAllSites) { sites = MultisiteManager.GetManager().GetSites().Select(s => s.Id).ToList(); } else { sites = this.GetSitesByPoint(pipe.PublishingPoint).Select(l => l.SiteId).ToList(); } if (sites.Contains(siteId)) { return(pipe.CatalogName); } } } return(string.Empty); }
public void PublishQos1Or2SavesMessageInStorage() { var chMock = new Mock <IMqttConnectionHandler>(); var pm = new PublishingManager(chMock.Object); int msgId = pm.Publish <string, AsciiPayloadConverter>("A/Topic", MqttQos.AtLeastOnce, "test"); var msgs = GetPublishedMessages(pm); Assert.True(msgs.ContainsKey(msgId)); }
public void PublishSendsPublishMessageThroughConnectionHandler() { var chMock = new Mock <IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny <MqttPublishMessage>())); var pm = new PublishingManager(chMock.Object); pm.Publish <string, AsciiPayloadConverter>("A/Topic", MqttQos.AtMostOnce, "test"); chMock.VerifyAll(); }
public void ConsequtivePublishOnSameTopicGetsNextMessageId() { var chMock = new Mock <IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny <MqttPublishMessage>())); // publish and save the first id var pm = new PublishingManager(chMock.Object); int firstMsgId = pm.Publish <string, AsciiPayloadConverter>("A/Topic", MqttQos.AtMostOnce, "test"); int secondMsgId = pm.Publish <string, AsciiPayloadConverter>("A/Topic", MqttQos.AtMostOnce, "test"); chMock.VerifyAll(); Assert.Equal <int>(firstMsgId + 1, secondMsgId); }
public void PublishReturnIdMatchesPublishedMessageId() { MqttPublishMessage pubMsg = null; var chMock = new Mock <IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny <MqttPublishMessage>())) .Callback((MqttMessage msg) => pubMsg = (MqttPublishMessage)msg); var pm = new PublishingManager(chMock.Object); int retId = pm.Publish <string, AsciiPayloadConverter>("A/Topic", MqttQos.AtMostOnce, "test"); chMock.VerifyAll(); // check the message message ids match Assert.Equal <int>(pubMsg.VariableHeader.MessageIdentifier, retId); }
protected void DeleteSearchIndex(string searchIndexName, Guid publishingPointId) { var transaction = Guid.NewGuid().ToString(); var manager = PublishingManager.GetManager(PublishingConfig.SearchProviderName, transaction); var pp = manager.GetPublishingPoint(publishingPointId); foreach (var settings in pp.PipeSettings) { manager.DeletePipeSettings(settings); } manager.DeletePublishingPoint(pp); TransactionManager.CommitTransaction(transaction); var service = ServiceBus.ResolveService <ISearchService>(); service.DeleteIndex(searchIndexName); }
public void PublishSendsPublishMessageWithCorrectQos() { MqttPublishMessage pubMsg = null; var chMock = new Mock <IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny <MqttPublishMessage>())) .Callback((MqttMessage msg) => pubMsg = (MqttPublishMessage)msg); var pm = new PublishingManager(chMock.Object); pm.Publish <string, AsciiPayloadConverter>(new PublicationTopic("A/rawTopic"), MqttQos.AtLeastOnce, "test"); chMock.VerifyAll(); // check the message QOS was correct Assert.Equal(MqttQos.AtLeastOnce, pubMsg.Header.Qos); }
public void PublishSendsPublishMessageWithCorrectTopic() { MqttPublishMessage pubMsg = null; var chMock = new Mock <IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny <MqttPublishMessage>())) .Callback((MqttMessage msg) => pubMsg = (MqttPublishMessage)msg); var pm = new PublishingManager(chMock.Object); pm.Publish <string, AsciiPayloadConverter>("A/Topic", MqttQos.AtMostOnce, "test"); chMock.VerifyAll(); // check the message topic was correct Assert.Equal("A/Topic", pubMsg.VariableHeader.TopicName); }
public void PublishSendsPublishMessageCorrectPayload() { MqttPublishMessage pubMsg = null; var chMock = new Mock <IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny <MqttPublishMessage>())) .Callback((MqttMessage msg) => pubMsg = (MqttPublishMessage)msg); var pm = new PublishingManager(chMock.Object); pm.Publish <string, AsciiPayloadConverter>("A/Topic", MqttQos.AtMostOnce, "test"); chMock.VerifyAll(); // check the message payload was correct Assert.Equal <string>("test", Encoding.ASCII.GetString(pubMsg.Payload.Message.ToArray <byte>())); }
public void AcknowledgedQos1MessageRemovedFromStorage() { Func <MqttMessage, bool> ackCallback = null; var chMock = new Mock <IMqttConnectionHandler>(); chMock.Setup(x => x.RegisterForMessage(MqttMessageType.PublishAck, It.IsAny <Func <MqttMessage, bool> >())) .Callback((MqttMessageType msgtype, Func <MqttMessage, bool> cb) => { ackCallback = cb; }); // send the message, verify we've stored it ok. var pm = new PublishingManager(chMock.Object); var msgId = pm.Publish <string, AsciiPayloadConverter>("A/Topic", MqttQos.AtLeastOnce, "test"); var msgs = GetPublishedMessages(pm); Assert.True(msgs.ContainsKey(msgId)); // now fake an acknowledgement of the message, and ensure it's been removed from storage. ackCallback(new MqttPublishAckMessage().WithMessageIdentifier(msgId)); Assert.False(msgs.ContainsKey(msgId)); }
public void ReceivedMessageAtQos2StoresMessage() { Func <MqttMessage, bool> pubCallback = null; short msgId = 1; var mock = new Mock <IMqttConnectionHandler>(); mock.Setup(x => x.RegisterForMessage(MqttMessageType.Publish, It.IsAny <Func <MqttMessage, bool> >())) .Callback((MqttMessageType mt, Func <MqttMessage, bool> cb) => pubCallback = cb); var pm = new PublishingManager(mock.Object); pubCallback(new MqttPublishMessage() .WithMessageIdentifier(msgId) .ToTopic("A/Topic") .WithQos(MqttQos.ExactlyOnce) .PublishData(new byte[] { 0, 1, 2 })); var rcvdMsgs = GetReceivedMessages(pm); Assert.True(rcvdMsgs.ContainsKey(msgId)); }
public void ReleasedQos2MessageRemovedFromStorage() { Func <MqttMessage, bool> rcvdCallback = null; Func <MqttMessage, bool> compCallback = null; var chMock = new Mock <IMqttConnectionHandler>(); chMock.Setup(x => x.RegisterForMessage(MqttMessageType.PublishReceived, It.IsAny <Func <MqttMessage, bool> >())) .Callback((MqttMessageType msgtype, Func <MqttMessage, bool> cb) => { rcvdCallback = cb; }); chMock.Setup(x => x.RegisterForMessage(MqttMessageType.PublishRelease, It.IsAny <Func <MqttMessage, bool> >())); chMock.Setup(x => x.RegisterForMessage(MqttMessageType.PublishComplete, It.IsAny <Func <MqttMessage, bool> >())) .Callback((MqttMessageType msgtype, Func <MqttMessage, bool> cb) => { compCallback = cb; }); chMock.Setup(x => x.SendMessage(It.IsAny <MqttPublishMessage>())); chMock.Setup(x => x.SendMessage(It.IsAny <MqttPublishReleaseMessage>())); // send the message, verify we've stored it ok. var pm = new PublishingManager(chMock.Object); var msgId = pm.Publish <string, AsciiPayloadConverter>("A/Topic", MqttQos.ExactlyOnce, "test"); var msgs = GetPublishedMessages(pm); Assert.True(msgs.ContainsKey(msgId)); // verify the pub msg has send a publish message. chMock.Verify(x => x.SendMessage(It.IsAny <MqttPublishMessage>())); // fake a response from the other party saying Received, this should initiate a Release to the other party rcvdCallback(new MqttPublishReceivedMessage().WithMessageIdentifier(msgId)); Assert.True(msgs.ContainsKey(msgId)); // verify the pub msg has sent a publish release message. chMock.Verify(x => x.SendMessage(It.IsAny <MqttPublishReleaseMessage>())); // fake a response from the other party saying "Complete", this should remove our copy of the message locally. compCallback(new MqttPublishCompleteMessage().WithMessageIdentifier(msgId)); Assert.False(msgs.ContainsKey(msgId)); }
public void PublishSendsPublishMessageCorrectPayload() { MqttPublishMessage pubMsg = null; var chMock = new Mock<IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny<MqttPublishMessage>())) .Callback((MqttMessage msg) => pubMsg = (MqttPublishMessage) msg); var pm = new PublishingManager(chMock.Object); pm.Publish<string, AsciiPayloadConverter>(new PublicationTopic("A/rawTopic"), MqttQos.AtMostOnce, "test"); chMock.VerifyAll(); // check the message payload was correct Assert.Equal<string>("test", Encoding.ASCII.GetString(pubMsg.Payload.Message.ToArray<byte>())); }
public void ConsequtivePublishOnSameTopicGetsNextMessageId() { var chMock = new Mock<IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny<MqttPublishMessage>())); // publish and save the first id var pm = new PublishingManager(chMock.Object); int firstMsgId = pm.Publish<string, AsciiPayloadConverter>(new PublicationTopic("A/rawTopic"), MqttQos.AtMostOnce, "test"); int secondMsgId = pm.Publish<string, AsciiPayloadConverter>(new PublicationTopic("A/rawTopic"), MqttQos.AtMostOnce, "test"); chMock.VerifyAll(); Assert.Equal<int>(firstMsgId + 1, secondMsgId); }
public void PublishQos1Or2SavesMessageInStorage() { var chMock = new Mock<IMqttConnectionHandler>(); var pm = new PublishingManager(chMock.Object); int msgId = pm.Publish<string, AsciiPayloadConverter>(new PublicationTopic("A/rawTopic"), MqttQos.AtLeastOnce, "test"); var msgs = GetPublishedMessages(pm); Assert.True(msgs.ContainsKey(msgId)); }
public void AcknowledgedQos1MessageRemovedFromStorage() { Func<MqttMessage, bool> ackCallback = null; var chMock = new Mock<IMqttConnectionHandler>(); chMock.Setup(x => x.RegisterForMessage(MqttMessageType.PublishAck, It.IsAny<Func<MqttMessage, bool>>())) .Callback((MqttMessageType msgtype, Func<MqttMessage, bool> cb) => { ackCallback = cb; }); // send the message, verify we've stored it ok. var pm = new PublishingManager(chMock.Object); var msgId = pm.Publish<string, AsciiPayloadConverter>(new PublicationTopic("A/rawTopic"), MqttQos.AtLeastOnce, "test"); var msgs = GetPublishedMessages(pm); Assert.True(msgs.ContainsKey(msgId)); // now fake an acknowledgement of the message, and ensure it's been removed from storage. ackCallback(new MqttPublishAckMessage().WithMessageIdentifier(msgId)); Assert.False(msgs.ContainsKey(msgId)); }
public void ReleasedQos2MessageRemovedFromStorage() { Func<MqttMessage, bool> rcvdCallback = null; Func<MqttMessage, bool> compCallback = null; var chMock = new Mock<IMqttConnectionHandler>(); chMock.Setup(x => x.RegisterForMessage(MqttMessageType.PublishReceived, It.IsAny<Func<MqttMessage, bool>>())) .Callback((MqttMessageType msgtype, Func<MqttMessage, bool> cb) => { rcvdCallback = cb; }); chMock.Setup(x => x.RegisterForMessage(MqttMessageType.PublishRelease, It.IsAny<Func<MqttMessage, bool>>())); chMock.Setup(x => x.RegisterForMessage(MqttMessageType.PublishComplete, It.IsAny<Func<MqttMessage, bool>>())) .Callback((MqttMessageType msgtype, Func<MqttMessage, bool> cb) => { compCallback = cb; }); chMock.Setup(x => x.SendMessage(It.IsAny<MqttPublishMessage>())); chMock.Setup(x => x.SendMessage(It.IsAny<MqttPublishReleaseMessage>())); // send the message, verify we've stored it ok. var pm = new PublishingManager(chMock.Object); var msgId = pm.Publish<string, AsciiPayloadConverter>(new PublicationTopic("A/rawTopic"), MqttQos.ExactlyOnce, "test"); var msgs = GetPublishedMessages(pm); Assert.True(msgs.ContainsKey(msgId)); // verify the pub msg has send a publish message. chMock.Verify(x => x.SendMessage(It.IsAny<MqttPublishMessage>())); // fake a response from the other party saying Received, this should initiate a Release to the other party rcvdCallback(new MqttPublishReceivedMessage().WithMessageIdentifier(msgId)); Assert.True(msgs.ContainsKey(msgId)); // verify the pub msg has sent a publish release message. chMock.Verify(x => x.SendMessage(It.IsAny<MqttPublishReleaseMessage>())); // fake a response from the other party saying "Complete", this should remove our copy of the message locally. compCallback(new MqttPublishCompleteMessage().WithMessageIdentifier(msgId)); Assert.False(msgs.ContainsKey(msgId)); }
public void ReceivedMessageAtQos2StoresMessage() { Func<MqttMessage, bool> pubCallback = null; short msgId = 1; var mock = new Mock<IMqttConnectionHandler>(); mock.Setup(x => x.RegisterForMessage(MqttMessageType.Publish, It.IsAny<Func<MqttMessage, bool>>())) .Callback((MqttMessageType mt, Func<MqttMessage, bool> cb) => pubCallback = cb); var pm = new PublishingManager(mock.Object); pubCallback(new MqttPublishMessage() .WithMessageIdentifier(msgId) .ToTopic("A/rawTopic") .WithQos(MqttQos.ExactlyOnce) .PublishData(new byte[] {0, 1, 2})); var rcvdMsgs = GetReceivedMessages(pm); Assert.True(rcvdMsgs.ContainsKey(msgId)); }
public void ReleasedMessageAtQos2RemovesMessageFromStorage() { Func<MqttMessage, bool> pubCallback = null; Func<MqttMessage, bool> pubRelCallback = null; short msgId = 1; var mock = new Mock<IMqttConnectionHandler>(); mock.Setup(x => x.RegisterForMessage(MqttMessageType.Publish, It.IsAny<Func<MqttMessage, bool>>())) .Callback((MqttMessageType mt, Func<MqttMessage, bool> cb) => pubCallback = cb); mock.Setup(x => x.RegisterForMessage(MqttMessageType.PublishRelease, It.IsAny<Func<MqttMessage, bool>>())) .Callback((MqttMessageType mt, Func<MqttMessage, bool> cb) => pubRelCallback = cb); var pm = new PublishingManager(mock.Object); // fake a publish from a remote party and verify we sent a received back. pubCallback(new MqttPublishMessage() .WithMessageIdentifier(msgId) .ToTopic("A/rawTopic") .WithQos(MqttQos.ExactlyOnce) .PublishData(new byte[] {0, 1, 2})); var rcvdMsgs = GetReceivedMessages(pm); Assert.True(rcvdMsgs.ContainsKey(msgId)); // fake the publish release message from remote party and verify that a publishcomplete is sent. pubRelCallback(new MqttPublishReleaseMessage().WithMessageIdentifier(msgId)); Assert.False(rcvdMsgs.ContainsKey(msgId)); }
/// <summary> /// Gets the received messages inside a publishing manager. /// </summary> /// <param name="pubMgr"></param> /// <returns></returns> private static Dictionary<int, MqttPublishMessage> GetReceivedMessages(PublishingManager pubMgr) { // we need to crack open the publishing manager and access some privates var fi = typeof (PublishingManager).GetField("receivedMessages", ReflectionBindingConstants.NonPublicField); return (Dictionary<int, MqttPublishMessage>) fi.GetValue(pubMgr); }
public void PublishSendsPublishMessageThroughConnectionHandler() { var chMock = new Mock<IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny<MqttPublishMessage>())); var pm = new PublishingManager(chMock.Object); pm.Publish<string, AsciiPayloadConverter>(new PublicationTopic("A/rawTopic"), MqttQos.AtMostOnce, "test"); chMock.VerifyAll(); }
public void PublishSendsPublishMessageWithCorrectQos() { MqttPublishMessage pubMsg = null; var chMock = new Mock<IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny<MqttPublishMessage>())) .Callback((MqttMessage msg) => pubMsg = (MqttPublishMessage) msg); var pm = new PublishingManager(chMock.Object); pm.Publish<string, AsciiPayloadConverter>(new PublicationTopic("A/rawTopic"), MqttQos.AtLeastOnce, "test"); chMock.VerifyAll(); // check the message QOS was correct Assert.Equal(MqttQos.AtLeastOnce, pubMsg.Header.Qos); }
public void PublishReturnIdMatchesPublishedMessageId() { MqttPublishMessage pubMsg = null; var chMock = new Mock<IMqttConnectionHandler>(); chMock.Setup(x => x.SendMessage(It.IsAny<MqttPublishMessage>())) .Callback((MqttMessage msg) => pubMsg = (MqttPublishMessage) msg); var pm = new PublishingManager(chMock.Object); int retId = pm.Publish<string, AsciiPayloadConverter>(new PublicationTopic("A/rawTopic"), MqttQos.AtMostOnce, "test"); chMock.VerifyAll(); // check the message message ids match Assert.Equal<int>(pubMsg.VariableHeader.MessageIdentifier, retId); }