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.
BrokeredHost.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="BrokeredDataPortal.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 host</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Linq;
11using System.Text;
12using System.Threading.Tasks;
13using System.Runtime.InteropServices.WindowsRuntime;
14using Windows.Foundation;
15
17{
22 public sealed class BrokeredHost
23 {
32 public IAsyncOperation<IList<byte>> Create(string objectTypeName, [ReadOnlyArray] byte[] criteriaData, [ReadOnlyArray] byte[] contextData)
33 {
34 return Task<IList<byte>>.Run(async () =>
35 {
36 var portal = GetPortal();
37 var method = portal.GetType().GetMethod("Create");
38 var result = await (Task<byte[]>)method.Invoke(portal, new object[] { objectTypeName, criteriaData, contextData });
39 return (IList<byte>)result;
40 }).AsAsyncOperation();
41 }
42
51 public IAsyncOperation<IList<byte>> Fetch(string objectTypeName, [ReadOnlyArray] byte[] criteriaData, [ReadOnlyArray] byte[] contextData)
52 {
53 return Task<IList<byte>>.Run(async () =>
54 {
55 var portal = GetPortal();
56 var method = portal.GetType().GetMethod("Fetch");
57 var result = await (Task<byte[]>)method.Invoke(portal, new object[] { objectTypeName, criteriaData, contextData });
58 return (IList<byte>)result;
59 }).AsAsyncOperation();
60 }
61
69 public IAsyncOperation<IList<byte>> Update([ReadOnlyArray] byte[] objectData, [ReadOnlyArray] byte[] contextData)
70 {
71 return Task<IList<byte>>.Run(async () =>
72 {
73 var portal = GetPortal();
74 var method = portal.GetType().GetMethod("Update");
75 var result = await (Task<byte[]>)method.Invoke(portal, new object[] { objectData, contextData });
76 return (IList<byte>)result;
77 }).AsAsyncOperation();
78 }
79
88 public IAsyncOperation<IList<byte>> Delete(string objectTypeName, [ReadOnlyArray] byte[] criteriaData, [ReadOnlyArray] byte[] contextData)
89 {
90 return Task<IList<byte>>.Run(async () =>
91 {
92 var portal = GetPortal();
93 var method = portal.GetType().GetMethod("Delete");
94 var result = await (Task<byte[]>)method.Invoke(portal, new object[] { objectTypeName, criteriaData, contextData });
95 return (IList<byte>)result;
96 }).AsAsyncOperation();
97 }
98
99 private object GetPortal()
100 {
101 var typeName = "Csla.Server.Hosts.BrokeredPortal, Csla.BrokeredDataPortal";
102 Type type = null;
103 try
104 {
105 type = Type.GetType(typeName);
106 if (type == null)
107 throw new TypeLoadException("BrokeredHost: " + typeName);
108 }
109 catch (Exception ex)
110 {
111 throw new TypeLoadException("BrokeredHost: " + typeName, ex);
112 }
113 return Activator.CreateInstance(type);
114 }
115 }
116}
Brokered assembly entry point for the data portal.
Definition: BrokeredHost.cs:23
IAsyncOperation< IList< byte > > Fetch(string objectTypeName, [ReadOnlyArray] byte[] criteriaData, [ReadOnlyArray] byte[] contextData)
Get an existing business object.
Definition: BrokeredHost.cs:51
IAsyncOperation< IList< byte > > Update([ReadOnlyArray] byte[] objectData, [ReadOnlyArray] byte[] contextData)
Update a business object.
Definition: BrokeredHost.cs:69
IAsyncOperation< IList< byte > > Delete(string objectTypeName, [ReadOnlyArray] byte[] criteriaData, [ReadOnlyArray] byte[] contextData)
Delete a business object.
Definition: BrokeredHost.cs:88
IAsyncOperation< IList< byte > > Create(string objectTypeName, [ReadOnlyArray] byte[] criteriaData, [ReadOnlyArray] byte[] contextData)
Create and initialize a business object.
Definition: BrokeredHost.cs:32