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.
DataPortalSelector.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="DataPortalSelector.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Selects the appropriate data portal implementation</summary>
7//-----------------------------------------------------------------------
8using System;
10using System.Collections.Generic;
11using System.Linq;
12using System.Text;
13using Csla.Properties;
14using System.Threading.Tasks;
15
16namespace Csla.Server
17{
23 {
33 public async Task<DataPortalResult> Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
34 {
35 try
36 {
37 context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
38 if (context.FactoryInfo == null)
39 {
40 var dp = new SimpleDataPortal();
41 return await dp.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
42 }
43 else
44 {
45 var dp = new FactoryDataPortal();
46 return await dp.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
47 }
48 }
50 {
51 throw;
52 }
53 catch (Exception ex)
54 {
55 throw DataPortal.NewDataPortalException(
56 "DataPortal.Create " + Resources.FailedOnServer,
57 ex, null);
58 }
59 }
60
70 public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
71 {
72 try
73 {
74 context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
75 if (context.FactoryInfo == null)
76 {
77 var dp = new SimpleDataPortal();
78 return await dp.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
79 }
80 else
81 {
82 var dp = new FactoryDataPortal();
83 return await dp.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
84 }
85 }
87 {
88 throw;
89 }
90 catch (Exception ex)
91 {
92 throw DataPortal.NewDataPortalException(
93 "DataPortal.Fetch " + Resources.FailedOnServer,
94 ex, null);
95 }
96 }
97
106 public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
107 {
108 try
109 {
110 context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(obj.GetType());
111 if (context.FactoryInfo == null)
112 {
113 var dp = new SimpleDataPortal();
114 return await dp.Update(obj, context, isSync).ConfigureAwait(false);
115 }
116 else
117 {
118 var dp = new FactoryDataPortal();
119 return await dp.Update(obj, context, isSync).ConfigureAwait(false);
120 }
121 }
122 catch (DataPortalException)
123 {
124 throw;
125 }
126 catch (Exception ex)
127 {
128 throw DataPortal.NewDataPortalException(
129 "DataPortal.Update " + Resources.FailedOnServer,
130 ex, obj);
131 }
132 }
133
143 public async Task<DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
144 {
145 try
146 {
147 context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
148 if (context.FactoryInfo == null)
149 {
150 var dp = new SimpleDataPortal();
151 return await dp.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
152 }
153 else
154 {
155 var dp = new FactoryDataPortal();
156 return await dp.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
157 }
158 }
159 catch (DataPortalException)
160 {
161 throw;
162 }
163 catch (Exception ex)
164 {
165 throw DataPortal.NewDataPortalException(
166 "DataPortal.Delete " + Resources.FailedOnServer,
167 ex, null);
168 }
169 }
170 }
171}
A strongly-typed resource class, for looking up localized strings, etc.
static string FailedOnServer
Looks up a localized string similar to failed on the server.
Provides consistent context information between the client and server DataPortal objects.
ObjectFactoryAttribute FactoryInfo
Gets the current ObjectFactory attribute value (if any).
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.
Selects the appropriate data portal implementation to invoke based on the object and configuration.
async Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Get an existing business object.
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.
Server-side data portal implementation that invokes an object factory rather than directly interactin...
Specifies that the data portal should invoke a factory object rather than the business object.
Implements the server-side DataPortal as discussed in Chapter 4.
Interface implemented by server-side data portal components.