Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Web / System / Web / Services / Discovery / DynamicDiscoSearcher.cs / 1305376 / DynamicDiscoSearcher.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Services.Discovery { using System; using System.IO; using System.Collections; using System.Web; using System.Web.Caching; using System.Diagnostics; using System.Text; using System.DirectoryServices; using System.Web.Services.Configuration; using System.ComponentModel; using System.Globalization; ////// /// Does a recursive search of subdirectories (physical and virtual) to find stuff to /// make a disco file from. *.disco files (or whatever the PrimarySearchPattern is) are /// treated as end-points - recursion stops where they are found. /// It's a base class for DynamicVirtualDiscoSearcher and DynamicPhysicalDiscoSearcher. /// internal abstract class DynamicDiscoSearcher { protected string origUrl; // original URL to start search protected string[] excludedUrls; // names relative to starting path protected string fileToSkipFirst; // name of file to skip on 1st level protected ArrayList filesFound; protected DiscoverySearchPattern[] primarySearchPatterns = null; protected DiscoverySearchPattern[] secondarySearchPatterns = null; protected DiscoveryDocument discoDoc = new DiscoveryDocument(); protected Hashtable excludedUrlsTable = null; protected int subDirLevel = 0; // current nested level of subdirectory relative to search root // ------------------------------------------------------------------------------- internal DynamicDiscoSearcher(string[] excludeUrlsList) { excludedUrls = excludeUrlsList; filesFound = new ArrayList(); } // ------------------------------------------------------------------------------- internal virtual void SearchInit(string fileToSkipAtBegin) { subDirLevel = 0; fileToSkipFirst = fileToSkipAtBegin; } // -------------------------------------------------------------------------------- protected bool IsExcluded(string url) { if (excludedUrlsTable == null) { excludedUrlsTable = new Hashtable(); foreach (string s in excludedUrls) { Debug.Assert( s != null, "null element in excluded list" ); excludedUrlsTable.Add( MakeAbsExcludedPath(s).ToLower(CultureInfo.InvariantCulture), null); } } return excludedUrlsTable.Contains( url.ToLower(CultureInfo.InvariantCulture) ); } // ------------------------------------------------------------------------------- internal DiscoveryDocument DiscoveryDocument { get { return discoDoc; } } // -------------------------------------------------------------------------------- internal DiscoverySearchPattern[] PrimarySearchPattern { get { if (primarySearchPatterns == null) { // For the primary search the pattern is ".vsdisco" primarySearchPatterns = new DiscoverySearchPattern[] { new DiscoveryDocumentSearchPattern() } ; } return primarySearchPatterns; } } // -------------------------------------------------------------------------------- internal DiscoverySearchPattern[] SecondarySearchPattern { get { if (secondarySearchPatterns == null) { // ****** Get pattern type from Config (no more needed) ******* // Type[] searchPattern = WebServicesConfiguration.Current.DiscoverySearchPatternTypes; // secondarySearchPatterns = new DiscoverySearchPattern[searchPattern.Length]; // // for (int i = 0; i < searchPattern.Length; i++) { // secondarySearchPatterns[i] = (DiscoverySearchPattern) Activator.CreateInstance(searchPattern[i]); // } secondarySearchPatterns = new DiscoverySearchPattern[] { new ContractSearchPattern(), new DiscoveryDocumentLinksPattern() }; } return secondarySearchPatterns; } } // ------------------------------------------------------------------------------- // Invokes searching by patterns in current dir. If needed, initiates further search in subdirectories. protected void ScanDirectory(string directory) { if ( CompModSwitches.DynamicDiscoverySearcher.TraceVerbose ) Debug.WriteLine( "DynamicDiscoSearcher.ScanDirectory(): directory=" + directory); if ( IsExcluded(directory) ) // what name is meant here? return; bool primaryFound = ScanDirByPattern(directory, true /*primary*/, PrimarySearchPattern); if (!primaryFound) { if (!IsVirtualSearch ) { ScanDirByPattern(directory, false /*secondary*/, SecondarySearchPattern); }else { // We restrict second stage of a virtual discovery only to static .disco documents // We assume that starting directory does not need a second stage if (subDirLevel != 0) { DiscoverySearchPattern[] staticDiscoPattern = new DiscoverySearchPattern[] { new DiscoveryDocumentLinksPattern() }; ScanDirByPattern(directory, false /*secondary*/, staticDiscoPattern); } } if ( IsVirtualSearch && subDirLevel > 0 ) return; // stop search in subdir levels deeper than 1 for virtual search subDirLevel++; fileToSkipFirst = ""; // do not skip this file on lower levels SearchSubDirectories(directory); // search deeper (indirect recursion) subDirLevel--; } } // -------------------------------------------------------------------------------- // Looks in a physical directory for a file matching whatever the configured pattern is. // Returns: 'true' if primary file has been found (and added to Discovery References). protected bool ScanDirByPattern(string dir, bool IsPrimary, DiscoverySearchPattern[] patterns) { DirectoryInfo directory = GetPhysicalDir(dir); // comment here if ( directory == null ) return false; if ( CompModSwitches.DynamicDiscoverySearcher.TraceVerbose ) Debug.WriteLine( "= DynamicDiscoSearcher.ScanDirByPattern(): dir=" + dir + " Phys.dir=" + directory.Name); bool isFileFound = false; for (int i = 0; i < patterns.Length; i++) { FileInfo[] files = directory.GetFiles(patterns[i].Pattern); // search in dir foreach (FileInfo file in files) { if ((file.Attributes & FileAttributes.Directory) == 0) { if ( CompModSwitches.DynamicDiscoverySearcher.TraceVerbose ) Debug.WriteLine( "=== DynamicDiscoSearcher.ScanDirByPattern(): file.Name=" + file.Name + " fileToSkipFirst=" + fileToSkipFirst); // first skip given (i.e. starting) file if ( String.Compare(file.Name, fileToSkipFirst, StringComparison.OrdinalIgnoreCase) == 0 ) { // ignore case compare continue; } string resultName = MakeResultPath(dir, file.Name); filesFound.Add( resultName ); discoDoc.References.Add(patterns[i].GetDiscoveryReference(resultName)); isFileFound = true; } } } return (IsPrimary && isFileFound); } // ------------ abstract methods ----------------- ////// /// Main function. Searches dir recursively for primary (.vsdisco) and seconary (.asmx) files. /// internal abstract void Search(string fileToSkipAtBegin); // Gets phisycal directory info from its virtual or actual name. protected abstract DirectoryInfo GetPhysicalDir(string dir ); // Search given directory for subdirectories, feasable for further searching. protected abstract void SearchSubDirectories(string directory); // Makes result URL found file path from diectory name and short file name. protected abstract string MakeResultPath(string dirName, string fileName); // Makes exclusion path absolute for quick comparision on search. protected abstract string MakeAbsExcludedPath(string pathRelativ); // 'true' if search isVirtual protected abstract bool IsVirtualSearch { get; } } } // 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
- ConfigurationStrings.cs
- SchemaCollectionPreprocessor.cs
- ShapeTypeface.cs
- TextTrailingCharacterEllipsis.cs
- OutputCacheProfileCollection.cs
- DelegatedStream.cs
- RequestCacheValidator.cs
- keycontainerpermission.cs
- MouseCaptureWithinProperty.cs
- Single.cs
- WCFBuildProvider.cs
- cookie.cs
- SectionRecord.cs
- OpacityConverter.cs
- CodeMemberEvent.cs
- CompensationTokenData.cs
- ClientConfigPaths.cs
- TabControl.cs
- Sentence.cs
- Timer.cs
- ClaimComparer.cs
- XPathSingletonIterator.cs
- HostingEnvironmentException.cs
- Types.cs
- ContainerFilterService.cs
- DescriptionAttribute.cs
- SqlRetyper.cs
- RectangleHotSpot.cs
- EventNotify.cs
- ConfigurationElementCollection.cs
- MouseEvent.cs
- MimePart.cs
- WebScriptMetadataMessageEncodingBindingElement.cs
- SqlMetaData.cs
- Int32AnimationUsingKeyFrames.cs
- WindowsListViewItemStartMenu.cs
- CacheSection.cs
- PerspectiveCamera.cs
- BevelBitmapEffect.cs
- DesignSurfaceEvent.cs
- MembershipSection.cs
- EventlogProvider.cs
- MultiView.cs
- XmlArrayItemAttributes.cs
- AttributeEmitter.cs
- DetailsViewModeEventArgs.cs
- SerializationAttributes.cs
- CAGDesigner.cs
- BamlResourceSerializer.cs
- ResourceDictionaryCollection.cs
- SqlColumnizer.cs
- ListViewDesigner.cs
- ItemsChangedEventArgs.cs
- XmlSchemaImporter.cs
- SqlTypesSchemaImporter.cs
- ScrollProperties.cs
- StrongTypingException.cs
- InstanceData.cs
- HtmlMobileTextWriter.cs
- CodeGenerator.cs
- ListCardsInFileRequest.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- regiisutil.cs
- UnsafeNativeMethods.cs
- ADMembershipUser.cs
- DataGridViewRowEventArgs.cs
- _SingleItemRequestCache.cs
- TextServicesDisplayAttribute.cs
- XPathMultyIterator.cs
- ListViewSelectEventArgs.cs
- SafeLibraryHandle.cs
- DataDesignUtil.cs
- MdiWindowListStrip.cs
- FrameworkElementFactoryMarkupObject.cs
- MemberListBinding.cs
- JavaScriptSerializer.cs
- AuthorizationRuleCollection.cs
- SurrogateDataContract.cs
- MarkupObject.cs
- Menu.cs
- MetaModel.cs
- DecimalConstantAttribute.cs
- ColorContextHelper.cs
- SingleObjectCollection.cs
- SharedStatics.cs
- MsmqBindingElementBase.cs
- VScrollProperties.cs
- FaultDescriptionCollection.cs
- ShaderEffect.cs
- UserNameSecurityToken.cs
- Model3D.cs
- SinglePageViewer.cs
- ListViewGroup.cs
- DateTimePicker.cs
- DbConnectionStringCommon.cs
- ExpressionBuilder.cs
- PageThemeParser.cs
- DialogWindow.cs
- FragmentQueryKB.cs
- ClipboardData.cs