9using System.Collections.Generic;
11using System.Security.Principal;
13using System.Threading.Tasks;
40 dataPortalServer = dataPortal;
50 public override async Task<ResponseMessage>
Invoke(RequestMessage request, ServerCallContext context)
52 var operation = request.Operation;
53 if (operation.Contains(
"/"))
55 var temp = operation.Split(
'/');
60 return await InvokePortal(operation, request.Body).ConfigureAwait(
false);
69 protected static Dictionary<string, string>
RoutingTagUrls =
new Dictionary<string, string>();
77 protected virtual async Task<ResponseMessage>
RouteMessage(
string operation,
string routingTag, RequestMessage request)
79 if (
RoutingTagUrls.TryGetValue(routingTag, out
string route) && route !=
"localhost")
81 var options =
new GrpcProxyOptions { DataPortalUrl = $
"{route}?operation={operation}" };
84 var clientRequest =
new RequestMessage
89 var clientResponse = await proxy.RouteMessage(clientRequest);
90 return new ResponseMessage { Body = clientResponse.Body };
94 return await InvokePortal(operation, request.Body).ConfigureAwait(
false);
98 private async Task<ResponseMessage> InvokePortal(
string operation, ByteString requestData)
104 var request = SerializationFormatterFactory.GetFormatter(
ApplicationContext).Deserialize(requestData.ToByteArray());
105 result = await CallPortal(operation, request);
113 portalResult.ObjectData = result.ObjectData;
114 var buffer = SerializationFormatterFactory.GetFormatter(
ApplicationContext).Serialize(portalResult);
115 return new ResponseMessage { Body = ByteString.CopyFrom(buffer) };
118 private async Task<DataPortalResponse> CallPortal(
string operation,
object request)
140 throw new InvalidOperationException(operation);
171 var dpr = await dataPortalServer.
Create(objectType, criteria, context,
true);
173 if (dpr.Error !=
null)
175 result.ObjectData = SerializationFormatterFactory.GetFormatter(
ApplicationContext).Serialize(dpr.ReturnObject);
215 var dpr = await dataPortalServer.
Fetch(objectType, criteria, context,
true);
217 if (dpr.Error !=
null)
219 result.ObjectData = SerializationFormatterFactory.GetFormatter(
ApplicationContext).Serialize(dpr.ReturnObject);
253 var dpr = await dataPortalServer.
Update(obj, context,
true);
255 if (dpr.Error !=
null)
258 result.ObjectData = SerializationFormatterFactory.GetFormatter(
ApplicationContext).Serialize(dpr.ReturnObject);
298 var dpr = await dataPortalServer.
Delete(objectType, criteria, context,
true);
300 if (dpr.Error !=
null)
302 result.ObjectData = SerializationFormatterFactory.GetFormatter(
ApplicationContext).Serialize(dpr.ReturnObject);
318 private static object GetCriteria(
ApplicationContext applicationContext,
byte[] criteriaData)
320 object criteria =
null;
321 if (criteriaData !=
null)
322 criteria = SerializationFormatterFactory.GetFormatter(applicationContext).Deserialize(criteriaData);
328 #region Extention Method for Requests
360 #endregion Extention Method for Requests
Csla.Server.DataPortalContext DataPortalContext
Provides consistent context information between the client and server DataPortal objects.
object CreateInstanceDI(Type objectType, params object[] parameters)
Creates an object using 'Activator.CreateInstance' using service provider (if one is available) to po...
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...
GrpcPortal(IDataPortalServer dataPortal, ApplicationContext applicationContext)
Creates an instance of the type
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
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[] 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.
DataPortalErrorInfo ErrorData
Server-side exception data if an exception occurred on the server.
Request message for updating a business 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.
Interface implemented by server-side data portal components.
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.