本文整理汇总了C#中Publisher.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# Publisher.Publish方法的具体用法?C# Publisher.Publish怎么用?C# Publisher.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Publisher
的用法示例。
在下文中一共展示了Publisher.Publish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
private static void Run()
{
using (var countdown = new CountdownEvent(2))
{
var subscriber = new Subscriber(MqttBrokerAddress, MqttBrokerPort);
subscriber.Subscribe(Topic.Hello, Topic.Goodbye);
subscriber.OnMessage += (topic, payload) =>
{
if (topic == Topic.Hello)
{
var msg = JsonConvert.DeserializeObject<HelloMessage>(payload);
_log.Info("Topic: " + topic);
_log.Info("Message: " + msg);
countdown.Signal();
}
else if (topic == Topic.Goodbye)
{
var msg = JsonConvert.DeserializeObject<GoodbyeMessage>(payload);
_log.Info("Topic: " + topic);
_log.Info("Message: " + msg);
countdown.Signal();
}
};
var publisher = new Publisher(MqttBrokerAddress, MqttBrokerPort);
publisher.Publish(Topic.Hello, new HelloMessage() { Name = "John Smith", Date = DateTime.Now });
publisher.Publish(Topic.Goodbye, new GoodbyeMessage() { Name = "Jane Smith", Date = DateTime.Now });
countdown.Wait();
}
}
示例2: Publish_will_send_the_message_to_listner
public void Publish_will_send_the_message_to_listner()
{
var assignee = new SimpleAssignee();
var publishWay = new SimpleDispatcher();
var handler = new TestHandler();
var message = new TestMessage();
var publisher = new Publisher(assignee, publishWay);
assignee.Subscribe(handler);
publisher.Publish(message);
Assert.That(handler.TestMessage, Is.SameAs(message));
}
示例3: Publisher_publishes_to_any_subscribers
public void Publisher_publishes_to_any_subscribers()
{
var publisher = new Publisher<string>();
publisher.Publish("test");
int ncalls = 0;
Subscriber<string> subscriber = (string val) =>
{
Assert.Equal("publish", val);
++ncalls;
};
publisher.Subscribe(subscriber);
Assert.Equal(0, ncalls);
publisher.Publish("publish");
Assert.Equal(1, ncalls);
publisher.Unsubscribe(subscriber);
Assert.Equal(1, ncalls);
publisher.Publish("no one subscribes");
Assert.Equal(1, ncalls);
}
示例4: Main
public static void Main()
{
var publishKey = "pub-c-aa7e75ee-ca5f-40ef-95c9-fe28cd6830f6";
var subscribeKey = "sub-c-9fe7c32e-8c77-11e5-84ee-0619f8945a4f";
var secretKey = "sec-c-YmVlY2I1YTAtNzQwYi00NjI2LTg2MmMtYzhhNTRkNDViZmFk";
var channel = "radio";
Publisher pubnub = new Publisher(publishKey, subscribeKey, secretKey);
while (true)
{
Console.WriteLine("Enter message:");
var message = Console.ReadLine();
pubnub.Publish(channel, message);
}
}
示例5: PublishMessageToWebSync
public void PublishMessageToWebSync(string message, string channel)
{
//verify WebSyncURL ends with "/"
if (!WebSyncURL.EndsWith("/")) WebSyncURL += "/";
//verify WebSyncChannel starts with "/"
if (!WebSyncChannel.StartsWith("/")) WebSyncChannel = "/" + WebSyncChannel;
Publisher publisher = new Publisher(new PublisherArgs
{
RequestUrl = this.WebSyncURL + "request.ashx"
});
var publication = publisher.Publish(new Publication
{
Channel = channel,
DataJson = JSON.Serialize(new Payload { Text = message, Source = "NLog", Time = DateTime.Now })
});
if (publication.Successful == false)
{
Console.WriteLine("Could not publish: " + publication.Error);
}
}
示例6: PublishData
/// <summary>Publish data to CMS.</summary>
/// <param name="item">Data item.</param>
/// <param name="language">Date item language.</param>
/// <param name="dbMaster">Database source.</param>
/// <param name="dbWeb">Database target.</param>
public void PublishData(Sitecore.Data.Items.Item item, Sitecore.Globalization.Language language, Sitecore.Data.Database dbMaster, Sitecore.Data.Database dbWeb)
{
// Use CMS security disabler to allow changes.
using(new SecurityDisabler()) {
PublishOptions opt = new PublishOptions(dbMaster, dbWeb, PublishMode.SingleItem, language, DateTime.Now);
opt.RootItem = item;
opt.Deep = false;
Publisher pub = new Publisher(opt);
pub.Publish();
}
}
示例7: Publish
public string Publish(string sourceDatabaseName, string[] targetNames = null, string[] languageNames = null)
{
var publisher = new Publisher();
return publisher.Publish(sourceDatabaseName, targetNames, languageNames);
}
示例8: PublishItem
public static void PublishItem(Item item, Database database)
{
PublishOptions publishOptions = new PublishOptions
(
item.Database,
database,
Sitecore.Publishing.PublishMode.SingleItem,
item.Language,
DateTime.Now
);
Publisher publisher = new Publisher(publishOptions);
publisher.Options.RootItem = item;
publisher.Publish();
}
示例9: Publish
public static void Publish(this Item item, bool deep)
{
var publishOptions = new PublishOptions(item.Database,
Database.GetDatabase("web"),
PublishMode.SingleItem,
item.Language,
DateTime.Now);
var publisher = new Publisher(publishOptions);
publisher.Options.RootItem = item;
publisher.Options.Deep = deep;
publisher.Publish();
}
示例10: PublishFiles
/// <summary>
/// Publishes the selected files.
/// </summary>
private void PublishFiles()
{
Project project = GetProjectForSelection();
ProjectSettings settings = SettingsStore.Get(project);
if (settings == null)
return;
// check if already publishing
if (Publisher.CheckIsPublishing())
return;
// check config
if (!CheckConfiguration(project, settings))
return;
Publisher publisher = new Publisher(settings);
publisher.Publish(dte.SelectedItems);
}
示例11: PublishActiveFile
/// <summary>
/// Publishes the file that is active in the editor.
/// </summary>
private void PublishActiveFile()
{
Document doc = Globals.ActiveDocument;
if (doc == null)
return;
// does the document have a project item assigned?
if (doc.ProjectItem is ProjectItem)
{
Project project = doc.ProjectItem.ContainingProject;
ProjectSettings settings = SettingsStore.Get(project);
if (settings == null)
return;
// check if already publishing
if (Publisher.CheckIsPublishing())
return;
// check config
if (!CheckConfiguration(project, settings))
return;
// ask if we should really publish
MessageBoxResult result = MessageBox.Show(
"Do you want to publish the following file?" +
Environment.NewLine + Environment.NewLine +
"File: " + doc.ProjectItem.GetRelativePath() + Environment.NewLine +
"Location: " + settings.GetPublishLocation(),
"Confirm Publish",
MessageBoxButton.YesNo,
MessageBoxImage.Question,
MessageBoxResult.Yes);
if (result != MessageBoxResult.Yes)
return;
Publisher publisher = new Publisher(settings);
publisher.Publish(doc.ProjectItem);
}
}
示例12: PublishTours
private static void PublishTours(Item itmToBePublished)
{
PublishOptions pubOptsTours = new PublishOptions(dbMaster, dbWeb, PublishMode.Smart, Sitecore.Globalization.Language.Predefined.English, System.DateTime.Now);
pubOptsTours.RootItem = itmToBePublished;
Publisher pub = new Publisher(pubOptsTours);
pub.Options.Deep = true;
pub.Publish();
}
示例13: PublishItem
private static void PublishItem(Item itmToBePublished)
{
Publisher pub = new Publisher(pubOpts);
pub.Options.RootItem = itmToBePublished;
pub.Options.Deep = false;
pub.Publish();
}
示例14: PublishGoogleProductFeedXMLItem
/// <summary>
/// Publish Google Product Feed XML Item
/// </summary>
/// <param name="item"></param>
/// <param name="isPublishAsync"></param>
public static void PublishGoogleProductFeedXMLItem(Item googleProductFeedXMLItem, Database masterDb, bool isPublishAsync, Database TargetDb)
{
try
{
PublishOptions publishOptions = new PublishOptions(masterDb,
TargetDb,
Sitecore.Publishing.PublishMode.SingleItem,
googleProductFeedXMLItem.Language,
System.DateTime.Now);
Publisher publisher = new Publisher(publishOptions);
publisher.Options.RootItem = googleProductFeedXMLItem;
publisher.Options.Deep = false;
if (isPublishAsync)
publisher.PublishAsync();
else
publisher.Publish();
}
catch (Exception ex)
{
Log.Error("Error in PublishGoogleProductFeedXMLItem(). Item ID: " + googleProductFeedXMLItem.ID, ex, typeof(GoogleProductFeedCreation));
}
}
示例15: PublishOneItem
private static void PublishOneItem(Item item)
{
Language language = Context.Language;
Database database = Factory.GetDatabase("master");
Database database2 = Factory.GetDatabase("web");
Publisher publisher = new Publisher(new PublishOptions(database, database2, PublishMode.SingleItem, language, DateTime.Now)
{
RootItem = item,
Deep = true,
RepublishAll = true
});
publisher.Publish();
}