本文整理汇总了C#中IPluginContext类的典型用法代码示例。如果您正苦于以下问题:C# IPluginContext类的具体用法?C# IPluginContext怎么用?C# IPluginContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPluginContext类属于命名空间,在下文中一共展示了IPluginContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessMessage
public void ProcessMessage(Message message, IPluginContext context, IJabbRClient client)
{
Guard.NullParameter(message, () => message);
Guard.NullParameter(context, () => context);
Guard.NullParameter(client, () => client);
foreach (var messageHandler in _messageHandlers)
{
Log.Trace("Applying handler: {0}", messageHandler.Name);
try
{
var result = messageHandler.Execute(message, context);
result.Execute(client, context.Room);
var continueProcessing = !result.IsHandled || messageHandler.ContinueProcessing;
if (!continueProcessing)
{
Log.Trace("Terminating message processing after: {0}.", messageHandler.Name);
break;
}
}
catch (Exception ex)
{
Log.ErrorException("Error applying handler: " + messageHandler.Name, ex);
}
}
}
示例2: OptimizeDocumentIndexesIfRunning
public static void OptimizeDocumentIndexesIfRunning(this IDocumentIndexProvider documentIndexProvider, IPluginContext context, IActivityLogger logger)
{
foreach (IDocumentIndex documentIndex in GetDocumentIndexes(documentIndexProvider, context, runningOnly:true).Where(d => !d.IsOptimized))
{
documentIndex.Optimize(DocumentIndexOptimizeSetup.ImmediateOptimize);
}
}
示例3: ExecuteCore
protected override MessageHandlerResult ExecuteCore(Message message, IPluginContext context)
{
if (context.IsBotAddressed
|| message.Type != MessageType.Default
|| context.RandomProvider.Next(2) == 0
|| !Matcher.IsMatch(message.Text))
{
return NotHandled();
}
var text = Matcher.Replace(
message.Text,
m =>
{
var capture = m.Captures[0].Value;
if (capture[0] == 'e')
{
return "s" + capture;
}
if (capture[1] == 'X')
{
return "SE" + capture.Substring(1);
}
return "Se" + capture.Substring(1);
});
return Handled(Message(text));
}
示例4: MashupInfoRepository
public MashupInfoRepository(ILogManager logManager, IPluginContext context, ITpBus bus, IMashupScriptStorage scriptStorage)
{
_bus = bus;
_scriptStorage = scriptStorage;
_log = logManager.GetLogger(GetType());
_context = context;
}
示例5: GetImage
private MessageHandlerResult GetImage(string query, IPluginContext context)
{
try
{
var bingContainer = new Bing.BingSearchContainer(new Uri(BingApiUri))
{
Credentials =
new NetworkCredential(BingApi, BingApi)
};
var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);
var imageResults = imageQuery.Execute();
if (imageResults != null)
{
var imageList = imageResults.ToList();
if (imageList.Count > 0)
{
var index = context.RandomProvider.Next(imageList.Count);
var url = imageList[index].MediaUrl;
return this.Handled(this.Message(url));
}
}
var response = context.TextProcessor.FormatPluginResponse("Really? Do you kiss ${SOMEONE}'s mum with that mouth?", context);
return this.Handled(this.Message(response));
}
catch (Exception ex)
{
Log.ErrorException("Unable to search for images on bing.", ex);
return this.Handled(this.Message("Uh Oh..."));
}
}
示例6: ExecuteCore
protected override MessageHandlerResult ExecuteCore(Message message, IPluginContext context)
{
var match = Matcher.Match(message.Text);
if (!match.Success)
{
return NotHandled();
}
var values = new List<string>();
values.Add(match.Groups[1].Value.Trim());
values.AddRange(match.Groups[2].Captures.OfType<Capture>().Select(x => x.Value.Trim()));
var options = (from v in values
where v.Length > 0 && !v.Equals("or", StringComparison.InvariantCultureIgnoreCase)
select v).ToList();
if (options.Count == 0)
{
return Handled(Message("{0}: confuse BawBag, receive kicking...", context.User.Name), Kick());
}
var index = context.RandomProvider.Next(0, options.Count);
return Handled(Message("@{0}: {1}", context.User.Name, options[index]));
}
示例7: MashupScriptStorage
public MashupScriptStorage(IPluginContext context, IMashupLocalFolder folder, ILogManager logManager, IMashupLoader mashupLoader)
{
_folder = folder;
_mashupLoader = mashupLoader;
_log = logManager.GetLogger(GetType());
_accountName = context.AccountName;
}
示例8: Parse
public static PluginRunContext Parse(PluginConfigItem configItem, IPluginContext context)
{
string runContext = configItem.RunContext;
if (string.IsNullOrEmpty(runContext))
runContext = MainThread;
// on the same current thread
if (runContext == MainThread)
{
if (!Contexts.ContainsKey(runContext))
Contexts[runContext] = new PluginRunContext(configItem, context);
}
else if (runContext == NewThread)
{
if (!Contexts.ContainsKey(runContext))
// get a new thread
Contexts[runContext] = new MultiThreadPluginRunContext(configItem, context);
}
else if (runContext == NewProcess)
{
if (!Contexts.ContainsKey(runContext))
// get a new process
Contexts[runContext] = new MultiProcessPluginRunContext(configItem, context);
}
else if (runContext == NewAppDomain)
{
if (!Contexts.ContainsKey(runContext))
// get a new AppDomain
Contexts[runContext] = new MultiAppDomainPuginRunContext(configItem, context);
}
Contexts[runContext].ConfigItem = configItem;
Contexts[runContext].Context = context;
configItem.PluginRunContext = Contexts[runContext];
return Contexts[runContext];
}
示例9: DoGetDocumentIndex
private Maybe<IDocumentIndex> DoGetDocumentIndex(IPluginContext context, DocumentIndexTypeToken documentIndexTypeToken)
{
Lazy<IDocumentIndex> fetched;
return _documentIndexes[documentIndexTypeToken].TryGetValue(context.AccountName.Value, out fetched)
? Maybe.Return(fetched.Value)
: Maybe.Nothing;
}
示例10: BuildSearchIndexesCommand
public BuildSearchIndexesCommand(ITpBus bus, IProfileCollection profileCollection, IPluginContext pluginContext, IPluginMetadata pluginMetadata)
{
_bus = bus;
_profileCollection = profileCollection;
_pluginContext = pluginContext;
_pluginMetadata = pluginMetadata;
}
示例11: SetEnableForTp2
public SetEnableForTp2(IPluginContext pluginContext, IActivityLogger log, IProfileCollection profileCollection, ITpBus bus)
{
_pluginContext = pluginContext;
_log = log;
_profileCollection = profileCollection;
_bus = bus;
}
示例12: ExecuteCore
protected override MessageHandlerResult ExecuteCore(Message message, IPluginContext context)
{
var match = Matcher.Match(message.Text);
if (!match.Success)
{
return NotHandled();
}
var index = context.RandomProvider.Next(0, 2);
string answerText;
if (index == 0)
{
// Negative
var answerIndex = context.RandomProvider.Next(0, NegativeResponses.Length);
answerText = NegativeResponses[answerIndex];
}
else
{
// Positive
var answerIndex = context.RandomProvider.Next(0, PositiveResponses.Length);
answerText = PositiveResponses[answerIndex];
}
return Handled(Message("@{0}: {1}!", context.User.Name, answerText));
}
示例13: Initialize
public void Initialize(IPluginContext context)
{
try // Try to load the config
{
string configPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\config.json"; // Define the config file 's path
string content = File.ReadAllText(configPath, System.Text.Encoding.UTF8); // Get the content of the config file
JsonTextReader reader = new JsonTextReader(new StringReader(content)); // Create the JSonTextReader
/*
* Parse the Json here
* */
string lastName = String.Empty;
while (reader.Read())
{
if (reader.TokenType == JsonToken.PropertyName)
{
lastName = (string) reader.Value;
}
else if (reader.TokenType == JsonToken.String)
{
planning.Add(lastName, (string)reader.Value);
lastName = "";
}
}
}
catch (Exception) { } // Catch any error and don't notify it
}
示例14: ShutdownDocumentIndexes
public static void ShutdownDocumentIndexes(this IDocumentIndexProvider documentIndexProvider, IPluginContext context, DocumentIndexShutdownSetup setup, IActivityLogger logger)
{
foreach (IDocumentIndex documentIndex in GetDocumentIndexes(documentIndexProvider, context, runningOnly:false))
{
var success = documentIndex.Shutdown(setup);
logger.DebugFormat("{0} was {1} shutted down", documentIndex.Type.TypeToken, success ? string.Empty : "not");
}
}
示例15: GetKarma
private MessageHandlerResult GetKarma(string nick, IPluginContext context)
{
var result = context.RavenSession.Query<KarmaTotal, KarmaTotals>().SingleOrDefault(x => x.Name == nick);
var quantity = (result == null) ? 0 : result.Quantity;
return Handled(Message("@{0}: {1} = {2}", context.User.Name, nick, quantity));
}