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.
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;
9using Csla.Properties;
10using System.Threading.Tasks;
11
12namespace Csla.Server
13{
19 {
26 public DataPortalSelector(ApplicationContext applicationContext, SimpleDataPortal simpleDataPortal, FactoryDataPortal factoryDataPortal)
27 {
28 ApplicationContext = applicationContext;
29 SimpleDataPortal = simpleDataPortal;
30 FactoryDataPortal = factoryDataPortal;
31 }
32
33 private ApplicationContext ApplicationContext { get; set; }
34 private SimpleDataPortal SimpleDataPortal { get; set; }
35 private FactoryDataPortal FactoryDataPortal { get; set; }
36
46 public async Task<DataPortalResult> Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
47 {
48 try
49 {
50 context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
51 if (context.FactoryInfo == null)
52 {
53 return await SimpleDataPortal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
54 }
55 else
56 {
57 return await FactoryDataPortal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
58 }
59 }
61 {
62 throw;
63 }
64 catch (Exception ex)
65 {
66 throw DataPortal.NewDataPortalException(
67 ApplicationContext, "DataPortal.Create " + Resources.FailedOnServer,
68 ex, null);
69 }
70 }
71
81 public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
82 {
83 try
84 {
85 context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
86 if (context.FactoryInfo == null)
87 {
88 return await SimpleDataPortal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
89 }
90 else
91 {
92 return await FactoryDataPortal.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false);
93 }
94 }
96 {
97 throw;
98 }
99 catch (Exception ex)
100 {
101 throw DataPortal.NewDataPortalException(
102 ApplicationContext, "DataPortal.Fetch " + Resources.FailedOnServer,
103 ex, null);
104 }
105 }
106
115 public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
116 {
117 try
118 {
119 context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(obj.GetType());
120 if (context.FactoryInfo == null)
121 {
122 return await SimpleDataPortal.Update(obj, context, isSync).ConfigureAwait(false);
123 }
124 else
125 {
126 return await FactoryDataPortal.Update(obj, context, isSync).ConfigureAwait(false);
127 }
128 }
129 catch (DataPortalException)
130 {
131 throw;
132 }
133 catch (Exception ex)
134 {
135 throw DataPortal.NewDataPortalException(
136 ApplicationContext, "DataPortal.Update " + Resources.FailedOnServer,
137 ex, obj);
138 }
139 }
140
150 public async Task<DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
151 {
152 try
153 {
154 context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
155 if (context.FactoryInfo == null)
156 {
157 return await SimpleDataPortal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
158 }
159 else
160 {
161 return await FactoryDataPortal.Delete(objectType, criteria, context, isSync).ConfigureAwait(false);
162 }
163 }
164 catch (DataPortalException)
165 {
166 throw;
167 }
168 catch (Exception ex)
169 {
170 throw DataPortal.NewDataPortalException(
171 ApplicationContext, "DataPortal.Delete " + Resources.FailedOnServer,
172 ex, null);
173 }
174 }
175 }
176}
Provides consistent context information between the client and server DataPortal objects.
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.
Definition: DataPortal.cs:24
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.
DataPortalSelector(ApplicationContext applicationContext, SimpleDataPortal simpleDataPortal, FactoryDataPortal factoryDataPortal)
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...
async Task< DataPortalResult > Update(object obj, DataPortalContext context, bool isSync)
Update a business object.
async Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Get an existing business object.
async Task< DataPortalResult > Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
Delete a business object.
async Task< DataPortalResult > Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
Create a new business object.
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.
async Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Get an existing business object.
async Task< DataPortalResult > Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
Create a new business object.
async Task< DataPortalResult > Update(object obj, DataPortalContext context, bool isSync)
Update a business object.
async Task< DataPortalResult > Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
Delete a business object.
Interface implemented by server-side data portal components.