public override HostDocument GetDocument(QualifiedModuleName moduleName) { try { if (moduleName.ComponentName.StartsWith(FormNamePrefix)) { var name = moduleName.ComponentName.Substring(FormNamePrefix.Length); using (var currentProject = new SafeIDispatchWrapper <_CurrentProject>(Application.CurrentProject)) using (var allForms = new SafeIDispatchWrapper <AllObjects>(currentProject.Target.AllForms)) using (var accessObject = new SafeIDispatchWrapper <AccessObject>(allForms.Target[name])) { return(LoadHostDocument(moduleName, FormClassName, accessObject)); } } if (moduleName.ComponentName.StartsWith(ReportNamePrefix)) { var name = moduleName.ComponentName.Substring(ReportNamePrefix.Length); using (var currentProject = new SafeIDispatchWrapper <_CurrentProject>(Application.CurrentProject)) using (var allReports = new SafeIDispatchWrapper <AllObjects>(currentProject.Target.AllReports)) using (var accessObject = new SafeIDispatchWrapper <AccessObject>(allReports.Target[name])) { return(LoadHostDocument(moduleName, name, accessObject)); } } } catch (Exception ex) { //Log and ignore _logger.Log(LogLevel.Info, ex, $"Failed to get host document {moduleName.ToString()}"); } return(null); }
/// <summary> /// Sets current scope to module-level. /// </summary> private void SetCurrentScope() { _currentScope = _qualifiedName.ToString(); _currentScopeDeclaration = _moduleDeclaration; _parentDeclaration = _moduleDeclaration; }
private static string FormattedDeclaration( Declaration declaration, string typeName, QualifiedModuleName moduleName, string declarationType) { if (declaration.ParentDeclaration != null) { if (declaration.ParentDeclaration.DeclarationType.HasFlag(DeclarationType.Member)) { // locals, parameters return($"{declaration.ParentDeclaration.QualifiedName}:{declaration.IdentifierName} {typeName}"); } if (declaration.ParentDeclaration.DeclarationType.HasFlag(DeclarationType.Module)) { // fields var withEvents = declaration.IsWithEvents ? "(WithEvents) " : string.Empty; return($"{withEvents}{moduleName}.{declaration.IdentifierName} {typeName}"); } } if (declaration.DeclarationType.HasFlag(DeclarationType.Member)) { var formattedDeclaration = declaration.QualifiedName.ToString(); if (declaration.DeclarationType == DeclarationType.Function || declaration.DeclarationType == DeclarationType.PropertyGet) { formattedDeclaration += typeName; } return(formattedDeclaration); } if (declaration.DeclarationType.HasFlag(DeclarationType.Module)) { return($"{moduleName} ({declarationType})"); } switch (declaration.DeclarationType) { case DeclarationType.Project: case DeclarationType.BracketedExpression: var filename = Path.GetFileName(declaration.QualifiedName.QualifiedModuleName.ProjectPath); return($"{filename}{(string.IsNullOrEmpty(filename) ? string.Empty : ";")}{declaration.IdentifierName} ({declarationType})"); case DeclarationType.Enumeration: case DeclarationType.UserDefinedType: return(!declaration.IsUserDefined // built-in enums & UDT's don't have a module ? $"{Path.GetFileName(moduleName.ProjectPath)};{moduleName.ProjectName}.{declaration.IdentifierName}" : moduleName.ToString()); case DeclarationType.EnumerationMember: case DeclarationType.UserDefinedTypeMember: return(declaration.IsUserDefined ? $"{moduleName}.{declaration.ParentDeclaration.IdentifierName}.{declaration.IdentifierName} {typeName}" : $"{Path.GetFileName(moduleName.ProjectPath)};{moduleName.ProjectName}.{declaration.ParentDeclaration.IdentifierName}.{declaration.IdentifierName} {typeName}"); case DeclarationType.ComAlias: return($"{Path.GetFileName(moduleName.ProjectPath)};{moduleName.ProjectName}.{declaration.IdentifierName} (alias:{declaration.AsTypeName})"); } return(string.Empty); }
private async Task <string> FormattedDeclarationAsync( Declaration declaration, string typeName, QualifiedModuleName moduleName, string declarationType, CancellationToken token) { return(await Task.Run(() => { token.ThrowIfCancellationRequested(); if (declaration.ParentDeclaration != null) { if (declaration.ParentDeclaration.DeclarationType.HasFlag(DeclarationType.Member)) { // locals, parameters return $"{declaration.ParentDeclaration.QualifiedName}:{declaration.IdentifierName} {typeName}"; } if (declaration.ParentDeclaration.DeclarationType.HasFlag(DeclarationType.Module)) { // fields var withEvents = declaration.IsWithEvents ? $"({Tokens.WithEvents}) " : string.Empty; return $"{withEvents}{moduleName}.{declaration.IdentifierName} {typeName}"; } } token.ThrowIfCancellationRequested(); if (declaration.DeclarationType.HasFlag(DeclarationType.Member)) { var formattedDeclaration = $"{declaration.QualifiedName}"; if (declaration.DeclarationType == DeclarationType.Function || declaration.DeclarationType == DeclarationType.PropertyGet) { formattedDeclaration += $" {typeName}"; } return formattedDeclaration; } if (declaration.DeclarationType.HasFlag(DeclarationType.Module)) { return $"{moduleName} ({declarationType})"; } token.ThrowIfCancellationRequested(); switch (declaration.DeclarationType) { case DeclarationType.Project: case DeclarationType.BracketedExpression: var filename = Path.GetFileName(declaration.QualifiedName.QualifiedModuleName.ProjectPath); return $"{filename}{(string.IsNullOrEmpty(filename) ? string.Empty : ";")}{declaration.IdentifierName} ({declarationType})"; case DeclarationType.Enumeration: case DeclarationType.UserDefinedType: return !declaration.IsUserDefined // built-in enums & UDTs don't have a module ? $"{Path.GetFileName(moduleName.ProjectPath)};{declaration.IdentifierName}" : moduleName.ToString(); case DeclarationType.EnumerationMember: case DeclarationType.UserDefinedTypeMember: return declaration.IsUserDefined ? $"{moduleName}.{declaration.ParentDeclaration.IdentifierName}.{declaration.IdentifierName} {typeName}" : $"{Path.GetFileName(moduleName.ProjectPath)};{declaration.ParentDeclaration.IdentifierName}.{declaration.IdentifierName} {typeName}"; case DeclarationType.ComAlias: return $"{Path.GetFileName(moduleName.ProjectPath)};{declaration.IdentifierName} (alias:{declaration.AsTypeName})"; } return string.Empty; }, token)); }
/// <summary> /// Sets current scope to module-level. /// </summary> private void SetCurrentScope() { _currentScope = _qualifiedName.ToString(); }
public override bool TryOpenDocumentDesigner(QualifiedModuleName moduleName) { try { if (moduleName.ComponentName.StartsWith(FormNamePrefix)) { var name = moduleName.ComponentName.Substring(FormNamePrefix.Length); using (var currentProject = new SafeIDispatchWrapper <_CurrentProject>(Application.CurrentProject)) using (var allForms = new SafeIDispatchWrapper <AllObjects>(currentProject.Target.AllForms)) using (var accessObject = new SafeIDispatchWrapper <AccessObject>(allForms.Target[name])) using (var doCmd = new SafeIDispatchWrapper <DoCmd>(Application.DoCmd)) { if (accessObject.Target.IsLoaded && accessObject.Target.CurrentView != AcCurrentView.acCurViewDesign) { doCmd.Target.Close(AcObjectType.acForm, name); } if (!accessObject.Target.IsLoaded) { doCmd.Target.OpenForm(name, AcFormView.acDesign); } return(accessObject.Target.IsLoaded && accessObject.Target.CurrentView == AcCurrentView.acCurViewDesign); } } if (moduleName.ComponentName.StartsWith(ReportNamePrefix)) { var name = moduleName.ComponentName.Substring(ReportNamePrefix.Length); using (var currentProject = new SafeIDispatchWrapper <_CurrentProject>(Application.CurrentProject)) using (var allReports = new SafeIDispatchWrapper <AllObjects>(currentProject.Target.AllReports)) using (var accessObject = new SafeIDispatchWrapper <AccessObject>(allReports.Target[name])) using (var doCmd = new SafeIDispatchWrapper <DoCmd>(Application.DoCmd)) { if (accessObject.Target.IsLoaded && accessObject.Target.CurrentView != AcCurrentView.acCurViewDesign) { doCmd.Target.Close(AcObjectType.acReport, name); } if (!accessObject.Target.IsLoaded) { doCmd.Target.OpenReport(name, AcView.acViewDesign); } return(accessObject.Target.IsLoaded && accessObject.Target.CurrentView == AcCurrentView.acCurViewDesign); } } } catch (Exception ex) { _logger.Log(LogLevel.Info, ex, $"Unable to open the document in design view for {moduleName.ToString()}"); } return(false); }