MeasureTrace.Database.psm1

function Add-MtDbTrace {
    param(
        [Parameter(Mandatory=$true)]
        [string] $ConnectionString
        ,
        [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
        [MeasureTrace.TraceModel.Trace[]]$MeasuredTrace
    )

    begin{
        $repository = Connect-MtDbRepository -ConnectionString $ConnectionString
        $repository.Database.EnsureCreated()
    }
    process{
        foreach($trace in $MeasuredTrace){
            $repository.SaveTraceAndMeasurements($trace)
        }
    }
    end{
        $repository.Dispose()
    }


}

function Connect-MtDbRepository {
    param(
        [Parameter(Mandatory=$true)]
        [string]$ConnectionString
    )

    New-Object MeasureTrace.Database.Repository -ArgumentList $ConnectionString

}