CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
DataPortal.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="DataPortal.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 DataPortal </summary>
7//-----------------------------------------------------------------------
8using System;
10using System.Security.Principal;
11using System.Threading.Tasks;
12using Csla.Properties;
14using System.Collections.Generic;
15
16namespace Csla.Server
17{
24 {
28 private ApplicationContext ApplicationContext { get; set; }
29
33 private IDashboard Dashboard { get; set; }
34 private DataPortalServerOptions Options { get; set; }
35 private IAuthorizeDataPortal Authorizer { get; set; }
36 private InterceptorManager InterceptorManager { get; set; }
37 private IObjectFactoryLoader FactoryLoader { get; set; }
38 private IDataPortalActivator Activator { get; set; }
39 private IDataPortalExceptionInspector ExceptionInspector { get; set; }
41
54 public DataPortal(
55 ApplicationContext applicationContext,
56 IDashboard dashboard,
57 CslaOptions options,
58 IAuthorizeDataPortal authorizer,
59 InterceptorManager interceptors,
60 IObjectFactoryLoader factoryLoader,
61 IDataPortalActivator activator,
62 IDataPortalExceptionInspector exceptionInspector,
63 DataPortalExceptionHandler exceptionHandler)
64 {
65 ApplicationContext = applicationContext;
66 Dashboard = dashboard;
67 Options = options.DataPortalServerOptions;
68 Authorizer = authorizer;
69 InterceptorManager = interceptors;
70 FactoryLoader = factoryLoader;
71 Activator = activator;
72 ExceptionInspector = exceptionInspector;
73 DataPortalExceptionHandler = exceptionHandler;
74 }
75
76 #region Data Access
77
78#if !NETSTANDARD2_0 && !NET5_0 && !NET6_0
79 private IDataPortalServer GetServicedComponentPortal(TransactionalAttribute transactionalAttribute)
80 {
81 switch (transactionalAttribute.TransactionIsolationLevel)
82 {
83 case TransactionIsolationLevel.Serializable:
85 case TransactionIsolationLevel.RepeatableRead:
87 case TransactionIsolationLevel.ReadCommitted:
89 case TransactionIsolationLevel.ReadUncommitted:
91 default:
92 throw new ArgumentOutOfRangeException("transactionalAttribute");
93 }
94 }
95#endif
96
97 private Reflection.ServiceProviderMethodCaller serviceProviderMethodCaller;
98 private Reflection.ServiceProviderMethodCaller ServiceProviderMethodCaller
99 {
100 get
101 {
102 if (serviceProviderMethodCaller == null)
103 serviceProviderMethodCaller = (Reflection.ServiceProviderMethodCaller)ApplicationContext.CreateInstanceDI(typeof(Reflection.ServiceProviderMethodCaller));
104 return serviceProviderMethodCaller;
105 }
106 }
107
117 public async Task<DataPortalResult> Create(
118 Type objectType, object criteria, DataPortalContext context, bool isSync)
119 {
120 try
121 {
122 SetContext(context);
123
124 AuthorizeRequest(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Create));
125
126 Initialize(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Create, IsSync = isSync });
127
128 DataPortalResult result;
129 DataPortalMethodInfo method;
130
131 Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
132 if (criteria is Server.EmptyCriteria)
133 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<CreateAttribute>(objectType, null);
134 else
135 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<CreateAttribute>(objectType, Server.DataPortal.GetCriteriaArray(criteria));
136 serviceProviderMethodInfo.PrepForInvocation();
137 method = serviceProviderMethodInfo.DataPortalMethodInfo;
138
139 IDataPortalServer portal;
140 switch (method.TransactionalAttribute.TransactionType)
141 {
142#if !NETSTANDARD2_0 && !NET5_0 && !NET6_0
143 case TransactionalTypes.EnterpriseServices:
144 portal = GetServicedComponentPortal(method.TransactionalAttribute);
145 try
146 {
147 result = await portal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
148 }
149 finally
150 {
151 ((System.EnterpriseServices.ServicedComponent)portal).Dispose();
152 }
153
154 break;
155#endif
156 case TransactionalTypes.TransactionScope:
157
159 portal = new TransactionalDataPortal(broker, method.TransactionalAttribute);
160 result = await portal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
161
162 break;
163 default:
165 result = await portal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
166 break;
167 }
168 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Create, IsSync = isSync });
169 return result;
170 }
172 {
173 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Create, IsSync = isSync });
174 throw;
175 }
176 catch (AggregateException ex)
177 {
178 Exception error = null;
179 if (ex.InnerExceptions.Count > 0)
180 error = ex.InnerExceptions[0].InnerException;
181 else
182 error = ex;
183 var fex = DataPortal.NewDataPortalException(
184 ApplicationContext, "DataPortal.Create " + Resources.FailedOnServer,
185 DataPortalExceptionHandler.InspectException(objectType, criteria, "DataPortal.Create", error),
186 null);
187 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Create, IsSync = isSync });
188 throw fex;
189 }
190 catch (Exception ex)
191 {
192 var fex = DataPortal.NewDataPortalException(
193 ApplicationContext, "DataPortal.Create " + Resources.FailedOnServer,
194 DataPortalExceptionHandler.InspectException(objectType, criteria, "DataPortal.Create", ex),
195 null);
196 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Create, IsSync = isSync });
197 throw fex;
198 }
199 finally
200 {
201 ClearContext(context);
202 }
203 }
204
214 public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
215 {
216 try
217 {
218 SetContext(context);
219
220 AuthorizeRequest(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Fetch));
221
222 Initialize(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Fetch, IsSync = isSync });
223
224 DataPortalResult result;
225 DataPortalMethodInfo method;
226
227 Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
228 if (criteria is EmptyCriteria)
229 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<FetchAttribute>(objectType, null);
230 else
231 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<FetchAttribute>(objectType, Server.DataPortal.GetCriteriaArray(criteria));
232
233 serviceProviderMethodInfo.PrepForInvocation();
234 method = serviceProviderMethodInfo.DataPortalMethodInfo;
235
236 IDataPortalServer portal;
237 switch (method.TransactionalAttribute.TransactionType)
238 {
239#if !NETSTANDARD2_0 && !NET5_0 && !NET6_0
240 case TransactionalTypes.EnterpriseServices:
241 portal = GetServicedComponentPortal(method.TransactionalAttribute);
242 try
243 {
244 result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
245 }
246 finally
247 {
248 ((System.EnterpriseServices.ServicedComponent)portal).Dispose();
249 }
250 break;
251#endif
252 case TransactionalTypes.TransactionScope:
254 portal = new TransactionalDataPortal(broker, method.TransactionalAttribute);
255 result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
256 break;
257 default:
259 result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
260 break;
261 }
262 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Fetch, IsSync = isSync });
263 return result;
264 }
266 {
267 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Fetch, IsSync = isSync });
268 throw;
269 }
270 catch (AggregateException ex)
271 {
272 Exception error = null;
273 if (ex.InnerExceptions.Count > 0)
274 error = ex.InnerExceptions[0].InnerException;
275 else
276 error = ex;
277 var fex = DataPortal.NewDataPortalException(
278 ApplicationContext, "DataPortal.Fetch " + Resources.FailedOnServer,
279 DataPortalExceptionHandler.InspectException(objectType, criteria, "DataPortal.Fetch", error),
280 null);
281 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Fetch, IsSync = isSync });
282 throw fex;
283 }
284 catch (Exception ex)
285 {
286 var fex = DataPortal.NewDataPortalException(
287 ApplicationContext, "DataPortal.Fetch " + Resources.FailedOnServer,
288 DataPortalExceptionHandler.InspectException(objectType, criteria, "DataPortal.Fetch", ex),
289 null);
290 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Fetch, IsSync = isSync });
291 throw fex;
292 }
293 finally
294 {
295 ClearContext(context);
296 }
297 }
298
307 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
308 public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
309 {
310 Type objectType = null;
312 try
313 {
314 SetContext(context);
315
316 objectType = obj.GetType();
317
318 if (obj is Core.ICommandObject)
319 operation = DataPortalOperations.Execute;
320
321 AuthorizeRequest(new AuthorizeRequest(objectType, obj, operation));
322
323 Initialize(new InterceptArgs { ObjectType = objectType, Parameter = obj, Operation = operation, IsSync = isSync });
324
325 DataPortalResult result;
326 DataPortalMethodInfo method;
327 var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
328 if (factoryInfo != null)
329 {
330 string methodName;
331 var factoryLoader = ApplicationContext.CurrentServiceProvider.GetService(typeof(Server.IObjectFactoryLoader)) as Server.IObjectFactoryLoader;
332 var factoryType = factoryLoader?.GetFactoryType(factoryInfo.FactoryTypeName);
333 if (obj is Core.BusinessBase bbase)
334 {
335 if (bbase.IsDeleted)
336 methodName = factoryInfo.DeleteMethodName;
337 else
338 methodName = factoryInfo.UpdateMethodName;
339 }
340 else if (obj is Core.ICommandObject)
341 methodName = factoryInfo.ExecuteMethodName;
342 else
343 methodName = factoryInfo.UpdateMethodName;
344 method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, methodName, new object[] { obj });
345 }
346 else
347 {
348 Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
349 if (obj is Core.BusinessBase bbase)
350 {
351 if (bbase.IsDeleted)
352 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<DeleteSelfAttribute>(objectType, null);
353 else
354 if (bbase.IsNew)
355 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<InsertAttribute>(objectType, null);
356 else
357 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<UpdateAttribute>(objectType, null);
358 }
359 else if (obj is Core.ICommandObject)
360 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<ExecuteAttribute>(objectType, null);
361 else
362 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<UpdateAttribute>(objectType, null);
363
364 serviceProviderMethodInfo.PrepForInvocation();
365 method = serviceProviderMethodInfo.DataPortalMethodInfo;
366 }
367
368 context.TransactionalType = method.TransactionalAttribute.TransactionType;
369 IDataPortalServer portal;
370 switch (method.TransactionalAttribute.TransactionType)
371 {
372#if !NETSTANDARD2_0 && !NET5_0 && !NET6_0
373 case TransactionalTypes.EnterpriseServices:
374 portal = GetServicedComponentPortal(method.TransactionalAttribute);
375 try
376 {
377 result = await portal.Update(obj, context, isSync).ConfigureAwait(false);
378 }
379 finally
380 {
381 ((System.EnterpriseServices.ServicedComponent)portal).Dispose();
382 }
383 break;
384#endif
385 case TransactionalTypes.TransactionScope:
387 portal = new TransactionalDataPortal(broker, method.TransactionalAttribute);
388 result = await portal.Update(obj, context, isSync).ConfigureAwait(false);
389 break;
390 default:
392 result = await portal.Update(obj, context, isSync).ConfigureAwait(false);
393 break;
394 }
395 Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Result = result, Operation = operation, IsSync = isSync });
396 return result;
397 }
399 {
400 Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Exception = ex, Operation = operation, IsSync = isSync });
401 throw;
402 }
403 catch (AggregateException ex)
404 {
405 Exception error = null;
406 if (ex.InnerExceptions.Count > 0)
407 error = ex.InnerExceptions[0].InnerException;
408 else
409 error = ex;
410 var fex = DataPortal.NewDataPortalException(
411 ApplicationContext, "DataPortal.Update " + Resources.FailedOnServer,
412 DataPortalExceptionHandler.InspectException(obj.GetType(), obj, null, "DataPortal.Update", error),
413 obj);
414 Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Exception = fex, Operation = operation, IsSync = isSync });
415 throw fex;
416 }
417 catch (Exception ex)
418 {
419 var fex = DataPortal.NewDataPortalException(
420 ApplicationContext, "DataPortal.Update " + Resources.FailedOnServer,
421 DataPortalExceptionHandler.InspectException(obj.GetType(), obj, null, "DataPortal.Update", ex),
422 obj);
423 Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Exception = fex, Operation = operation, IsSync = isSync });
424 throw fex;
425 }
426 finally
427 {
428 ClearContext(context);
429 }
430 }
431
441 public async Task<DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
442 {
443 try
444 {
445 SetContext(context);
446
447 AuthorizeRequest(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Delete));
448
449 Initialize(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Delete, IsSync = isSync });
450
451 DataPortalResult result;
452 DataPortalMethodInfo method;
453 var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
454 if (factoryInfo != null)
455 {
456 var factoryLoader = ApplicationContext.CurrentServiceProvider.GetService(typeof(Server.IObjectFactoryLoader)) as Server.IObjectFactoryLoader;
457 var factoryType = factoryLoader?.GetFactoryType(factoryInfo.FactoryTypeName);
458 string methodName = factoryInfo.DeleteMethodName;
459 method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, methodName, criteria);
460 }
461 else
462 {
463 Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
464 if (criteria is EmptyCriteria)
465 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<DeleteAttribute>(objectType, null);
466 else
467 serviceProviderMethodInfo = ServiceProviderMethodCaller.FindDataPortalMethod<DeleteAttribute>(objectType, Server.DataPortal.GetCriteriaArray(criteria));
468 serviceProviderMethodInfo.PrepForInvocation();
469 method = serviceProviderMethodInfo.DataPortalMethodInfo;
470 }
471
472 IDataPortalServer portal;
473 switch (method.TransactionalAttribute.TransactionType)
474 {
475#if !NETSTANDARD2_0 && !NET5_0 && !NET6_0
476 case TransactionalTypes.EnterpriseServices:
477 portal = GetServicedComponentPortal(method.TransactionalAttribute);
478 try
479 {
480 result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
481 }
482 finally
483 {
484 ((System.EnterpriseServices.ServicedComponent)portal).Dispose();
485 }
486 break;
487#endif
488 case TransactionalTypes.TransactionScope:
490 portal = new TransactionalDataPortal(broker, method.TransactionalAttribute);
491 result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
492 break;
493 default:
495 result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
496 break;
497 }
498 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Delete, IsSync = isSync });
499 return result;
500 }
502 {
503 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Delete, IsSync = isSync });
504 throw;
505 }
506 catch (AggregateException ex)
507 {
508 Exception error = null;
509 if (ex.InnerExceptions.Count > 0)
510 error = ex.InnerExceptions[0].InnerException;
511 else
512 error = ex;
513 var fex = DataPortal.NewDataPortalException(
514 ApplicationContext, "DataPortal.Delete " + Resources.FailedOnServer,
515 DataPortalExceptionHandler.InspectException(objectType, criteria, "DataPortal.Delete", error),
516 null);
517 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Delete, IsSync = isSync });
518 throw fex;
519 }
520 catch (Exception ex)
521 {
522 var fex = DataPortal.NewDataPortalException(
523 ApplicationContext, "DataPortal.Delete " + Resources.FailedOnServer,
524 DataPortalExceptionHandler.InspectException(objectType, criteria, "DataPortal.Delete", ex),
525 null);
526 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Delete, IsSync = isSync });
527 throw fex;
528 }
529 finally
530 {
531 ClearContext(context);
532 }
533 }
534
535 internal void Complete(InterceptArgs e)
536 {
538
539 var timer = ApplicationContext.ClientContext.GetValueOrNull("__dataportaltimer");
540 if (timer == null) return;
541
542 var startTime = (DateTimeOffset)timer;
543 e.Runtime = DateTimeOffset.Now - startTime;
544 Dashboard.CompleteCall(e);
545 }
546
547 internal void Initialize(InterceptArgs e)
548 {
549 ApplicationContext.ClientContext["__dataportaltimer"] = DateTimeOffset.Now;
550 Dashboard.InitializeCall(e);
551
552 InterceptorManager.Initialize(e);
553 }
554
555#endregion
556
557#region Context
558
559 ApplicationContext.LogicalExecutionLocations _oldLocation;
560
561 private void SetContext(DataPortalContext context)
562 {
563 _oldLocation = ApplicationContext.LogicalExecutionLocation;
564 ApplicationContext.SetLogicalExecutionLocation(ApplicationContext.LogicalExecutionLocations.Server);
565
566 if (context.IsRemotePortal)
567 {
568 // indicate that the code is physically running on the server
569 ApplicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
570 }
571
572 // set the app context to the value we got from the caller
573 ApplicationContext.SetContext(context.ClientContext);
574
575 // set the thread's culture to match the caller
576 SetCulture(context);
577
578 // set current user principal
579 SetPrincipal(context);
580 }
581
582 private void SetPrincipal(DataPortalContext context)
583 {
584 if (ApplicationContext.AuthenticationType == "Windows")
585 {
586 // When using integrated security, Principal must be null
587 if (context.Principal != null)
588 {
591 //ex.Action = System.Security.Permissions.SecurityAction.Deny;
592 throw ex;
593 }
594 // Set .NET to use integrated security
595 AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
596 }
597 else
598 {
599 // We expect the some Principal object
600 if (context.Principal == null)
601 {
605 //ex.Action = System.Security.Permissions.SecurityAction.Deny;
606 throw ex;
607 }
608 ApplicationContext.User = context.Principal;
609 }
610 }
611
612 private static void SetCulture(DataPortalContext context)
613 {
614 // set the thread's culture to match the client
615 System.Threading.Thread.CurrentThread.CurrentCulture =
616 new System.Globalization.CultureInfo(context.ClientCulture);
617 System.Threading.Thread.CurrentThread.CurrentUICulture =
618 new System.Globalization.CultureInfo(context.ClientUICulture);
619 }
620
621 private void ClearContext(DataPortalContext context)
622 {
623 ApplicationContext.SetLogicalExecutionLocation(_oldLocation);
624 // if the dataportal is not remote then
625 // do nothing
626 if (!context.IsRemotePortal) return;
627 ApplicationContext.Clear();
628 if (ApplicationContext.AuthenticationType != "Windows")
629 ApplicationContext.User = null;
630 }
631
632 #endregion
633
634 private void AuthorizeRequest(AuthorizeRequest clientRequest)
635 {
636 Authorizer.Authorize(clientRequest);
637 }
638
639 internal static DataPortalException NewDataPortalException(
640 ApplicationContext applicationContext, string message, Exception innerException, object businessObject)
641 {
642 if (!ApplicationContext.DataPortalReturnObjectOnException)
643 businessObject = null;
644
645 throw new DataPortalException(
646 message,
647 innerException, new DataPortalResult(applicationContext, businessObject));
648 }
649
656 public static object GetCriteriaFromArray(params object[] criteria)
657 {
658 var clength = 0;
659 if (criteria != null)
660 if (criteria.GetType().Equals(typeof(object[])))
661 clength = criteria.GetLength(0);
662 else
663 return criteria;
664
665 if (criteria == null || (clength == 1 && criteria[0] == null))
666 return NullCriteria.Instance;
667 else if (clength == 0)
668 return EmptyCriteria.Instance;
669 else if (clength == 1)
670 return criteria[0];
671 else
672 return new Core.MobileList<object>(criteria);
673 }
674
681 public static object[] GetCriteriaArray(object criteria)
682 {
683 if (criteria == null)
684 return null;
685 else if (criteria is EmptyCriteria)
686 return Array.Empty<object>();
687 else if (criteria is NullCriteria)
688 return new object[] { null };
689 else if (criteria.GetType().Equals(typeof(object[])))
690 {
691 var array = (object[])criteria;
692 var clength = array.GetLength(0);
693 if (clength == 1 && array[0] is EmptyCriteria)
694 return Array.Empty<object>();
695 else
696 return array;
697 }
698 else if (criteria is Core.MobileList<object> list)
699 return list.ToArray();
700 else
701 return new object[] { criteria };
702 }
703 }
704}
Csla.Server.DataPortalContext DataPortalContext
Provides consistent context information between the client and server DataPortal objects.
LogicalExecutionLocations LogicalExecutionLocation
Return Logical Execution Location - Client or Server This is applicable to Local mode as well
ExecutionLocations
Enum representing the locations code can execute.
LogicalExecutionLocations
Enum representing the logical execution location The setting is set to server when server is execting...
object CreateInstanceDI(Type objectType, params object[] parameters)
Creates an object using 'Activator.CreateInstance' using service provider (if one is available) to po...
void Clear()
Clears all context collections.
static bool DataPortalReturnObjectOnException
Gets a value indicating whether the server-side business object should be returned to the client as p...
static string AuthenticationType
Gets the authentication type being used by the CSLA .NET framework.
IPrincipal User
Get or set the current IPrincipal object representing the user's identity.
ContextDictionary ClientContext
Returns the application-specific context data provided by the client.
Use this type to configure the settings for CSLA .NET.
Definition: CslaOptions.cs:18
Specifies a method used by the server-side data portal to initialize a new domain object.
Specifies a method used by the server-side data portal to delete domain object data during an update ...
Specifies a method used by the server-side data portal to delete domain object data during an explici...
Specifies a method used by the server-side data portal to execute a command object.
Specifies a method used by the server-side data portal to load existing data into the domain object.
Specifies a method used by the server-side data portal to insert domain object data during an update ...
A strongly-typed resource class, for looking up localized strings, etc.
static string BusinessPrincipalException
Looks up a localized string similar to Principal must be of type BusinessPrincipal,...
static string FailedOnServer
Looks up a localized string similar to failed on the server.
static string NoPrincipalAllowedException
Looks up a localized string similar to No principal object should be passed to DataPortal when using ...
Object containing information about the client request to the data portal.
Data portal server dashboard.
Definition: Dashboard.cs:21
Allows the Data Portal call to be intercepted by a custom IDataPortalServer implementation.
Task< DataPortalResult > Update(object obj, DataPortalContext context, bool isSync)
Update a business object.
Task< DataPortalResult > Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
Create a new business object.
Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Get an existing business object.
Task< DataPortalResult > Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
Delete a business object.
Provides consistent context information between the client and server DataPortal objects.
TransactionalTypes TransactionalType
Gets the current transactional type.
This class provides a hook for developers to add custom error handling in the DataPortal.
Exception InspectException(Type objectType, object criteria, string methodName, Exception ex)
Transforms the exception in a Fetch, Create or Execute method.
This exception is returned from the server-side DataPortal and contains the exception and context dat...
Implements the server-side DataPortal message router as discussed in Chapter 4.
Definition: DataPortal.cs:24
DataPortal(ApplicationContext applicationContext, IDashboard dashboard, CslaOptions options, IAuthorizeDataPortal authorizer, InterceptorManager interceptors, IObjectFactoryLoader factoryLoader, IDataPortalActivator activator, IDataPortalExceptionInspector exceptionInspector, DataPortalExceptionHandler exceptionHandler)
Creates an instance of the type.
Definition: DataPortal.cs:54
async Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Get an existing business object.
Definition: DataPortal.cs:214
static object[] GetCriteriaArray(object criteria)
Converts a single serializable criteria value into an array of type object.
Definition: DataPortal.cs:681
static object GetCriteriaFromArray(params object[] criteria)
Converts a params array to a single serializable criteria value.
Definition: DataPortal.cs:656
async Task< DataPortalResult > Update(object obj, DataPortalContext context, bool isSync)
Update a business object.
Definition: DataPortal.cs:308
async Task< DataPortalResult > Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
Create a new business object.
Definition: DataPortal.cs:117
async Task< DataPortalResult > Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
Delete a business object.
Definition: DataPortal.cs:441
Returns data from the server-side DataPortal to the client-side DataPortal.
Empty criteria used by the data portal as a placeholder for a create/fetch request that has no criter...
static EmptyCriteria Instance
Gets an instance of EmptyCriteria
Arguments parameter passed to the interceptor methods.
TimeSpan Runtime
Gets or sets a value containing the elapsed runtime for this operation (only valid at end of operatio...
Manage dataportal interception using DI-registered implementations
void Initialize(InterceptArgs e)
Cascade the initial interception request prior to the main DataPortal operation
void Complete(InterceptArgs e)
Cascade the final interception request after the main DataPortal operation has completed
Null criteria used by the data portal as a placeholder for a create/fetch request that has a single n...
Definition: NullCriteria.cs:19
static NullCriteria Instance
Gets an instance of NullCriteria
Definition: NullCriteria.cs:25
Specifies that the data portal should invoke a factory object rather than the business object.
Implements the server-side Serviced DataPortal described in Chapter 4.
Implements the server-side Serviced DataPortal described in Chapter 4.
Implements the server-side Serviced DataPortal described in Chapter 4.
Implements the server-side Serviced DataPortal described in Chapter 4.
Implements the server-side Serviced DataPortal described in Chapter 4.
Marks a DataPortal_XYZ method to run within the specified transactional context.
TransactionIsolationLevel TransactionIsolationLevel
Specifies override for transaction isolation level.
Specifies a method used by the server-side data portal to update domain object data during an update ...
Data portal server dashboard.
Definition: IDashboard.cs:17
Interface to be implemented by a custom authorization provider.
void Authorize(AuthorizeRequest clientRequest)
Implement this method to perform custom authorization on every data portal call.
Defines a type used to activate concrete business instances.
Implement this interface to check a DataPortalException before returning Exception to the client.
Interface implemented by server-side data portal components.
Task< DataPortalResult > Update(object obj, DataPortalContext context, bool isSync)
Update a business object.
Task< DataPortalResult > Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
Create a new business object.
Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Get an existing business object.
Task< DataPortalResult > Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
Delete a business object.
Defines an interface to be implemented by a factory loader object that returns ObjectFactory objects ...
TransactionalTypes
Provides a list of possible transactional technologies to be used by the server-side DataPortal.
TransactionIsolationLevel
Specifies an isolation level for transactions controlled by TransactionalAttribute
DataPortalOperations
List of data portal operations.