/// <summary> /// Loads a specified Revit link external resource. /// </summary> /// <param name="resourceReference">An ExternalResourceReference identifying which particular resource to load.</param> /// <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> private void LoadRevitLink(ExternalResourceReference resourceReference, ExternalResourceLoadContent loadContent) { LinkLoadContent linkLoadContent = (LinkLoadContent)loadContent; if (linkLoadContent == null) { throw new ArgumentException("Wrong type of ExternalResourceLoadContent (expecting a LinkLoadContent) for Revit links.", "loadContent"); } try { // Copy the file from the path under the server "root" folder to a secret "cache" folder on the users machine String fullCachedPath = GetFullLinkCachedFilePath(resourceReference); String cacheFolder = System.IO.Path.GetDirectoryName(fullCachedPath); if (!System.IO.Directory.Exists(cacheFolder)) { System.IO.Directory.CreateDirectory(cacheFolder); } String serverLinkPath = GetFullServerLinkFilePath(resourceReference); System.IO.File.Copy(serverLinkPath, fullCachedPath, true); // Overwrite ModelPath linksPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(fullCachedPath); linkLoadContent.SetLinkDataPath(linksPath); loadContent.LoadStatus = ExternalResourceLoadStatus.Success; } catch (System.Exception) { } }
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 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; }
private void LoadKeynoteDataResource(ExternalResourceReference resourceReference, ExternalResourceLoadContent loadContent) { try { KeyBasedTreeEntriesLoadContent entriesContent = (KeyBasedTreeEntriesLoadContent)loadContent; if (null == entriesContent) { throw new ArgumentException("Wrong type of ExternalResourceLoadContent (expecting a KeyBasedTreeEntriesLoadContent) for keynote data.", "loadContent"); } entriesContent.Reset(); IDictionary <string, string> refMap = resourceReference.GetReferenceInformation(); if (refMap.ContainsKey("VersionNumber") && refMap.ContainsKey("ProjectName")) { KeynoteDatabase.LoadKeynoteEntries(refMap, ref entriesContent); entriesContent.BuildEntries(); loadContent.LoadStatus = ExternalResourceLoadStatus.Success; } } catch (Exception ex) { string message = ex.Message; } }
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; } }
/// <summary> /// Loads the keynote data resources, either from the fictitious French/German database, or from a file. /// </summary> /// <param name="resourceReference">An ExternalResourceReference identifying which particular resource to load.</param> /// <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> private void LoadKeynoteDataResource(ExternalResourceReference resourceReference, ExternalResourceLoadContent loadContent) { KeyBasedTreeEntriesLoadContent kdrlc = (KeyBasedTreeEntriesLoadContent)loadContent; if (kdrlc == null) { throw new ArgumentException("Wrong type of ExternalResourceLoadContent (expecting a KeyBasedTreeEntriesLoadContent) for keynote data.", "loadContent"); } kdrlc.Reset(); // Either the ExternalResourceReference has a valid database key (German/French case) ... IDictionary <string, string> refMap = resourceReference.GetReferenceInformation(); if (refMap.ContainsKey(RefMapDBKeyEntry)) { try { KeynotesDatabase.LoadKeynoteEntries(refMap[RefMapDBKeyEntry], ref kdrlc); kdrlc.BuildEntries(); loadContent.LoadStatus = ExternalResourceLoadStatus.Success; } catch (ArgumentOutOfRangeException) { } catch (ArgumentNullException) { } } else { // ... OR it is a real file (all other cases). String serverKeynoteFilePath = GetFullServerKeynoteFilePath(resourceReference); bool doesReadingSucceed = KeynoteEntries.LoadKeynoteEntriesFromFile(serverKeynoteFilePath, kdrlc); if (doesReadingSucceed) { kdrlc.BuildEntries(); loadContent.LoadStatus = ExternalResourceLoadStatus.Success; } } }
/// <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); } }