本文整理汇总了C#中Csla.Server.DataPortalContext类的典型用法代码示例。如果您正苦于以下问题:C# DataPortalContext类的具体用法?C# DataPortalContext怎么用?C# DataPortalContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataPortalContext类属于Csla.Server命名空间,在下文中一共展示了DataPortalContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:MarimerLLC,项目名称:csla,代码行数:30,代码来源:FactoryDataPortal.cs
示例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;
}
开发者ID:Jaans,项目名称:csla,代码行数:22,代码来源:DataPortalEventArgs.cs
示例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);
}
开发者ID:BiYiTuan,项目名称:csla,代码行数:33,代码来源:WcfPortal.cs
示例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);
}
}
开发者ID:nschonni,项目名称:csla-svn,代码行数:36,代码来源:DataPortalSelector.cs
示例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;
}
开发者ID:Jaans,项目名称:csla,代码行数:44,代码来源:WcfBfProxy.cs
示例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;
}
开发者ID:Jaans,项目名称:csla,代码行数:35,代码来源:WcfProxy.cs
示例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);
}
}
开发者ID:nschonni,项目名称:csla-svn,代码行数:60,代码来源:SimpleDataPortal.cs
示例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;
}
}
开发者ID:BiYiTuan,项目名称:csla,代码行数:35,代码来源:LocalProxy.cs
示例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;
}
开发者ID:Jaans,项目名称:csla,代码行数:11,代码来源:Proxy.cs
示例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));
}
}
开发者ID:RodrigoGT,项目名称:csla,代码行数:20,代码来源:LocalProxy.cs
示例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));
}
}
开发者ID:RodrigoGT,项目名称:csla,代码行数:21,代码来源:LocalProxy.cs
示例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;
}
开发者ID:nschonni,项目名称:csla-svn,代码行数:31,代码来源:TransactionalDataPortal.cs
示例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);
}
}
开发者ID:transformersprimeabcxyz,项目名称:cslacontrib-MarimerLLC,代码行数:49,代码来源:CacheDataPortal.cs
示例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);
}
}
开发者ID:transformersprimeabcxyz,项目名称:cslacontrib-MarimerLLC,代码行数:44,代码来源:CacheDataPortal.cs
示例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;
}
开发者ID:BiYiTuan,项目名称:csla,代码行数:47,代码来源:BrokeredProxy.cs
示例16: InvokeMethod
private async Task<DataPortalResult> InvokeMethod(string factoryTypeName, DataPortalOperations operation, string methodName, Type objectType, object e, DataPortalContext context)
{
object factory = FactoryLoader.GetFactory(factoryTypeName);
var eventArgs = new DataPortalEventArgs(context, objectType, e, operation);
Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "Invoke", eventArgs);
object result = null;
try
{
result = await Csla.Reflection.MethodCaller.CallMethodTryAsync(factory, methodName, e);
var error = result as Exception;
if (error != null)
throw error;
Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "InvokeComplete", eventArgs);
}
catch (Exception ex)
{
Csla.Reflection.MethodCaller.CallMethodIfImplemented(factory, "InvokeError", new DataPortalEventArgs(context, objectType, e, operation, ex));
throw;
}
return new DataPortalResult(result);
}
开发者ID:nschonni,项目名称:csla-svn,代码行数:22,代码来源:FactoryDataPortal.cs
示例17: Update
public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
{
var portal = new DataPortalSelector();
return await portal.Update(obj, context, isSync).ConfigureAwait(false);
}
开发者ID:tiger2soft,项目名称:csla,代码行数:5,代码来源:ServicedDataPortalReadUncommitted.cs
示例18: GetRequest
private UpdateRequest GetRequest(ISerializationFormatter formatter, object obj, DataPortalContext context)
{
UpdateRequest request = new UpdateRequest();
request.ClientContext = formatter.Serialize(Csla.ApplicationContext.ClientContext);
request.ClientCulture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
request.ClientUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
request.GlobalContext = formatter.Serialize(Csla.ApplicationContext.GlobalContext);
request.Principal = formatter.Serialize(Csla.ApplicationContext.User);
request.ObjectData = formatter.Serialize(obj);
request = ConvertRequest(request);
return request;
}
开发者ID:Jaans,项目名称:csla,代码行数:12,代码来源:WcfProxy.cs
示例19: SetContext
private void SetContext(DataPortalContext context)
{
_oldLocation = Csla.ApplicationContext.LogicalExecutionLocation;
ApplicationContext.SetLogicalExecutionLocation(ApplicationContext.LogicalExecutionLocations.Server);
// if the dataportal is not remote then
// do nothing
if (!context.IsRemotePortal) return;
// set the context value so everyone knows the
// code is running on the server
ApplicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);
// set the app context to the value we got from the
// client
ApplicationContext.SetContext(context.ClientContext, context.GlobalContext);
// set the thread's culture to match the client
#if NETFX_CORE
var list = new System.Collections.ObjectModel.ReadOnlyCollection<string>(new List<string> { context.ClientUICulture });
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Languages = list;
list = new System.Collections.ObjectModel.ReadOnlyCollection<string>(new List<string> { context.ClientCulture });
Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Languages = list;
#else
System.Threading.Thread.CurrentThread.CurrentCulture =
new System.Globalization.CultureInfo(context.ClientCulture);
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo(context.ClientUICulture);
#endif
if (ApplicationContext.AuthenticationType == "Windows")
{
// When using integrated security, Principal must be null
if (context.Principal != null)
{
Csla.Security.SecurityException ex =
new Csla.Security.SecurityException(Resources.NoPrincipalAllowedException);
//ex.Action = System.Security.Permissions.SecurityAction.Deny;
throw ex;
}
#if !SILVERLIGHT && !NETFX_CORE
// Set .NET to use integrated security
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
#endif
}
else
{
// We expect the some Principal object
if (context.Principal == null)
{
Csla.Security.SecurityException ex =
new Csla.Security.SecurityException(
Resources.BusinessPrincipalException + " Nothing");
//ex.Action = System.Security.Permissions.SecurityAction.Deny;
throw ex;
}
ApplicationContext.User = context.Principal;
}
}
开发者ID:BiYiTuan,项目名称:csla,代码行数:59,代码来源:DataPortal.cs
示例20: Delete
public DataPortalResult Delete(Type objectType, object criteria, DataPortalContext context)
{
Thread t = new Thread(DoDelete);
DeleteTask task = new DeleteTask();
task.ObjectType = objectType;
task.Criteria = criteria;
task.Context = context;
t.Start(task);
t.Join();
return task.Result;
}
开发者ID:Jaans,项目名称:csla,代码行数:11,代码来源:Proxy.cs
注:本文中的Csla.Server.DataPortalContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论