private IAsyncDocumentSession CreateAsyncSession() { var session = RavenDocumentStore.OpenAsyncSession(); session.Advanced.UseOptimisticConcurrency = true; return(session); }
protected override void SeedDocuments() { using (var session = RavenDocumentStore.OpenSession()) { session.Store(new RavenIdentityUser() { UserName = "******", Email = "*****@*****.**" }); session.Store(new RavenIdentityUser() { UserName = "******", Email = "*****@*****.**" }); session.SaveChanges(); } }
public ReadOnlyRepository(RavenDocumentStore ravenDocumentStore) { _ravenDocumentStore = ravenDocumentStore; }
public DiskIoPerformanceMonitor(MonitorOptions options) { var process = Process.GetProcessById(options.ProcessId); RavenDocumentStore.Init(options.ServerUrl); store = RavenDocumentStore.DocumentStore; var resourcesToMonitor = GetResourcesToMonitor(); run.StartTime = SystemTime.UtcNow; run.ProcessId = options.ProcessId; run.ProcessName = process.ProcessName; run.DurationInMinutes = options.IoOptions.DurationInMinutes; run.DisplayName = GenerateDisplayName(run); if (options.IoOptions.DurationInMinutes > 0) { timer = new Timer(_ => Stop(), null, TimeSpan.FromMinutes(options.IoOptions.DurationInMinutes), TimeSpan.FromMilliseconds(-1)); } session = new TraceEventSession(KernelTraceEventParser.KernelSessionName); session.EnableKernelProvider(KernelTraceEventParser.Keywords.FileIOInit | KernelTraceEventParser.Keywords.FileIO); session.Source.Kernel.FileIORead += data => { if (data.ProcessID != options.ProcessId) { return; } var fileName = data.FileName; if (string.IsNullOrEmpty(fileName)) { return; } if (resourcesToMonitor.Any(x => x.IsMatch(fileName)) == false) { return; } operations.AddOrUpdate(data.IrpPtr, new FileIoData(fileName, OperationType.Read, data.TimeStampRelativeMSec, data.IoSize), (_, d) => { d.IoSizeInBytes += data.IoSize; return(d); }); }; session.Source.Kernel.FileIOWrite += data => { if (data.ProcessID != options.ProcessId) { return; } var fileName = data.FileName; if (string.IsNullOrEmpty(fileName)) { return; } if (resourcesToMonitor.Any(x => x.IsMatch(fileName)) == false) { return; } operations.AddOrUpdate(data.IrpPtr, new FileIoData(fileName, OperationType.Write, data.TimeStampRelativeMSec, data.IoSize), (_, d) => { d.IoSizeInBytes += data.IoSize; return(d); }); }; session.Source.Kernel.FileIOOperationEnd += data => { //NOTE: we can't compare data.ProcessID with options.ProcessId, because data.ProcessID is always -1 on Windows 7 (however it works on Win 8). FileIoData value; if (operations.TryRemove(data.IrpPtr, out value) == false) { return; } var fileName = value.FileName; var ioSize = value.IoSizeInBytes; var durationInMilliseconds = data.TimeStampRelativeMSec - value.TimeStampRelativeInMilliseconds; var resourceInformation = GetResourceInformation(fileName, resourcesToMonitor); var operationType = value.OperationType; var utcTimeStamp = data.TimeStamp.ToUniversalTime(); var endTimeStamp = new DateTime(utcTimeStamp.Year, utcTimeStamp.Month, utcTimeStamp.Day, utcTimeStamp.Hour, utcTimeStamp.Minute, utcTimeStamp.Second); fileOperations.Add(new FileOperation(fileName, operationType, ioSize, durationInMilliseconds, endTimeStamp, resourceInformation)); }; }