/// <summary> /// Tries the get the document. /// </summary> /// <param name="searchPath">The search path.</param> /// <returns>ViewEngineResult.</returns> protected virtual DocumentEngineResult TryGetDocument(string searchPath) { try { var document = Application.LoadComponent(new Uri(searchPath, UriKind.Relative)) as FrameworkContentElement; if (document != null) { var documentInfo = document as ISourceInformation; if (documentInfo != null) { documentInfo.OriginalLoadLocation = searchPath; } var documentResult = new DocumentEngineResult { Document = document, FoundDocument = true, DocumentSource = "XAML Resource: " + searchPath }; TryAttachingDocumentLayoutResources(document, searchPath); return(documentResult); } } catch { } return(null); }
/// <summary> /// Tries the get the document. /// </summary> /// <param name="searchPath">The search path.</param> /// <returns>ViewEngineResult.</returns> protected virtual DocumentEngineResult TryGetDocument(string searchPath) { try { var document = Application.LoadComponent(new Uri(searchPath, UriKind.Relative)) as FrameworkContentElement; if (document != null) { var documentInfo = document as ISourceInformation; if (documentInfo != null) documentInfo.OriginalLoadLocation = searchPath; var documentResult = new DocumentEngineResult { Document = document, FoundDocument = true, DocumentSource = "XAML Resource: " + searchPath }; TryAttachingDocumentLayoutResources(document, searchPath); return documentResult; } } catch { } return null; }
/// <summary> /// Finds and instantiates the specified document (document) /// </summary> /// <param name="documentName">Name of the document to find</param> /// <param name="controllerName">Name of the controller that requested the document</param> /// <returns>Document result indicating the success of the operation</returns> /// <exception cref="System.NotImplementedException"></exception> public DocumentEngineResult GetDocument(string documentName, string controllerName) { documentName = documentName.ToLower(); var failureResult = new DocumentEngineResult { FoundDocument = false }; var searchPath = "/views/" + controllerName + "/" + documentName + ".xaml"; var documentResult = TryGetDocument(searchPath); if (documentResult != null) { return(documentResult); } failureResult.LocationsSearched.Add(searchPath); searchPath = "/views/shared/" + documentName + ".xaml"; documentResult = TryGetDocument(searchPath); if (documentResult != null) { return(documentResult); } failureResult.LocationsSearched.Add(searchPath); searchPath = "/views/shareddocuments/" + documentName + ".xaml"; documentResult = TryGetDocument(searchPath); if (documentResult != null) { return(documentResult); } failureResult.LocationsSearched.Add(searchPath); foreach (var assemblyName in ApplicationEx.SecondaryAssemblies.Keys) { var secondaryAssembly = ApplicationEx.SecondaryAssemblies[assemblyName]; searchPath = "/" + secondaryAssembly.GetName().Name + ";component/views/" + controllerName + "/" + documentName + ".xaml"; documentResult = TryGetDocument(searchPath); if (documentResult != null) { return(documentResult); } failureResult.LocationsSearched.Add(searchPath); searchPath = "/" + secondaryAssembly.GetName().Name + ";component/views/shared/" + documentName + ".xaml"; documentResult = TryGetDocument(searchPath); if (documentResult != null) { return(documentResult); } failureResult.LocationsSearched.Add(searchPath); searchPath = "/" + secondaryAssembly.GetName().Name + ";component/views/shareddocuments/" + documentName + ".xaml"; documentResult = TryGetDocument(searchPath); if (documentResult != null) { return(documentResult); } failureResult.LocationsSearched.Add(searchPath); } return(failureResult); }
/// <summary> /// Finds and instantiates the specified document (document) /// </summary> /// <param name="documentName">Name of the document to find</param> /// <param name="controllerName">Name of the controller that requested the document</param> /// <returns>Document result indicating the success of the operation</returns> /// <exception cref="System.NotImplementedException"></exception> public DocumentEngineResult GetDocument(string documentName, string controllerName) { documentName = documentName.ToLower(); var failureResult = new DocumentEngineResult { FoundDocument = false }; var searchPath = "/views/" + controllerName + "/" + documentName + ".xaml"; var documentResult = TryGetDocument(searchPath); if (documentResult != null) return documentResult; failureResult.LocationsSearched.Add(searchPath); searchPath = "/views/shared/" + documentName + ".xaml"; documentResult = TryGetDocument(searchPath); if (documentResult != null) return documentResult; failureResult.LocationsSearched.Add(searchPath); searchPath = "/views/shareddocuments/" + documentName + ".xaml"; documentResult = TryGetDocument(searchPath); if (documentResult != null) return documentResult; failureResult.LocationsSearched.Add(searchPath); foreach (var assemblyName in ApplicationEx.SecondaryAssemblies.Keys) { var secondaryAssembly = ApplicationEx.SecondaryAssemblies[assemblyName]; searchPath = "/" + secondaryAssembly.GetName().Name + ";component/views/" + controllerName + "/" + documentName + ".xaml"; documentResult = TryGetDocument(searchPath); if (documentResult != null) return documentResult; failureResult.LocationsSearched.Add(searchPath); searchPath = "/" + secondaryAssembly.GetName().Name + ";component/views/shared/" + documentName + ".xaml"; documentResult = TryGetDocument(searchPath); if (documentResult != null) return documentResult; failureResult.LocationsSearched.Add(searchPath); searchPath = "/" + secondaryAssembly.GetName().Name + ";component/views/shareddocuments/" + documentName + ".xaml"; documentResult = TryGetDocument(searchPath); if (documentResult != null) return documentResult; failureResult.LocationsSearched.Add(searchPath); } return failureResult; }