本文整理汇总了C#中Snapshot类的典型用法代码示例。如果您正苦于以下问题:C# Snapshot类的具体用法?C# Snapshot怎么用?C# Snapshot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Snapshot类属于命名空间,在下文中一共展示了Snapshot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListChangedCommand
public ListChangedCommand(CollectionObserver collection, NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
foreach (var item in e.NewItems)
{
snapshot = new Snapshot()
{
Collection = collection,
NewState = DataState.Created,
NewValue = item,
Index = e.NewStartingIndex
};
}
}
else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
{
foreach (var item in e.OldItems)
{
snapshot = new Snapshot()
{
Collection = collection,
NewState = DataState.Deleted,
OldValue = item,
Index = e.OldStartingIndex
};
}
}
}
示例2: Save
public void Save(Snapshot snapshot)
{
if(snapshot.Version == 0)
FirstSaved = true;
SavedVersion = snapshot.Version;
_snapshot = snapshot;
}
示例3: ChainBuilderContinuesIfYouAskForAStoreOrSinkThatDoesntExist
public void ChainBuilderContinuesIfYouAskForAStoreOrSinkThatDoesntExist()
{
var snapshot = new Snapshot { new MetricData(0.5, DateTime.Parse("12 Aug 2008"), new List<string> { "value" }) };
var configs = new List<ChainElement>
{
new ChainElement("id", "storageChain", "testSourceId", "testBufferId", ""),
};
var source = MockRepository.GenerateMock<ISnapshotProvider>();
source.Expect(s => s.Snapshot()).Return(snapshot).Repeat.Any();
source.Expect(s => s.Name).Return("testSource").Repeat.Any();
source.Expect(s => s.Id).Return("testSourceId").Repeat.Any();
var sources = new HashSet<ISnapshotProvider> { source };
var sourceChains = ChainBuilder.Build(sources, new HashSet<ISnapshotConsumer>(), new HashSet<IMultipleSnapshotConsumer>(), configs);
Assert.AreEqual(0, sourceChains.Count());
var buffer = MockRepository.GenerateMock<ISnapshotConsumer>();
buffer.Expect(b => b.Update(snapshot));
buffer.Expect(s => s.Name).Return("testBuffer").Repeat.Any();
buffer.Expect(s => s.Id).Return("testBufferId").Repeat.Any();
var sinks = new HashSet<ISnapshotConsumer> { buffer };
var sinkChains = ChainBuilder.Build(new HashSet<ISnapshotProvider>(), sinks, new HashSet<IMultipleSnapshotConsumer>(), configs);
Assert.AreEqual(0, sinkChains.Count());
}
示例4: SetRight
public void SetRight(Snapshot right)
{
Right = new Snapshot(right);
Debug.Assert(Left != null);
CalculateDiff();
}
示例5: CollectionChangedCommand
public CollectionChangedCommand(IStatefulCollection collection, NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
foreach (StatefulObject obj in e.NewItems)
{
snapshot = new Snapshot()
{
Collection = collection,
OldState = obj.DataState,
NewState = DataState.Created,
NewValue = obj
};
}
}
else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
{
foreach (StatefulObject obj in e.OldItems)
{
snapshot = new Snapshot()
{
Collection = collection,
OldState = obj.DataState,
NewState = DataState.Deleted,
OldValue = obj
};
}
}
}
示例6: TryLoadFromSnapshot
public bool TryLoadFromSnapshot(Type aggregateRootType, Snapshot snapshot, CommittedEventStream committedEventStream, out AggregateRoot aggregateRoot)
{
aggregateRoot = null;
if (snapshot == null) return false;
if (AggregateSupportsSnapshot(aggregateRootType, snapshot.Payload.GetType()))
{
Log.DebugFormat("Reconstructing aggregate root {0}[{1}] from snapshot", aggregateRootType.FullName,
snapshot.EventSourceId.ToString("D"));
aggregateRoot = _aggregateRootCreator.CreateAggregateRoot(aggregateRootType);
aggregateRoot.InitializeFromSnapshot(snapshot);
var memType = aggregateRoot.GetType().GetSnapshotInterfaceType();
var restoreMethod = memType.GetMethod("RestoreFromSnapshot");
restoreMethod.Invoke(aggregateRoot, new[] { snapshot.Payload });
Log.DebugFormat("Applying remaining historic event to reconstructed aggregate root {0}[{1}]",
aggregateRootType.FullName, snapshot.EventSourceId.ToString("D"));
aggregateRoot.InitializeFromHistory(committedEventStream);
return true;
}
return false;
}
示例7: ChainCanBeConfiguredWithASingleSourceAndMultipleSinks
public void ChainCanBeConfiguredWithASingleSourceAndMultipleSinks()
{
var snapshot = new Snapshot { new MetricData(0.5, DateTime.Parse("12 Aug 2008"), new List<string>()) };
var name = "testChain";
var source = MockRepository.GenerateMock<ISnapshotProvider>();
source.Expect(s => s.Snapshot()).Return(snapshot);
var buffer = MockRepository.GenerateMock<ISnapshotConsumer>();
buffer.Expect(b => b.Update(snapshot));
var store = MockRepository.GenerateMock<ISnapshotConsumer>();
store.Expect(s => s.Update(snapshot));
var chain = new MultipleSinkChain("id", name, source, buffer, store);
chain.Update();
store.VerifyAllExpectations();
buffer.VerifyAllExpectations();
source.VerifyAllExpectations();
}
示例8: Main
static void Main(string[] args)
{
// Null-conditional operator.
string name = null;
var nameLength = name?.Length;
List<string> names = null;
nameLength = names?[0].Length;
var notifier = new Notifier();
notifier.ChangeState();
notifier.StateChanged += (sender, e) => WriteLine("StateChanged notification received...");
notifier.ChangeState();
// await in catch/finally blocks.
notifier.ChangeStateAsync().Wait();
// Auto-property initializers + expression-bodied members + string interpolation.
var snapshot = new Snapshot();
WriteLine(snapshot);
WriteLine($"{snapshot.UserName} created on {snapshot.Timestamp} with name length of {name?.Length ?? 0}");
// nameof expressions.
WriteLine(nameof(args));
WriteLine(nameof(notifier));
WriteLine(nameof(Main));
WriteLine(nameof(Program));
ReadLine();
}
示例9: CanBeReset
public void CanBeReset()
{
var firstSnapshot = new Snapshot { Name = "first" };
firstSnapshot.Add(new MetricData(10, DateTime.Now.AddMinutes(-2), new List<string> { "value" }));
firstSnapshot.Add(new MetricData(11, DateTime.Now.AddMinutes(-1.5), new List<string> { "value" }));
firstSnapshot.Add(new MetricData(15, DateTime.Now.AddMinutes(-1), new List<string> { "value" }));
var secondSnapshot = new Snapshot { Name = "second" };
secondSnapshot.Add(new MetricData(10, DateTime.Now.AddMinutes(-2), new List<string> { "value2" }));
secondSnapshot.Add(new MetricData(5, DateTime.Now.AddMinutes(-1.5), new List<string> { "value2" }));
secondSnapshot.Add(new MetricData(6, DateTime.Now.AddMinutes(-1), new List<string> { "value2" }));
var name = "testPlotter";
var config = new PlotterElement("id", name, ".", 0, 15, 1, "");
var sink = new MultiPlotter(config);
sink.ResetWith(new [] { firstSnapshot, secondSnapshot });
var plotFile = Path.Combine(".", Path.ChangeExtension(name, "png"));
Assert.IsTrue(File.Exists(plotFile));
File.Delete(plotFile);
}
示例10: GetSnapshotVersionNumber
/// <summary>
///
/// </summary>
/// <param name="snapshot"></param>
/// <returns></returns>
public static String GetSnapshotVersionNumber(Snapshot snapshot)
{
if (snapshot != null && snapshot.Annotation != null && snapshot.Annotation.Version != null)
return snapshot.Annotation.Version;
return null;
}
示例11: TryLoadFromSnapshot
public bool TryLoadFromSnapshot(Type aggregateRootType, Snapshot snapshot, CommittedEventStream committedEventStream, out Domain.AggregateRoot aggregateRoot)
{
aggregateRoot = null;
if (snapshot == null) return false;
if (AggregateSupportsSnapshot(aggregateRootType, snapshot.Payload.GetType()))
{
try
{
Log.DebugFormat("Reconstructing aggregate root {0}[{1}] from snapshot", aggregateRootType.FullName,
snapshot.EventSourceId.ToString("D"));
aggregateRoot = _aggregateRootCreator.CreateAggregateRoot(aggregateRootType);
aggregateRoot.InitializeFromSnapshot(snapshot);
aggregateRoot.RestoreFromSnapshot(snapshot.Payload);
Log.DebugFormat("Applying remaining historic event to reconstructed aggregate root {0}[{1}]",
aggregateRootType.FullName, snapshot.EventSourceId.ToString("D"));
aggregateRoot.InitializeFromHistory(committedEventStream);
}
catch (Exception ex)
{
Log.ErrorFormat("Cannot load snapshot for '{0}' aggregate. {1}",
aggregateRoot.GetType().FullName, ex.Message);
aggregateRoot = null;
return false;
}
return true;
}
return false;
}
示例12: GetCostComplexityName
/// <summary>
///
/// </summary>
/// <param name="snapshot"></param>
/// <param name="CategorieIndex"></param>
/// <param name="Metricindex"></param>
/// <returns></returns>
public static string GetCostComplexityName(Snapshot snapshot, int categorieId)
{
var result = snapshot.CostComplexityResults.Where(_ => _.Reference.Key == categorieId)
.FirstOrDefault();
return (result != null && result.Reference!=null) ? result.Reference.Name : null;
}
示例13: stats_should_be_zero_for_empty_snapshot
public void stats_should_be_zero_for_empty_snapshot() {
var snapshot = new Snapshot(new long[] {});
Assert.That(snapshot.Min, Is.EqualTo(0));
Assert.That(snapshot.Max, Is.EqualTo(0));
Assert.That(snapshot.Mean, Is.EqualTo(0));
Assert.That(snapshot.StdDev, Is.EqualTo(0));
}
示例14: ScheduleBuilderCanBuildAScheduleForMultipleChains
// ChainWorkerBuilder -> ChainThreadBuilder -> ChainTaskBuilder -> SnapshotUpdaterBuilder
// -> TimedSnapshotUpdaterBuilder -> SnapshotScheduleBuilder -> DelayedScheduleBuilder
// -> ScheduleBuilder
public void ScheduleBuilderCanBuildAScheduleForMultipleChains()
{
var scheduleName = "testSchedule";
var delay = 10;
var snapshot = new Snapshot { new MetricData(0.5, DateTime.Parse("12 Aug 2008"), new List<string>()) };
var configs = new List<ChainElement>
{
new ChainElement("id1", "firstTestChain", "testSourceId", "testBufferId", ""),
new ChainElement("id2", "secondTestChain", "testSourceId", "testBufferId", "")
};
var source = MockRepository.GenerateMock<ISnapshotProvider>();
source.Expect(s => s.Snapshot()).Return(snapshot).Repeat.Any();
source.Expect(s => s.Name).Return("testSource").Repeat.Any();
source.Expect(s => s.Id).Return("testSourceId").Repeat.Any();
var buffer = MockRepository.GenerateMock<ISnapshotConsumer>();
buffer.Expect(b => b.Update(snapshot));
buffer.Expect(s => s.Name).Return("testBuffer").Repeat.Any();
buffer.Expect(s => s.Id).Return("testBufferId").Repeat.Any();
var sources = new HashSet<ISnapshotProvider> { source };
var sinks = new HashSet<ISnapshotConsumer> { buffer };
var chains = ChainBuilder.Build(sources, sinks, new HashSet<IMultipleSnapshotConsumer>(), configs);
var schedule = ScheduleBuilder.Build(scheduleName, delay, chains);
Assert.IsInstanceOf<ISchedule>(schedule);
Assert.AreEqual(scheduleName, schedule.Name);
Assert.AreEqual(2, schedule.Chains.Count());
}
示例15: GetBusinessCriteriaGradesModules
/// <summary>
///
/// </summary>
/// <returns></returns>
public static List<BusinessCriteriaDTO> GetBusinessCriteriaGradesModules(Snapshot snapshot, bool Round)
{
if (snapshot != null && snapshot.BusinessCriteriaResults != null)
{
List<BusinessCriteriaDTO> result = new List<BusinessCriteriaDTO>();
var modules = snapshot.BusinessCriteriaResults.SelectMany(_ => _.ModulesResult).Select(_ => _.Module).Distinct();
result = modules.Select(module => new BusinessCriteriaDTO
{
Name = module.Name,
TQI = GetBusinessCriteriaModuleGrade(snapshot, module.Href, Constants.BusinessCriteria.TechnicalQualityIndex, Round),
Robustness = GetBusinessCriteriaModuleGrade(snapshot, module.Href, Constants.BusinessCriteria.Robustness, Round),
Performance = GetBusinessCriteriaModuleGrade(snapshot, module.Href, Constants.BusinessCriteria.Performance, Round),
Security = GetBusinessCriteriaModuleGrade(snapshot, module.Href, Constants.BusinessCriteria.Security, Round),
Changeability = GetBusinessCriteriaModuleGrade(snapshot, module.Href, Constants.BusinessCriteria.Changeability, Round),
Transferability = GetBusinessCriteriaModuleGrade(snapshot, module.Href, Constants.BusinessCriteria.Transferability, Round),
})
.ToList();
return result;
}
return null;
}