Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WebForms / System / Web / UI / Design / DataSourceDesigner.cs / 1 / DataSourceDesigner.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.Design { using System.ComponentModel; using System.Collections; using System.ComponentModel.Design; using System.Design; using System.Drawing; ///[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] public class DataSourceDesigner : ControlDesigner, IDataSourceDesigner { private event EventHandler _dataSourceChangedEvent; private event EventHandler _schemaRefreshedEvent; private int _suppressEventsCount; private bool _raiseDataSourceChangedEvent; private bool _raiseSchemaRefreshedEvent; /// public override DesignerActionListCollection ActionLists { get { DesignerActionListCollection actionLists = new DesignerActionListCollection(); actionLists.AddRange(base.ActionLists); actionLists.Add(new DataSourceDesignerActionList(this)); return actionLists; } } /// /// /// Indicates whether the Configure() method can be called. /// public virtual bool CanConfigure { get { return false; } } ////// /// Indicates whether the RefreshSchema() method can be called. /// public virtual bool CanRefreshSchema { get { return false; } } ////// Raised when the properties of the DataSource have changed. This allows /// a data-bound control designer to take actions to refresh its /// control in the designer. /// public event EventHandler DataSourceChanged { add { _dataSourceChangedEvent += value; } remove { _dataSourceChangedEvent -= value; } } ////// Raised when the schema of the DataSource has changed. This notifies /// a data-bound control designer that the available schema fields have /// changed. /// public event EventHandler SchemaRefreshed { add { _schemaRefreshedEvent += value; } remove { _schemaRefreshedEvent -= value; } } protected bool SuppressingDataSourceEvents { get { return (_suppressEventsCount > 0); } } ////// /// Launches the data source's configuration wizard. /// This method should only be called if the CanConfigure property is true. /// public virtual void Configure() { throw new NotSupportedException(); } ////// /// Gets the design-time HTML. /// public override string GetDesignTimeHtml() { return CreatePlaceHolderDesignTimeHtml(); } ////// /// Gets a DesignerDataSourceView representing the view indicated by /// the viewName parameter. If the view does not exist, null should /// be returned. /// public virtual DesignerDataSourceView GetView(string viewName) { return null; } ////// /// Returns an array of the view names available in this data source. /// public virtual string[] GetViewNames() { return new string[0]; } ////// Raises the DataSourceChanged ecent. /// protected virtual void OnDataSourceChanged(EventArgs e) { if (SuppressingDataSourceEvents) { _raiseDataSourceChangedEvent = true; return; } if (_dataSourceChangedEvent != null) { _dataSourceChangedEvent(this, e); } _raiseDataSourceChangedEvent = false; } ////// Raises the SchemaRefreshed event. /// protected virtual void OnSchemaRefreshed(EventArgs e) { if (SuppressingDataSourceEvents) { _raiseSchemaRefreshedEvent = true; return; } if (_schemaRefreshedEvent != null) { _schemaRefreshedEvent(this, e); } _raiseSchemaRefreshedEvent = false; } public virtual void RefreshSchema(bool preferSilent) { throw new NotSupportedException(); } public virtual void ResumeDataSourceEvents() { if (_suppressEventsCount == 0) { throw new InvalidOperationException(SR.GetString(SR.DataSource_CannotResumeEvents)); } _suppressEventsCount--; if (_suppressEventsCount == 0) { // If this is the last call to resume, we raise the events if necessary if (_raiseDataSourceChangedEvent) { OnDataSourceChanged(EventArgs.Empty); } if (_raiseSchemaRefreshedEvent) { OnSchemaRefreshed(EventArgs.Empty); } } } public virtual void SuppressDataSourceEvents() { _suppressEventsCount++; } ////// Compares two schemas based on their views and the names and types /// of the fields in the views they contain. Returns true if they are /// equivalent. /// public static bool SchemasEquivalent(IDataSourceSchema schema1, IDataSourceSchema schema2) { if (schema1 == null ^ schema2 == null) { return false; } if (schema1 == null && schema2 == null) { return true; } IDataSourceViewSchema[] viewSchemas1 = schema1.GetViews(); IDataSourceViewSchema[] viewSchemas2 = schema2.GetViews(); if (viewSchemas1 == null ^ viewSchemas2 == null) { return false; } if (viewSchemas1 == null && viewSchemas2 == null) { return true; } int viewSchemasCount1 = viewSchemas1.Length; int viewSchemasCount2 = viewSchemas2.Length; if (viewSchemasCount1 != viewSchemasCount2) { return false; } foreach (IDataSourceViewSchema viewSchema1 in viewSchemas1) { bool foundView = false; string viewName1 = viewSchema1.Name; foreach (IDataSourceViewSchema viewSchema2 in viewSchemas2) { if (viewName1 == viewSchema2.Name && ViewSchemasEquivalent(viewSchema1, viewSchema2)) { foundView = true; break; } } if (!foundView) { return false; } } return true; } ////// Compares two view schemas based on the names and types of the /// fields they contain. Returns true if they are equivalent. /// public static bool ViewSchemasEquivalent(IDataSourceViewSchema viewSchema1, IDataSourceViewSchema viewSchema2) { if (viewSchema1 == null ^ viewSchema2 == null) { return false; } if (viewSchema1 == null && viewSchema2 == null) { return true; } IDataSourceFieldSchema[] fieldSchemas1 = viewSchema1.GetFields(); IDataSourceFieldSchema[] fieldSchemas2 = viewSchema2.GetFields(); if (fieldSchemas1 == null ^ fieldSchemas2 == null) { return false; } if (fieldSchemas1 == null && fieldSchemas2 == null) { return true; } int fieldSchemasCount1 = fieldSchemas1.Length; int fieldSchemasCount2 = fieldSchemas2.Length; if (fieldSchemasCount1 != fieldSchemasCount2) { return false; } foreach (IDataSourceFieldSchema fieldSchema1 in fieldSchemas1) { bool foundField = false; string fieldName1 = fieldSchema1.Name; Type fieldType1 = fieldSchema1.DataType; foreach (IDataSourceFieldSchema fieldSchema2 in fieldSchemas2) { if (fieldName1 == fieldSchema2.Name && fieldType1 == fieldSchema2.DataType) { foundField = true; break; } } if (!foundField) { return false; } } return true; } private class DataSourceDesignerActionList : DesignerActionList { private DataSourceDesigner _parent; public DataSourceDesignerActionList(DataSourceDesigner parent) : base(parent.Component) { _parent = parent; } public override bool AutoShow { get { return true; } set { } } public void Configure() { _parent.Configure(); } public void RefreshSchema() { _parent.RefreshSchema(false); } public override DesignerActionItemCollection GetSortedActionItems() { DesignerActionItemCollection items = new DesignerActionItemCollection(); if (_parent.CanConfigure) { DesignerActionMethodItem methodItem = new DesignerActionMethodItem(this, "Configure", SR.GetString(SR.DataSourceDesigner_ConfigureDataSourceVerb), SR.GetString(SR.DataSourceDesigner_DataActionGroup), SR.GetString(SR.DataSourceDesigner_ConfigureDataSourceVerbDesc), true); methodItem.AllowAssociate = true; items.Add(methodItem); } if (_parent.CanRefreshSchema) { DesignerActionMethodItem methodItem = new DesignerActionMethodItem(this, "RefreshSchema", SR.GetString(SR.DataSourceDesigner_RefreshSchemaVerb), SR.GetString(SR.DataSourceDesigner_DataActionGroup), SR.GetString(SR.DataSourceDesigner_RefreshSchemaVerbDesc), false); methodItem.AllowAssociate = true; items.Add(methodItem); } return items; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TypeConverter.cs
- StatusBarDrawItemEvent.cs
- SystemIPGlobalProperties.cs
- ParameterBuilder.cs
- ResourceExpressionEditorSheet.cs
- WindowsAuthenticationEventArgs.cs
- Point3DCollectionConverter.cs
- ReadOnlyDataSourceView.cs
- SendMailErrorEventArgs.cs
- XmlSchemaException.cs
- IsolationInterop.cs
- ExtendedPropertyInfo.cs
- SerialPinChanges.cs
- DataServiceContext.cs
- DragEventArgs.cs
- CardSpaceSelector.cs
- ToolZone.cs
- FontNamesConverter.cs
- FigureParagraph.cs
- MetabaseSettings.cs
- FlowDocumentFormatter.cs
- TransactionScope.cs
- relpropertyhelper.cs
- ListBoxItemAutomationPeer.cs
- DataControlFieldHeaderCell.cs
- CollaborationHelperFunctions.cs
- RegexTypeEditor.cs
- TextContainerHelper.cs
- JsonStringDataContract.cs
- SpellerError.cs
- EncryptedType.cs
- MultiDataTrigger.cs
- ListViewItemMouseHoverEvent.cs
- XslTransform.cs
- MetafileHeader.cs
- ValidatorCompatibilityHelper.cs
- MultiView.cs
- FixedPageStructure.cs
- OAVariantLib.cs
- CurrentTimeZone.cs
- XmlSchemaObjectCollection.cs
- OutputCacheProfileCollection.cs
- ACE.cs
- Int64KeyFrameCollection.cs
- HtmlCommandAdapter.cs
- SessionStateModule.cs
- DocumentViewerConstants.cs
- SizeFConverter.cs
- NativeMethods.cs
- DataGridColumnCollection.cs
- KeyedPriorityQueue.cs
- MinimizableAttributeTypeConverter.cs
- XmlJsonWriter.cs
- updatecommandorderer.cs
- NamespaceCollection.cs
- Vector.cs
- TypedCompletedAsyncResult.cs
- Span.cs
- DataGridViewColumnConverter.cs
- _OverlappedAsyncResult.cs
- SocketSettings.cs
- SessionParameter.cs
- ObjectDataSourceMethodEventArgs.cs
- StaticContext.cs
- ValidationRule.cs
- AmbientValueAttribute.cs
- Gdiplus.cs
- CanonicalFontFamilyReference.cs
- InkPresenterAutomationPeer.cs
- WebBrowserDocumentCompletedEventHandler.cs
- TemplatedAdorner.cs
- CatalogPartDesigner.cs
- OutputCacheSettings.cs
- XmlQuerySequence.cs
- StyleTypedPropertyAttribute.cs
- InfoCardTrace.cs
- ObjectHandle.cs
- TextTreeRootTextBlock.cs
- DoubleSumAggregationOperator.cs
- OperatorExpressions.cs
- TargetInvocationException.cs
- DynamicEndpointElement.cs
- XPathConvert.cs
- WindowsUpDown.cs
- bidPrivateBase.cs
- TraceUtils.cs
- XamlTypeMapper.cs
- FunctionNode.cs
- WebEvents.cs
- PageCatalogPart.cs
- PropertyDescriptorGridEntry.cs
- BitmapEffect.cs
- DataGridHeaderBorder.cs
- AssociationSetMetadata.cs
- StylusPointCollection.cs
- WhitespaceRule.cs
- AppliedDeviceFiltersDialog.cs
- FeatureSupport.cs
- DBSqlParserTable.cs
- FlowSwitchLink.cs