Scripts/About.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
$ErrorActionPreference = 1 Import-Module Mdbc . $PSScriptRoot/Clear-BsonFile.ps1 . $PSScriptRoot/Close-BsonFile.ps1 . $PSScriptRoot/Open-BsonFile.ps1 . $PSScriptRoot/Save-BsonFile.ps1 function Get-BFPathMD5($Path) { $bytes = [System.Text.Encoding]::UTF8.GetBytes($Path.ToUpper()) [guid][System.Security.Cryptography.MD5]::Create().ComputeHash($bytes) } function Get-BFIndexInfo($Id) { $Collection = Get-MdbcCollection _index Get-MdbcData @{_id = $Id} } function Set-BFIndexInfo($Info) { $Collection = Get-MdbcCollection _index $info | Set-MdbcData -Add } function Test-BFSameFileTime($Info, $Item) { $diff = ($Info.FileTime - $Item.LastWriteTimeUtc).TotalMilliseconds [Math]::Abs($diff) -lt 10 } function Resolve-BFCollection { if (!$Collection) { $Collection = $PSCmdlet.SessionState.PSVariable.GetValue('Collection') } if ($Collection -isnot [MongoDB.Driver.IMongoCollection[MongoDB.Bson.BsonDocument]]) { throw 'Specify a collection by the parameter or variable Collection.' } try { $md5 = [guid]$Collection.CollectionNamespace.CollectionName } catch { throw "Collection $($Collection.CollectionNamespace.FullName) is not supported." } $info = Get-BFIndexInfo $md5 if (!$info) { throw "Collection has no record in 'BsonFile._index'." } $Path = $info.Path } function Get-BFNextTimestamp { $r = Invoke-MdbcCommand @{ping = 1} $ts = $r['operationTime'] if ($ts) { New-Object MongoDB.Bson.BsonTimestamp $ts.Timestamp, ($ts.Increment + 1) } else { $null } } |