本文整理汇总了C#中Counter.Increment方法的典型用法代码示例。如果您正苦于以下问题:C# Counter.Increment方法的具体用法?C# Counter.Increment怎么用?C# Counter.Increment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Counter
的用法示例。
在下文中一共展示了Counter.Increment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnError
private Task OnError(Exception e, int countCapture, Counter error)
{
logger.Info("Got exception {0} on handle {1}", e.ToString(), countCapture);
error.Increment();
return TaskDone.Done;
}
示例2: ReadTrait
private Trait ReadTrait(XmlReader reader, Counter<string> badTags)
{
string identifier = null;
string description = null;
string label = null;
int oppositeOpinion = 0;
int sameOpinion = 0;
string[] opposites = new string[0];
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "id")
{
identifier = reader.ReadElementContentAsString();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "description")
{
description = reader.ReadElementContentAsString();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "label")
{
label = reader.ReadElementContentAsString();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "opposites")
{
opposites = XmlHelper.ReadList(reader, "opposite", badTags);
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "opposite_opinion")
{
oppositeOpinion = reader.ReadElementContentAsInt();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "same_opinion")
{
sameOpinion = reader.ReadElementContentAsInt();
}
else if (reader.NodeType == XmlNodeType.Element)
{
badTags.Increment(reader.Name);
}
else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "trait")
{
break;
}
}
return new Trait(identifier, label, description, sameOpinion, oppositeOpinion, opposites);
}
示例3: should_call_initializer_methods_in_right_order
public void should_call_initializer_methods_in_right_order()
{
var counter = new Counter();
var bus = new TestBus();
bus.Starting += () => counter.Increment();
bus.Started += () => counter.Increment();
bus.Stopping += () => counter.Increment();
bus.Stopped += () => counter.Increment();
var testHostInitializer = new TestHostInitializer(counter);
var host = new Host();
var container = host.ContainerFactory.Invoke();
host.ContainerFactory = () =>
{
container.Configure(x =>
{
x.ForSingletonOf<IBus>().Use(bus);
x.ForSingletonOf<HostInitializer>().Add(testHostInitializer);
});
return container;
};
host.Start();
host.Stop();
testHostInitializer.CapturedContainer.ShouldEqual(container);
testHostInitializer.ConfigureContainerCounterValue.ShouldEqual(0);
testHostInitializer.BeforeStartCounterValue.ShouldEqual(0);
testHostInitializer.AfterStartCounterValue.ShouldEqual(2);
testHostInitializer.BeforeStopCounterValue.ShouldEqual(2);
testHostInitializer.AfterStopCounterValue.ShouldEqual(4);
}
示例4: ReadAreaType
public static AreaType ReadAreaType(XmlReader reader, Counter<string> badTags)
{
string type = null;
int level = 0;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "type")
{
type = reader.ReadElementContentAsString();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "level")
{
level = reader.ReadElementContentAsInt();
}
else if (reader.NodeType == XmlNodeType.Element)
{
badTags.Increment(reader.Name);
}
else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "area")
{
break;
}
}
if (level == 0 || type == null)
throw new Exception("Area type or level not specified.");
return new AreaType(level, type);
}
示例5: DeactivationTest_ClientConsumer
public async Task DeactivationTest_ClientConsumer(Guid streamGuid, string streamNamespace)
{
// get producer and consumer
var producer = GrainClient.GrainFactory.GetGrain<ISampleStreaming_ProducerGrain>(Guid.NewGuid());
var count = new Counter();
// get stream and subscribe
IStreamProvider streamProvider = GrainClient.GetStreamProvider(streamProviderName);
var stream = streamProvider.GetStream<int>(streamGuid, streamNamespace);
StreamSubscriptionHandle<int> subscriptionHandle = await stream.SubscribeAsync((e, t) => count.Increment());
// produce one message (PubSubRendezvousGrain will have one consumer and one producer)
await producer.BecomeProducer(streamGuid, streamNamespace, streamProviderName);
await producer.Produce();
Assert.AreEqual(count.Value, 1, "Client consumer grain has not received stream message");
//TODO: trigger deactivation programmatically
await Task.Delay(TimeSpan.FromMilliseconds(130000)); // wait for the PubSubRendezvousGrain and the SampleStreaming_ProducerGrain to be deactivated
// deactivating PubSubRendezvousGrain and SampleStreaming_ProducerGrain during the same GC cycle causes a deadlock
// resume producing after the PubSubRendezvousGrain and the SampleStreaming_ProducerGrain grains have been deactivated:
await producer.BecomeProducer(streamGuid, streamNamespace, streamProviderName).WithTimeout(Timeout, "BecomeProducer is hung due to deactivation deadlock");
await producer.Produce().WithTimeout(Timeout, "Produce is hung due to deactivation deadlock");
Assert.AreEqual(count.Value, 2, "Client consumer grain did not receive stream messages after PubSubRendezvousGrain and SampleStreaming_ProducerGrain reactivation");
}
示例6: BecomeConsumer
public async Task<StreamSubscriptionHandle<int>> BecomeConsumer(Guid streamId, string streamNamespace, string providerToUse)
{
logger.Info("BecomeConsumer");
// new counter for this subscription
var count = new Counter();
// get stream
IStreamProvider streamProvider = GetStreamProvider(providerToUse);
var stream = streamProvider.GetStream<int>(streamId, streamNamespace);
// subscribe
StreamSubscriptionHandle<int> handle = await stream.SubscribeAsync(
(e, t) =>
{
logger.Info("Got next event {0}", e);
count.Increment();
return TaskDone.Done;
});
// track counter
consumedMessageCounts.Add(handle, count);
// return handle
return handle;
}
示例7: should_increment_counter_by_given_delta
public void should_increment_counter_by_given_delta() {
var counter = new Counter(new MetricConfig("counter1"));
counter.Increment(15);
double count = Testing.Sync(counter, counter.GetMeasure, counter.context_);
Assert.That(count, Is.EqualTo(15));
}
示例8: PrintWord
private void PrintWord(string word, Counter counter)
{
counter.Increment();
if (counter.Value > 1)
_returnValue = word + " " + counter.Value + " times!";
else
_returnValue = word;
}
示例9: Increment
public void Increment()
{
Counter target = new Counter ();
Assert.AreEqual (0, target.Value(), "The initial Value was not zero");
target.Increment ();
Assert.AreEqual (1, target.Value(), "The incremented Value was not 1");
}
示例10: SingleThreadForSpecifiedTimeStrategy
public void SingleThreadForSpecifiedTimeStrategy()
{
Counter c = new Counter();
ThreadManager tt = new ThreadManager();
tt.AddThreadAction(
delegate
{
c.Increment();
});
tt.RunBehavior = ThreadRunBehavior.RunForSpecificTime;
tt.StartAllThreads(500);
Assert.IsTrue(tt.LastRunTime >499,"runtime was "+ tt.LastRunTime);
}
示例11: SingleThread
public void SingleThread()
{
Counter c = new Counter();
ThreadManager tt = new ThreadManager();
tt.AddThreadAction(
delegate
{
c.Increment();
});
tt.RunBehavior=ThreadRunBehavior.RunUntilAllThreadsFinish;
tt.StartAllThreads(500);
Assert.IsTrue(tt.LastRunTime<tt.TimeOut);
}
示例12: Main
static void Main(string[] args)
{
Counter c = new Counter(30);
c.Buzz += ((sender,e) => Console.WriteLine("BUZZ"));
c.Fizz += ((sender, e) => Console.WriteLine("FIZZ"));
c.End += ((sender, e) => {
Console.WriteLine("End !!");
Console.Read();
Environment.Exit(0);
});
c.Other += ((sender,e) => Console.WriteLine(e.Value));
Console.WriteLine("press 'a'");
while (Console.ReadKey(true).KeyChar == 'a')
{
c.Increment();
}
}
示例13: ReadFeat
private FeatData ReadFeat(XmlReader reader, Counter<string> badTags)
{
string identifier = null;
string name = null;
string imageName = null;
List<FeatType> types = new List<FeatType>();
EffectParams effectParams = null;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "id")
{
identifier = reader.ReadElementContentAsString();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "name")
{
name = reader.ReadElementContentAsString();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "image_name")
{
imageName = reader.ReadElementContentAsString();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "type")
{
FeatType type = (FeatType)Enum.Parse(typeof(FeatType), reader.ReadElementContentAsString());
types.Add(type);
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "effect")
{
effectParams = XmlHelper.ReadEffectParams(reader, badTags);
}
else if (reader.NodeType == XmlNodeType.Element)
{
badTags.Increment(reader.Name);
}
else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "feat")
{
break;
}
}
return new FeatData(identifier, name, imageName, types, effectParams);
}
示例14: HundredThreads
public void HundredThreads()
{
Counter c = new Counter();
ThreadManager tt = new ThreadManager();
for (int i = 0; i < 100; i++)
{
tt.AddThreadAction(delegate
{
for (int j = 0; j < 10; j++)
{
c.Increment();
Thread.Sleep(new Random(j+1).Next(100,300));
}
});
}
//this test will run for 22.5 seconds
tt.RunBehavior=ThreadRunBehavior.RunForSpecificTime;
tt.StartAllThreads(22500);
}
示例15: ReadEffect
private EffectData ReadEffect(XmlReader reader, Counter<string> badTags)
{
string identifier = null;
string name = null;
string imageName = null;
bool incapacitate = false;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "id")
{
identifier = reader.ReadElementContentAsString();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "name")
{
name = reader.ReadElementContentAsString();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "image_name")
{
imageName = reader.ReadElementContentAsString();
}
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "incapacitate")
{
incapacitate = reader.ReadElementContentAsBoolean();
}
else if (reader.NodeType == XmlNodeType.Element)
{
badTags.Increment(reader.Name);
}
else if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "effect")
{
break;
}
}
return new EffectData(identifier, name, imageName, incapacitate);
}