本文整理汇总了C#中CommandProcessorContext类的典型用法代码示例。如果您正苦于以下问题:C# CommandProcessorContext类的具体用法?C# CommandProcessorContext怎么用?C# CommandProcessorContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandProcessorContext类属于命名空间,在下文中一共展示了CommandProcessorContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:danieldeb,项目名称:EventStore,代码行数:27,代码来源:PingProcessor.cs
示例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;
}
开发者ID:base31,项目名称:geteventstore_EventStore,代码行数:28,代码来源:PingHttpLongTermProcessor.cs
示例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;
}
开发者ID:danieldeb,项目名称:EventStore,代码行数:29,代码来源:WriteFloodClientApiProcessor.cs
示例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;
}
开发者ID:danieldeb,项目名称:EventStore,代码行数:30,代码来源:ReadFloodProcessor.cs
示例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;
}
开发者ID:jpierson,项目名称:EventStore,代码行数:32,代码来源:PingProcessor.cs
示例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;
}
开发者ID:AigizK,项目名称:Seo,代码行数:35,代码来源:FindingUrlProcessor.cs
示例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;
}
开发者ID:thinkbeforecoding,项目名称:EventStore,代码行数:28,代码来源:MultiWriteFloodWaiting.cs
示例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;
}
开发者ID:AigizK,项目名称:lokad-data-platform,代码行数:34,代码来源:ReadProcessor.cs
示例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;
}
开发者ID:czcz1024,项目名称:EventStore,代码行数:26,代码来源:WriteFloodWaitingProcessor.cs
示例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;
}
开发者ID:thinkbeforecoding,项目名称:EventStore,代码行数:34,代码来源:WriteLongTermHttpProcessor.cs
示例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;
}
开发者ID:vishal-h,项目名称:EventStore-1,代码行数:28,代码来源:ReadFloodHttpProcessor.cs
示例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;
}
开发者ID:Lokad,项目名称:lokad-data-platform,代码行数:30,代码来源:StartLocalServerProcessor.cs
示例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;
}
开发者ID:kijanawoodard,项目名称:EventStore,代码行数:60,代码来源:WriteHttpProcessor.cs
示例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;
}
开发者ID:AigizK,项目名称:lokad-data-platform,代码行数:31,代码来源:WriteProccessor.cs
示例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();
}
开发者ID:czcz1024,项目名称:EventStore,代码行数:59,代码来源:PingFloodWaitingProcessor.cs
示例16: Execute
public bool Execute(CommandProcessorContext context, CancellationToken token, string[] args)
{
var allCommands = string.Join("\n\n", _commands.RegisteredProcessors
.OrderBy(a => a.Key.ToLowerInvariant())
.Select(x => x.Usage));
context.Log.Info("Available commands:\n{0}", allCommands);
return true;
}
开发者ID:AigizK,项目名称:Seo,代码行数:8,代码来源:UsageProcessor.cs
示例17: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
var eventStreamId = "test-stream";
var expectedVersion = ExpectedVersion.Any;
if (args.Length > 0)
{
if (args.Length > 2)
return false;
eventStreamId = args[0];
if (args.Length == 2)
expectedVersion = args[1].Trim().ToUpper() == "ANY" ? ExpectedVersion.Any : int.Parse(args[1]);
}
context.IsAsync();
var sw = new Stopwatch();
context.Client.CreateTcpConnection(
context,
connectionEstablished: conn =>
{
context.Log.Info("[{0}, L{1}]: Trying to delete event stream '{2}'...", conn.RemoteEndPoint, conn.LocalEndPoint, eventStreamId);
var corrid = Guid.NewGuid();
var deleteDto = new TcpClientMessageDto.DeleteStream(eventStreamId, expectedVersion, false);
var package = new TcpPackage(TcpCommand.DeleteStream, corrid, deleteDto.Serialize()).AsByteArray();
sw.Start();
conn.EnqueueSend(package);
},
handlePackage: (conn, pkg) =>
{
sw.Stop();
context.Log.Info("Delete request took: {0}.", sw.Elapsed);
if (pkg.Command != TcpCommand.DeleteStreamCompleted)
{
context.Fail(reason: string.Format("Unexpected TCP package: {0}.", pkg.Command));
return;
}
var dto = pkg.Data.Deserialize<TcpClientMessageDto.DeleteStreamCompleted>();
if (dto.Result == TcpClientMessageDto.OperationResult.Success)
{
context.Log.Info("DELETED event stream {0}.", eventStreamId);
PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword), (int)sw.ElapsedMilliseconds);
context.Success();
}
else
{
context.Log.Info("DELETION FAILED for event stream {0}: {1} ({2}).", eventStreamId, dto.Message, dto.Result);
context.Fail();
}
conn.Close();
},
connectionClosed:(connection, error) => context.Fail(reason: "Connection was closed prematurely."));
context.WaitForCompletion();
return true;
}
开发者ID:jjvdangelo,项目名称:EventStore,代码行数:57,代码来源:DeleteProcessor.cs
示例18: Execute
public bool Execute(CommandProcessorContext context, CancellationToken token, string[] args)
{
// [abdullin]: we don't need checkpoint write flood (multi-threads)
// since there is only one writer by default
int repeat = 10000;
if (args.Length > 0)
int.TryParse(args[0], out repeat);
const string checkpointName = "epfl.chk";
AzureStoreConfiguration configuration;
var location = context.Client.Options.StoreLocation;
if (AzureStoreConfiguration.TryParse(location, out configuration))
{
var container = CloudStorageAccount.Parse(configuration.ConnectionString)
.CreateCloudBlobClient()
.GetContainerReference(configuration.RootBlobContainerName);
container.CreateIfNotExist();
var blob = container.GetPageBlobReference(checkpointName);
blob.Create(512);
try
{
using (var pointer = new TestAzurePointer(blob))
{
TestPointer(context, pointer, repeat, "page");
}
using (var pointer = AzureEventPointer.OpenWriteable(blob))
{
TestPointer(context, pointer, repeat, "meta");
}
}
finally
{
blob.DeleteIfExists();
}
}
else
{
var fullName = Path.Combine(location, checkpointName);
try
{
using (var openOrCreateForWriting = FileEventPointer.OpenOrCreateForWriting(fullName))
{
TestPointer(context, openOrCreateForWriting, repeat, "file");
}
}
finally
{
File.Delete(fullName);
}
}
return true;
}
开发者ID:Lokad,项目名称:lokad-data-platform,代码行数:57,代码来源:EventPointerFloodProcessor.cs
示例19: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
var threads = 50;
var tasks = 100000;
var producers = new[] {"test"};
if (args.Length != 0 && args.Length != 3)
{
context.Log.Error("Invalid number of arguments. Should be 0 or 3");
return false;
}
if (args.Length > 0)
{
int threadsArg;
if (int.TryParse(args[0], out threadsArg))
{
threads = threadsArg;
int tasksArg;
if (int.TryParse(args[1], out tasksArg))
{
tasks = tasksArg;
string[] producersArg;
if ((producersArg = args[2].Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries)).Length > 0)
{
producersArg = producersArg.Select(p => p.Trim().ToLower()).Distinct().ToArray();
if (producersArg.Any(p => !_availableProducers.Contains(p)))
{
context.Log.Error(
"Invalid producers argument. Pass comma-separated subset of [{0}]",
String.Join(",", _availableProducers));
return false;
}
producers = producersArg;
}
else
{
context.Log.Error("Invalid argument value for <producers>");
return false;
}
}
else
{
context.Log.Error("Invalid argument value for <tasks>");
return false;
}
}
else
{
context.Log.Error("Invalid argument value for <threads>");
return false;
}
}
return InitProducers(producers) && Run(context, threads, tasks);
}
开发者ID:jpierson,项目名称:EventStore,代码行数:57,代码来源:DvuAdvancedProcessor.cs
示例20: Execute
public bool Execute(CommandProcessorContext context, string[] args)
{
var eventStreamId = "test-stream";
var expectedVersion = ExpectedVersion.Any;
var data = "test-data";
string metadata = null;
if (args.Length > 0)
{
if (args.Length < 3 || args.Length > 4)
return false;
eventStreamId = args[0];
expectedVersion = args[1].ToUpper() == "ANY" ? ExpectedVersion.Any : int.Parse(args[1]);
data = args[2];
if (args.Length == 4)
metadata = args[3];
}
context.IsAsync();
var client = new HttpAsyncClient();
var url = context.Client.HttpEndpoint.ToHttpUrl("/streams/{0}", eventStreamId);
context.Log.Info("Writing to {0}...", url);
var request = Codec.Xml.To(new ClientMessageDto.WriteEventText(
Guid.Empty,
expectedVersion,
new[] { new ClientMessageDto.EventText(Guid.NewGuid(), "type", data, metadata) }));
var sw = Stopwatch.StartNew();
client.Post(
url,
request,
Codec.Xml.ContentType,
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("Write request took: {0}.", sw.Elapsed);
context.Success();
},
e =>
{
context.Log.ErrorException(e, "Error during POST");
context.Fail(e, "Error during POST.");
});
return true;
}
开发者ID:jpierson,项目名称:EventStore,代码行数:53,代码来源:WriteHttpProcessor.cs
注:本文中的CommandProcessorContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论