Example #1
0
        public override HostDocument GetDocument(QualifiedModuleName moduleName)
        {
            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));
                        }
            }

            return(null);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
 public AccessApp(IVBE vbe) : base(vbe, "Access", true)
 {
     _dbcProject = new Lazy <IVBProject>(() =>
     {
         using (var wizHook = new SafeIDispatchWrapper <WizHook>(Application.WizHook))
         {
             wizHook.Target.Key = 51488399;
             return(new VBProject(wizHook.Target.DbcVbProject));
         }
     });
 }
        public bool TryGetTarget(out SafeIDispatchWrapper iDispatch)
        {
            if (_getTargetFunc == null)
            {
                iDispatch = null;
                return(false);
            }

            try
            {
                iDispatch = _getTargetFunc.Invoke();
                return(true);
            }
            catch
            {
                iDispatch = null;
                return(false);
            }
        }
Example #6
0
        private DocumentState GetDocumentState(IVBProject project, string name, string className)
        {
            if (!project.Equals(_dbcProject.Value))
            {
                return(DocumentState.Inaccessible);
            }

            using (var currentProject = new SafeIDispatchWrapper <_CurrentProject>(Application.CurrentProject))
            {
                switch (className)
                {
                case FormClassName:
                    using (var allForms = new SafeIDispatchWrapper <AllObjects>(currentProject.Target.AllForms))
                        using (var accessObject = new SafeIDispatchWrapper <AccessObject>(allForms.Target[name]))
                        {
                            if (accessObject.Target.IsLoaded)
                            {
                                return(DetermineDocumentState(accessObject.Target.CurrentView));
                            }
                        }

                    break;

                case ReportClassName:
                    using (var allReports = new SafeIDispatchWrapper <AllObjects>(currentProject.Target.AllReports))
                        using (var accessObject = new SafeIDispatchWrapper <AccessObject>(allReports.Target[name]))
                        {
                            if (accessObject.Target.IsLoaded)
                            {
                                return(DetermineDocumentState(accessObject.Target.CurrentView));
                            }
                        }

                    break;
                }
            }

            return(DocumentState.Inaccessible);
        }
Example #7
0
        private HostDocument LoadHostDocument(QualifiedModuleName moduleName, string className, SafeIDispatchWrapper <AccessObject> accessObject)
        {
            var state = DocumentState.Inaccessible;

            if (!accessObject.Target.IsLoaded)
            {
                return(new HostDocument(moduleName, accessObject.Target.Name, className, state, null));
            }

            if (moduleName.ProjectName == _dbcProject.Value.Name && moduleName.ProjectId == _dbcProject.Value.HelpFile)
            {
                state = DetermineDocumentState(accessObject.Target.CurrentView);
            }

            return(new HostDocument(moduleName, accessObject.Target.Name, className, state, null));
        }