Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / UI / DataSourceView.cs / 1 / DataSourceView.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI {
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public abstract class DataSourceView {
private static readonly object EventDataSourceViewChanged = new object();
private EventHandlerList _events;
private string _name;
protected DataSourceView(IDataSource owner, string viewName) {
if (owner == null) {
throw new ArgumentNullException("owner");
}
if (viewName == null) {
throw new ArgumentNullException("viewName");
}
_name = viewName;
DataSourceControl dataSourceControl = owner as DataSourceControl;
if (dataSourceControl != null) {
dataSourceControl.DataSourceChangedInternal += new EventHandler(OnDataSourceChangedInternal);
}
else {
owner.DataSourceChanged += new EventHandler(OnDataSourceChangedInternal);
}
}
// CanX properties indicate whether the data source allows each
// operation, and if so, whether it's appropriate to do so.
// For instance, a control may allow Deletion, but if a required Delete
// command isn't set, CanDelete should be false, because a Delete
// operation would fail.
public virtual bool CanDelete {
get {
return false;
}
}
public virtual bool CanInsert {
get {
return false;
}
}
public virtual bool CanPage {
get {
return false;
}
}
public virtual bool CanRetrieveTotalRowCount {
get {
return false;
}
}
public virtual bool CanSort {
get {
return false;
}
}
public virtual bool CanUpdate {
get {
return false;
}
}
///
/// Indicates the list of event handler delegates for the view. This property is read-only.
///
protected EventHandlerList Events {
get {
if (_events == null) {
_events = new EventHandlerList();
}
return _events;
}
}
public string Name {
get {
return _name;
}
}
public event EventHandler DataSourceViewChanged {
add {
Events.AddHandler(EventDataSourceViewChanged, value);
}
remove {
Events.RemoveHandler(EventDataSourceViewChanged, value);
}
}
public virtual void Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) {
if (callback == null) {
throw new ArgumentNullException("callback");
}
int affectedRecords = 0;
bool performedCallback = false;
try {
affectedRecords = ExecuteDelete(keys, oldValues);
}
catch (Exception ex) {
performedCallback = true;
if (!callback(affectedRecords, ex)) {
throw;
}
}
finally {
if (!performedCallback) {
callback(affectedRecords, null);
}
}
}
///
/// Performs a delete operation on the specified list. This is only
/// supported by a DataSourceControl when CanDelete returns true.
///
///
/// The set of name/value pairs used to filter
/// the items in the list that should be deleted.
///
///
/// The complete set of name/value pairs used to filter
/// the items in the list that should be deleted.
///
///
/// The number of items that were affected by the operation.
///
protected virtual int ExecuteDelete(IDictionary keys, IDictionary oldValues) {
throw new NotSupportedException();
}
///
/// Performs an insert operation on the specified list. This is only
/// supported by a DataControl when CanInsert is true.
///
///
/// The set of name/value pairs to be used to initialize
/// a new item in the list.
///
///
/// The number of items that were affected by the operation.
///
protected virtual int ExecuteInsert(IDictionary values) {
throw new NotSupportedException();
}
///
///
protected internal abstract IEnumerable ExecuteSelect(DataSourceSelectArguments arguments);
///
/// Performs an update operation on the specified list. This is only
/// supported by a DataControl when CanUpdate is true.
///
///
/// The set of name/value pairs used to filter
/// the items in the list that should be updated.
///
///
/// The set of name/value pairs to be used to update the
/// items in the list.
///
///
/// The set of name/value pairs to be used to identify the
/// item to be updated.
///
///
/// The number of items that were affected by the operation.
///
protected virtual int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) {
throw new NotSupportedException();
}
private void OnDataSourceChangedInternal(object sender, EventArgs e) {
OnDataSourceViewChanged(e);
}
protected virtual void OnDataSourceViewChanged(EventArgs e) {
EventHandler handler = Events[EventDataSourceViewChanged] as EventHandler;
if (handler != null) {
handler(this, e);
}
}
public virtual void Insert(IDictionary values, DataSourceViewOperationCallback callback) {
if (callback == null) {
throw new ArgumentNullException("callback");
}
int affectedRecords = 0;
bool performedCallback = false;
try {
affectedRecords = ExecuteInsert(values);
}
catch (Exception ex) {
performedCallback = true;
if (!callback(affectedRecords, ex)) {
throw;
}
}
finally {
if (!performedCallback) {
callback(affectedRecords, null);
}
}
}
protected internal virtual void RaiseUnsupportedCapabilityError(DataSourceCapabilities capability) {
if (!CanPage && ((capability & DataSourceCapabilities.Page) != 0)) {
throw new NotSupportedException(SR.GetString(SR.DataSourceView_NoPaging));
}
if (!CanSort && ((capability & DataSourceCapabilities.Sort) != 0)) {
throw new NotSupportedException(SR.GetString(SR.DataSourceView_NoSorting));
}
if (!CanRetrieveTotalRowCount && ((capability & DataSourceCapabilities.RetrieveTotalRowCount) != 0)) {
throw new NotSupportedException(SR.GetString(SR.DataSourceView_NoRowCount));
}
}
public virtual void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) {
if (callback == null) {
throw new ArgumentNullException("callback");
}
callback(ExecuteSelect(arguments));
}
public virtual void Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) {
if (callback == null) {
throw new ArgumentNullException("callback");
}
int affectedRecords = 0;
bool performedCallback = false;
try {
affectedRecords = ExecuteUpdate(keys, values, oldValues);
}
catch (Exception ex) {
performedCallback = true;
if (!callback(affectedRecords, ex)) {
throw;
}
}
finally {
if (!performedCallback) {
callback(affectedRecords, null);
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI {
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions;
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public abstract class DataSourceView {
private static readonly object EventDataSourceViewChanged = new object();
private EventHandlerList _events;
private string _name;
protected DataSourceView(IDataSource owner, string viewName) {
if (owner == null) {
throw new ArgumentNullException("owner");
}
if (viewName == null) {
throw new ArgumentNullException("viewName");
}
_name = viewName;
DataSourceControl dataSourceControl = owner as DataSourceControl;
if (dataSourceControl != null) {
dataSourceControl.DataSourceChangedInternal += new EventHandler(OnDataSourceChangedInternal);
}
else {
owner.DataSourceChanged += new EventHandler(OnDataSourceChangedInternal);
}
}
// CanX properties indicate whether the data source allows each
// operation, and if so, whether it's appropriate to do so.
// For instance, a control may allow Deletion, but if a required Delete
// command isn't set, CanDelete should be false, because a Delete
// operation would fail.
public virtual bool CanDelete {
get {
return false;
}
}
public virtual bool CanInsert {
get {
return false;
}
}
public virtual bool CanPage {
get {
return false;
}
}
public virtual bool CanRetrieveTotalRowCount {
get {
return false;
}
}
public virtual bool CanSort {
get {
return false;
}
}
public virtual bool CanUpdate {
get {
return false;
}
}
///
/// Indicates the list of event handler delegates for the view. This property is read-only.
///
protected EventHandlerList Events {
get {
if (_events == null) {
_events = new EventHandlerList();
}
return _events;
}
}
public string Name {
get {
return _name;
}
}
public event EventHandler DataSourceViewChanged {
add {
Events.AddHandler(EventDataSourceViewChanged, value);
}
remove {
Events.RemoveHandler(EventDataSourceViewChanged, value);
}
}
public virtual void Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) {
if (callback == null) {
throw new ArgumentNullException("callback");
}
int affectedRecords = 0;
bool performedCallback = false;
try {
affectedRecords = ExecuteDelete(keys, oldValues);
}
catch (Exception ex) {
performedCallback = true;
if (!callback(affectedRecords, ex)) {
throw;
}
}
finally {
if (!performedCallback) {
callback(affectedRecords, null);
}
}
}
///
/// Performs a delete operation on the specified list. This is only
/// supported by a DataSourceControl when CanDelete returns true.
///
///
/// The set of name/value pairs used to filter
/// the items in the list that should be deleted.
///
///
/// The complete set of name/value pairs used to filter
/// the items in the list that should be deleted.
///
///
/// The number of items that were affected by the operation.
///
protected virtual int ExecuteDelete(IDictionary keys, IDictionary oldValues) {
throw new NotSupportedException();
}
///
/// Performs an insert operation on the specified list. This is only
/// supported by a DataControl when CanInsert is true.
///
///
/// The set of name/value pairs to be used to initialize
/// a new item in the list.
///
///
/// The number of items that were affected by the operation.
///
protected virtual int ExecuteInsert(IDictionary values) {
throw new NotSupportedException();
}
///
///
protected internal abstract IEnumerable ExecuteSelect(DataSourceSelectArguments arguments);
///
/// Performs an update operation on the specified list. This is only
/// supported by a DataControl when CanUpdate is true.
///
///
/// The set of name/value pairs used to filter
/// the items in the list that should be updated.
///
///
/// The set of name/value pairs to be used to update the
/// items in the list.
///
///
/// The set of name/value pairs to be used to identify the
/// item to be updated.
///
///
/// The number of items that were affected by the operation.
///
protected virtual int ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) {
throw new NotSupportedException();
}
private void OnDataSourceChangedInternal(object sender, EventArgs e) {
OnDataSourceViewChanged(e);
}
protected virtual void OnDataSourceViewChanged(EventArgs e) {
EventHandler handler = Events[EventDataSourceViewChanged] as EventHandler;
if (handler != null) {
handler(this, e);
}
}
public virtual void Insert(IDictionary values, DataSourceViewOperationCallback callback) {
if (callback == null) {
throw new ArgumentNullException("callback");
}
int affectedRecords = 0;
bool performedCallback = false;
try {
affectedRecords = ExecuteInsert(values);
}
catch (Exception ex) {
performedCallback = true;
if (!callback(affectedRecords, ex)) {
throw;
}
}
finally {
if (!performedCallback) {
callback(affectedRecords, null);
}
}
}
protected internal virtual void RaiseUnsupportedCapabilityError(DataSourceCapabilities capability) {
if (!CanPage && ((capability & DataSourceCapabilities.Page) != 0)) {
throw new NotSupportedException(SR.GetString(SR.DataSourceView_NoPaging));
}
if (!CanSort && ((capability & DataSourceCapabilities.Sort) != 0)) {
throw new NotSupportedException(SR.GetString(SR.DataSourceView_NoSorting));
}
if (!CanRetrieveTotalRowCount && ((capability & DataSourceCapabilities.RetrieveTotalRowCount) != 0)) {
throw new NotSupportedException(SR.GetString(SR.DataSourceView_NoRowCount));
}
}
public virtual void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) {
if (callback == null) {
throw new ArgumentNullException("callback");
}
callback(ExecuteSelect(arguments));
}
public virtual void Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) {
if (callback == null) {
throw new ArgumentNullException("callback");
}
int affectedRecords = 0;
bool performedCallback = false;
try {
affectedRecords = ExecuteUpdate(keys, values, oldValues);
}
catch (Exception ex) {
performedCallback = true;
if (!callback(affectedRecords, ex)) {
throw;
}
}
finally {
if (!performedCallback) {
callback(affectedRecords, null);
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HTMLTextWriter.cs
- BStrWrapper.cs
- DataRelation.cs
- querybuilder.cs
- UriExt.cs
- ProjectionPlanCompiler.cs
- WindowsContainer.cs
- ConfigXmlAttribute.cs
- DataGridViewLinkCell.cs
- KeyValueInternalCollection.cs
- ConfigurationSettings.cs
- HelpFileFileNameEditor.cs
- HtmlTitle.cs
- HelloOperationCD1AsyncResult.cs
- TrustManagerPromptUI.cs
- DefaultValidator.cs
- RoleBoolean.cs
- WebPartConnection.cs
- ExtractedStateEntry.cs
- webproxy.cs
- DesignerTransaction.cs
- BindingObserver.cs
- Int32AnimationUsingKeyFrames.cs
- Stacktrace.cs
- DesignerSerializationManager.cs
- SessionPageStatePersister.cs
- RadioButtonBaseAdapter.cs
- StandardOleMarshalObject.cs
- XPathExpr.cs
- ZipIOExtraFieldZip64Element.cs
- UpDownEvent.cs
- BlockCollection.cs
- XmlLanguage.cs
- _AutoWebProxyScriptEngine.cs
- MultiSelectRootGridEntry.cs
- InvalidCommandTreeException.cs
- ScriptBehaviorDescriptor.cs
- AnnotationObservableCollection.cs
- MarkupCompilePass1.cs
- SequentialActivityDesigner.cs
- AdornerHitTestResult.cs
- DynamicRendererThreadManager.cs
- DataSourceView.cs
- DataServiceHostFactory.cs
- DataBindingCollectionConverter.cs
- ZipPackagePart.cs
- GiveFeedbackEventArgs.cs
- Point.cs
- FirstQueryOperator.cs
- EmptyQuery.cs
- CodeRegionDirective.cs
- JournalNavigationScope.cs
- DrawListViewColumnHeaderEventArgs.cs
- DescendantQuery.cs
- IsolatedStorageException.cs
- SqlMetaData.cs
- __Filters.cs
- DrawingAttributes.cs
- FileChangeNotifier.cs
- GACMembershipCondition.cs
- BaseCAMarshaler.cs
- TableRowsCollectionEditor.cs
- HttpWriter.cs
- TextModifier.cs
- ToolStripDropDownClosedEventArgs.cs
- SetterBaseCollection.cs
- Site.cs
- DescendantBaseQuery.cs
- DesignerEventService.cs
- DynamicDiscoveryDocument.cs
- CacheEntry.cs
- HttpResponseBase.cs
- WebProxyScriptElement.cs
- SystemPens.cs
- AdornerLayer.cs
- SqlUDTStorage.cs
- BindableTemplateBuilder.cs
- DrawingGroupDrawingContext.cs
- SqlAggregateChecker.cs
- InheritanceAttribute.cs
- ImageFormat.cs
- KeyGesture.cs
- OpCopier.cs
- RawStylusInput.cs
- SqlBulkCopyColumnMapping.cs
- UseLicense.cs
- BitmapScalingModeValidation.cs
- TitleStyle.cs
- PersonalizableTypeEntry.cs
- CodeAccessSecurityEngine.cs
- ProfileSection.cs
- StatusBarItem.cs
- CustomError.cs
- SchemaElementDecl.cs
- ArrayElementGridEntry.cs
- QilInvokeEarlyBound.cs
- BehaviorEditorPart.cs
- nulltextcontainer.cs
- JoinGraph.cs
- ErrorActivity.cs