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.
BrokeredProxy.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="BrokeredProxy.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.Collections.Generic;
10using System.Linq;
11using System.Text;
12using System.Threading.Tasks;
13using Csla.Server;
17
19{
25 public class BrokeredProxy : Csla.DataPortalClient.IDataPortalProxy
26 {
32 public bool IsServerRemote
33 {
34 get { return true; }
35 }
36
45 public async Task<DataPortalResult> Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
46 {
47 DataPortalResult result = null;
48 if (isSync)
49 throw new NotSupportedException("isSync == true");
50 try
51 {
52 if (!(criteria is IMobileObject))
53 criteria = new PrimitiveCriteria(criteria);
54 var contextData = Csla.Serialization.Mobile.MobileFormatter.Serialize(context);
55 var criteriaData = Csla.Serialization.Mobile.MobileFormatter.Serialize(criteria);
56 var portal = new BrokeredHost();
57 var objectTypeName = objectType.AssemblyQualifiedName;
58 var resultData = await portal.Create(objectTypeName, criteriaData, contextData);
59 var response = (Csla.Server.Hosts.HttpChannel.HttpResponse)Csla.Serialization.Mobile.MobileFormatter.Deserialize(resultData.ToArray());
60 var globalContext = (Csla.Core.ContextDictionary)Csla.Serialization.Mobile.MobileFormatter.Deserialize(response.GlobalContext);
61 if (response != null && response.ErrorData == null)
62 {
63 var obj = MobileFormatter.Deserialize(response.ObjectData);
64 result = new DataPortalResult(obj, null, globalContext);
65 }
66 else if (response != null && response.ErrorData != null)
67 {
68 var ex = new DataPortalException(response.ErrorData);
69 result = new DataPortalResult(null, ex, globalContext);
70 }
71 else
72 {
73 throw new DataPortalException("null response", null);
74 }
75 }
76 catch (Exception ex)
77 {
78 result = new DataPortalResult(null, ex, null);
79 }
80 if (result.Error != null)
81 throw result.Error;
82 return result;
83 }
84
93 public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
94 {
95 DataPortalResult result = null;
96 if (isSync)
97 throw new NotSupportedException("isSync == true");
98 try
99 {
100 if (!(criteria is IMobileObject))
101 criteria = new PrimitiveCriteria(criteria);
102 var contextData = Csla.Serialization.Mobile.MobileFormatter.Serialize(context);
103 var criteriaData = Csla.Serialization.Mobile.MobileFormatter.Serialize(criteria);
104 var portal = new BrokeredHost();
105 var objectTypeName = objectType.AssemblyQualifiedName;
106 var resultData = await portal.Fetch(objectTypeName, criteriaData, contextData);
107 var response = (Csla.Server.Hosts.HttpChannel.HttpResponse)Csla.Serialization.Mobile.MobileFormatter.Deserialize(resultData.ToArray());
108 var globalContext = (Csla.Core.ContextDictionary)Csla.Serialization.Mobile.MobileFormatter.Deserialize(response.GlobalContext);
109 if (response != null && response.ErrorData == null)
110 {
111 var obj = MobileFormatter.Deserialize(response.ObjectData);
112 result = new DataPortalResult(obj, null, globalContext);
113 }
114 else if (response != null && response.ErrorData != null)
115 {
116 var ex = new DataPortalException(response.ErrorData);
117 result = new DataPortalResult(null, ex, globalContext);
118 }
119 else
120 {
121 throw new DataPortalException("null response", null);
122 }
123 }
124 catch (Exception ex)
125 {
126 result = new DataPortalResult(null, ex, null);
127 }
128 if (result.Error != null)
129 throw result.Error;
130 return result;
131 }
132
140 public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
141 {
142 DataPortalResult result = null;
143 if (isSync)
144 throw new NotSupportedException("isSync == true");
145 try
146 {
147 var contextData = Csla.Serialization.Mobile.MobileFormatter.Serialize(context);
148 var objectData = Csla.Serialization.Mobile.MobileFormatter.Serialize(obj);
149 var portal = new BrokeredHost();
150 var resultData = await portal.Update(objectData, contextData);
151 var response = (Csla.Server.Hosts.HttpChannel.HttpResponse)Csla.Serialization.Mobile.MobileFormatter.Deserialize(resultData.ToArray());
152 var globalContext = (Csla.Core.ContextDictionary)Csla.Serialization.Mobile.MobileFormatter.Deserialize(response.GlobalContext);
153 if (response != null && response.ErrorData == null)
154 {
155 obj = MobileFormatter.Deserialize(response.ObjectData);
156 result = new DataPortalResult(obj, null, globalContext);
157 }
158 else if (response != null && response.ErrorData != null)
159 {
160 var ex = new DataPortalException(response.ErrorData);
161 result = new DataPortalResult(null, ex, globalContext);
162 }
163 else
164 {
165 throw new DataPortalException("null response", null);
166 }
167 }
168 catch (Exception ex)
169 {
170 result = new DataPortalResult(null, ex, null);
171 }
172 if (result.Error != null)
173 throw result.Error;
174 return result;
175 }
176
185 public async Task<DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
186 {
187 DataPortalResult result = null;
188 if (isSync)
189 throw new NotSupportedException("isSync == true");
190 try
191 {
192 if (!(criteria is IMobileObject))
193 criteria = new PrimitiveCriteria(criteria);
194 var contextData = Csla.Serialization.Mobile.MobileFormatter.Serialize(context);
195 var criteriaData = Csla.Serialization.Mobile.MobileFormatter.Serialize(criteria);
196 var portal = new BrokeredHost();
197 var objectTypeName = objectType.AssemblyQualifiedName;
198 var resultData = await portal.Delete(objectTypeName, criteriaData, contextData);
199 var response = (Csla.Server.Hosts.HttpChannel.HttpResponse)Csla.Serialization.Mobile.MobileFormatter.Deserialize(resultData.ToArray());
200 var globalContext = (Csla.Core.ContextDictionary)Csla.Serialization.Mobile.MobileFormatter.Deserialize(response.GlobalContext);
201 if (response != null && response.ErrorData == null)
202 {
203 var obj = MobileFormatter.Deserialize(response.ObjectData);
204 result = new DataPortalResult(obj, null, globalContext);
205 }
206 else if (response != null && response.ErrorData != null)
207 {
208 var ex = new DataPortalException(response.ErrorData);
209 result = new DataPortalResult(null, ex, globalContext);
210 }
211 else
212 {
213 throw new DataPortalException("null response", null);
214 }
215 }
216 catch (Exception ex)
217 {
218 result = new DataPortalResult(null, ex, null);
219 }
220 if (result.Error != null)
221 throw result.Error;
222 return result;
223 }
224 }
225}
Brokered assembly entry point for the data portal.
Definition: BrokeredHost.cs:23
Dictionary type that is serializable with the SerializationFormatterFactory.GetFormatter().
Implements a data portal proxy to relay data portal calls to an application server hosted locally in ...
async Task< DataPortalResult > Update(object obj, DataPortalContext context, bool isSync)
Called by the client-side DataPortal to update a business object.
async Task< DataPortalResult > Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
Called by the client-side DataPortal to delete a business object.
async Task< DataPortalResult > Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
Called by the client-side DataPortal to create a new business object.
async Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Called by the client-side DataPortal to fetch a business object.
bool IsServerRemote
Get a value indicating whether this proxy will invoke a remote data portal server,...
Class used as a wrapper for criteria based requests that use primitives
This exception is returned for any errors occurring during the server-side DataPortal invocation.
DataPortalResult defines the results of DataPortal operation.
Exception Error
Error that occurred during the DataPotal call.
Serializes and deserializes objects at the field level.
object Deserialize(Stream serializationStream)
Deserialize an object from XML.
void Serialize(Stream serializationStream, object graph)
Serialize an object graph into XML.
Provides consistent context information between the client and server DataPortal objects.
Interface implemented by client-side data portal proxy objects.
Interface to be implemented by any object that supports serialization by the SerializationFormatterFa...