protected void SelectAsync(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { if (!_owner.DataControl.Page.IsAsync) { throw new InvalidOperationException(Resources.ExtendedModelDataSourceView_MustBeAsyncPage); } _isAsyncSelect = true; DataSourceSelectResultProcessingOptions selectResultProcessingOptions = null; ModelDataSourceMethod modelMethod = EvaluateSelectMethodParameters(arguments, out selectResultProcessingOptions); ModelDataMethodResult result = InvokeMethod(modelMethod); _owner.DataControl.Page.RegisterAsyncTask(new PageAsyncTask(async() => { var selectResult = await(Task <SelectResult>) result.ReturnValue; if (arguments.RetrieveTotalRowCount) { if (!selectResult.TotalRowCount.HasValue) { throw new InvalidOperationException(Resources.ExtendedModelDataSourceView_TotalRowCountNotSet); } arguments.TotalRowCount = selectResult.TotalRowCount.Value; } _isAsyncSelect = false; callback(CreateSelectResult(selectResult.Results)); })); }
private void OnEndSelect(IAsyncResult asyncResult) { IEnumerable data = EndExecuteSelect(asyncResult); DataSourceViewSelectCallback callback = (DataSourceViewSelectCallback)asyncResult.AsyncState; callback(data); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { esDataSourceSelectEventArgs e = null; try { e = new esDataSourceSelectEventArgs(); e.Arguments = arguments; e.Collection = this.owner.Collection; this.OnPreSelect(e); if (e.Cancel) { return; } this.CalculatePageSizeAndNumber(e); this.SetTotalRowCount(e); this.PopulateSortItems(e); //this.OnPreSelect(e); this.OnSelect(e); this.PerformAutoLogic(e); this.FetchTotalRowCount(e); this.OnPostSelect(e); if (e.Collection != null) { this.owner.Collection = e.Collection; } } catch (Exception ex) { esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex); exArgs.EventType = esDataSourceEventType.Select; exArgs.SelectArgs = e; try { this.OnException(exArgs); } catch { } if (!exArgs.ExceptionWasHandled) { throw; } } finally { callback(e.Collection); } }
public virtual void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { if (callback == null) { throw new ArgumentNullException("callback"); } callback(this.ExecuteSelect(arguments)); }
private IAsyncResult OnBeginSelect(object sender, EventArgs e, AsyncCallback asyncCallback, object extraData) { object[] data = (object[])extraData; DataSourceSelectArguments arguments = (DataSourceSelectArguments)data[0]; DataSourceViewSelectCallback callback = (DataSourceViewSelectCallback)data[1]; return(BeginExecuteSelect(arguments, asyncCallback, callback)); }
/// <summary> /// Gets a list of data asynchronously from the underlying data storage. /// </summary> /// <param name="arguments">A <see cref="T:System.Web.UI.DataSourceSelectArguments"></see> that is used to request operations on the data beyond basic data retrieval.</param> /// <param name="callback">A <see cref="T:System.Web.UI.DataSourceViewSelectCallback"></see> delegate that is used to notify a data-bound control when the asynchronous operation is complete.</param> /// <exception cref="T:System.ArgumentNullException">The <see cref="T:System.Web.UI.DataSourceViewSelectCallback"></see> supplied is null.</exception> public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { if (callback == null) { throw new ArgumentNullException("callback"); } callback(ExecuteSelect(arguments)); }
protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments) { IEnumerable callbackResult = null; DataSourceViewSelectCallback syncCallback = delegate(IEnumerable result) { callbackResult = result; }; Select(arguments, syncCallback); return(callbackResult); }
public virtual void Select(DataSourceSelectArguments selectArgs, DataSourceViewSelectCallback callBack) { if (callBack == null) { throw new ArgumentNullException("callBack"); } selectArgs.RaiseUnsupportedCapabilitiesError(this); IEnumerable selectList = ExecuteSelect(selectArgs); callBack(selectList); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { var selectArgs = new SelectEventArgs() { DataSourceView = UnderlyingView, SelectArgs = arguments }; selectArgs.Callback = delegate(IEnumerable data) { selectArgs.Data = data; callback(data); }; AppContext.EventBroker.Publish(ActionDS, selectArgs); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { if (_owner.IsAsync) { System.Web.UI.Page page = ((Control)_owner).Page; PageAsyncTask task = new PageAsyncTask( new BeginEventHandler(OnBeginSelect), new EndEventHandler(OnEndSelect), null, new object[] { arguments, callback }); page.RegisterAsyncTask(task); } else { base.Select(arguments, callback); } }
private int GetTotalRowCount() { int totalRowCount = 0; DataSourceView dataSourceView = GetData(); if (dataSourceView.CanRetrieveTotalRowCount) { DataSourceSelectArguments selectArguments = CreateDataSourceSelectArguments(); selectArguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount); selectArguments.RetrieveTotalRowCount = true; DataSourceViewSelectCallback callback = delegate { totalRowCount = selectArguments.TotalRowCount; }; dataSourceView.Select(selectArguments, callback); } return(totalRowCount); }
protected override void PerformSelect() { if (!IsBoundUsingDataSourceID) { OnDataBinding(EventArgs.Empty); } DataSourceView dataSourceView = GetData(); DataSourceViewSelectCallback callback = delegate(IEnumerable data) { if (IsBoundUsingDataSourceID) { OnDataBinding(EventArgs.Empty); } PerformDataBinding(data); }; if (EnablePaging && dataSourceView.CanPage) { DataSourceSelectArguments selectArguments = CreateDataSourceSelectArguments(); selectArguments.StartRowIndex = PageSize * PageIndex; selectArguments.MaximumRows = PageSize; dataSourceView.Select(selectArguments, callback); } else { DataSourceSelectArguments selectArguments = CreateDataSourceSelectArguments(); if (dataSourceView.CanPage) { selectArguments.AddSupportedCapabilities(DataSourceCapabilities.None); selectArguments.StartRowIndex = 0; selectArguments.MaximumRows = Int16.MaxValue; } dataSourceView.Select(selectArguments, callback); } RequiresDataBinding = false; MarkAsDataBound(); OnDataBound(EventArgs.Empty); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { var selectActionArgs = new SelectEventArgs() { DataSourceView = UnderlyingView, SelectArgs = arguments }; selectActionArgs.Callback = delegate(IEnumerable data) { selectActionArgs.Data = data; callback(data); }; WebManager.ExecuteAction( new ActionContext( selectActionArgs ) { Origin = ActionDS.ActionSourceControl ?? ActionDS.NamingContainer, Sender = ActionDS }); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { var selectArgs = new ComponentDataSourceSelectEventArgs(arguments); DS.OnSelecting(this, selectArgs); var data = AppContext.ComponentFactory.GetComponent(DS.ComponentName, typeof(IEnumerable)) as IEnumerable; if (data == null) { throw new Exception("Component not found: " + DS.ComponentName); } var result = new List <object>(); foreach (var entry in data) { result.Add(entry is IDictionary ? new DictionaryView((IDictionary)entry) : entry); } callback(result); }
// Select call tree: // DataBoundControl.PerformSelect // DataSourceView.Select // ExecuteSelect // GetSelectMethodResult // EvaluateSelectMethodParamaters // InvokeMethod // ProcessSelectMethodResult // CreateSelectResult public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { if (_viewOperationInProgress) { // There appears to be a race somewhere in the model binding or data control base // so we have to ensure we don't honor any call to select if a view operation // (insert, update, delete) is still in progress as it results odd exceptions. return; } var method = FindMethod(SelectMethod); if (InheritsFromTask <SelectResult>(method.MethodInfo.ReturnType)) { SelectAsync(arguments, callback); } else { base.Select(arguments, callback); } }
public object LoadDataItem() { if (CurrentMode == FormViewMode.Insert) { return(null); } var dataSourceView = GetData(); var selectArguments = CreateDataSourceSelectArguments(); object res = null; DataSourceViewSelectCallback selectCallback = delegate(IEnumerable data) { foreach (var dataEntry in data) { res = dataEntry; break; } }; //this will fail for really async datasource. TBD: investigate how to handle async correctly dataSourceView.Select(selectArguments, selectCallback); return(res); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { var selectArgs = new ProviderDataSourceSelectEventArgs(arguments); DS.OnSelecting(this, selectArgs); var provider = WebManager.GetService <IProvider <object, object> >(DS.ProviderName); if (provider == null) { throw new Exception("Underlying data provider service not found: " + DS.ProviderName); } var result = provider.Provide(selectArgs.ProviderContext); var resultList = result is IList ? (IList)result : new object[] { result }; var resultArr = new object[resultList.Count]; for (int i = 0; i < resultList.Count; i++) { resultArr[i] = resultList[i] is IDictionary ? new DictionaryView((IDictionary)resultList[i]) : resultList[i]; } callback(resultArr); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { esDataSourceSelectEventArgs e = null; try { e = new esDataSourceSelectEventArgs(); e.Arguments = arguments; e.Collection = this.owner.Collection; this.OnPreSelect(e); if (e.Cancel) return; this.CalculatePageSizeAndNumber(e); this.SetTotalRowCount(e); this.PopulateSortItems(e); //this.OnPreSelect(e); this.OnSelect(e); this.PerformAutoLogic(e); this.FetchTotalRowCount(e); this.OnPostSelect(e); if (e.Collection != null) { this.owner.Collection = e.Collection; } } catch (Exception ex) { esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex); exArgs.EventType = esDataSourceEventType.Select; exArgs.SelectArgs = e; try { this.OnException(exArgs); } catch { } if (!exArgs.ExceptionWasHandled) { throw; } } finally { callback(e.Collection); } }
/// <summary> /// 从基础数据存储中异步获取数据列表。 /// </summary> /// <param name="arguments">用于请求对数据执行基本数据检索以外的操作。</param> /// <param name="callback">用于在异步操作完成时通知数据绑定控件的 <see cref="DataSourceViewSelectCallback"/> 委托。</param> public virtual void Select(DataSourceSelectArgumentsEx arguments, DataSourceViewSelectCallback callback) { if (callback == null) throw new ArgumentNullException("callback"); callback(this.ExecuteSelect(arguments)); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { callback(ExecuteSelect(arguments)); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { callback(ExecuteSelect(arguments)); }
public virtual new void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { base.Select(arguments, callback); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { var selectActionArgs = new SelectEventArgs() { DataSourceView = UnderlyingView, SelectArgs = arguments }; selectActionArgs.Callback = delegate(IEnumerable data) { selectActionArgs.Data = data; callback(data); }; WebManager.ExecuteAction( new ActionContext( selectActionArgs ) { Origin = ActionDS.ActionSourceControl ?? ActionDS.NamingContainer, Sender = ActionDS }); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { var selectArgs = new ProviderDataSourceSelectEventArgs(arguments); DS.OnSelecting(this, selectArgs); var provider = WebManager.GetService<IProvider<object,object>>(DS.ProviderName); if (provider==null) throw new Exception("Underlying data provider service not found: "+DS.ProviderName); var result = provider.Provide(selectArgs.ProviderContext); var resultList = result is IList ? (IList)result : new object[] { result }; var resultArr = new object[resultList.Count]; for (int i = 0; i < resultList.Count; i++) resultArr[i] = resultList[i] is IDictionary ? new DictionaryView((IDictionary)resultList[i]) : resultList[i]; callback(resultArr); }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { ModelDataSourceMethod method; if (RequireAsyncModelBinding(SelectMethod, out method)) { // We have to remember the method to make sure the method we later would use in the async function // is the method we validate here in case the method later might be changed by UpdateProperties. SelectAsync(arguments, callback, method); } else { base.Select(arguments, callback); } }
public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) { base.Select(arguments, callback); }
private void SelectAsync(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback, ModelDataSourceMethod method) { Func<object, Task> func = GetSelectAsyncFunc(arguments, callback, method); var syncContext = _owner.DataControl.Page.Context.SyncContext as AspNetSynchronizationContext; if (null == syncContext) { throw new InvalidOperationException(SR.GetString(SR.ModelDataSourceView_UseAsyncMethodMustBeUsingAsyncPage)); } // The first edition of the async model binding feature was implemented by registering async binding // function as PageAsyncTask. We, however, decided not to do that because postponing data binding // to page async point changed the order of page events and caused many problems. // See the comment on SynchronizationHelper.QueueAsynchronousAsync for more details regarding to the PostAsync // function. syncContext.PostAsync(func, null); }
private Func<object, Task> GetSelectAsyncFunc(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback, ModelDataSourceMethod method) { Func<object, Task> func = async _ => { ValidateAsyncModelBindingRequirements(); CancellationTokenSource cancellationTokenSource = _owner.DataControl.Page.CreateCancellationTokenFromAsyncTimeout(); CancellationToken cancellationToken = cancellationTokenSource.Token; DataSourceSelectResultProcessingOptions selectResultProcessingOptions = null; ModelDataSourceMethod modelMethod = EvaluateSelectMethodParameters(arguments, method, true/*isAsyncSelect*/, out selectResultProcessingOptions); SetCancellationTokenIfRequired(modelMethod, true/*isAsyncMethod*/, cancellationToken); ModelDataMethodResult result = InvokeMethod(modelMethod); IEnumerable finalResult = null; if (result.ReturnValue != null) { await (Task)result.ReturnValue; var returnValue = GetPropertyValueByName(result.ReturnValue, "Result"); if (null == returnValue) { // do nothing } // Users needs to use SelectResult as return type to use // custom paging. else if (returnValue is SelectResult) { var viewOperationTask = _viewOperationTask; if (viewOperationTask != null) { await viewOperationTask; } var selectResult = (SelectResult)returnValue; arguments.TotalRowCount = selectResult.TotalRowCount; finalResult = CreateSelectResult(selectResult.Results, true/*isAsyncSelect*/); } else { // The returnValue does not have to run through ProcessSelectMethodResult() as we // don't support auto-paging or auto-sorting when using async select. finalResult = CreateSelectResult(returnValue, true/*isAsyncSelect*/); } } callback(finalResult); if (cancellationToken.IsCancellationRequested) { throw new TimeoutException(SR.GetString(SR.Async_task_timed_out)); } }; return func; }
public virtual void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) {}
public virtual void Select (DataSourceSelectArguments selectArgs, DataSourceViewSelectCallback callBack) { if (callBack == null) throw new ArgumentNullException("callBack"); selectArgs.RaiseUnsupportedCapabilitiesError (this); IEnumerable selectList = ExecuteSelect (selectArgs); callBack (selectList); }
// For unit testing. // Return the select async func that we use in the SelectAsync method. internal Func<object, Task> SelectAsyncInternal(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback, ModelDataSourceMethod method) { return GetSelectAsyncFunc(arguments, callback, method); }