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.
BrokeredPortal.cs
Go to the documentation of this file.
1using Csla.Server;
2using System;
3using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
9{
14 public class BrokeredPortal
15 {
24 public async Task<byte[]> Create(string objectTypeName, byte[] criteriaData, byte[] contextData)
25 {
26 DataPortalResult result;
27 try
28 {
29 var objectType = Csla.Reflection.MethodCaller.GetType(objectTypeName);
30 var criteria = Csla.Serialization.Mobile.MobileFormatter.Deserialize(criteriaData);
32 var portal = new Csla.Server.DataPortal();
33 result = await portal.Create(objectType, criteria, context, false);
34 }
35 catch (Exception ex)
36 {
37 result = new DataPortalResult(null, ex, null);
38 }
39 var response = GetDataPortalResult(result);
40 var resultData = Csla.Serialization.Mobile.MobileFormatter.Serialize(response);
41 return resultData;
42 }
43
52 public async Task<byte[]> Fetch(string objectTypeName, byte[] criteriaData, byte[] contextData)
53 {
54 DataPortalResult result;
55 try
56 {
57 var objectType = Csla.Reflection.MethodCaller.GetType(objectTypeName);
58 var criteria = Csla.Serialization.Mobile.MobileFormatter.Deserialize(criteriaData);
60 var portal = new Csla.Server.DataPortal();
61 result = await portal.Fetch(objectType, criteria, context, false);
62 }
63 catch (Exception ex)
64 {
65 result = new DataPortalResult(null, ex, null);
66 }
67 var response = GetDataPortalResult(result);
68 var resultData = Csla.Serialization.Mobile.MobileFormatter.Serialize(response);
69 return resultData;
70 }
71
79 public async Task<byte[]> Update(byte[] objectData, byte[] contextData)
80 {
81 DataPortalResult result;
82 try
83 {
86 var portal = new Csla.Server.DataPortal();
87 result = await portal.Update(obj, context, false);
88 }
89 catch (Exception ex)
90 {
91 result = new DataPortalResult(null, ex, null);
92 }
93 var response = GetDataPortalResult(result);
94 var resultData = Csla.Serialization.Mobile.MobileFormatter.Serialize(response);
95 return resultData;
96 }
97
106 public async Task<byte[]> Delete(string objectTypeName, byte[] criteriaData, byte[] contextData)
107 {
108 DataPortalResult result;
109 try
110 {
111 var objectType = Csla.Reflection.MethodCaller.GetType(objectTypeName);
112 var criteria = Csla.Serialization.Mobile.MobileFormatter.Deserialize(criteriaData);
114 var portal = new Csla.Server.DataPortal();
115 result = await portal.Delete(objectType, criteria, context, false);
116 }
117 catch (Exception ex)
118 {
119 result = new DataPortalResult(null, ex, null);
120 }
121 var response = GetDataPortalResult(result);
122 var resultData = Csla.Serialization.Mobile.MobileFormatter.Serialize(response);
123 return resultData;
124 }
125
126 private Csla.Server.Hosts.HttpChannel.HttpResponse GetDataPortalResult(DataPortalResult dataportalResult)
127 {
128 var result = new Csla.Server.Hosts.HttpChannel.HttpResponse();
129 if (dataportalResult.Error != null)
130 result.ErrorData = new HttpChannel.HttpErrorInfo(dataportalResult.Error);
131 if (dataportalResult.GlobalContext != null)
132 result.GlobalContext = Csla.Serialization.Mobile.MobileFormatter.Serialize(dataportalResult.GlobalContext);
133 if (dataportalResult.ReturnObject != null)
134 result.ObjectData = Csla.Serialization.Mobile.MobileFormatter.Serialize(dataportalResult.ReturnObject);
135 return result;
136 }
137 }
138}
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.
Implements the server-side DataPortal message router as discussed in Chapter 4.
Returns data from the server-side DataPortal to the client-side DataPortal.
object ReturnObject
The business object being returned from the server.
ContextDictionary GlobalContext
The global context being returned from the server.
Exception Error
Error that occurred during the DataPotal call.
Data portal to be invoked by the brokered data portal proxy/host implementation.
async Task< byte[]> Create(string objectTypeName, byte[] criteriaData, byte[] contextData)
Create and initialize a business object.
async Task< byte[]> Fetch(string objectTypeName, byte[] criteriaData, byte[] contextData)
Get an existing business object.
async Task< byte[]> Update(byte[] objectData, byte[] contextData)
Update a business object.
async Task< byte[]> Delete(string objectTypeName, byte[] criteriaData, byte[] contextData)
Delete a business object.