/// <summary> /// Loads the resources. /// </summary> /// <param name="loadRequestId">A GUID that uniquely identifies this resource load request from Revit.</param> /// <param name="resourceType">The type of external resource that Revit is asking the server to load.</param> /// <param name="resourceReference">An ExternalResourceReference identifying which particular resource to load.</param> /// <param name="loadContext">Context information, including the name of Revit document that is calling the server, /// </param>the resource that is currently loaded and the type of load operation (automatic or user-driven). /// <param name="loadContent">An ExternalResourceLoadContent object that will be populated with load data by the /// server. There are different subclasses of ExternalResourceLoadContent for different ExternalResourceTypes.</param> public void LoadResource(Guid loadRequestId, ExternalResourceType resourceType, ExternalResourceReference resourceReference, ExternalResourceLoadContext loadContext, ExternalResourceLoadContent loadContent) { loadContent.LoadStatus = ExternalResourceLoadStatus.Failure; // The following checks can help with testing. However, they should not be necessary, since Revit checks all input paramters // before calling this method. if (loadRequestId == null) { throw new ArgumentNullException("loadRequestId"); } ; if (resourceType == null) { throw new ArgumentNullException("resourceType"); } ; if (resourceReference == null) { throw new ArgumentNullException("resourceReference"); } ; if (loadContext == null) { throw new ArgumentNullException("loadContext"); } ; if (loadContent == null) { throw new ArgumentNullException("loadContent"); } ; if (!SupportsExternalResourceType(resourceType)) { throw new ArgumentOutOfRangeException("resourceType", "The specified resource type is not supported by this server."); } // The server indicates what version of the resource is being loaded. loadContent.Version = GetCurrentlyAvailableResourceVersion(resourceReference); // resourceReference is for Keynote Data if (resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.KeynoteTable) { LoadKeynoteDataResource(resourceReference, loadContent); } else // resourceReference is a Revit Link { LoadRevitLink(resourceReference, loadContent); } }
public void LoadResource(Guid loadRequestId, ExternalResourceType resourceType, ExternalResourceReference resourceReference, ExternalResourceLoadContext loadContext, ExternalResourceLoadContent content) { LinkLoadContent linkLoadContent = (LinkLoadContent)content; string file = resourceReference.GetReferenceInformation()["File"]; DBUtils.DBItem dbItem = DBUtils.FindDBItem(file); ModelPath linksPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(dbItem.Path); linkLoadContent.SetLinkDataPath(linksPath); content.LoadStatus = ExternalResourceLoadStatus.Success; return; }
public void LoadResource(Guid loadRequestId, ExternalResourceType resourceType, ExternalResourceReference desiredResource, ExternalResourceLoadContext loadContext, ExternalResourceLoadContent loadResults) { try { loadResults.LoadStatus = ExternalResourceLoadStatus.Failure; if (loadRequestId == null) { throw new ArgumentNullException("loadRequestId"); } ; if (resourceType == null) { throw new ArgumentNullException("resourceType"); } ; if (desiredResource == null) { throw new ArgumentNullException("resourceReference"); } ; if (loadContext == null) { throw new ArgumentNullException("loadContext"); } ; if (loadResults == null) { throw new ArgumentNullException("loadContent"); } ; if (!SupportsExternalResourceType(resourceType)) { throw new ArgumentOutOfRangeException("resourceType", "The specified resource type is not supported by this server."); } loadResults.Version = GetCurrentAvailableResourceVersion(desiredResource); if (resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.KeynoteTable) { LoadKeynoteDataResource(desiredResource, loadResults); } } catch (Exception ex) { string message = ex.Message; } }
public void LoadResource(Guid loadRequestId, ExternalResourceType resourceType, ExternalResourceReference resourceReference, ExternalResourceLoadContext loadContext, ExternalResourceLoadContent content) { KeyBasedTreeEntriesLoadContent kdrlc = (KeyBasedTreeEntriesLoadContent)content; string tableName = resourceReference.GetReferenceInformation()["TableName"]; DBUtils.GetAllDBItems(tableName).ForEach(item => { kdrlc.AddEntry(new KeynoteEntry(item.Key, item.ParentKey, item.Text)); }); kdrlc.BuildEntries(); kdrlc.LoadStatus = ExternalResourceLoadStatus.Success; return; }
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> /// Инициализация таблицы "Типы внешних ресурсов" /// </summary> /// <param name="serviceProvider"></param> /// <param name="configuration"></param> /// <returns></returns> public static async Task CreateExternalResourceTypes(IServiceProvider serviceProvider, IConfiguration configuration) { using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { AppIdentityDBContext context = serviceScope.ServiceProvider.GetService <AppIdentityDBContext>(); #region Инициализация таблицы "Типы внешних ресурсов" if (!await context.ExternalResourceTypes.AnyAsync()) { var row01 = new ExternalResourceType { ExternalResourceTypeId = (int)ExternalResourceTypeEnum.SocialNetworks, ExternalResourceTypeName = "Социальные сети" }; var row02 = new ExternalResourceType { ExternalResourceTypeId = (int)ExternalResourceTypeEnum.ScienceNetworks, ExternalResourceTypeName = "Научные сети" }; var row03 = new ExternalResourceType { ExternalResourceTypeId = (int)ExternalResourceTypeEnum.Messengers, ExternalResourceTypeName = "Мессенджеры" }; var row04 = new ExternalResourceType { ExternalResourceTypeId = (int)ExternalResourceTypeEnum.CitationBases, ExternalResourceTypeName = "Базы цитирования" }; await context.ExternalResourceTypes.AddRangeAsync( row01, row02, row03, row04 ); await context.SaveChangesAsync(); } #endregion } }
/// <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); } }
public bool SupportsExternalResourceType(ExternalResourceType resourceType) { return(resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.CADLink); }
public bool SupportsExternalResourceType(ExternalResourceType type) { return(type == ExternalResourceTypes.BuiltInExternalResourceTypes.KeynoteTable); }
/// <summary> /// Reports the results of loads from the DB server (SampleExternalResourceServer). /// This method should be implemented to provide UI to communicate success or failure /// of a particular external resource load operation to the user. /// </summary> /// <param name="doc">The Revit model into which the External Resource was loaded. /// </param> /// <param name="loadDataList">Contains a list of ExternalResourceLoadData with results /// for all external resources loaded by the DB server. It is possible for the DB server /// to have loaded more than one resource (for example, loading several linked files /// when a host file is opened by the user). /// </param> public void HandleLoadResourceResults(Document doc, IList <ExternalResourceLoadData> loadDataList) { foreach (ExternalResourceLoadData data in loadDataList) { ExternalResourceType resourceType = data.ExternalResourceType; // This message will be posted in a dialog box at the end of this method. String myMessage = String.Empty; ExternalResourceLoadContext loadContext = data.GetLoadContext(); ExternalResourceReference desiredRef = data.GetExternalResourceReference(); ExternalResourceReference currentlyLoadedRef = loadContext.GetCurrentlyLoadedReference(); LoadOperationType loadType = loadContext.LoadOperationType; switch (loadType) { case LoadOperationType.Automatic: myMessage = "This is an Automatic load operation. "; break; case LoadOperationType.Explicit: myMessage = "This is an Explicit load operation. "; break; default: myMessage = "There is no load type information!! "; break; } bool bUnrecognizedStatus = false; if (data.LoadStatus == ExternalResourceLoadStatus.ResourceAlreadyCurrent) { if (data.GetLoadContext().LoadOperationType == LoadOperationType.Explicit) { string resourcePath = currentlyLoadedRef.InSessionPath; myMessage += "\n No new changes to load for link: " + resourcePath; } else { continue; } } else if (data.LoadStatus == ExternalResourceLoadStatus.Uninitialized) { myMessage += "\n The load status is uninitialized - this generally shouldn't happen"; } else if (data.LoadStatus == ExternalResourceLoadStatus.Failure) { myMessage += "\n The load failed and the reason is unknown."; } else if (data.LoadStatus == ExternalResourceLoadStatus.Success) { if (resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.KeynoteTable) { string resourcePath = data.GetExternalResourceReference().InSessionPath; myMessage += "\n Version " + data.GetLoadContent().Version + " of keynote data \'" + resourcePath + "\' has been loaded successfully"; } else if (resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.RevitLink) { string resourcePath = data.GetExternalResourceReference().InSessionPath; LinkLoadContent ldrlc = (LinkLoadContent)(data.GetLoadContent()); string destinationPath = ModelPathUtils.ConvertModelPathToUserVisiblePath(ldrlc.GetLinkDataPath()); myMessage += "\n Version " + data.GetLoadContent().Version + " of the file: " + resourcePath + " has been downloaded into the cached folder: " + destinationPath + " for this Revit Link."; } } else { myMessage += "Unrecognized external resource load status."; bUnrecognizedStatus = true; } if (!bUnrecognizedStatus && resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.RevitLink) { // For Revit links, the UI server can also obtain a RevitLinkLoadResult which contains detailed // information about the status of the attempt to load the local copy of the link into Revit. LinkLoadContent ldrlc = (LinkLoadContent)(data.GetLoadContent()); LinkLoadResult loadResult = ldrlc.GetLinkLoadResult(); if (loadResult != null) { myMessage += "\n LinkLoadResultType: " + loadResult.LoadResult.ToString("g"); } } System.Windows.Forms.MessageBox.Show(myMessage, "UI Server for SDK Sample External Resource Server"); } }
/// <summary> /// IExternalResourceServer classes can support more than one type of external resource. /// This one supports keynotes and Revit links. /// </summary> public bool SupportsExternalResourceType(ExternalResourceType resourceType) { return(resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.KeynoteTable || resourceType == ExternalResourceTypes.BuiltInExternalResourceTypes.RevitLink); }