9using System.Collections.Generic;
11using System.Security.Principal;
13using System.Threading.Tasks;
36 public override async Task<ResponseMessage>
Invoke(RequestMessage request, ServerCallContext context)
38 var operation = request.Operation;
39 if (operation.Contains(
"/"))
41 var temp = operation.Split(
'/');
46 return await InvokePortal(operation, request.Body).ConfigureAwait(
false);
55 protected static Dictionary<string, string>
RoutingTagUrls =
new Dictionary<string, string>();
63 protected virtual async Task<ResponseMessage>
RouteMessage(
string operation,
string routingTag, RequestMessage request)
65 if (
RoutingTagUrls.TryGetValue(routingTag, out
string route) && route !=
"localhost")
67 var url = $
"{route}?operation={operation}";
69 var clientRequest =
new RequestMessage
74 var clientResponse = await proxy.RouteMessage(clientRequest);
75 return new ResponseMessage { Body = clientResponse.Body };
79 return await InvokePortal(operation, request.Body).ConfigureAwait(
false);
83 private async Task<ResponseMessage> InvokePortal(
string operation, ByteString requestData)
89 var request = SerializationFormatterFactory.GetFormatter().Deserialize(requestData.ToByteArray());
90 result = await CallPortal(operation, request);
96 var portalResult =
new DataPortalResponse { ErrorData = errorData, GlobalContext = result.GlobalContext, ObjectData = result.ObjectData };
97 var buffer = SerializationFormatterFactory.GetFormatter().Serialize(portalResult);
98 return new ResponseMessage { Body = ByteString.CopyFrom(buffer) };
101 private async Task<DataPortalResponse> CallPortal(
string operation,
object request)
123 throw new InvalidOperationException(operation);
148 (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.
Principal),
156 var dpr = await prtl.
Create(objectType, criteria, context,
true);
158 if (dpr.Error !=
null)
160 result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(dpr.GlobalContext);
161 result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(dpr.ReturnObject);
195 (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.
Principal),
203 var dpr = await prtl.
Fetch(objectType, criteria, context,
true);
205 if (dpr.Error !=
null)
207 result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(dpr.GlobalContext);
208 result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(dpr.ReturnObject);
236 (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.
Principal),
244 var dpr = await prtl.
Update(obj, context,
true);
246 if (dpr.Error !=
null)
249 result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(dpr.GlobalContext);
250 result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(dpr.ReturnObject);
284 (IPrincipal)SerializationFormatterFactory.GetFormatter().Deserialize(request.
Principal),
292 var dpr = await prtl.
Delete(objectType, criteria, context,
true);
294 if (dpr.Error !=
null)
296 result.GlobalContext = SerializationFormatterFactory.GetFormatter().Serialize(dpr.GlobalContext);
297 result.ObjectData = SerializationFormatterFactory.GetFormatter().Serialize(dpr.ReturnObject);
313 private static object GetCriteria(
byte[] criteriaData)
315 object criteria =
null;
316 if (criteriaData !=
null)
317 criteria = SerializationFormatterFactory.GetFormatter().Deserialize(criteriaData);
323 #region Extention Method for Requests
355 #endregion Extention Method for Requests
Exposes server-side DataPortal functionality through gRPC.
async Task< DataPortalResponse > Delete(CriteriaRequest request)
Delete a business object.
static Dictionary< string, string > RoutingTagUrls
Gets a dictionary containing the URLs for each data portal route, where each key is the routing tag i...
async Task< DataPortalResponse > Create(CriteriaRequest request)
Create and initialize an existing business object.
async Task< DataPortalResponse > Fetch(CriteriaRequest request)
Get an existing business object.
virtual DataPortalResponse ConvertResponse(DataPortalResponse response)
Override to convert the response data after it comes back from the network.
virtual CriteriaRequest ConvertRequest(CriteriaRequest request)
Override to convert the request data before it is transferred over the network.
async Task< DataPortalResponse > Update(UpdateRequest request)
Update a business object.
override async Task< ResponseMessage > Invoke(RequestMessage request, ServerCallContext context)
Handle inbound message.
virtual UpdateRequest ConvertRequest(UpdateRequest request)
Override to convert the request data before it is transferred over the network.
virtual async Task< ResponseMessage > RouteMessage(string operation, string routingTag, RequestMessage request)
Entry point for routing tag based data portal operations.
Implements a data portal proxy to relay data portal calls to a remote application server by using gRP...
Dictionary type that is serializable with the SerializationFormatterFactory.GetFormatter().
Class used as a wrapper for criteria based requests that use primitives
Provides consistent context information between the client and server DataPortal objects.
Implements the server-side DataPortal message router 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 > 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.
Message sent to the WCF data portal.
string ClientCulture
Serialized client culture.
byte[] CriteriaData
Serialized data for the criteria object.
string TypeName
Assembly qualified name of the business object type to create.
byte[] GlobalContext
Serialized data for the global context object.
byte[] ClientContext
Serialized data for the client context object.
byte[] Principal
Serialized data for the principal object.
string ClientUICulture
Serialized client UI culture.
Message containing details about any server-side exception.
Response message for returning the results of a data portal call.
Request message for updating a business object.
byte[] GlobalContext
Serialized data for the global context object.
byte[] ClientContext
Serialized data for the client context object.
string ClientCulture
Serialized client culture.
byte[] ObjectData
Serialized object data.
string ClientUICulture
Serialized client UI culture.
byte[] Principal
Serialized data for the principal object.