本文整理汇总了C#中Csla.Server.DataPortalContext类的典型用法代码示例。如果您正苦于以下问题:C# DataPortalContext类的具体用法?C# DataPortalContext怎么用?C# DataPortalContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataPortalContext类属于Csla.Server命名空间,在下文中一共展示了DataPortalContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeMethod
private async Task<DataPortalResult> InvokeMethod(string factoryTypeName, DataPortalOperations operation, string methodName, Type objectType, DataPortalContext context, bool isSync)
{
object factory = FactoryLoader.GetFactory(factoryTypeName);
var eventArgs = new DataPortalEventArgs(context, objectType, null, operation);
Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "Invoke", eventArgs);
object result = null;
try
{
Utilities.ThrowIfAsyncMethodOnSyncClient(isSync, factory, methodName);
result = await Csla.Reflection.MethodCaller.CallMethodTryAsync(factory, methodName).ConfigureAwait(false);
var error = result as Exception;
if (error != null)
throw error;
var busy = result as Csla.Core.ITrackStatus;
if (busy != null && busy.IsBusy)
throw new InvalidOperationException(string.Format("{0}.IsBusy == true", objectType.Name));
Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "InvokeComplete", eventArgs);
}
catch (Exception ex)
{
Csla.Reflection.MethodCaller.CallMethodIfImplemented(
factory, "InvokeError", new DataPortalEventArgs(context, objectType, null, operation, ex));
throw;
}
return new DataPortalResult(result);
}
示例2: DataPortalEventArgs
/// <summary>
/// Creates an instance of the object.
/// </summary>
/// <param name="dataPortalContext">
/// Data portal context object.
/// </param>
/// <param name="objectType">
/// Business object type.
/// </param>
/// <param name="obj">
/// Criteria or business object for request.
/// </param>
/// <param name="operation">
/// Data portal operation being performed.
/// </param>
public DataPortalEventArgs(Server.DataPortalContext dataPortalContext, Type objectType, object obj, DataPortalOperations operation)
{
_dataPortalContext = dataPortalContext;
_operation = operation;
_objectType = objectType;
_object = obj;
}
示例3: Fetch
public WcfResponse Fetch(CriteriaRequest request)
{
Csla.Server.DataPortal portal = new Csla.Server.DataPortal();
Exception error = null;
DataPortalResult result = null;
WcfResponse response = null;
ISerializationFormatter formatter = SerializationFormatterFactory.GetFormatter();
try
{
request = ConvertRequest(request);
DataPortalContext context = new DataPortalContext(
formatter.Deserialize(request.Principal) as IPrincipal,
true,
request.ClientCulture,
request.ClientUICulture,
formatter.Deserialize(request.ClientContext) as ContextDictionary,
formatter.Deserialize(request.GlobalContext) as ContextDictionary);
result = portal.Fetch(Type.GetType(request.TypeName), formatter.Deserialize(request.CriteriaData), context);
response = new WcfResponse(
formatter.Serialize(result.ReturnObject),
formatter.Serialize(error),
formatter.Serialize(Csla.ApplicationContext.GlobalContext));
}
catch (Exception ex)
{
error = ex;
response = new WcfResponse(
null,
formatter.Serialize(error),
formatter.Serialize(Csla.ApplicationContext.GlobalContext));
}
return ConvertResponse(response);
}
示例4: Fetch
/// <summary>
/// Get an existing business object.
/// </summary>
/// <param name="objectType">Type of business object to retrieve.</param>
/// <param name="criteria">Criteria object describing business object.</param>
/// <param name="context">
/// <see cref="Server.DataPortalContext" /> object passed to the server.
/// </param>
/// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
{
try
{
context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
if (context.FactoryInfo == null)
{
var dp = new SimpleDataPortal();
return await dp.Fetch(objectType, criteria, context, isSync);
}
else
{
var dp = new FactoryDataPortal();
return await dp.Fetch(objectType, criteria, context, isSync);
}
}
catch (DataPortalException)
{
throw;
}
catch (Exception ex)
{
throw DataPortal.NewDataPortalException(
"DataPortal.Fetch " + Resources.FailedOnServer,
ex, null);
}
}
示例5: Create
/// <summary>
/// Called by <see cref="DataPortal" /> to create a
/// new business object.
/// </summary>
/// <param name="objectType">Type of business object to create.</param>
/// <param name="criteria">Criteria object describing business object.</param>
/// <param name="context">
/// <see cref="Server.DataPortalContext" /> object passed to the server.
/// </param>
public DataPortalResult Create(Type objectType, object criteria, DataPortalContext context)
{
ChannelFactory<IWcfBfPortal> cf = GetChannelFactory();
IWcfBfPortal svr = GetProxy(cf);
WcfResponse response = null;
try
{
var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
byte[] outbound;
byte[] inbound;
using (var buffer = new System.IO.MemoryStream())
{
formatter.Serialize(buffer, new CreateRequest(objectType, criteria, context));
outbound = buffer.ToArray();
}
inbound = svr.Create(outbound);
using (var buffer = new System.IO.MemoryStream(inbound))
{
response = (WcfResponse)formatter.Deserialize(buffer);
}
if (cf != null)
cf.Close();
}
catch
{
cf.Abort();
throw;
}
object result = response.Result;
if (result is Exception)
throw (Exception)result;
return (DataPortalResult)result;
}
示例6: Create
/// <summary>
/// Called by <see cref="DataPortal" /> to create a
/// new business object.
/// </summary>
/// <param name="objectType">Type of business object to create.</param>
/// <param name="criteria">Criteria object describing business object.</param>
/// <param name="context">
/// <see cref="Server.DataPortalContext" /> object passed to the server.
/// </param>
public DataPortalResult Create(Type objectType, object criteria, DataPortalContext context)
{
ChannelFactory<IExtendableWcfPortalForDotNet> cf = GetChannelFactory();
IExtendableWcfPortalForDotNet svr = GetProxy(cf);
WcfResponse response = null;
ISerializationFormatter formatter = SerializationFormatterFactory.GetFormatter();
try
{
response =
svr.Create(GetRequest(formatter, objectType, criteria, context));
if (cf != null)
cf.Close();
}
catch
{
cf.Abort();
throw;
}
DataPortalResult result = GetResult(formatter, response);
Exception error = (Exception)formatter.Deserialize(response.Error);
if (error != null)
{
throw error;
}
return result;
}
示例7: Create
public async Task<DataPortalResult> Create(
Type objectType, object criteria, DataPortalContext context, bool isSync)
{
LateBoundObject obj = null;
IDataPortalTarget target = null;
var eventArgs = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Create);
try
{
// create an instance of the business object.
obj = new LateBoundObject(objectType);
target = obj.Instance as IDataPortalTarget;
if (target != null)
{
target.DataPortal_OnDataPortalInvoke(eventArgs);
target.MarkNew();
}
else
{
obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs);
obj.CallMethodIfImplemented("MarkNew");
}
// tell the business object to create its data
if (criteria is EmptyCriteria)
await obj.CallMethodTryAsync("DataPortal_Create");
else
await obj.CallMethodTryAsync("DataPortal_Create", criteria);
if (target != null)
target.DataPortal_OnDataPortalInvokeComplete(eventArgs);
else
obj.CallMethodIfImplemented(
"DataPortal_OnDataPortalInvokeComplete", eventArgs);
// return the populated business object as a result
return new DataPortalResult(obj.Instance);
}
catch (Exception ex)
{
try
{
if (target != null)
target.DataPortal_OnDataPortalException(eventArgs, ex);
else if (obj != null)
obj.CallMethodIfImplemented("DataPortal_OnDataPortalException", eventArgs, ex);
}
catch
{
// ignore exceptions from the exception handler
}
object outval = null;
if (obj != null) outval = obj.Instance;
throw DataPortal.NewDataPortalException(
"DataPortal.Create " + Resources.FailedOnServer,
new DataPortalExceptionHandler().InspectException(objectType, outval, criteria, "DataPortal.Create", ex),
outval);
}
}
示例8: Fetch
/// <summary>
/// Called by <see cref="DataPortal" /> to load an
/// existing business object.
/// </summary>
/// <param name="objectType">Type of business object to retrieve.</param>
/// <param name="criteria">Criteria object describing business object.</param>
/// <param name="context">
/// <see cref="Server.DataPortalContext" /> object passed to the server.
/// </param>
/// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
{
if (isSync || Csla.ApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Server)
{
return await _portal.Fetch(objectType, criteria, context, isSync);
}
else
{
var tcs = new TaskCompletionSource<DataPortalResult>();
var bw = new Csla.Threading.BackgroundWorker();
bw.DoWork += (s, o) =>
{
o.Result = _portal.Fetch(objectType, criteria, context, isSync).Result;
};
bw.RunWorkerCompleted += (s, o) =>
{
if (o.Error == null)
tcs.TrySetResult((DataPortalResult)o.Result);
else
tcs.TrySetException(o.Error);
};
bw.RunWorkerAsync();
return await tcs.Task;
}
}
示例9: Fetch
public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context)
{
Thread t = new Thread(DoFetch);
FetchTask task = new FetchTask();
task.ObjectType = objectType;
task.Criteria = criteria;
task.Context = context;
t.Start(task);
t.Join();
return task.Result;
}
示例10: Update
/// <summary>
/// Called by <see cref="DataPortal" /> to update a
/// business object.
/// </summary>
/// <param name="obj">The business object to update.</param>
/// <param name="context">
/// <see cref="Server.DataPortalContext" /> object passed to the server.
/// </param>
/// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
{
if (isSync || Csla.ApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Server)
{
return await _portal.Update(obj, context, isSync);
}
else
{
return await await _taskFactory.StartNew(() => this._portal.Update(obj, context, isSync));
}
}
示例11: Fetch
/// <summary>
/// Called by <see cref="DataPortal" /> to load an
/// existing business object.
/// </summary>
/// <param name="objectType">Type of business object to retrieve.</param>
/// <param name="criteria">Criteria object describing business object.</param>
/// <param name="context">
/// <see cref="Server.DataPortalContext" /> object passed to the server.
/// </param>
/// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
{
if (isSync || Csla.ApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Server)
{
return await _portal.Fetch(objectType, criteria, context, isSync);
}
else
{
return await await _taskFactory.StartNew(() => this._portal.Fetch(objectType, criteria, context, isSync));
}
}
示例12: Create
/// <summary>
/// Wraps a Create call in a TransactionScope
/// </summary>
/// <remarks>
/// This method delegates to
/// <see cref="SimpleDataPortal">SimpleDataPortal</see>
/// but wraps that call within a
/// <see cref="TransactionScope">TransactionScope</see>
/// to provide transactional support via
/// System.Transactions.
/// </remarks>
/// <param name="objectType">A <see cref="Type">Type</see> object
/// indicating the type of business object to be created.</param>
/// <param name="criteria">A custom criteria object providing any
/// extra information that may be required to properly create
/// the object.</param>
/// <param name="context">Context data from the client.</param>
/// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
/// <returns>A populated business object.</returns>
public async Task<DataPortalResult> Create(
Type objectType, object criteria, DataPortalContext context, bool isSync)
{
DataPortalResult result;
using (TransactionScope tr = CreateTransactionScope())
{
var portal = new DataPortalSelector();
result = await portal.Create(objectType, criteria, context, isSync);
tr.Complete();
}
return result;
}
示例13: Fetch
public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
{
var cachingAttribute = ObjectCacheAttribute.GetObjectCacheAttribute(objectType);
var cacheProvider = CacheManager.GetCacheProvider();
if (cachingAttribute != null && cacheProvider != null)
{
//get scenario details
var scope = cachingAttribute.Scope;
var cacheByCriteria = cachingAttribute.CacheByCriteria;
var expiration = cachingAttribute.Expiration;
//get key
var key = GetCacheItemKey(objectType, cachingAttribute);
//include criteria hash if needed
if (cachingAttribute.CacheByCriteria)
key = string.Format("{0}::{1}", key, criteria.GetHashCode());
var data = cacheProvider.Get(key);
if (data == null)
{
//cache miss
proxy = GetDataPortalProxy();
var results = await proxy.Fetch(objectType, criteria, context, isSync);
if (expiration > 0)
cacheProvider.Put(key, results.ReturnObject, new TimeSpan(0, expiration, 0));
else
cacheProvider.Put(key, results.ReturnObject);
return results;
}
else
{
//cache hit
#if !NET45
await TaskEx.Delay(0);
#else
await Task.Delay(0);
#endif
return new DataPortalResult(data);
}
}
else
{
proxy = GetDataPortalProxy();
return await proxy.Fetch(objectType, criteria, context, isSync);
}
}
示例14: Fetch
public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context)
{
var cachingAttribute = ObjectCacheAttribute.GetObjectCacheAttribute(objectType);
var cacheProvider = CacheManager.GetCacheProvider();
if (cachingAttribute != null && cacheProvider != null)
{
//get scenario details
var scope = cachingAttribute.Scope;
var cacheByCriteria = cachingAttribute.CacheByCriteria;
var expiration = cachingAttribute.Expiration;
//get key
var key = GetCacheItemKey(objectType, cachingAttribute);
//include criteria hash if needed
if (cachingAttribute.CacheByCriteria)
key = string.Format("{0}::{1}", key, criteria.GetHashCode());
var data = cacheProvider.Get(key);
if (data == null)
{
//cache miss
proxy = GetDataPortalProxy();
var results = proxy.Fetch(objectType, criteria, context);
if (expiration > 0)
cacheProvider.Put(key, results, new TimeSpan(0, expiration, 0));
else
cacheProvider.Put(key, results);
return results;
}
else
{
//cache hit
return (DataPortalResult)data;
}
}
else
{
proxy = GetDataPortalProxy();
return proxy.Fetch(objectType, criteria, context);
}
}
示例15: Create
/// <summary>
/// Called by the client-side DataPortal to create a
/// new business object.
/// </summary>
/// <param name="objectType">Type of business object to create.</param>
/// <param name="criteria">Criteria object describing business object.</param>
/// <param name="context">Server.DataPortalContext object passed to the server.</param>
/// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
public async Task<DataPortalResult> Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
{
DataPortalResult result = null;
if (isSync)
throw new NotSupportedException("isSync == true");
try
{
if (!(criteria is IMobileObject))
criteria = new PrimitiveCriteria(criteria);
var contextData = Csla.Serialization.Mobile.MobileFormatter.Serialize(context);
var criteriaData = Csla.Serialization.Mobile.MobileFormatter.Serialize(criteria);
var portal = new BrokeredHost();
var objectTypeName = objectType.AssemblyQualifiedName;
var resultData = await portal.Create(objectTypeName, criteriaData, contextData);
var response = (Csla.Server.Hosts.HttpChannel.HttpResponse)Csla.Serialization.Mobile.MobileFormatter.Deserialize(resultData.ToArray());
var globalContext = (Csla.Core.ContextDictionary)Csla.Serialization.Mobile.MobileFormatter.Deserialize(response.GlobalContext);
if (response != null && response.ErrorData == null)
{
var obj = MobileFormatter.Deserialize(response.ObjectData);
result = new DataPortalResult(obj, null, globalContext);
}
else if (response != null && response.ErrorData != null)
{
var ex = new DataPortalException(response.ErrorData);
result = new DataPortalResult(null, ex, globalContext);
}
else
{
throw new DataPortalException("null response", null);
}
}
catch (Exception ex)
{
result = new DataPortalResult(null, ex, null);
}
if (result.Error != null)
throw result.Error;
return result;
}