コード例 #1
0
ファイル: LocalProxy.cs プロジェクト: zuiwanting/csla
 /// <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);
     }
 }
コード例 #2
0
        /// <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)
        {
            DataPortalResult result;

            SetApplicationContext(criteria, CurrentApplicationContext);
            if (isSync || OriginalApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Server)
            {
                result = await _portal.Fetch(objectType, criteria, context, isSync);
            }
            else
            {
                if (!Options.FlowSynchronizationContext || SynchronizationContext.Current == null)
                {
                    result = await Task.Run(() => this._portal.Fetch(objectType, criteria, context, isSync));
                }
                else
                {
                    result = await await Task.Factory.StartNew(() => this._portal.Fetch(objectType, criteria, context, isSync),
                                                               CancellationToken.None,
                                                               TaskCreationOptions.None,
                                                               TaskScheduler.FromCurrentSynchronizationContext());
                }
            }
            SetApplicationContext(result.ReturnObject, OriginalApplicationContext);
            SetApplicationContext(result.Error, OriginalApplicationContext);
            return(result);
        }
コード例 #3
0
 /// <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)));
     }
 }
コード例 #4
0
ファイル: LocalProxy.cs プロジェクト: viethien/csla
        /// <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
            {
                if (SynchronizationContext.Current == null)
                {
                    return(await await this._taskFactory.StartNew(() => this._portal.Fetch(objectType, criteria, context, isSync)));
                }

                return(await await this._taskFactory.StartNew(() => this._portal.Fetch(objectType, criteria, context, isSync),
                                                              CancellationToken.None,
                                                              TaskCreationOptions.None,
                                                              TaskScheduler.FromCurrentSynchronizationContext()));
            }
        }
コード例 #5
0
ファイル: LocalProxy.cs プロジェクト: hudsonchoi/Church
 public DataPortalResult Fetch(object criteria, DataPortalContext context)
 {
     return(_portal.Fetch(criteria, context));
 }
コード例 #6
0
ファイル: RemotingProxy.cs プロジェクト: hudsonchoi/Church
 public Server.DataPortalResult Fetch(object criteria, Server.DataPortalContext context)
 {
     return(Portal.Fetch(criteria, context));
 }