public void SetupBrowserData(ExternalResourceBrowserData browserData)
        {
            string curPath = browserData.FolderPath;

            DBUtils.GetAllDBItems().ForEach(item =>
            {
                Dictionary <string, string> referenceInformation = new Dictionary <string, string>();
                referenceInformation["File"] = item.File;

                string toDisplay = DBUtils.GetDBItemName(item, Application.CurrentLanguage);
                if (!FileUtils.FileBelongsToFolder(curPath, toDisplay))
                {
                    return;
                }

                string [] dirInfo = FileUtils.SplitRelativePath(curPath, toDisplay);
                if (dirInfo.Length == 1)
                {
                    browserData.AddResource(dirInfo[0], "1", referenceInformation);
                }
                else if (dirInfo.Length > 1)
                {
                    if (!browserData.GetSubFolders().Contains(dirInfo[0]))
                    {
                        browserData.AddSubFolder(dirInfo[0]);
                    }
                }
            });
        }
Beispiel #2
0
        public void SetupKeynoteDatabaseBrowserData(ExternalResourceBrowserData browserData)
        {
            try
            {
                string folderPath    = browserData.FolderPath;
                string versionFolder = "RVT" + versionNumber;
                if (folderPath == "/")
                {
                    browserData.AddSubFolder("RVT2014");
                    browserData.AddSubFolder("RVT2015");
                    browserData.AddSubFolder("RVT2016");
                }
                else if (folderPath.EndsWith("/" + versionFolder))
                {
                    Dictionary <string, string> referenceMap = new Dictionary <string, string>();
                    referenceMap.Add("VersionNumber", versionNumber);
                    referenceMap.Add("ProjectName", "Test");
                    browserData.AddResource("Test Keynote.txt", KeynoteDatabase.GetCurrentVersion(), referenceMap);

                    Dictionary <string, string> referenceMap2 = new Dictionary <string, string>();
                    referenceMap2.Add("VersionNumber", versionNumber);
                    referenceMap2.Add("ProjectName", "LocalDB");
                    browserData.AddResource("KeynoteDB_local.txt", KeynoteDatabase.GetCurrentVersion(), referenceMap2);

                    Dictionary <string, string> referenceMap3 = new Dictionary <string, string>();
                    referenceMap3.Add("VersionNumber", versionNumber);
                    referenceMap3.Add("ProjectName", "CloudDB");
                    browserData.AddResource("KeynoteDB_cloud.txt", KeynoteDatabase.GetCurrentVersion(), referenceMap3);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
 public void SetupBrowserData(ExternalResourceBrowserData browserData)
 {
     Application.DynamoDBTables.ForEach(table =>
     {
         IDictionary <String, String> referenceInformation = new Dictionary <String, String>();
         referenceInformation["TableName"] = table;
         browserData.AddResource(table + ".txt", "1", referenceInformation);
     });
 }
        /// <summary>
        /// Provides Revit's file browser dialog with information for navigating the
        /// fictitious database containing French and German keynotes data.
        /// </summary>
        private void SetupKeynoteDatabaseBrowserData(ExternalResourceBrowserData browserData, String currentCultureName)
        {
            string folderPath = browserData.FolderPath;

            // To make this demonstration simple and clear, this code creates two sub-folders with names hard-coded
            // in French and German, and one keynote data source (must have the extension *.txt) under each of
            // these sub-folders.
            // To make subsequent recognition of these resources easier (in the server's LoadResource method and
            // elsewhere), a database "key" is stored in each resource's string-string Dictionary.
            if (currentCultureName == "de-DE")
            {
                if (folderPath == "/") // Top-level
                {
                    browserData.AddSubFolder("Unterordner1");
                    browserData.AddSubFolder("Unterordner2");
                }
                else if (folderPath.EndsWith("/Unterordner1"))
                {
                    var refMap = new Dictionary <String, String>();
                    refMap[RefMapDBKeyEntry] = "1";
                    browserData.AddResource("Keynotes1_de-DE.txt", KeynotesDatabase.CurrentVersion, refMap);
                }
                else if (folderPath.EndsWith("/Unterordner2"))
                {
                    var refMap = new Dictionary <String, String>();
                    refMap[RefMapDBKeyEntry] = "2";
                    browserData.AddResource("Keynotes2_de-DE.txt", KeynotesDatabase.CurrentVersion, refMap);
                }
            }
            else if (currentCultureName == "fr-FR")
            {
                if (folderPath == "/") // Top-level
                {
                    browserData.AddSubFolder("Sous-dossier1");
                    browserData.AddSubFolder("Sous-dossier2");
                }
                else if (folderPath.EndsWith("/Sous-dossier1"))
                {
                    var refMap = new Dictionary <String, String>();
                    refMap[RefMapDBKeyEntry] = "3";
                    browserData.AddResource("Keynotes1_fr-FR.txt", KeynotesDatabase.CurrentVersion, refMap);
                }
                else if (folderPath.EndsWith("/Sous-dossier2"))
                {
                    var refMap = new Dictionary <String, String>();
                    refMap[RefMapDBKeyEntry] = "4";
                    browserData.AddResource("Keynotes2_fr-FR.txt", KeynotesDatabase.CurrentVersion, refMap);
                }
            }
        }
Beispiel #5
0
        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;
            }
        }
Beispiel #6
0
        public void SetupBrowserData(ExternalResourceBrowserData browserData)
        {
            string curPath = Application.BaseFolder + browserData.FolderPath;

            Directory.GetFiles(curPath).ToList().ForEach(path =>
            {
                Dictionary <string, string> referenceInformation = new Dictionary <string, string>();
                var file = Path.GetFileName(path);
                referenceInformation["File"] = file;
                browserData.AddResource(file, "1", referenceInformation);
            });

            Directory.GetDirectories(curPath).ToList().ForEach(path =>
            {
                var dir = Path.GetFileName(path);
                browserData.AddSubFolder(dir);
            });
        }
        /// <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);
            }
        }