Creating a snapshot from code

Important!

To be able to perform analysis as well, a license has to be obtainable by the ORM Profiler code from the folder the application calling the ORM Profiler code is executed from. It's however recommended to simply save the snapshot to a file and perform the analysis in the visual UI, OrmProfiler.exe, by using the Re-analyze button.

It is possible to create a snapshot from within code, without running OrmProfiler.exe or CliOrmProfiler.exe. To do so, you have to do the following:

First, reference SD.Tools.OrmProfiler.Client.Core.dll. Then, at the spot where you want to create the snapshot, use code similar to the following:

// default ctor call, no filters, default analysis settings. You can specify filter 
// settings and analysis settings in an overload of the ctor.
var snapshot = new Snapshot();
snapshot.Record();

// execute database activity here.
// ...

// make sure the interceptor has flushed all messages over the named pipe.
InterceptorCore.Flush();

// messages arrive on another thread, so we have to wait here before all messages 
// have arrived 
Thread.Sleep(200);
// after the pause, we can stop recording. 
snapshot.Stop();

// if you've specified filter settings in the ctor call, you have to do the 
// following:
snapshot.ApplyFilters();
// if you want to perform analysis in code prior to saving the snapshot, you 
// should uncomment the following line. NOTE: requires license file to be 
// present.
// snapshot.ApplyAnalysis();

// the snapshot can now be saved:
string error=string.Empty;
snapshot.SaveToFile(filename, out error);

You can use this mechanism to create a snapshot from within your profiled application, for example from a website application where you have built-in a way to enable / disable message sending using the production profiling system and when enabling message sending you create a snapshot, save it to a file and then move it to a different system to load it into the visual UI.