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.
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>This is the client-side DataPortal.</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.ComponentModel;
10using Csla.Reflection;
11using Csla.Properties;
12using Csla.Server;
14using System.Threading.Tasks;
15
16namespace Csla
17{
21 public static class DataPortal
22 {
28 public static event Action<System.Object> DataPortalInitInvoke;
29
34 public static event Action<DataPortalEventArgs> DataPortalInvoke;
35
40 public static event Action<DataPortalEventArgs> DataPortalInvokeComplete;
41
42 internal static void OnDataPortalInitInvoke(object e)
43 {
44 DataPortalInitInvoke?.Invoke(e);
45 }
46
47 internal static void OnDataPortalInvoke(DataPortalEventArgs e)
48 {
49 DataPortalInvoke?.Invoke(e);
50 }
51
52 internal static void OnDataPortalInvokeComplete(DataPortalEventArgs e)
53 {
54 DataPortalInvokeComplete?.Invoke(e);
55 }
56
65 public static T Create<T>(params object[] criteria)
66 {
67 var dp = new DataPortal<T>();
68 return dp.Create(criteria);
69 }
70
78 public static T Create<T>()
79 {
81 }
82
91 public static object Create(Type objectType, object criteria)
92 {
93 return DataPortal<object>.Create(objectType, criteria);
94 }
95
108 [Obsolete]
109 public static void BeginCreate<T>(EventHandler<DataPortalResult<T>> callback)
110 where T : IMobileObject
111 {
112 BeginCreate<T>(EmptyCriteria.Instance, callback, null);
113 }
114
128 [Obsolete]
129 public static void BeginCreate<T>(EventHandler<DataPortalResult<T>> callback, object userState)
130 where T : IMobileObject
131 {
132 BeginCreate<T>(EmptyCriteria.Instance, callback, userState);
133 }
134
150 [Obsolete]
151 public static void BeginCreate<T>(object criteria, EventHandler<DataPortalResult<T>> callback)
152 where T : IMobileObject
153 {
154 BeginCreate<T>(criteria, callback, null);
155 }
156
173 [Obsolete]
174 public static void BeginCreate<T>(object criteria, EventHandler<DataPortalResult<T>> callback, object userState)
175 where T : IMobileObject
176 {
177 DataPortal<T> dp = new DataPortal<T>();
178 dp.CreateCompleted += callback;
179 dp.BeginCreate(criteria, userState);
180 }
181
189 public static async Task<T> CreateAsync<T>()
190 {
191 DataPortal<T> dp = new DataPortal<T>();
192 return await dp.CreateAsync();
193 }
194
205 public static async Task<T> CreateAsync<T>(params object[] criteria)
206 {
207 DataPortal<T> dp = new DataPortal<T>();
208 return await dp.CreateAsync(criteria);
209 }
210
218 public static T Fetch<T>(params object[] criteria)
219 {
220 var dp = new DataPortal<T>();
221 return dp.Fetch(criteria);
222 }
223
230 public static T Fetch<T>()
231 {
233 }
234
235 internal static object Fetch(Type objectType, object criteria)
236 {
237 return DataPortal<object>.Fetch(objectType, criteria);
238 }
239
252 [Obsolete]
253 public static void BeginFetch<T>(EventHandler<DataPortalResult<T>> callback)
254 where T : IMobileObject
255 {
256 BeginFetch<T>(EmptyCriteria.Instance, callback, null);
257 }
258
272 [Obsolete]
273 public static void BeginFetch<T>(EventHandler<DataPortalResult<T>> callback, object userState)
274 where T : IMobileObject
275 {
276 BeginFetch<T>(EmptyCriteria.Instance, callback, userState);
277 }
278
294 [Obsolete]
295 public static void BeginFetch<T>(object criteria, EventHandler<DataPortalResult<T>> callback)
296 where T : IMobileObject
297 {
298 BeginFetch<T>(criteria, callback, null);
299 }
300
317 [Obsolete]
318 public static void BeginFetch<T>(object criteria, EventHandler<DataPortalResult<T>> callback, object userState)
319 where T : IMobileObject
320 {
321 var dp = new DataPortal<T>();
322 dp.FetchCompleted += callback;
323 dp.BeginFetch(criteria, userState);
324 }
325
333 public static async Task<T> FetchAsync<T>()
334 where T : IMobileObject
335 {
336 var dp = new DataPortal<T>();
337 return await dp.FetchAsync();
338 }
339
350 public static async Task<T> FetchAsync<T>(params object[] criteria)
351 where T : IMobileObject
352 {
353 var dp = new DataPortal<T>();
354 return await dp.FetchAsync(criteria);
355 }
356
370 public static T Update<T>(T obj)
371 {
372 var dp = new DataPortal<T>();
373 return dp.Update(obj);
374 }
375
391 [Obsolete]
392 public static void BeginUpdate<T>(T obj, EventHandler<DataPortalResult<T>> callback)
393 where T : IMobileObject
394 {
395 BeginUpdate<T>(obj, callback, null);
396 }
397
414 [Obsolete]
415 public static void BeginUpdate<T>(T obj, EventHandler<DataPortalResult<T>> callback, object userState)
416 where T : IMobileObject
417 {
418 DataPortal<T> dp = new DataPortal<T>();
419 dp.UpdateCompleted += callback;
420 dp.BeginUpdate(obj, userState);
421 }
422
433 public static async Task<T> UpdateAsync<T>(T obj)
434 where T : IMobileObject
435 {
436 DataPortal<T> dp = new DataPortal<T>();
437 return await dp.UpdateAsync(obj);
438 }
439
445 public static void Delete<T>(params object[] criteria)
446 {
447 var dp = new DataPortal<T>();
448 dp.Delete(criteria);
449 }
450
451 internal static void Delete(Type objectType, object criteria)
452 {
453 DataPortal<object>.Delete(objectType, criteria);
454 }
455
471 [Obsolete]
472 public static void BeginDelete<T>(object criteria, EventHandler<DataPortalResult<T>> callback)
473 where T : IMobileObject
474 {
475 BeginDelete<T>(criteria, callback, null);
476 }
477
494 [Obsolete]
495 public static void BeginDelete<T>(object criteria, EventHandler<DataPortalResult<T>> callback, object userState)
496 where T : IMobileObject
497 {
498 var dp = new DataPortal<T>();
499 dp.DeleteCompleted += callback;
500 dp.BeginDelete(criteria, userState);
501 }
502
513 public static async Task DeleteAsync<T>(params object[] criteria)
514 where T : IMobileObject
515 {
516 var dp = new DataPortal<T>();
517 await dp.DeleteAsync(criteria);
518 }
519
541 public static T Execute<T>(T obj)
542 {
543 return Update(obj);
544 }
545
561 [Obsolete]
562 public static void BeginExecute<T>(T obj, EventHandler<DataPortalResult<T>> callback)
563 where T : IMobileObject
564 {
565 BeginExecute<T>(obj, callback, null);
566 }
567
584 [Obsolete]
585 public static void BeginExecute<T>(T obj, EventHandler<DataPortalResult<T>> callback, object userState)
586 where T : IMobileObject
587 {
588 var dp = new DataPortal<T>();
589 dp.ExecuteCompleted += callback;
590 dp.BeginExecute(obj, userState);
591 }
592
603 public static async Task<T> ExecuteAsync<T>(T command)
604 where T : IMobileObject
605 {
606 var dp = new DataPortal<T>();
607 return await dp.ExecuteAsync(command);
608 }
609
617 public static T CreateChild<T>()
618 {
619 Server.ChildDataPortal portal = new Server.ChildDataPortal();
620 return (T)(portal.Create(typeof(T)));
621 }
622
633 public static T CreateChild<T>(params object[] parameters)
634 {
635 Server.ChildDataPortal portal = new Server.ChildDataPortal();
636 return (T)(portal.Create(typeof(T), parameters));
637 }
638
646 public static async Task<T> CreateChildAsync<T>()
647 {
648 Server.ChildDataPortal portal = new Server.ChildDataPortal();
649 return await portal.CreateAsync<T>();
650 }
651
662 public static async Task<T> CreateChildAsync<T>(params object[] parameters)
663 {
664 Server.ChildDataPortal portal = new Server.ChildDataPortal();
665 return await portal.CreateAsync<T>(parameters);
666 }
667
675 public static T FetchChild<T>()
676 {
677 Server.ChildDataPortal portal = new Server.ChildDataPortal();
678 return (T)(portal.Fetch(typeof(T)));
679 }
680
691 public static T FetchChild<T>(params object[] parameters)
692 {
693 Server.ChildDataPortal portal = new Server.ChildDataPortal();
694 return (T)(portal.Fetch(typeof(T), parameters));
695 }
696
704 public static async Task<T> FetchChildAsync<T>()
705 {
706 Server.ChildDataPortal portal = new Server.ChildDataPortal();
707 return await portal.FetchAsync<T>();
708 }
709
720 public static async Task<T> FetchChildAsync<T>(params object[] parameters)
721 {
722 Server.ChildDataPortal portal = new Server.ChildDataPortal();
723 return await portal.FetchAsync<T>(parameters);
724 }
725
733 public static void UpdateChild(object child)
734 {
735 Server.ChildDataPortal portal = new Server.ChildDataPortal();
736 portal.Update(child);
737 }
738
749 public static void UpdateChild(object child, params object[] parameters)
750 {
751 Server.ChildDataPortal portal = new Server.ChildDataPortal();
752 portal.Update(child, parameters);
753 }
754
762 public static async Task UpdateChildAsync(object child)
763 {
764 Server.ChildDataPortal portal = new Server.ChildDataPortal();
765 await portal.UpdateAsync(child).ConfigureAwait(false);
766 }
767
778 public static async Task UpdateChildAsync(object child, params object[] parameters)
779 {
780 Server.ChildDataPortal portal = new Server.ChildDataPortal();
781 await portal.UpdateAsync(child, parameters).ConfigureAwait(false);
782 }
783
784 private static DataPortalClient.IDataPortalProxyFactory _dataProxyFactory;
785
789 internal static void LoadDataPortalProxyFactory()
790 {
791 if (_dataProxyFactory == null)
792 {
793 if (String.IsNullOrEmpty(ApplicationContext.DataPortalProxyFactory) || ApplicationContext.DataPortalProxyFactory == "Default")
794 {
795 _dataProxyFactory = new DataPortalClient.DataPortalProxyFactory();
796 }
797 else
798 {
799 var proxyFactoryType =
800 Type.GetType(ApplicationContext.DataPortalProxyFactory) ??
801 throw new InvalidOperationException(
802 string.Format(Resources.UnableToLoadDataPortalProxyFactory, ApplicationContext.DataPortalProxyFactory));
803
804 _dataProxyFactory = (DataPortalClient.IDataPortalProxyFactory)MethodCaller.CreateInstance(proxyFactoryType);
805 }
806 }
807 }
808
814 public static DataPortalClient.IDataPortalProxyFactory ProxyFactory
815 {
816 get
817 {
818 if (_dataProxyFactory == null)
819 LoadDataPortalProxyFactory();
820 return _dataProxyFactory;
821 }
822 set
823 {
824 _dataProxyFactory = value;
825 }
826 }
827
838 public static string ProxyTypeName
839 {
840 get { return ApplicationContext.DataPortalProxy; }
841 set { ApplicationContext.DataPortalProxy = value; }
842 }
843
849 public static void ResetProxyFactory()
850 {
851 _dataProxyFactory = null;
852 }
853
859 public static void ResetProxyType()
860 {
861 if (_dataProxyFactory != null)
862 {
863 _dataProxyFactory.ResetProxyType();
864 }
865 }
866
872 [EditorBrowsable(EditorBrowsableState.Never)]
873 [Obsolete("Proxies no longer cached")]
874 public static void ReleaseProxy()
875 { }
876 }
877}
Provides information about the DataPortal call.
This is the client-side DataPortal.
Definition: DataPortalT.cs:24
static T Update< T >(T obj)
Called by the business object's Save() method to insert, update or delete an object in the database.
Definition: DataPortal.cs:370
static T Create< T >()
Called by a factory method in a business class to create a new object, which is loaded with default v...
Definition: DataPortal.cs:78
static async Task< T > FetchChildAsync< T >()
Fetchs and initializes a new child business object.
Definition: DataPortal.cs:704
static void BeginExecute< T >(T obj, EventHandler< DataPortalResult< T > > callback)
Starts an asynchronous data portal operation to execute a command object.
Definition: DataPortal.cs:562
async Task< T > CreateAsync(params object[] criteria)
Called by a factory method in a business class or by the UI to create a new object,...
Definition: DataPortalT.cs:168
static void ResetProxyFactory()
Resets the data portal proxy type, so the next data portal call will reload the proxy type based on c...
Definition: DataPortal.cs:849
static async Task< T > CreateAsync< T >()
Starts an asynchronous data portal operation to create a business object.
Definition: DataPortal.cs:189
static void ResetProxyType()
Resets the data portal proxy type, so the next data portal call will reload the proxy type based on c...
Definition: DataPortal.cs:859
static string ProxyTypeName
Gets or sets the assembly qualified type name of the proxy object to be loaded by the data portal.
Definition: DataPortal.cs:839
T Update(T obj)
Called by a factory method in a business class or by the UI to update an object.
Definition: DataPortalT.cs:715
static T CreateChild< T >()
Creates and initializes a new child business object.
Definition: DataPortal.cs:617
static void UpdateChild(object child)
Inserts, updates or deletes an existing child business object.
Definition: DataPortal.cs:733
static void BeginFetch< T >(EventHandler< DataPortalResult< T > > callback)
Starts an asynchronous data portal operation to fetch a business object.
Definition: DataPortal.cs:253
void BeginUpdate(T obj)
Called by a factory method in a business class or by the UI to update an object.
Definition: DataPortalT.cs:736
static async Task UpdateChildAsync(object child, params object[] parameters)
Inserts, updates or deletes an existing child business object.
Definition: DataPortal.cs:778
static void BeginDelete< T >(object criteria, EventHandler< DataPortalResult< T > > callback)
Starts an asynchronous data portal operation to delete a business object.
Definition: DataPortal.cs:472
static void BeginCreate< T >(EventHandler< DataPortalResult< T > > callback)
Starts an asynchronous data portal operation to create a business object.
Definition: DataPortal.cs:109
static Action< DataPortalEventArgs > DataPortalInvoke
Raised by DataPortal prior to calling the requested server-side DataPortal method.
Definition: DataPortal.cs:34
static async Task< T > CreateChildAsync< T >()
Creates and initializes a new child business object.
Definition: DataPortal.cs:646
EventHandler< DataPortalResult< T > > UpdateCompleted
Event raised when the operation has completed.
Definition: DataPortalT.cs:681
static async Task< T > ExecuteAsync< T >(T command)
Starts an asynchronous data portal operation to execute a command object.
Definition: DataPortal.cs:603
static void BeginUpdate< T >(T obj, EventHandler< DataPortalResult< T > > callback)
Starts an asynchronous data portal operation to update a business object.
Definition: DataPortal.cs:392
static async Task UpdateChildAsync(object child)
Inserts, updates or deletes an existing child business object.
Definition: DataPortal.cs:762
static void ReleaseProxy()
Releases any remote data portal proxy object, so the next data portal call will create a new proxy in...
Definition: DataPortal.cs:874
static async Task< T > UpdateAsync< T >(T obj)
Starts an asynchronous data portal operation to update a business object.
Definition: DataPortal.cs:433
async Task< T > UpdateAsync(T obj)
Called by a factory method in a business class or by the UI to update an object.
Definition: DataPortalT.cs:773
static T Execute< T >(T obj)
Called to execute a Command object on the server.
Definition: DataPortal.cs:541
void BeginCreate()
Called by a factory method in a business class or by the UI to create a new object,...
Definition: DataPortalT.cs:227
EventHandler< DataPortalResult< T > > CreateCompleted
Event raised when the operation has completed.
Definition: DataPortalT.cs:192
static object Create(Type objectType, object criteria)
Called by a factory method in a business class to create a new object, which is loaded with default v...
Definition: DataPortal.cs:91
static async Task< T > FetchAsync< T >()
Starts an asynchronous data portal operation to fetch a business object.
Definition: DataPortal.cs:333
static async Task DeleteAsync< T >(params object[] criteria)
Starts an asynchronous data portal operation to delete a business object.
Definition: DataPortal.cs:513
static void UpdateChild(object child, params object[] parameters)
Inserts, updates or deletes an existing child business object.
Definition: DataPortal.cs:749
static Action< System.Object > DataPortalInitInvoke
Raised by DataPortal before it starts setting up to call a server-side DataPortal method.
Definition: DataPortal.cs:28
static Action< DataPortalEventArgs > DataPortalInvokeComplete
Raised by DataPortal after the requested server-side DataPortal method call is complete.
Definition: DataPortal.cs:40
static DataPortalClient.IDataPortalProxyFactory ProxyFactory
Gets or sets a reference to a ProxyFactory object that is used to create an instance of the data port...
Definition: DataPortal.cs:815
static T FetchChild< T >()
Creates and loads an existing child business object.
Definition: DataPortal.cs:675
static T Fetch< T >()
Called by a factory method in a business class to retrieve an object, which is loaded with values fro...
Definition: DataPortal.cs:230
static void Delete< T >(params object[] criteria)
Called by a Shared (static in C#) method in the business class to cause immediate deletion of a speci...
Definition: DataPortal.cs:445
DataPortalResult defines the results of DataPortal operation.
A strongly-typed resource class, for looking up localized strings, etc.
static string UnableToLoadDataPortalProxyFactory
Looks up a localized string similar to Unable to load DataPortalProxyFactory {0}.
Implements the server-side DataPortal message router as discussed in Chapter 4.
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
Interface to be implemented by any object that supports serialization by the SerializationFormatterFa...