本文整理汇总了C#中IExecutionContext.WriteMessage方法的典型用法代码示例。如果您正苦于以下问题:C# IExecutionContext.WriteMessage方法的具体用法?C# IExecutionContext.WriteMessage怎么用?C# IExecutionContext.WriteMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IExecutionContext
的用法示例。
在下文中一共展示了IExecutionContext.WriteMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnReportTerminate
protected virtual void OnReportTerminate(IExecutionContext context)
{
string pluginName = this.GetType().Name;
context.WriteMessage(String.Format("Process {0} caused {1} plugin to terminate execution context.", this.TerminateHandle.TerminatingProcesName ,pluginName));
}
示例2: Install
public override void Install(IApplicationLicense license, IExecutionContext context, ref bool forceCreation)
{
if (context.HasCompleted | context.AutoLaunch)
{
if(cToken!=null && cToken.Token.CanBeCanceled)
{
cToken.Cancel();
}
else
{
cToken = new CancellationTokenSource();
}
var settings = this.SettingsAs<BattleNetManagerSettings>();
var key = license.KeyAs<BattleNetLicenseKey>();
#region VALIDATION
if (settings == null)
throw new ArgumentNullException("Settings");
if (key == null)
throw new ArgumentNullException("Key");
if (string.IsNullOrWhiteSpace(key.Username))
throw new ArgumentNullException("Username");
if (string.IsNullOrWhiteSpace(key.Password))
throw new ArgumentNullException("Password");
#endregion
//get full path to executable
string fulleExePath = Environment.ExpandEnvironmentVariables(context.Executable.ExecutablePath);
//if working directory not specified set it to null
string workingDirectory = string.IsNullOrWhiteSpace(context.Executable.WorkingDirectory) ? null : Environment.ExpandEnvironmentVariables(context.Executable.WorkingDirectory);
string userName = key.Username;
string passWord = key.Password;
#region VALIDATE FILE EXISTS
if (!File.Exists(fulleExePath))
{
context.WriteMessage(string.Format("BattleNet executable not found at {0}", fulleExePath));
return;
}
#endregion
#region PROCESS CLEANUP
//ensure no battlenet processes running
foreach (var processModuleFileName in processImageFileNames)
{
if (string.IsNullOrWhiteSpace(processModuleFileName))
continue;
var processList = Process.GetProcessesByName(processModuleFileName);
processList.ToList().ForEach(x =>
{
try
{
x.Kill();
}
catch
{
Trace.WriteLine(string.Format("Could not kill BattleNet process {0}", processModuleFileName));
}
});
}
#endregion
#region CONFIG CLEANUP
//ensure configuration valid for login operation
if (File.Exists(configPath))
{
var fullConfig = File.ReadAllText(configPath);
fullConfig = RemoveLineForPattern(fullConfig, @"AutoLogin");
fullConfig = RemoveLineForPattern(fullConfig, @"SavedAccountNames");
File.WriteAllText(configPath, fullConfig);
}
#endregion
//create process start info
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = fulleExePath;
startInfo.WorkingDirectory = workingDirectory;
//startInfo.WindowStyle = ProcessWindowStyle.Hidden;
//startInfo.CreateNoWindow = true;
//create process class
Process bnProcess = new Process() { StartInfo = startInfo };
//try to start process and add it to execution context
if (context.AddProcessIfStarted(bnProcess,true))
{
//assign event handler
context.ExecutionStateChaged += OnExecutionStateChaged;
//enable event raising and hook event handlers
//.........这里部分代码省略.........