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; }
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> /// 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> /// 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); } }