public void SetupBrowserData(ExternalResourceBrowserData browseData) { try { ExternalResourceMatchOptions options = browseData.GetMatchOptions(); ExternalResourceType resourceType = options.ResourceType; if (resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.KeynoteTable) { SetupKeynoteDatabaseBrowserData(browseData); } } catch (Exception ex) { string message = ex.Message; } }
/// <summary> /// <para>Provides Revit's file browser dialog with information for navigating a /// directory stucture of files available from the server.</para> /// <para>In this example implementation, the server simply echoes the directories /// and files that it locates under its RootFolder (subject to the appropriate file /// type filter pattern). </para> /// </summary> private void SetupFileBasedBrowserData(ExternalResourceBrowserData browserData) { ExternalResourceMatchOptions matchOptions = browserData.GetMatchOptions(); // filter some resources out by specified filter pattern ExternalResourceType resourceType = matchOptions.ResourceType; string filterPattern = resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.KeynoteTable ? "*.txt" : "*.rvt"; // Expose a "real" directory structure for the user to browse. // The server's root folder is specified in the RootFolder property. string folderPath = browserData.FolderPath; string path = RootFolder + folderPath.Replace('/', '\\'); if (Directory.Exists(path)) { DirectoryInfo dir = new DirectoryInfo(path); DirectoryInfo[] subDirs = dir.GetDirectories(); foreach (DirectoryInfo subDir in subDirs) { browserData.AddSubFolder(subDir.Name); } FileInfo[] subFiles = dir.GetFiles(filterPattern, SearchOption.TopDirectoryOnly); foreach (FileInfo file in subFiles) { if (resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.KeynoteTable) { browserData.AddResource(file.Name, GetFileVersion(file.FullName)); } else { var refMap = new Dictionary <String, String>(); // Relative Path of Link File is Stored in the ExternalResourceReference that // Will Be Addded to the BrowserData. refMap[RefMapLinkPathEntry] = folderPath.TrimEnd('/') + '/' + file.Name; browserData.AddResource(file.Name, GetFileVersion(file.FullName), refMap); } } } else { throw new ArgumentException("Path is invalid"); } }
/// <summary> /// Return a list of resources and sub folders under a folder. /// The Revit user always loads external resources by browsing with a file navigation /// dialog, much like they would when selecting files on a locally-accessible drive. /// The SetupBrowserData method allows the server implementer to simulate an organized /// system of files and folders to support browsing for external resources. /// Purely for demonstration purposes, this sample server obtains its keynote data from /// a "database," and creates a "fake" directory structure for either German or French users /// to browse keynote data. However, for all other users - and for Revit Links, file browsing /// data is generated using actual files on in a folder location under the directory containing /// this DLL. /// </summary> public void SetupBrowserData(ExternalResourceBrowserData browserData) { ExternalResourceMatchOptions matchOptions = browserData.GetMatchOptions(); ExternalResourceType resourceType = matchOptions.ResourceType; CultureInfo currentCulture = CultureInfo.CurrentCulture; String currentCultureName = currentCulture.ToString(); // Revit will call SupportsExternalResourceType() before calling this method, so we // can assume that resourceType will be KeynoteTable or RevitLink. if (resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.KeynoteTable && (currentCultureName == "de-DE" || currentCultureName == "fr-FR")) { // French and German Keynote Data Are Obtained From a "Database" SetupKeynoteDatabaseBrowserData(browserData, currentCultureName); } else { // Keynote Data in Other Languages, and Revit Links, are Obtained From File SetupFileBasedBrowserData(browserData); } }