10using System.Globalization;
11using System.Threading;
13using System.Threading.Tasks;
36 if (_factoryLoader ==
null)
38 string setting = ConfigurationManager.AppSettings[
"CslaMobileFactoryLoader"];
39 if (!
string.IsNullOrEmpty(setting))
45 return _factoryLoader;
49 _factoryLoader = value;
66 Type businessObjectType =
null;
67 object criteria =
null;
72 businessObjectType = Type.GetType(request.
TypeName);
73 if (businessObjectType ==
null)
74 throw new InvalidOperationException(
82 object newObject =
null;
83 var factoryInfo = GetMobileFactoryAttribute(businessObjectType);
84 if (factoryInfo ==
null)
93 if (
string.IsNullOrEmpty(factoryInfo.CreateMethodName))
98 newObject = await
Csla.
Reflection.
MethodCaller.CallMethodTryAsync(f, factoryInfo.CreateMethodName, criteria).ConfigureAwait(
false);
102 result.Object = newObject;
103#pragma warning disable CS0618
104 result.GlobalContext = ApplicationContext.GlobalContext;
105#pragma warning restore CS0618
110 result.Error = inspected.InnerException;
115 result.Error = inspected;
119 if (result.Error !=
null)
120 serverDataPortal.Complete(
new InterceptArgs { ObjectType = businessObjectType, Parameter = criteria, Operation =
DataPortalOperations.Create, Exception = result.Error, Result =
new DataPortalResult(result.Object, result.Error, result.GlobalContext) });
137 Type businessObjectType =
null;
138 object criteria =
null;
145 businessObjectType = Type.GetType(request.
TypeName);
146 if (businessObjectType ==
null)
147 throw new InvalidOperationException(
155 object newObject =
null;
156 var factoryInfo = GetMobileFactoryAttribute(businessObjectType);
157 if (factoryInfo ==
null)
159 if (criteria !=
null)
166 if (
string.IsNullOrEmpty(factoryInfo.FetchMethodName))
170 if (criteria !=
null)
171 newObject = await
Csla.
Reflection.
MethodCaller.CallMethodTryAsync(f, factoryInfo.FetchMethodName, criteria).ConfigureAwait(
false);
175 result.Object = newObject;
176#pragma warning disable CS0618
177 result.GlobalContext = ApplicationContext.GlobalContext;
178#pragma warning restore CS0618
183 result.Error = inspected.InnerException;
188 result.Error = inspected;
192 if (result.Error !=
null)
193 serverDataPortal.Complete(
new InterceptArgs { ObjectType = businessObjectType, Parameter = criteria, Operation =
DataPortalOperations.Fetch, Exception = result.Error, Result =
new DataPortalResult(result.Object, result.Error, result.GlobalContext) });
210 Type businessObjectType =
null;
222 businessObjectType = obj.GetType();
226 serverDataPortal.Initialize(
new InterceptArgs { ObjectType = businessObjectType, Parameter = obj, Operation = operation });
227 serverDataPortal.Authorize(
new AuthorizeRequest(businessObjectType, obj, operation));
229 object newObject =
null;
230 var factoryInfo = GetMobileFactoryAttribute(businessObjectType);
231 if (factoryInfo ==
null)
237 if (
string.IsNullOrEmpty(factoryInfo.UpdateMethodName))
241 newObject = await
Csla.
Reflection.
MethodCaller.CallMethodTryAsync(f, factoryInfo.UpdateMethodName, obj).ConfigureAwait(
false);
243 result.Object = newObject;
244#pragma warning disable CS0618
245 result.GlobalContext = ApplicationContext.GlobalContext;
246#pragma warning restore CS0618
251 result.Error = inspected.InnerException;
256 result.Error = inspected;
260 if (result.Error !=
null)
261 serverDataPortal.Complete(
new InterceptArgs { ObjectType = businessObjectType, Parameter = obj, Operation = operation, Exception = result.Error, Result =
new DataPortalResult(result.Object, result.Error, result.GlobalContext) });
263 serverDataPortal.Complete(
new InterceptArgs { ObjectType = businessObjectType, Parameter = obj, Operation = operation, Result =
new DataPortalResult(result.Object, result.GlobalContext) });
278 Type businessObjectType =
null;
279 object criteria =
null;
286 businessObjectType = Type.GetType(request.
TypeName);
287 if (businessObjectType ==
null)
288 throw new InvalidOperationException(
296 var factoryInfo = GetMobileFactoryAttribute(businessObjectType);
297 if (factoryInfo ==
null)
303 if (
string.IsNullOrEmpty(factoryInfo.DeleteMethodName))
309#pragma warning disable CS0618
310 result.GlobalContext = ApplicationContext.GlobalContext;
311#pragma warning restore CS0618
316 result.Error = inspected.InnerException;
321 result.Error = inspected;
325 if (result.Error !=
null)
326 serverDataPortal.Complete(
new InterceptArgs { ObjectType = businessObjectType, Parameter = criteria, Operation =
DataPortalOperations.Delete, Exception = result.Error, Result =
new DataPortalResult(result.Object, result.Error, result.GlobalContext) });
336#region Mobile Factory
341 if (result !=
null && result.Length > 0)
349#region Context and Criteria
350 private void SetContext(IMobileRequest request)
352 ApplicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
353 ApplicationContext.SetLogicalExecutionLocation(ApplicationContext.LogicalExecutionLocations.Server);
355 ApplicationContext.SetContext(request.ClientContext, request.GlobalContext);
356 if (ApplicationContext.AuthenticationType !=
"Windows")
357 ApplicationContext.User = request.Principal;
358 SetClientCultures(request);
366 ApplicationContext.Clear();
367 if (ApplicationContext.AuthenticationType !=
"Windows")
368 ApplicationContext.User =
new System.Security.Principal.GenericPrincipal(
new System.Security.Principal.GenericIdentity(
string.Empty),
new string[] { });
371#region client culture
378 CultureInfo culture =
null;
382 Thread.CurrentThread.CurrentCulture = culture;
387 Thread.CurrentThread.CurrentUICulture = culture;
398 private bool TryGetCulture(
string clientCulture, ref CultureInfo culture)
400 if (
string.IsNullOrWhiteSpace(clientCulture))
return false;
404 culture = CultureInfo.GetCultureInfo(clientCulture);
407 catch (CultureNotFoundException)
This is the client-side DataPortal.
A strongly-typed resource class, for looking up localized strings, etc.
static string CreateMethodNameNotSpecified
Looks up a localized string similar to Create method name not specified in MobileFactory attribute.
static string DeleteMethodNameNotSpecified
Looks up a localized string similar to Delete method name not specified in MobileFactory attribute.
static string ObjectTypeCouldNotBeLoaded
Looks up a localized string similar to Object type or assembly could not be loaded ({0}).
static string UpdateMethodNameNotSpecified
Looks up a localized string similar to Update method name not specified in MobileFactory attribute.
static string FetchMethodNameNotSpecified
Looks up a localized string similar to Fetch method name not specified in MobileFactory attribute.
This exception is returned from the CallMethod method in the server-side DataPortal and contains the ...
Object containing information about the client request to the data portal.
This class provides a hoook 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.
Implements the server-side DataPortal message router as discussed in Chapter 4.
Returns data from the server-side DataPortal to the client-side DataPortal.
Class that will be used to execute a request from a client.
string TypeName
Type of object that is the target of the request
object Criteria
Criteria object.
Class containing the default implementation for the FactoryLoader delegate used by the data portal ho...
Object that processes all the requests from a client
async Task< MobileResponse > Create(MobileCriteriaRequest request)
Create a new business object.
static IMobileFactoryLoader FactoryLoader
Gets or sets a delegate reference to the method called to create instances of factory objects as requ...
async Task< MobileResponse > Update(MobileUpdateRequest request)
Update a business object.
async Task< MobileResponse > Delete(MobileCriteriaRequest request)
Delete a business object.
static void ClearContext()
Clears the application context and current principal.
async Task< MobileResponse > Fetch(MobileCriteriaRequest request)
Get an existing business object.
Object that encompasses the resut of the request from a client
Class that will be used to execute an Update request from a client.
object ObjectToUpdate
Business object that will be updated.
Arguments parameter passed to the interceptor methods.
Specifies that the WCF data portal should invoke a factory object rather than the business object.
This interface is implemented by all Command objects.
Defines an interface to be implemented by a factory object that returns MobileFactory objects based o...
object GetFactory(string factoryName)
Returns a MobileFactory object.
Interface for all requests from client
string ClientCulture
The client culture.
string ClientUICulture
The client UI culture.
DataPortalOperations
List of data portal operations.