CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
TransactionalDataPortal.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="TransactionalDataPortal.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Implements the server-side Serviced </summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Threading.Tasks;
10using System.Transactions;
11
12namespace Csla.Server
13{
19 {
20 private readonly TransactionalAttribute _transactionalAttribute;
21
28 public TransactionalDataPortal(TransactionalAttribute transactionalAttribute)
29 {
30 _transactionalAttribute = transactionalAttribute;
31 }
51 public async Task<DataPortalResult> Create(
52 Type objectType, object criteria, DataPortalContext context, bool isSync)
53 {
54 DataPortalResult result;
55 using (TransactionScope tr = CreateTransactionScope())
56 {
57 var portal = new DataPortalBroker();
58 result = await portal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
59 tr.Complete();
60 }
61 return result;
62 }
63
64 private TransactionScope CreateTransactionScope()
65 {
66 return new TransactionScope(TransactionScopeOption.Required, GetTransactionOptions(), _transactionalAttribute.AsyncFlowOption);
67 }
68
69 private TransactionOptions GetTransactionOptions()
70 {
71 var option = new TransactionOptions
72 {
73 IsolationLevel = GetIsolationLevel(_transactionalAttribute.TransactionIsolationLevel),
74 Timeout = TimeSpan.FromSeconds(_transactionalAttribute.TimeoutInSeconds)
75 };
76 return option;
77 }
78
79 private IsolationLevel GetIsolationLevel(TransactionIsolationLevel transactionIsolationLevel)
80 {
81 switch (transactionIsolationLevel)
82 {
83 case TransactionIsolationLevel.Unspecified:
84 return IsolationLevel.Unspecified;
85 case TransactionIsolationLevel.Serializable:
86 return IsolationLevel.Serializable;
87 case TransactionIsolationLevel.RepeatableRead:
88 return IsolationLevel.RepeatableRead;
89 case TransactionIsolationLevel.ReadCommitted:
90 return IsolationLevel.ReadCommitted;
91 case TransactionIsolationLevel.ReadUncommitted:
92 return IsolationLevel.ReadUncommitted;
93 default:
94 return IsolationLevel.Unspecified;
95 }
96 }
97
114 public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
115 {
116 DataPortalResult result;
117 using (TransactionScope tr = CreateTransactionScope())
118 {
119 var portal = new DataPortalBroker();
120 result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
121 tr.Complete();
122 }
123 return result;
124 }
125
141 public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
142 {
143 DataPortalResult result;
144 using (TransactionScope tr = CreateTransactionScope())
145 {
146 var portal = new DataPortalBroker();
147 result = await portal.Update(obj, context, isSync).ConfigureAwait(false);
148 tr.Complete();
149 }
150 return result;
151 }
152
168 public async Task<DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
169 {
170 DataPortalResult result;
171 using (TransactionScope tr = CreateTransactionScope())
172 {
173 var portal = new DataPortalBroker();
174 result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
175 tr.Complete();
176 }
177 return result;
178 }
179 }
180}
Allows the Data Portal call to be intercepted by a custom IDataPortalServer implementation.
Provides consistent context information between the client and server DataPortal objects.
Returns data from the server-side DataPortal to the client-side DataPortal.
Implements the server-side Serviced DataPortal described in Chapter 4.
async Task< DataPortalResult > Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
Called by the client-side DataPortal to delete an object.
async Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Called by the client-side DataProtal to retrieve an object.
TransactionalDataPortal(TransactionalAttribute transactionalAttribute)
Initializes a new instance of the TransactionalDataPortal class.
async Task< DataPortalResult > Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
Wraps a Create call in a TransactionScope
async Task< DataPortalResult > Update(object obj, DataPortalContext context, bool isSync)
Called by the client-side DataPortal to update an object.
Marks a DataPortal_XYZ method to run within the specified transactional context.
Interface implemented by server-side data portal components.
@ TransactionScope
Causes the server-side DataPortal to use System.Transactions TransactionScope style transactions.
TransactionIsolationLevel
Specifies an isolation level for transactions controlled by TransactionalAttribute