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.
LocalProxy.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="LocalProxy.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Implements a data portal proxy to relay data portal</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Threading;
10using System.Threading.Tasks;
12using Csla.Server;
13using Csla.Threading;
14
16{
22 public class LocalProxy : DataPortalClient.IDataPortalProxy
23 {
24 private Server.IDataPortalServer _portal = new Server.DataPortal();
25
36 public async Task<DataPortalResult> Create(
37 Type objectType, object criteria, DataPortalContext context, bool isSync)
38 {
39 if (isSync || Csla.ApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Server)
40 {
41 return await _portal.Create(objectType, criteria, context, isSync);
42 }
43 else
44 {
45 if (!FlowSynchronizationContext || SynchronizationContext.Current == null)
46 return await Task.Run(() => this._portal.Create(objectType, criteria, context, isSync));
47 else
48 return await await Task.Factory.StartNew(() => this._portal.Create(objectType, criteria, context, isSync),
49 CancellationToken.None,
50 TaskCreationOptions.None,
51 TaskScheduler.FromCurrentSynchronizationContext());
52 }
53 }
54
65 public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
66 {
67 if (isSync || Csla.ApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Server)
68 {
69 return await _portal.Fetch(objectType, criteria, context, isSync);
70 }
71 else
72 {
73 if (!FlowSynchronizationContext || SynchronizationContext.Current == null)
74 return await Task.Run(() => this._portal.Fetch(objectType, criteria, context, isSync));
75 else
76 return await await Task.Factory.StartNew(() => this._portal.Fetch(objectType, criteria, context, isSync),
77 CancellationToken.None,
78 TaskCreationOptions.None,
79 TaskScheduler.FromCurrentSynchronizationContext());
80 }
81 }
82
92 public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
93 {
94 if (isSync || Csla.ApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Server)
95 {
96 return await _portal.Update(obj, context, isSync);
97 }
98 else
99 {
100 if (!FlowSynchronizationContext || SynchronizationContext.Current == null)
101 return await Task.Run(() => this._portal.Update(obj, context, isSync));
102 else
103 return await await Task.Factory.StartNew(() => this._portal.Update(obj, context, isSync),
104 CancellationToken.None,
105 TaskCreationOptions.None,
106 TaskScheduler.FromCurrentSynchronizationContext());
107 }
108 }
109
120 public async Task<DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
121 {
122 if (isSync || Csla.ApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Server)
123 {
124 return await _portal.Delete(objectType, criteria, context, isSync);
125 }
126 else
127 {
128 if (!FlowSynchronizationContext || SynchronizationContext.Current == null)
129 return await Task.Run(() => this._portal.Delete(objectType, criteria, context, isSync));
130 else
131 return await await Task.Factory.StartNew(() => this._portal.Delete(objectType, criteria, context, isSync),
132 CancellationToken.None,
133 TaskCreationOptions.None,
134 TaskScheduler.FromCurrentSynchronizationContext());
135 }
136 }
137
143 public bool IsServerRemote
144 {
145 get { return false; }
146 }
147
155 {
156 get
157 {
158 if (ConfigurationManager.AppSettings["CslaFlowSynchronizationContext"] == null)
159 return false;
160 else
161 return bool.Parse(ConfigurationManager.AppSettings["CslaFlowSynchronizationContext"]);
162 }
163 }
164 }
165}
Implements a data portal proxy to relay data portal calls to an application server hosted locally in ...
Definition: LocalProxy.cs:23
bool FlowSynchronizationContext
Gets a value indicating whether any synchronization context should be flowed to child tasks.
Definition: LocalProxy.cs:155
bool IsServerRemote
Gets a value indicating whether this proxy will invoke a remote data portal server,...
Definition: LocalProxy.cs:144
async Task< DataPortalResult > Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
Called by DataPortal to create a new business object.
Definition: LocalProxy.cs:36
async Task< DataPortalResult > Update(object obj, DataPortalContext context, bool isSync)
Called by DataPortal to update a business object.
Definition: LocalProxy.cs:92
async Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Called by DataPortal to load an existing business object.
Definition: LocalProxy.cs:65
async Task< DataPortalResult > Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
Called by DataPortal to delete a business object.
Definition: LocalProxy.cs:120
Provides consistent context information between the client and server DataPortal objects.
Interface implemented by client-side data portal proxy objects.
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.