-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbd5ce1
commit 17e1bde
Showing
12 changed files
with
470 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
| ||
// Copyright (c) Roman Kuzmin | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
using MongoDB.Driver; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
|
||
namespace Mdbc.Commands | ||
{ | ||
[Cmdlet(VerbsOther.Use, "MdbcTransaction"), OutputType(typeof(IMongoDatabase))] | ||
public sealed class UseTransactionCommand : AbstractClientCommand | ||
{ | ||
[Parameter(Position = 0, Mandatory = true)] | ||
public ScriptBlock Script { get; set; } | ||
|
||
protected override void BeginProcessing() | ||
{ | ||
var session = Client.StartSession(); | ||
AbstractSessionCommand.PushDefaultSession(session); | ||
try | ||
{ | ||
session.StartTransaction(); | ||
try | ||
{ | ||
var vars = new List<PSVariable>() { new PSVariable("Session", session) }; | ||
var result = Script.InvokeWithContext(null, vars); | ||
foreach (var item in result) | ||
WriteObject(item); | ||
|
||
session.CommitTransaction(); | ||
} | ||
catch (RuntimeException exn) | ||
{ | ||
var text = $"{exn.Message}{Environment.NewLine}{exn.ErrorRecord.InvocationInfo.PositionMessage}"; | ||
var exn2 = new RuntimeException(text, exn); | ||
WriteException(exn2, null); | ||
} | ||
} | ||
finally | ||
{ | ||
AbstractSessionCommand.PopDefaultSession(); | ||
session.Dispose(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,5 +127,6 @@ task PublicTypes { | |
'RenameCollectionCommand' | ||
'SetDataCommand' | ||
'UpdateDataCommand' | ||
'UseTransactionCommand' | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.