本文整理汇总了C#中CommandProcessorContext类的典型用法代码示例。如果您正苦于以下问题:C# CommandProcessorContext类的具体用法?C# CommandProcessorContext怎么用?C# CommandProcessorContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandProcessorContext类属于命名空间,在下文中一共展示了CommandProcessorContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
context.IsAsync();
context.Client.CreateTcpConnection(
context,
connectionEstablished: conn =>
{
var package = new TcpPackage(TcpCommand.Ping, Guid.NewGuid(), null);
context.Log.Info("[{0}:{1}]: PING...", context.Client.Options.Ip, context.Client.Options.TcpPort);
conn.EnqueueSend(package.AsByteArray());
},
handlePackage: (conn, pkg) =>
{
if (pkg.Command != TcpCommand.Pong)
{
context.Fail(reason: string.Format("Unexpected TCP package: {0}.", pkg.Command));
return;
}
context.Log.Info("[{0}:{1}]: PONG!", context.Client.Options.Ip, context.Client.Options.TcpPort);
context.Success();
conn.Close();
},
connectionClosed: (typedConnection, error) => context.Fail(reason: "Connection was closed prematurely."));
context.WaitForCompletion();
return true;
}
示例2: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
int clientsCnt = 1;
int minPerSecond = 1;
int maxPerSecond = 2;
int runTimeMinutes = 1;
if (args.Length > 0)
{
if (args.Length != 4)
return false;
try
{
clientsCnt = int.Parse(args[0]);
minPerSecond = int.Parse(args[1]);
maxPerSecond = int.Parse(args[2]);
runTimeMinutes = int.Parse(args[3]);
}
catch
{
return false;
}
}
Flood(context, clientsCnt, minPerSecond, maxPerSecond, runTimeMinutes);
return true;
}
示例3: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
int clientsCnt = 1;
long requestsCnt = 5000;
int streamsCnt = 1000;
int size = 256;
if (args.Length > 0)
{
if (args.Length < 2 || args.Length > 4)
return false;
try
{
clientsCnt = int.Parse(args[0]);
requestsCnt = long.Parse(args[1]);
if (args.Length >= 3)
streamsCnt = int.Parse(args[2]);
if (args.Length >= 4)
size = int.Parse(args[3]);
}
catch
{
return false;
}
}
WriteFlood(context, clientsCnt, requestsCnt, streamsCnt, size);
return true;
}
示例4: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
int clientsCnt = 1;
long requestsCnt = 5000;
var eventStreamId = "test-stream";
bool resolveLinkTos = false;
bool requireMaster = false;
if (args.Length > 0)
{
if (args.Length != 2 && args.Length != 3 && args.Length != 4)
return false;
try
{
clientsCnt = int.Parse(args[0]);
requestsCnt = long.Parse(args[1]);
if (args.Length >= 3)
eventStreamId = args[2];
if (args.Length >= 4)
requireMaster = bool.Parse(args[3]);
}
catch
{
return false;
}
}
ReadFlood(context, eventStreamId, clientsCnt, requestsCnt, resolveLinkTos, requireMaster);
return true;
}
示例5: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
context.IsAsync();
var package = new TcpPackage(TcpCommand.Ping, Guid.NewGuid(), null);
context.Log.Info("[{0}:{1}]: PING...", context.Client.Options.Ip, context.Client.Options.TcpPort);
var connection = context.Client.CreateTcpConnection(
context,
(conn, pkg) =>
{
if (pkg.Command != TcpCommand.Pong)
{
context.Fail(reason: string.Format("Unexpected TCP package: {0}.", pkg.Command));
return;
}
context.Log.Info("[{0}:{1}]: PONG!", context.Client.Options.Ip, context.Client.Options.TcpPort);
conn.Close();
context.Success();
},
null,
(typedConnection, error) =>
{
if (error == SocketError.Success)
context.Success();
else
context.Fail();
});
connection.EnqueueSend(package.AsByteArray());
context.WaitForCompletion();
return true;
}
示例6: Execute
public bool Execute(CommandProcessorContext context, CancellationToken token, string[] args)
{
var events = context.Client.EventStores.ReadAllEvents(new EventStoreOffset(0));
foreach (RetrievedEventsWithMetaData eventData in events)
{
if (eventData.StreamId != "EngineSearchResult")
continue;
var result = KeywordResult.TryGetFromBinary(eventData.EventData);
if (!args[0].Equals(result.Keyword, StringComparison.CurrentCultureIgnoreCase))
continue;
foreach (EngineResult engineResult in result.EngineResults)
{
if (args.Length == 1)
context.Log.Info("{0} - {1}", engineResult.Url, engineResult.Title);
else
{
string format = "";
if (args[1].IndexOf("U", StringComparison.CurrentCultureIgnoreCase) != -1)
format += "{0} ";
if (args[1].IndexOf("T", StringComparison.CurrentCultureIgnoreCase) != -1)
format += "{1}";
if (args[1].IndexOf("H", StringComparison.CurrentCultureIgnoreCase) != -1)
format += "\r\n{2}\r\n\r\n";
context.Log.Info(format, engineResult.Url, engineResult.Title, engineResult.ItemHtml);
}
}
}
return false;
}
示例7: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
int clientsCnt = 1;
long requestsCnt = 5000;
var writeCount = 10;
if (args.Length > 0)
{
if (args.Length != 1 && args.Length != 3)
return false;
try
{
writeCount = int.Parse(args[0]);
if (args.Length > 1)
{
clientsCnt = int.Parse(args[1]);
requestsCnt = long.Parse(args[2]);
}
}
catch
{
return false;
}
}
WriteFlood(context, writeCount, clientsCnt, requestsCnt);
return true;
}
示例8: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
var fromOffset = 0;
int maxRecordCount = int.MaxValue;
if (args.Length > 0)
{
if (args.Length > 2)
{
context.Log.Info("More arguments: {0}", args.Length);
return false;
}
int.TryParse(args[0], out fromOffset);
if (args.Length > 1)
int.TryParse(args[1], out maxRecordCount);
}
context.IsAsync();
var result = _reader.ReadAll(fromOffset, maxRecordCount);
var dataRecords = result as DataRecord[] ?? result.ToArray();
context.Log.Info("Read {0} records{1}", dataRecords.Length, dataRecords.Length > 0 ? ":" : ".");
foreach (var record in dataRecords)
{
context.Log.Info(" stream-id: {0}, data: {0}", record.Key, Encoding.UTF8.GetString(record.Data));
}
var nextOffset = dataRecords.Length > 0 ? dataRecords.Last().NextOffset : 0;
context.Log.Info("Next stream offset: {0}", nextOffset);
context.Completed();
return true;
}
示例9: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
int clientsCnt = 1;
int requestsCnt = 5000;
int payloadSize = 256 + 100;
if (args.Length > 0)
{
if (args.Length > 3 || args.Length < 2)
return false;
try
{
clientsCnt = int.Parse(args[0]);
requestsCnt = int.Parse(args[1]);
if (args.Length == 3)
payloadSize = int.Parse(args[2]);
}
catch
{
return false;
}
}
WriteFlood(context, clientsCnt, requestsCnt, payloadSize);
return true;
}
示例10: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
int clientsCnt = 1;
int minPerSecond = 1;
int maxPerSecond = 2;
int runTimeMinutes = 1;
int dataSize = 8;
string eventStreamId = null;
if (args.Length > 0)
{
if (args.Length != 4 && args.Length != 5 && args.Length != 6)
return false;
try
{
clientsCnt = int.Parse(args[0]);
minPerSecond = int.Parse(args[1]);
maxPerSecond = int.Parse(args[2]);
runTimeMinutes = int.Parse(args[3]);
if (args.Length >= 5)
dataSize = int.Parse(args[4]);
if (args.Length >= 6)
eventStreamId = args[5];
}
catch
{
return false;
}
}
Flood(context, eventStreamId, clientsCnt, minPerSecond, maxPerSecond, runTimeMinutes, dataSize);
return true;
}
示例11: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
int clientsCnt = 1;
int requestsCnt = 5000;
var eventStreamId = "test-stream";
if (args.Length > 0)
{
if (args.Length != 2 && args.Length != 3)
return false;
try
{
clientsCnt = int.Parse(args[0]);
requestsCnt = int.Parse(args[1]);
if (args.Length == 3)
eventStreamId = args[2];
}
catch
{
return false;
}
}
ReadFlood(context, eventStreamId, clientsCnt, requestsCnt);
return true;
}
示例12: Execute
public bool Execute(CommandProcessorContext context, CancellationToken token, string[] args)
{
var file = @"..\server\Platform.Node.exe";
if (!File.Exists(file))
{
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";
file = Path.Combine(dir, file);
}
if (!File.Exists(file))
{
context.Log.Error("Not found {0}. Did you compile?", file);
return false;
}
var ip = context.Client.Options.Ip;
if (ip != "localhost" && ip != "127.0.0.1")
{
context.Log.Error("Client IP should be localhost or 127.0.0.1. Was {0}", ip);
return false;
}
var all = string.Join(" ", args);
var arguments = string.Format("-h {0} -s {1} {2}", context.Client.Options.HttpPort, context.Client.Options.StoreLocation, all);
context.Log.Debug("Starting {0} with args {1}", file, arguments);
var proc = Process.Start(new ProcessStartInfo(file, arguments));
token.WaitHandle.WaitOne(1000 * 2);
context.Log.Debug("Consider as started");
return true;
}
示例13: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
var eventStreamId = "test-stream";
var expectedVersion = ExpectedVersion.Any;
string metadata = "{'user' : 'test'}";
var requireMaster = false;
var data = "{'a' : 3 }";
if (args.Length > 0)
{
if (args.Length != 5)
return false;
eventStreamId = args[0];
expectedVersion = args[1].ToUpper() == "ANY" ? ExpectedVersion.Any : int.Parse(args[1]);
data = args[2];
metadata = args[3];
requireMaster = bool.Parse(args[4]);
}
context.IsAsync();
var client = new HttpAsyncClient();
var url = context.Client.HttpEndpoint.ToHttpUrl("/streams/{0}", eventStreamId);
context.Log.Info("Writing to {0}...", url);
var msg = "[{'eventType': 'fooevent', 'eventId' : '" + Guid.NewGuid() + "'" + ",'data' : " + data + ", 'metadata' : " + metadata + "}]";
var sw = Stopwatch.StartNew();
client.Post(
url,
msg,
Codec.Json.ContentType,
new Dictionary<string, string>
{
{SystemHeaders.ExpectedVersion, expectedVersion.ToString()},
{SystemHeaders.RequireMaster, requireMaster ? "True" : "False"}
},
TimeSpan.FromMilliseconds(10000),
response =>
{
sw.Stop();
if (response.HttpStatusCode == HttpStatusCode.Created)
context.Log.Info("Successfully written");
else
{
context.Log.Info("Error while writing: [{0}] - [{1}]", response.HttpStatusCode, response.StatusDescription);
context.Log.Info("Response:\n{0}\n\n{1}\n",
string.Join("\n", response.Headers.AllKeys.Select(x => string.Format("{0,-20}: {1}", x, response.Headers[x]))),
response.Body);
}
context.Log.Info("Write request took: {0}.", sw.Elapsed);
context.Success();
},
e =>
{
context.Log.ErrorException(e, "Error during POST");
context.Fail(e, "Error during POST.");
});
return true;
}
示例14: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
var eventStreamId = "default stream";
var expectedVersion = -1;
var data = "default-data";
if (args.Length > 0)
{
if (args.Length != 3)
{
context.Log.Info("More arguments: {0}",args.Length);
return false;
}
eventStreamId = args[0];
int.TryParse(args[1], out expectedVersion);
data = args[2];
}
context.IsAsync();
context.Client.JsonClient.Post<ClientDto.WriteEvent>("/stream", new ClientDto.WriteEvent()
{
Data = Encoding.UTF8.GetBytes(data),
Stream = eventStreamId,
ExpectedVersion = expectedVersion
});
context.Completed();
return true;
}
示例15: PingFloodWaiting
private void PingFloodWaiting(CommandProcessorContext context, int clientsCnt, long requestsCnt)
{
context.IsAsync();
var clients = new List<TcpTypedConnection<byte[]>>();
var threads = new List<Thread>();
var doneEvent = new ManualResetEventSlim(false);
var clientsDone = 0;
long all = 0;
for (int i = 0; i < clientsCnt; i++)
{
var autoResetEvent = new AutoResetEvent(false);
var client = context.Client.CreateTcpConnection(
context,
(_, __) =>
{
Interlocked.Increment(ref all);
autoResetEvent.Set();
},
connectionClosed: (conn, err) => context.Fail(reason: "Connection was closed prematurely."));
clients.Add(client);
var count = requestsCnt / clientsCnt + ((i == clientsCnt - 1) ? requestsCnt % clientsCnt : 0);
threads.Add(new Thread(() =>
{
for (int j = 0; j < count; ++j)
{
var package = new TcpPackage(TcpCommand.Ping, Guid.NewGuid(), null);
client.EnqueueSend(package.AsByteArray());
autoResetEvent.WaitOne();
}
if (Interlocked.Increment(ref clientsDone) == clientsCnt)
{
context.Success();
doneEvent.Set();
}
}) { IsBackground = true });
}
var sw = Stopwatch.StartNew();
threads.ForEach(thread => thread.Start());
doneEvent.Wait();
sw.Stop();
clients.ForEach(x => x.Close());
var reqPerSec = (all + 0.0)/sw.ElapsedMilliseconds*1000;
context.Log.Info("{0} requests completed in {1}ms ({2:0.00} reqs per sec).", all, sw.ElapsedMilliseconds, reqPerSec);
PerfUtils.LogData(Keyword,
PerfUtils.Row(PerfUtils.Col("clientsCnt", clientsCnt),
PerfUtils.Col("requestsCnt", requestsCnt),
PerfUtils.Col("ElapsedMilliseconds", sw.ElapsedMilliseconds)));
PerfUtils.LogTeamCityGraphData(string.Format("{0}-{1}-{2}-reqPerSec", Keyword, clientsCnt, requestsCnt), (int) reqPerSec);
PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword), (int) Math.Round(sw.Elapsed.TotalMilliseconds/all));
if (Interlocked.Read(ref all) == requestsCnt)
context.Success();
else
context.Fail();
}