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.
Server/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;
13
14namespace Csla.Server
15{
22 {
26 public static Dashboard.IDashboard Dashboard { get; internal set; }
27
28 static DataPortal()
29 {
30 Dashboard = Server.Dashboard.DashboardFactory.GetDashboard();
31 }
32
33 #region Constructors
37 public DataPortal()
38 : this("CslaAuthorizationProvider")
39 {
40
41 }
42
48 protected DataPortal(string cslaAuthorizationProviderAppSettingName)
49 : this(GetAuthProviderType(cslaAuthorizationProviderAppSettingName))
50 {
51 }
52
57 protected DataPortal(Type authProviderType)
58 {
59 if (null == authProviderType)
60 throw new ArgumentNullException(nameof(authProviderType), Resources.CslaAuthenticationProviderNotSet);
61 if (!typeof(IAuthorizeDataPortal).IsAssignableFrom(authProviderType))
62 throw new ArgumentException(Resources.AuthenticationProviderDoesNotImplementIAuthorizeDataPortal, nameof(authProviderType));
63
64 //only construct the type if it was not constructed already
65 if (null == _authorizer)
66 {
67 lock (_syncRoot)
68 {
69 if (null == _authorizer)
70 _authorizer = (IAuthorizeDataPortal)Reflection.MethodCaller.CreateInstance(authProviderType);
71 }
72 }
73
74 if (InterceptorType != null)
75 {
76 if (_interceptor == null)
77 {
78 lock (_syncRoot)
79 {
80 if (_interceptor == null)
81 _interceptor = (IInterceptDataPortal)Reflection.MethodCaller.CreateInstance(InterceptorType);
82 }
83 }
84 }
85 }
86
87 private static Type GetAuthProviderType(string cslaAuthorizationProviderAppSettingName)
88 {
89 if (cslaAuthorizationProviderAppSettingName == null)
90 throw new ArgumentNullException("cslaAuthorizationProviderAppSettingName", Resources.AuthorizationProviderNameNotSpecified);
91
92
93 if (null == _authorizer)//not yet instantiated
94 {
95 var authProvider = ConfigurationManager.AppSettings[cslaAuthorizationProviderAppSettingName];
96 return string.IsNullOrEmpty(authProvider) ?
97 typeof(NullAuthorizer) :
98 Type.GetType(authProvider, true);
99
100 }
101 else
102 return _authorizer.GetType();
103
104 }
105
106 #endregion
107
108 #region Data Access
109
110#if !NETSTANDARD2_0 && !NET5_0
111 private IDataPortalServer GetServicedComponentPortal(TransactionalAttribute transactionalAttribute)
112 {
113 switch (transactionalAttribute.TransactionIsolationLevel)
114 {
115 case TransactionIsolationLevel.Serializable:
116 return new ServicedDataPortalSerializable();
117 case TransactionIsolationLevel.RepeatableRead:
118 return new ServicedDataPortalRepeatableRead();
119 case TransactionIsolationLevel.ReadCommitted:
120 return new ServicedDataPortalReadCommitted();
121 case TransactionIsolationLevel.ReadUncommitted:
122 return new ServicedDataPortalReadUncommitted();
123 default:
124 throw new ArgumentOutOfRangeException("transactionalAttribute");
125 }
126 }
127#endif
128
138 public async Task<DataPortalResult> Create(
139 Type objectType, object criteria, DataPortalContext context, bool isSync)
140 {
141 try
142 {
143 SetContext(context);
144
145 Initialize(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Create, IsSync = isSync });
146
147 AuthorizeRequest(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Create));
148 DataPortalResult result;
149 DataPortalMethodInfo method;
150
151 Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
152 if (criteria is Server.EmptyCriteria)
153 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<CreateAttribute>(objectType, null);
154 else
155 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<CreateAttribute>(objectType, Server.DataPortal.GetCriteriaArray(criteria));
156 serviceProviderMethodInfo.PrepForInvocation();
157 method = serviceProviderMethodInfo.DataPortalMethodInfo;
158
159 IDataPortalServer portal;
160 switch (method.TransactionalAttribute.TransactionType)
161 {
162#if !NETSTANDARD2_0 && !NET5_0
163 case TransactionalTypes.EnterpriseServices:
164 portal = GetServicedComponentPortal(method.TransactionalAttribute);
165 try
166 {
167 result = await portal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
168 }
169 finally
170 {
171 ((System.EnterpriseServices.ServicedComponent)portal).Dispose();
172 }
173
174 break;
175#endif
176 case TransactionalTypes.TransactionScope:
177
178 portal = new TransactionalDataPortal(method.TransactionalAttribute);
179 result = await portal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
180
181 break;
182 default:
183 portal = new DataPortalBroker();
184 result = await portal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
185 break;
186 }
187 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Create, IsSync = isSync });
188 return result;
189 }
191 {
192 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Create, IsSync = isSync });
193 throw;
194 }
195 catch (AggregateException ex)
196 {
197 Exception error = null;
198 if (ex.InnerExceptions.Count > 0)
199 error = ex.InnerExceptions[0].InnerException;
200 else
201 error = ex;
202 var fex = DataPortal.NewDataPortalException(
203 "DataPortal.Create " + Resources.FailedOnServer,
204 new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Create", error),
205 null);
206 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Create, IsSync = isSync });
207 throw fex;
208 }
209 catch (Exception ex)
210 {
211 var fex = DataPortal.NewDataPortalException(
212 "DataPortal.Create " + Resources.FailedOnServer,
213 new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Create", ex),
214 null);
215 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Create, IsSync = isSync });
216 throw fex;
217 }
218 finally
219 {
220 ClearContext(context);
221 }
222 }
223
233 public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
234 {
235 try
236 {
237 SetContext(context);
238
239 Initialize(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Fetch, IsSync = isSync });
240
241 AuthorizeRequest(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Fetch));
242 DataPortalResult result;
243 DataPortalMethodInfo method;
244
245 Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
246 if (criteria is EmptyCriteria)
247 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<FetchAttribute>(objectType, null);
248 else
249 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<FetchAttribute>(objectType, Server.DataPortal.GetCriteriaArray(criteria));
250
251 serviceProviderMethodInfo.PrepForInvocation();
252 method = serviceProviderMethodInfo.DataPortalMethodInfo;
253
254 IDataPortalServer portal;
255 switch (method.TransactionalAttribute.TransactionType)
256 {
257#if !NETSTANDARD2_0 && !NET5_0
258 case TransactionalTypes.EnterpriseServices:
259 portal = GetServicedComponentPortal(method.TransactionalAttribute);
260 try
261 {
262 result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
263 }
264 finally
265 {
266 ((System.EnterpriseServices.ServicedComponent)portal).Dispose();
267 }
268 break;
269#endif
270 case TransactionalTypes.TransactionScope:
271 portal = new TransactionalDataPortal(method.TransactionalAttribute);
272 result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
273 break;
274 default:
275 portal = new DataPortalBroker();
276 result = await portal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
277 break;
278 }
279 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Fetch, IsSync = isSync });
280 return result;
281 }
283 {
284 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Fetch, IsSync = isSync });
285 throw;
286 }
287 catch (AggregateException ex)
288 {
289 Exception error = null;
290 if (ex.InnerExceptions.Count > 0)
291 error = ex.InnerExceptions[0].InnerException;
292 else
293 error = ex;
294 var fex = DataPortal.NewDataPortalException(
295 "DataPortal.Fetch " + Resources.FailedOnServer,
296 new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Fetch", error),
297 null);
298 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Fetch, IsSync = isSync });
299 throw fex;
300 }
301 catch (Exception ex)
302 {
303 var fex = DataPortal.NewDataPortalException(
304 "DataPortal.Fetch " + Resources.FailedOnServer,
305 new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Fetch", ex),
306 null);
307 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Fetch, IsSync = isSync });
308 throw fex;
309 }
310 finally
311 {
312 ClearContext(context);
313 }
314 }
315
324 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
325 public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
326 {
327 Type objectType = null;
329 try
330 {
331 SetContext(context);
332
333 objectType = obj.GetType();
334
335 if (obj is Core.ICommandObject)
336 operation = DataPortalOperations.Execute;
337 Initialize(new InterceptArgs { ObjectType = objectType, Parameter = obj, Operation = operation, IsSync = isSync });
338
339 AuthorizeRequest(new AuthorizeRequest(objectType, obj, operation));
340 DataPortalResult result;
341 DataPortalMethodInfo method;
342 var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
343 if (factoryInfo != null)
344 {
345 string methodName;
346 var factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName);
347 var bbase = obj as Core.BusinessBase;
348 if (bbase != null)
349 {
350 if (bbase.IsDeleted)
351 methodName = factoryInfo.DeleteMethodName;
352 else
353 methodName = factoryInfo.UpdateMethodName;
354 }
355 else if (obj is Core.ICommandObject)
356 methodName = factoryInfo.ExecuteMethodName;
357 else
358 methodName = factoryInfo.UpdateMethodName;
359 method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, methodName, new object[] { obj });
360 }
361 else
362 {
363 Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
364 var bbase = obj as Core.BusinessBase;
365 if (bbase != null)
366 {
367 if (bbase.IsDeleted)
368 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<DeleteSelfAttribute>(objectType, null);
369 else
370 if (bbase.IsNew)
371 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<InsertAttribute>(objectType, null);
372 else
373 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<UpdateAttribute>(objectType, null);
374 }
375 else if (obj is Core.ICommandObject)
376 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<ExecuteAttribute>(objectType, null);
377 else
378 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<UpdateAttribute>(objectType, null);
379
380 serviceProviderMethodInfo.PrepForInvocation();
381 method = serviceProviderMethodInfo.DataPortalMethodInfo;
382 }
383
384 context.TransactionalType = method.TransactionalAttribute.TransactionType;
385 IDataPortalServer portal;
386 switch (method.TransactionalAttribute.TransactionType)
387 {
388#if !NETSTANDARD2_0 && !NET5_0
389 case TransactionalTypes.EnterpriseServices:
390 portal = GetServicedComponentPortal(method.TransactionalAttribute);
391 try
392 {
393 result = await portal.Update(obj, context, isSync).ConfigureAwait(false);
394 }
395 finally
396 {
397 ((System.EnterpriseServices.ServicedComponent)portal).Dispose();
398 }
399 break;
400#endif
401 case TransactionalTypes.TransactionScope:
402 portal = new TransactionalDataPortal(method.TransactionalAttribute);
403 result = await portal.Update(obj, context, isSync).ConfigureAwait(false);
404 break;
405 default:
406 portal = new DataPortalBroker();
407 result = await portal.Update(obj, context, isSync).ConfigureAwait(false);
408 break;
409 }
410 Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Result = result, Operation = operation, IsSync = isSync });
411 return result;
412 }
414 {
415 Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Exception = ex, Operation = operation, IsSync = isSync });
416 throw;
417 }
418 catch (AggregateException ex)
419 {
420 Exception error = null;
421 if (ex.InnerExceptions.Count > 0)
422 error = ex.InnerExceptions[0].InnerException;
423 else
424 error = ex;
425 var fex = DataPortal.NewDataPortalException(
426 "DataPortal.Update " + Resources.FailedOnServer,
427 new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", error),
428 obj);
429 Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Exception = fex, Operation = operation, IsSync = isSync });
430 throw fex;
431 }
432 catch (Exception ex)
433 {
434 var fex = DataPortal.NewDataPortalException(
435 "DataPortal.Update " + Resources.FailedOnServer,
436 new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", ex),
437 obj);
438 Complete(new InterceptArgs { ObjectType = objectType, Parameter = obj, Exception = fex, Operation = operation, IsSync = isSync });
439 throw fex;
440 }
441 finally
442 {
443 ClearContext(context);
444 }
445 }
446
456 public async Task<DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
457 {
458 try
459 {
460 SetContext(context);
461
462 Initialize(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Operation = DataPortalOperations.Delete, IsSync = isSync });
463
464 AuthorizeRequest(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Delete));
465 DataPortalResult result;
466 DataPortalMethodInfo method;
467 var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
468 if (factoryInfo != null)
469 {
470 var factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName);
471 string methodName = factoryInfo.DeleteMethodName;
472 method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, methodName, criteria);
473 }
474 else
475 {
476 Reflection.ServiceProviderMethodInfo serviceProviderMethodInfo;
477 if (criteria is EmptyCriteria)
478 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<DeleteAttribute>(objectType, null);
479 else
480 serviceProviderMethodInfo = Reflection.ServiceProviderMethodCaller.FindDataPortalMethod<DeleteAttribute>(objectType, Server.DataPortal.GetCriteriaArray(criteria));
481 serviceProviderMethodInfo.PrepForInvocation();
482 method = serviceProviderMethodInfo.DataPortalMethodInfo;
483 }
484
485 IDataPortalServer portal;
486 switch (method.TransactionalAttribute.TransactionType)
487 {
488#if !NETSTANDARD2_0 && !NET5_0
489 case TransactionalTypes.EnterpriseServices:
490 portal = GetServicedComponentPortal(method.TransactionalAttribute);
491 try
492 {
493 result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
494 }
495 finally
496 {
497 ((System.EnterpriseServices.ServicedComponent)portal).Dispose();
498 }
499 break;
500#endif
501 case TransactionalTypes.TransactionScope:
502 portal = new TransactionalDataPortal(method.TransactionalAttribute);
503 result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
504 break;
505 default:
506 portal = new DataPortalBroker();
507 result = await portal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
508 break;
509 }
510 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Result = result, Operation = DataPortalOperations.Delete, IsSync = isSync });
511 return result;
512 }
514 {
515 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = ex, Operation = DataPortalOperations.Delete, IsSync = isSync });
516 throw;
517 }
518 catch (AggregateException ex)
519 {
520 Exception error = null;
521 if (ex.InnerExceptions.Count > 0)
522 error = ex.InnerExceptions[0].InnerException;
523 else
524 error = ex;
525 var fex = DataPortal.NewDataPortalException(
526 "DataPortal.Delete " + Resources.FailedOnServer,
527 new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Delete", error),
528 null);
529 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Delete, IsSync = isSync });
530 throw fex;
531 }
532 catch (Exception ex)
533 {
534 var fex = DataPortal.NewDataPortalException(
535 "DataPortal.Delete " + Resources.FailedOnServer,
536 new DataPortalExceptionHandler().InspectException(objectType, criteria, "DataPortal.Delete", ex),
537 null);
538 Complete(new InterceptArgs { ObjectType = objectType, Parameter = criteria, Exception = fex, Operation = DataPortalOperations.Delete, IsSync = isSync });
539 throw fex;
540 }
541 finally
542 {
543 ClearContext(context);
544 }
545 }
546
547 private IInterceptDataPortal _interceptor = null;
548 private static Type _interceptorType = null;
549 private static bool _InterceptorTypeSet = false;
550
556 public static Type InterceptorType
557 {
558 get
559 {
560 if (!_InterceptorTypeSet)
561 {
562 var typeName = ConfigurationManager.AppSettings["CslaDataPortalInterceptor"];
563 if (!string.IsNullOrWhiteSpace(typeName))
564 InterceptorType = Type.GetType(typeName);
565 _InterceptorTypeSet = true;
566 }
567 return _interceptorType;
568 }
569 set
570 {
571 _interceptorType = value;
572 _InterceptorTypeSet = true;
573 }
574 }
575
576 internal void Complete(InterceptArgs e)
577 {
578 var timer = ApplicationContext.ClientContext.GetValueOrNull("__dataportaltimer");
579 if (timer != null)
580 {
581 var startTime = (DateTimeOffset)timer;
582 e.Runtime = DateTimeOffset.Now - startTime;
583 Dashboard.CompleteCall(e);
584 }
585
586 if (_interceptor != null)
587 _interceptor.Complete(e);
588 }
589
590 internal void Initialize(InterceptArgs e)
591 {
592 ApplicationContext.ClientContext["__dataportaltimer"] = DateTimeOffset.Now;
593 Dashboard.InitializeCall(e);
594
595 if (_interceptor != null)
596 _interceptor.Initialize(e);
597 }
598
599#endregion
600
601#region Context
602
603 ApplicationContext.LogicalExecutionLocations _oldLocation;
604
605 private void SetContext(DataPortalContext context)
606 {
607 _oldLocation = Csla.ApplicationContext.LogicalExecutionLocation;
608 ApplicationContext.SetLogicalExecutionLocation(ApplicationContext.LogicalExecutionLocations.Server);
609
610 if (!context.IsRemotePortal && ApplicationContext.WebContextManager != null && !ApplicationContext.WebContextManager.IsValid)
611 ApplicationContext.SetContext(context.ClientContext, context.GlobalContext);
612
613 // if the dataportal is not remote then
614 // do nothing
615 if (!context.IsRemotePortal) return;
616
617 // set the context value so everyone knows the
618 // code is running on the server
619 ApplicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
620
621 // set the app context to the value we got from the
622 // client
623 ApplicationContext.SetContext(context.ClientContext, context.GlobalContext);
624
625 // set the thread's culture to match the client
626 System.Threading.Thread.CurrentThread.CurrentCulture =
627 new System.Globalization.CultureInfo(context.ClientCulture);
628 System.Threading.Thread.CurrentThread.CurrentUICulture =
629 new System.Globalization.CultureInfo(context.ClientUICulture);
630
631 if (ApplicationContext.AuthenticationType == "Windows")
632 {
633 // When using integrated security, Principal must be null
634 if (context.Principal != null)
635 {
638 //ex.Action = System.Security.Permissions.SecurityAction.Deny;
639 throw ex;
640 }
641 // Set .NET to use integrated security
642 AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
643 }
644 else
645 {
646 // We expect the some Principal object
647 if (context.Principal == null)
648 {
652 //ex.Action = System.Security.Permissions.SecurityAction.Deny;
653 throw ex;
654 }
655 ApplicationContext.User = context.Principal;
656 }
657 }
658
659 private void ClearContext(DataPortalContext context)
660 {
661 ApplicationContext.SetLogicalExecutionLocation(_oldLocation);
662 // if the dataportal is not remote then
663 // do nothing
664 if (!context.IsRemotePortal) return;
665 ApplicationContext.Clear();
666 if (ApplicationContext.AuthenticationType != "Windows")
667 ApplicationContext.User = null;
668 }
669
670#endregion
671
672#region Authorize
673
674 private static object _syncRoot = new object();
675 private static IAuthorizeDataPortal _authorizer = null;
676
681 {
682 get { return _authorizer; }
683 set { _authorizer = value; }
684 }
685
686 internal void Authorize(AuthorizeRequest clientRequest)
687 {
688 AuthorizeRequest(clientRequest);
689 }
690
691 private static void AuthorizeRequest(AuthorizeRequest clientRequest)
692 {
693 _authorizer.Authorize(clientRequest);
694 }
695
701 {
708 public void Authorize(AuthorizeRequest clientRequest)
709 { /* default is to allow all requests */ }
710 }
711
712#endregion
713
714 internal static DataPortalException NewDataPortalException(string message, Exception innerException, object businessObject)
715 {
716 if (!ApplicationContext.DataPortalReturnObjectOnException)
717 businessObject = null;
718
719 throw new DataPortalException(
720 message,
721 innerException, new DataPortalResult(businessObject));
722 }
723
730 public static object GetCriteriaFromArray(params object[] criteria)
731 {
732 var clength = 0;
733 if (criteria != null)
734 if (criteria.GetType().Equals(typeof(object[])))
735 clength = criteria.GetLength(0);
736 else
737 return criteria;
738
739 if (criteria == null || (clength == 1 && criteria[0] == null))
740 return NullCriteria.Instance;
741 else if (clength == 0)
742 return EmptyCriteria.Instance;
743 else if (clength == 1)
744 return criteria[0];
745 else
746 return new Core.MobileList<object>(criteria);
747 }
748
755 public static object[] GetCriteriaArray(object criteria)
756 {
757 if (criteria == null)
758 return null;
759 else if (criteria is EmptyCriteria)
760 return Array.Empty<object>();
761 else if (criteria is NullCriteria)
762 return new object[] { null };
763 else if (criteria.GetType().Equals(typeof(object[])))
764 {
765 var array = (object[])criteria;
766 var clength = array.GetLength(0);
767 if (clength == 1 && array[0] is EmptyCriteria)
768 return Array.Empty<object>();
769 else
770 return array;
771 }
772 else if (criteria is Core.MobileList<object> list)
773 return list.ToArray();
774 else
775 return new object[] { criteria };
776 }
777 }
778}
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 AuthenticationProviderDoesNotImplementIAuthorizeDataPortal
Looks up a localized string similar to Csla Authentication Provider specified does not implement IAut...
static string AuthorizationProviderNameNotSpecified
Looks up a localized string similar to Csla Authorization Provider App Setting name not specified.
static string BusinessPrincipalException
Looks up a localized string similar to Principal must be of type BusinessPrincipal,...
static string CslaAuthenticationProviderNotSet
Looks up a localized string similar to Csla Authentication Provider not set!.
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.
Default implementation of the authorizer that allows all data portal calls to pass.
void Authorize(AuthorizeRequest clientRequest)
Creates an instance of the type.
Allows the Data Portal call to be intercepted by a custom IDataPortalServer implementation.
Provides consistent context information between the client and server DataPortal objects.
TransactionalTypes TransactionalType
Gets the current transactional type.
This class provides a hoook for developers to add custom error handling in the DataPortal.
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.
DataPortal(string cslaAuthorizationProviderAppSettingName)
This construcor accepts the App Setting name for the Csla Authorization Provider, therefore getting t...
DataPortal()
Default constructor
async Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Get an existing business object.
static Type InterceptorType
Gets or sets the type of interceptor invoked by the data portal for pre- and post-processing of each ...
static object[] GetCriteriaArray(object criteria)
Converts a single serializable criteria value into an array of type object.
DataPortal(Type authProviderType)
This constructor accepts the Authorization Provider Type as a parameter.
static object GetCriteriaFromArray(params object[] criteria)
Converts a params array to a single serializable criteria value.
async Task< DataPortalResult > Update(object obj, DataPortalContext context, bool isSync)
Update a business object.
async Task< DataPortalResult > Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
Create a new business object.
async Task< DataPortalResult > Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
Delete a business object.
static IAuthorizeDataPortal Authorizer
Gets or sets a reference to the current authorizer.
static Dashboard.IDashboard Dashboard
Gets the data portal dashboard instance.
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
Server-side data portal implementation that invokes an object factory rather than directly interactin...
static IObjectFactoryLoader FactoryLoader
Gets or sets a delegate reference to the method called to create instances of factory objects as requ...
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...
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.
Specifies a method used by the server-side data portal to update domain object data during an update ...
Interface to be implemented by a custom authorization provider.
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.
Implement this interface to create a data portal interceptor that is notified each time the data port...
void Complete(InterceptArgs e)
Invoked at the end of each server-side data portal invocation for success and exception scenarios.
void Initialize(InterceptArgs e)
Invoked at the start of each server-side data portal invocation, immediately after the context has be...
Type GetFactoryType(string factoryName)
Returns the type of the factory object.
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.