本文整理汇总了C#中IExecutionContext类的典型用法代码示例。如果您正苦于以下问题:C# IExecutionContext类的具体用法?C# IExecutionContext怎么用?C# IExecutionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IExecutionContext类属于命名空间,在下文中一共展示了IExecutionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
{
ISettingsHandler handler = Application as ISettingsHandler;
if (handler == null) {
Error.WriteLine("The application doesn't support settings.");
return CommandResultCode.ExecutionFailed;
}
if (args.MoveNext())
return CommandResultCode.SyntaxError;
VarColumns[0].ResetWidth();
VarColumns[1].ResetWidth();
TableRenderer table = new TableRenderer(VarColumns, Out);
table.EnableHeader = true;
table.EnableFooter = true;
foreach(KeyValuePair<string, string> setting in handler.Settings) {
if (setting.Key == ApplicationSettings.SpecialLastCommand)
continue;
ColumnValue[] row = new ColumnValue[4];
row[0] = new ColumnValue(setting.Key);
row[1] = new ColumnValue(setting.Value);
table.AddRow(row);
}
table.CloseTable();
Error.WriteLine();
return CommandResultCode.Success;
}
示例2: AssignValue
public void AssignValue(IExecutionContext context, object val)
{
object obj = Expr1.Eval(context);
if(obj is Hashtable)
{
((Hashtable)obj)[Expr2.Eval(context)] = val;
return;
}
else if(obj is Array)
{
object index = Expr2.Eval(context);
if(!IsInteger(index))
throw new Exception("Index pole musí být celočíselný");
((Array)obj).SetValue(val, Convert.ToInt64(index));
return;
}
else
{
object index = Expr2.Eval(context);
Type t = obj.GetType();
// find indexer //
PropertyInfo prop = t.GetProperty("Item");
prop.GetSetMethod().Invoke(obj, new object[] {index, val});
}
//throw new System.NotImplementedException ();
}
示例3: GetBuildDirectoryHashKey
public string GetBuildDirectoryHashKey(IExecutionContext executionContext, ServiceEndpoint endpoint)
{
// Validate parameters.
Trace.Entering();
ArgUtil.NotNull(executionContext, nameof(executionContext));
ArgUtil.NotNull(executionContext.Variables, nameof(executionContext.Variables));
ArgUtil.NotNull(endpoint, nameof(endpoint));
ArgUtil.NotNull(endpoint.Url, nameof(endpoint.Url));
// Calculate the hash key.
const string Format = "{{{{ \r\n \"system\" : \"build\", \r\n \"collectionId\" = \"{0}\", \r\n \"definitionId\" = \"{1}\", \r\n \"repositoryUrl\" = \"{2}\", \r\n \"sourceFolder\" = \"{{0}}\",\r\n \"hashKey\" = \"{{1}}\"\r\n}}}}";
string hashInput = string.Format(
CultureInfo.InvariantCulture,
Format,
executionContext.Variables.System_CollectionId,
executionContext.Variables.System_DefinitionId,
endpoint.Url.AbsoluteUri);
using (SHA1 sha1Hash = SHA1.Create())
{
byte[] data = sha1Hash.ComputeHash(Encoding.UTF8.GetBytes(hashInput));
StringBuilder hexString = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
hexString.Append(data[i].ToString("x2"));
}
return hexString.ToString();
}
}
示例4: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
List<IDocument> results = new List<IDocument>();
IEnumerable<IDocument> documents = inputs;
foreach (Tuple<DocumentConfig, IModule[]> condition in _conditions)
{
// Split the documents into ones that satisfy the predicate and ones that don't
List<IDocument> handled = new List<IDocument>();
List<IDocument> unhandled = new List<IDocument>();
foreach (IDocument document in documents)
{
if (condition.Item1 == null || condition.Item1.Invoke<bool>(document, context))
{
handled.Add(document);
}
else
{
unhandled.Add(document);
}
}
// Run the modules on the documents that satisfy the predicate
results.AddRange(context.Execute(condition.Item2, handled));
// Continue with the documents that don't satisfy the predicate
documents = unhandled;
}
// Add back any documents that never matched a predicate
results.AddRange(documents);
return results;
}
示例5: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
return inputs
.AsParallel()
.Select(input =>
{
try
{
object data = _data(input, context);
if (data != null)
{
string result = JsonConvert.SerializeObject(data,
_indenting ? Formatting.Indented : Formatting.None);
if (string.IsNullOrEmpty(_destinationKey))
{
return context.GetDocument(input, result);
}
return context.GetDocument(input, new MetadataItems
{
{_destinationKey, result}
});
}
}
catch (Exception ex)
{
Trace.Error("Error serializing JSON for {0}: {1}", input.Source, ex.ToString());
}
return input;
})
.Where(x => x != null);
}
示例6: Run
public override void Run(IExecutionContext context)
{
if(IsInitializer)
{
context.InitVariable(Name);
}
}
示例7: Do
public override CommandResult Do(IExecutionContext context)
{
RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"CLSID\" + ClassId);
context.SaveResult(ResultName, key != null);
return CommandResult.Next;
}
示例8: Execute
public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
{
if (args.MoveNext())
return CommandResultCode.SyntaxError;
NetworkContext networkContext = context as NetworkContext;
if (networkContext == null)
return CommandResultCode.ExecutionFailed;
Out.WriteLine();
Out.WriteLine("refreshing...");
Out.Flush();
networkContext.Network.Refresh();
try {
//TODO:
// networkContext.Network.Configuration.Reload();
} catch (IOException e) {
Error.WriteLine("Unable to refresh network config due to IO error");
Error.WriteLine(e.Message);
Error.WriteLine(e.StackTrace);
}
Out.WriteLine("done.");
Out.WriteLine();
return CommandResultCode.Success;
}
示例9: HandleException
protected override void HandleException(IExecutionContext executionContext, Exception exception)
{
var putObjectRequest = executionContext.RequestContext.OriginalRequest as PutObjectRequest;
if (putObjectRequest != null)
{
// If InputStream was a HashStream, compare calculated hash to returned etag
HashStream hashStream = putObjectRequest.InputStream as HashStream;
if (hashStream != null)
{
// Set InputStream to its original value
putObjectRequest.InputStream = hashStream.GetNonWrapperBaseStream();
}
}
var uploadPartRequest = executionContext.RequestContext.OriginalRequest as UploadPartRequest;
if (uploadPartRequest != null)
{
// If InputStream was a HashStream, compare calculated hash to returned etag
HashStream hashStream = uploadPartRequest.InputStream as HashStream;
if (hashStream != null)
{
// Set InputStream to its original value
uploadPartRequest.InputStream = hashStream.GetNonWrapperBaseStream();
}
}
if (executionContext.RequestContext.Request != null)
AmazonS3Client.CleanupRequest(executionContext.RequestContext.Request);
}
示例10: Execute
public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
return _searchPattern != null
? Execute(null, _searchPattern, context)
: inputs.AsParallel().SelectMany(input =>
Execute(input, _sourcePathDelegate.Invoke<string>(input, context), context));
}
示例11:
IEnumerable<IDocument> IModule.Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
if (_executeDocuments != null)
return inputs.SelectMany(x => _executeDocuments.Invoke<IEnumerable<IDocument>>(x, context) ?? Array.Empty<IDocument>());
else
return _executeContext.Invoke<IEnumerable<IDocument>>(context) ?? Array.Empty<IDocument>();
}
示例12: DoProcessRequest
public override void DoProcessRequest(IExecutionContext context)
{
userProfile profile = UserHelper.Instance.LoadUser(username);
if (profile == null || !profile.Authenticate(password))
{
ReportError(null, "The user name or password is incorrect");
return;
}
else
// this is the key line. this sets the profile as the
// current user, and marks the session as authenticated
context.Authenticate(profile);
if (ContentTypeHelper.Instance.Parse(defaultContentType) != profile.UserType.ContentType)
defaultContentType = ContentTypeHelper.Instance.GetSimpleName(profile.UserType.ContentType);
// hack. we didn't create a table to store the roles, so now
// we're faking them through here
if (profile.UserType.Equals(UserType.Company)) {
var node = profile.role.AppendNode();
node.Name = "company";
}
if (String.IsNullOrEmpty(originalRequest))
context.Transfer("/default");
else
context.Transfer(HttpUtility.UrlDecode(originalRequest));
}
示例13: WriteLog
/// <summary>
/// Writes the log.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="stream">The stream.</param>
/// <param name="callback">The callback for UI updates.</param>
public void WriteLog(IExecutionContext context, Stream stream, ProgressCallback callback)
{
using (BinaryWriter s = new BinaryWriter(stream, Encoding.ASCII))
{
s.Write("[PacketLogConverter v1]");
foreach (PacketLog log in context.LogManager.Logs)
{
for (int i = 0; i < log.Count; i++)
{
if (callback != null && (i & 0xFFF) == 0) // update progress every 4096th packet
callback(i + 1, log.Count);
Packet packet = log[i];
if (context.FilterManager.IsPacketIgnored(packet))
continue;
byte[] buf = packet.GetBuffer();
s.Write((ushort) buf.Length);
s.Write(packet.GetType().FullName);
s.Write((ushort) packet.Code);
s.Write((byte) packet.Direction);
s.Write((byte) packet.Protocol);
s.Write(packet.Time.Ticks);
s.Write(buf);
}
}
}
}
示例14: WriteLog
/// <summary>
/// Writes the log.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="stream">The stream.</param>
/// <param name="callback">The callback for UI updates.</param>
public void WriteLog(IExecutionContext context, Stream stream, ProgressCallback callback)
{
TimeSpan baseTime = new TimeSpan(0);
using (StreamWriter s = new StreamWriter(stream))
{
foreach (PacketLog log in context.LogManager.Logs)
{
// Log file name
s.WriteLine();
s.WriteLine();
s.WriteLine("Log file: " + log.StreamName);
s.WriteLine("==============================================");
for (int i = 0; i < log.Count; i++)
{
// Update progress every 4096th packet
if (callback != null && (i & 0xFFF) == 0)
callback(i, log.Count - 1);
Packet packet = log[i];
if (context.FilterManager.IsPacketIgnored(packet))
continue;
s.WriteLine(packet.ToHumanReadableString(baseTime, true));
}
}
}
}
示例15: Execute
public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
{
if (args.Count != 1)
return CommandResultCode.SyntaxError;
PropertyRegistry properties = Properties;
if (properties == null) {
Application.Error.WriteLine("the current context does not support properties.");
return CommandResultCode.ExecutionFailed;
}
if (!args.MoveNext())
return CommandResultCode.SyntaxError;
String name = args.Current;
PropertyHolder holder = properties.GetProperty(name);
if (holder == null)
return CommandResultCode.ExecutionFailed;
string defaultValue = holder.DefaultValue;
try {
properties.SetProperty(name, defaultValue);
} catch (Exception) {
Application.Error.WriteLine("setting to default '" + defaultValue + "' failed.");
return CommandResultCode.ExecutionFailed;
}
return CommandResultCode.Success;
}