9using System.Reflection;
10using System.Threading;
11using System.Threading.Tasks;
25 private const int TIMEOUT = 70000;
36 if (_appDomain ==
null)
38 var current = AppDomain.CurrentDomain;
39 var setup = current.SetupInformation;
40 setup.ApplicationName =
"Csla.DataPortal";
42 AppDomain.CreateDomain(
"ServerDomain",
null, setup);
43 current.DomainUnload += UnloadDomain;
44 SerializationWorkaround(AppDomain.CurrentDomain);
45 SerializationWorkaround(_appDomain);
46 _appDomain.UnhandledException +=
new UnhandledExceptionEventHandler(_appDomain_UnhandledException);
49 _portal = (
Csla.
Server.
Hosts.RemotingPortal)_appDomain.CreateInstanceAndUnwrap(
50 "Csla",
"Csla.Server.Hosts.RemotingPortal");
54 UnloadDomain(
null,
null);
55 Console.WriteLine(ex);
62 void _appDomain_UnhandledException(
object sender, UnhandledExceptionEventArgs e)
64 Console.WriteLine(e.ExceptionObject);
67 void UnloadDomain(
object sender, EventArgs e)
69 if (_appDomain !=
null)
71 AppDomain.CurrentDomain.DomainUnload -= UnloadDomain;
72 AppDomain.Unload(_appDomain);
78 private class CreateTask
80 public Type ObjectType;
81 public object Criteria;
84 public Exception ResultException;
89 var task =
new CreateTask{
90 ObjectType = objectType,
97 await Task.Factory.StartNew(DoCreate, task);
98 if (task.ResultException !=
null)
99 throw task.ResultException;
103 void DoCreate(
object state)
105 CreateTask task =
null;
108 task = state as CreateTask;
110 task.Result = Portal.Create(task.ObjectType, task.Criteria, task.Context);
115 task.ResultException = ex;
123 private class FetchTask
125 public Type ObjectType;
126 public object Criteria;
129 public Exception ResultException;
137 ObjectType = objectType,
144 await Task.Factory.StartNew(DoFetch, task);
145 if (task.ResultException !=
null)
146 throw task.ResultException;
150 void DoFetch(
object state)
152 FetchTask task =
null;
155 task = state as FetchTask;
157 task.Result = Portal.Fetch(task.ObjectType, task.Criteria, task.Context);
162 task.ResultException = ex;
170 private class UpdateTask
175 public Exception ResultException;
190 await Task.Factory.StartNew(DoUpdate, task);
191 if (task.ResultException !=
null)
192 throw task.ResultException;
196 void DoUpdate(
object state)
198 UpdateTask task =
null;
201 task = (UpdateTask)state;
204 task.Result = Portal.Update(task.Obj, task.Context);
209 task.ResultException = ex;
224 ObjectType = objectType
229 await Task.Factory.StartNew(DoDelete, task);
230 if (task.ResultException !=
null)
231 throw task.ResultException;
235 private class DeleteTask
237 public object Criteria;
240 public Type ObjectType;
241 public Exception ResultException;
244 void DoDelete(
object state)
246 DeleteTask task =
null;
249 task = state as DeleteTask;
251 task.Result = Portal.Delete(task.ObjectType, task.Criteria, task.Context);
256 task.ResultException = ex;
262 #region Serialization bug workaround
264 private static void SerializationWorkaround(AppDomain domain)
269 AppDomain currentDomain = AppDomain.CurrentDomain;
271 domain.AssemblyResolve +=
272 new ResolveEventHandler(ResolveEventHandler);
275 private static Assembly ResolveEventHandler(
276 object sender, ResolveEventArgs args)
278 var domain = sender as AppDomain;
281 Assembly[] list = domain.GetAssemblies();
286 foreach (Assembly
asm in list)
287 if (
asm.FullName == args.Name)
DataPortalResult defines the results of DataPortal operation.
Provides consistent context information between the client and server DataPortal objects.
This is a test proxy used to test any type of calls that have to be send accross to a different AppDo...
async Task< DataPortalResult > Update(object obj, DataPortalContext context, bool isSync)
Update a business object.
async Task< DataPortalResult > Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
Delete a business object.
async Task< DataPortalResult > Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
Create a new business object.
async Task< DataPortalResult > Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
Get an existing business object.
Interface implemented by server-side data portal components.
@ Serializable
Prevents updating or inserting until the transaction is complete.