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
- ListMarkerLine.cs
- ApplicationDirectoryMembershipCondition.cs
- DoubleLinkListEnumerator.cs
- Pair.cs
- PathFigureCollectionValueSerializer.cs
- DeviceSpecificDialogCachedState.cs
- DBSchemaTable.cs
- OutputChannelBinder.cs
- PolyQuadraticBezierSegment.cs
- StyleSheetComponentEditor.cs
- ListViewGroupItemCollection.cs
- RequestCachePolicy.cs
- LocatorManager.cs
- ComEventsSink.cs
- FileUpload.cs
- SqlClientPermission.cs
- COSERVERINFO.cs
- WmpBitmapEncoder.cs
- DSASignatureFormatter.cs
- DataSourceConverter.cs
- FactoryGenerator.cs
- XsltLoader.cs
- FlatButtonAppearance.cs
- Directory.cs
- WebPartHelpVerb.cs
- DataBindingHandlerAttribute.cs
- EntityObject.cs
- ReceiveContextCollection.cs
- Translator.cs
- HtmlPhoneCallAdapter.cs
- ApplicationContext.cs
- StateManagedCollection.cs
- SingleAnimation.cs
- FixedTextBuilder.cs
- URLMembershipCondition.cs
- PriorityQueue.cs
- MdImport.cs
- LocalIdKeyIdentifierClause.cs
- XmlMemberMapping.cs
- Interlocked.cs
- SortableBindingList.cs
- XmlDomTextWriter.cs
- CodeCatchClauseCollection.cs
- RuntimeHelpers.cs
- AutomationElementIdentifiers.cs
- SmtpException.cs
- ApplicationFileParser.cs
- SmiEventStream.cs
- Int32Storage.cs
- SafeFileHandle.cs
- HostedHttpRequestAsyncResult.cs
- DataGridColumn.cs
- ContextStack.cs
- TextParagraphCache.cs
- PriorityRange.cs
- SQLInt16.cs
- String.cs
- CodeTypeConstructor.cs
- XPathNode.cs
- DataGridViewCellStateChangedEventArgs.cs
- VirtualPathProvider.cs
- WpfXamlMember.cs
- ObjectMemberMapping.cs
- UnhandledExceptionEventArgs.cs
- GestureRecognizer.cs
- DetailsViewInsertEventArgs.cs
- TemplateControlParser.cs
- DataSourceSelectArguments.cs
- ObjectDataSourceView.cs
- EmptyStringExpandableObjectConverter.cs
- TextTreePropertyUndoUnit.cs
- Dynamic.cs
- CheckBox.cs
- Fonts.cs
- Expression.cs
- BaseCollection.cs
- XmlEntityReference.cs
- BaseEntityWrapper.cs
- KeysConverter.cs
- ObjectListItem.cs
- CounterCreationDataCollection.cs
- XpsS0ValidatingLoader.cs
- PrintSystemException.cs
- HttpHeaderCollection.cs
- ObjectItemCachedAssemblyLoader.cs
- M3DUtil.cs
- StateManagedCollection.cs
- DriveNotFoundException.cs
- BinarySecretKeyIdentifierClause.cs
- SerializationHelper.cs
- NetworkInterface.cs
- ObjectDataSourceStatusEventArgs.cs
- VisualState.cs
- GeneralTransformGroup.cs
- Int16.cs
- PlanCompiler.cs
- SoapTransportImporter.cs
- GridViewPageEventArgs.cs
- TemplateComponentConnector.cs
- odbcmetadatacollectionnames.cs