Example #1
0
        public SyntaxTreeNode Parse(VBProject project)
        {
            var nodes = new List <SyntaxTreeNode>();

            try
            {
                var components = project.VBComponents.Cast <VBComponent>().ToList();
                foreach (var component in components)
                {
                    var lineCount = component.CodeModule.CountOfLines;
                    if (lineCount <= 0)
                    {
                        continue;
                    }

                    var code          = component.CodeModule.Lines[1, lineCount];
                    var isClassModule = component.Type == vbext_ComponentType.vbext_ct_ClassModule ||
                                        component.Type == vbext_ComponentType.vbext_ct_Document ||
                                        component.Type == vbext_ComponentType.vbext_ct_MSForm;

                    nodes.Add(Parse(project.Name, component.Name, code, isClassModule));
                }
            }
            catch
            {
                // todo: handle exception like a chief
                Debug.Assert(false);
            }

            return(new ProjectNode(project, nodes));
        }
        public static void make_excel_file(String csv_filename)
        {
            Excel.Application excel = new Excel.Application();
            excel.Visible       = true;
            excel.DisplayAlerts = false;

            Excel.Workbook  workbook  = excel.Workbooks.Add();
            Excel.Worksheet worksheet = workbook.Worksheets["Sheet1"];

            VBProject   project   = workbook.VBProject;
            VBComponent component = project.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);

            component.CodeModule.AddFromString(String.Format(Properties.Resources.items_info_macro, csv_filename));
            excel.Run("items_info_macro");
            project.VBComponents.Remove(component);

            String xlsx_filename = utility.show_save_dialog("Excel Workbook (*.xlsx)|*.xlsx|All Files (*.*)|*.*", 1);

            if (xlsx_filename != "")
            {
                workbook.SaveAs(xlsx_filename);
            }

            workbook.Close();
            excel.Quit();

            Marshal.ReleaseComObject(workbook);
            Marshal.ReleaseComObject(excel);
        }
Example #3
0
 public GitProvider(VBProject project, RepositorySettings repoSettings)
 {
     _project = project;
     _unsyncedLocalCommits  = new List <Commit>();
     _unsyncedRemoteCommits = new List <Commit>();
     _repo = new Repository(repoSettings.LocalPath);
 }
Example #4
0
        private string GetReferenceProjectId(Reference reference, IReadOnlyList <VBProject> projects)
        {
            VBProject project = null;

            foreach (var item in projects)
            {
                try
                {
                    if (item.FileName == reference.FullPath)
                    {
                        project = item;
                    }
                }
                catch (IOException)
                {
                    // Filename throws exception if unsaved.
                }
            }

            if (project != null)
            {
                return(QualifiedModuleName.GetProjectId(project));
            }
            return(QualifiedModuleName.GetProjectId(reference));
        }
 /// <summary>
 /// Exports all code modules in the VbProject to a destination directory. Files are given the same name as their parent code Module name and file extensions are based on what type of code Module it is.
 /// </summary>
 /// <param name="project">The <see cref="VBProject"/> to be exported to source files.</param>
 /// <param name="directoryPath">The destination directory path.</param>
 public static void ExportSourceFiles(this VBProject project, string directoryPath)
 {
     foreach (VBComponent component in project.VBComponents)
     {
         component.ExportAsSourceFile(directoryPath);
     }
 }
Example #6
0
        public void Indent(VBProject project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (project.Protection == vbext_ProjectProtection.vbext_pp_locked)
            {
                throw new InvalidOperationException("Project is protected.");
            }

            var lineCount = 0; // to set progressbar max value
            if (project.VBComponents.Cast<VBComponent>().All(component => !HasCode(component.CodeModule, ref lineCount)))
            {
                throw new InvalidOperationException("Project contains no code.");
            }

            _originalTopLine = _vbe.ActiveCodePane.TopLine;
            _originalSelection = GetSelection(_vbe.ActiveCodePane);

            var progress = 0; // to set progressbar value
            foreach (var component in project.VBComponents.Cast<VBComponent>().Where(component => HasCode(component.CodeModule)))
            {
                Indent(component, true, progress);
                progress += component.CodeModule.CountOfLines;
            }

            _vbe.ActiveCodePane.TopLine = _originalTopLine;
            _vbe.ActiveCodePane.SetSelection(_originalSelection.StartLine, _originalSelection.StartColumn, _originalSelection.EndLine, _originalSelection.EndColumn);
        }
Example #7
0
        /// <summary>
        /// Create new repository for project
        /// </summary>
        /// <param name="project">VBProject</param>
        public void CreateNewRepo(VBProject project)
        {
            try
            {
                EnableFileSystemWatcher = false;

                using (var gitCommand = new CommandInit(project))
                {
                    gitCommand.Execute();

                    if (gitCommand.Status == CommandStatus.Success)
                    {
                        RepositorySettings repo = new RepositorySettings();
                        repo.Name      = project.GetRepoName();
                        repo.LocalPath = gitCommand.Repository.Info.WorkingDirectory;

                        if (!_config.Repositories.Exists(r => (r.Name == repo.Name &&
                                                               r.LocalPath == repo.LocalPath &&
                                                               r.RemotePath == repo.RemotePath)))
                        {
                            _config.Repositories.Add(repo);
                            _configService.SaveConfiguration(_config);
                        }

                        AddVBProject(project);
                    }
                }
            }
            finally
            {
                EnableFileSystemWatcher = true;
            }
        }
Example #8
0
 public static IEnumerable <string> ComponentNames(this VBProject project)
 {
     foreach (VBComponent component in project.VBComponents)
     {
         yield return(component.Name);
     }
 }
        private static string GetNextTestModuleName(VBProject project)
        {
            var names = project.ComponentNames();
            var index = names.Count(n => n.StartsWith(TestModuleBaseName)) + 1;

            return string.Concat(TestModuleBaseName, index);
        }
Example #10
0
        /// <summary>
        /// Performs additional checks before importing.
        /// Checks if given component name can be found in active project. If so, will check
        /// its type and if the type is a document type, it will insert text inside the component
        /// instead of importing it. If the component is recognized as a class, will import it standard way.
        /// </summary>
        /// <param name="vbe">a reference to the VBE</param>
        /// <param name="item">a form to be imported</param>
        /// <param name="shouldOverride">true if the component should be overridden</param>
        public void Import(VBE vbe, Component item, bool shouldOverride)
        {
            VBProject vbProject             = vbe.ActiveVBProject;
            IEnumerable <CodeModule> module = Extensions.VbeExtensions.FindCodeModules(vbe, item.ToString());

            if (module == null || !module.ToArray().Any())
            {
                //the component name was not found in the active project, import it standard way
                vbProject.VBComponents.Import(item.FullPath);
            }
            else
            {
                if (module.ToArray()[0].Parent.Type == vbext_ComponentType.vbext_ct_ClassModule)
                {
                    // the item with the same name is not a document type => was replaced in calling method, we can import standard way
                    vbProject.VBComponents.Import(item.FullPath);
                }
                else
                {
                    // here is the interesting part, the imported item has the same name as one of the document type component
                    // user want's to replace it, which is not possible for that type, so we will copy text of the imported item
                    // to the module with the same name (its text was removed in calling method)
                    module.ToArray()[0].AddFromFile(item.FullPath);
                }
            }
        }
Example #11
0
        /// <summary>
        /// Bevan Test Add Component method
        /// We can't use reflection to call the classes by name
        /// </summary>
        /// <param name="xlApp">Excel application object</param>
        /// <param name="sClassName">Validator Class Name</param>
        /// <returns>The Validator Class Reference</returns>
        private object GetVBAClass(Excel.Application xlApp, string sClassName)
        {
            // Grab the Class component being passed in from name
            // If this errors:
            // Click the Trust Center tab, and then click Trust Center Settings.
            // Click the Macro Settings tab, click to select the Trust access to the VBA project object model check box
            VBProject   xlProj  = xlApp.VBE.ActiveVBProject;
            VBComponent compVal = xlProj.VBComponents.Item(sClassName);

            // Function name to run
            string sFunctionName = "UNIT_TEST" + sClassName;

            // Add a new module/function
            VBComponent compModule = xlProj.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);

            compModule.CodeModule.InsertLines(
                compModule.CodeModule.CountOfLines + 1,
                "Public Function " + sFunctionName + "() As " + sClassName + "\r\n Set " + sFunctionName + " = New " + sClassName + "\r\n End Function");

            // Run the function
            object val = xlApp._Run2(sFunctionName);

            // Remove the function
            xlProj.VBComponents.Remove(compModule);

            // Clean the COM references
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(compModule);
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(compVal);
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlProj);

            // Return the object
            return(val);
        }
Example #12
0
        public void RecreateMenu(VBProject project)
        {
            int windowMenuId    = 30038;
            var menuBarControls = _app.IDE.CommandBars[1].Controls;
            var beforeIndex     = FindMenuInsertionIndex(menuBarControls, windowMenuId);

            if (_menu != null)
            {
                UnsubsribeCommandBarButtonClickEvents();
                beforeIndex = _menu.Index;
                _menu.Delete();
            }

            _menu         = menuBarControls.Add(MsoControlType.msoControlPopup, Before: beforeIndex, Temporary: true) as CommandBarPopup;
            _menu.Tag     = "VBAGit";
            _menu.Caption = VBAGitUI.VBAGitMenu;

            if (_app.GetVBProjectRepository(project) != null)
            {
                _gitSync   = AddButton(_menu, VBAGitUI.VBAGitMenu_Sync, false, OnGitSync, "git_sync");
                _gitCommit = AddButton(_menu, VBAGitUI.VBAGitMenu_Commit, false, OnGitCommit, "git_commit");
                _gitPull   = AddButton(_menu, VBAGitUI.VBAGitMenu_Pull, true, OnGitPull, "git_pull");
                _gitFetch  = AddButton(_menu, VBAGitUI.VBAGitMenu_Fecth, false, OnGitFetch, "git_pull");
                _gitPush   = AddButton(_menu, VBAGitUI.VBAGitMenu_Push, false, OnGitPush, "git_push");

                AddVBAGitMenu(true);
            }
            else
            {
                _gitCreate = AddButton(_menu, VBAGitUI.VBAGitMenu_Create, false, OnGitCreate, "create_repo");

                AddVBAGitMenu(false);
            }
        }
 /// <summary>
 /// Removes All VbComponents from the VbProject.
 /// </summary>
 /// <remarks>
 /// Document type Components cannot be physically removed from a project through the VBE.
 /// Instead, the code will simply be deleted from the code Module.
 /// </remarks>
 /// <param name="project"></param>
 public static void RemoveAllComponents(this VBProject project)
 {
     foreach (VBComponent component in project.VBComponents)
     {
         project.VBComponents.RemoveSafely(component);
     }
 }
Example #14
0
        /// <summary>
        /// Insert the sample macro code into the specified VBProject and call the code from VSTO.
        /// </summary>
        /// <param name="prj">Target VBProject.</param>
        /// <returns>The return value from the VBA function.</returns>
        private object InsertAndRun(VBProject prj)
        {
            // Check for existing module.
            foreach (VBComponent component in prj.VBComponents)
            {
                if (component.Name == ModuleName)
                {
                    throw new ApplicationException("There is already a " + ModuleName + " in this VBA project.");
                }
            }

            // Add a standard module
            VBComponent mod = prj.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);

            // Name the module
            mod.Name = ModuleName;
            // Add code into the module directly from a string.
            mod.CodeModule.AddFromString(txtVbaSub.Text);

            // Call the newly added VBA function.
            // The first parameter to the function is a string "VSTO".
            return(Globals.ThisAddIn.Application.Run(VbaFunctionName, "VSTO", Type.Missing, Type.Missing,
                                                     Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                     Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                     Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                     Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                     Type.Missing, Type.Missing, Type.Missing));
        }
Example #15
0
        private static string GetProjectDefinitionXml(VBProject project)
        {
            var sb = new StringBuilder()
                     .AppendLine($"<Project")
                     .AppendLine($"  Name='{project.Name}'")
                     .AppendLine($"  FileName='{project.FileName}'")
                     .AppendLine($"  HelpContextID='{project.HelpContextID}'")
                     .AppendLine($"  HelpFile='{project.HelpFile}'")
                     .AppendLine($"  Protection='{project.Protection}'")
                     .AppendLine($"  Type='{project.Type}'")
                     .AppendLine($">");

            foreach (Reference r in project.References)
            {
                sb.AppendLine($"   <References")
                .AppendLine($"      Description='{r.Description}'")
                .AppendLine($"      FullPath='{r.FullPath}'")
                .AppendLine($"      Guid='{r.Guid}'")
                .AppendLine($"      Major='{r.Major}'")
                .AppendLine($"      Minor='{r.Minor}'")
                .AppendLine($"      Name='{r.Name}'")
                .AppendLine($"      Type='{r.Type}'")
                .AppendLine($"   />");
            }

            return(sb.AppendLine("</Project>").ToString());
        }
Example #16
0
        public async Task <VBProjectParseResult> ParseAsync(VBProject project)
        {
            return(await Task.Run(() => Parse(project)));

            // note: the above has been seen to cause issues with VBProject.Equals and break navigation...
            //return Parse(project);
        }
        private static string GetNextTestModuleName(VBProject project)
        {
            var names = project.ComponentNames();
            var index = names.Count(n => n.StartsWith(TestModuleBaseName)) + 1;

            return(string.Concat(TestModuleBaseName, index));
        }
Example #18
0
        protected static void ExtractProjectModules(VBProject project, string path)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            var retries = 3;

            while (retries > 0)
            {
                try {
                    foreach (VBComponent component in project.VBComponents)
                    {
                        component.Export(Path.ChangeExtension(Path.Combine(path, component.Name),
                                                              TypeExtension((VbExt_ct)component.Type)));
                    }

                    File.WriteAllText(Path.Combine(path, "VBAProject.xml"), GetProjectDefinitionXml(project));
                    break;
                }
                catch (COMException ex) when(ex.HResult == unchecked ((int)0x800AC372) ||
                                             ex.HResult == unchecked ((int)0x800AC373) ||
                                             ex.HResult == unchecked ((int)0x800AC35C))
                {
                    if (retries-- > 0)
                    {
                        continue;
                    }

                    throw new IOException(
                              $"A file or directory conflict occurred. Please retry.\n\nPath:\n{path}", ex);
                }
            }
        }
Example #19
0
        public void SetModuleState(VBComponent component, ParserState state, SyntaxErrorException parserError = null)
        {
            if (AllUserDeclarations.Count > 0)
            {
                var projectId = component.Collection.Parent.HelpFile;

                VBProject project = null;
                foreach (var item in _projects)
                {
                    if (item.Value.HelpFile == projectId)
                    {
                        project = project != null ? null : item.Value;
                    }
                }

                if (project == null)
                {
                    // ghost component shouldn't even exist
                    ClearStateCache(component);
                    Status = EvaluateParserState();
                    return;
                }
            }
            var key = new QualifiedModuleName(component);

            _moduleStates.AddOrUpdate(key, new ModuleState(state), (c, e) => e.SetState(state));
            _moduleStates.AddOrUpdate(key, new ModuleState(parserError), (c, e) => e.SetModuleException(parserError));
            Logger.Debug("Module '{0}' state is changing to '{1}' (thread {2})", key.ComponentName, state, Thread.CurrentThread.ManagedThreadId);
            OnModuleStateChanged(component, state);
            Status = EvaluateParserState();
        }
 public void ItemAdded(VBProject VBProject)
 {
     if (VBProject.Protection == vbext_ProjectProtection.vbext_pp_none)
     {
         OnDispatch(ProjectAdded, VBProject);
     }
 }
Example #21
0
        public void Indent(VBProject project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (project.Protection == vbext_ProjectProtection.vbext_pp_locked)
            {
                throw new InvalidOperationException("Project is protected.");
            }

            var lineCount = 0; // to set progressbar max value

            if (project.VBComponents.Cast <VBComponent>().All(component => !HasCode(component.CodeModule, ref lineCount)))
            {
                throw new InvalidOperationException("Project contains no code.");
            }

            _originalTopLine   = _vbe.ActiveCodePane.TopLine;
            _originalSelection = GetSelection(_vbe.ActiveCodePane);

            var progress = 0; // to set progressbar value

            foreach (var component in project.VBComponents.Cast <VBComponent>().Where(component => HasCode(component.CodeModule)))
            {
                Indent(component, true, progress);
                progress += component.CodeModule.CountOfLines;
            }

            _vbe.ActiveCodePane.TopLine = _originalTopLine;
            _vbe.ActiveCodePane.SetSelection(_originalSelection.StartLine, _originalSelection.StartColumn, _originalSelection.EndLine, _originalSelection.EndColumn);
        }
Example #22
0
        public void AddProject(VBProject project)
        {
            if (project.Protection == vbext_ProjectProtection.vbext_pp_locked)
            {
                // adding protected project to parser state is asking for COMExceptions..
                return;
            }

            //assign a hashcode if no helpfile is present
            if (string.IsNullOrEmpty(project.HelpFile))
            {
                project.HelpFile = project.GetHashCode().ToString();
            }

            //loop until the helpfile is unique for this host session
            while (!IsProjectIdUnique(project.HelpFile))
            {
                project.HelpFile = (project.GetHashCode() ^ project.HelpFile.GetHashCode()).ToString();
            }

            var projectId = project.HelpFile;

            if (!_projects.ContainsKey(projectId))
            {
                _projects.Add(projectId, project);
            }

            foreach (VBComponent component in project.VBComponents)
            {
                _moduleStates.TryAdd(new QualifiedModuleName(component), new ModuleState(ParserState.Pending));
            }
        }
Example #23
0
        private bool LoadXlWings(VBProject pyxelRest = null)
        {
            try
            {
                if (!TrustAccessToTheVBAObjectModel())
                {
                    return(false);
                }
                VBProject vbProject = pyxelRest == null?GetPyxelRestVBProject() : pyxelRest;

                if (vbProject == null)
                {
                    Log.Error("PyxelRest VB Project cannot be found.");
                    return(false);
                }
                if (PathToBasFile == null)
                {
                    return(false);
                }

                vbProject.VBComponents.Import(PathToBasFile);
                Log.Debug("XLWings module imported.");
                return(true);
            }
            catch (Exception ex)
            {
                Log.Error("XlWings module could not be imported.", ex);
                return(false);
            };
        }
 public void ItemAdded(VBProject VBProject)
 {
     if (VBProject.Protection == vbext_ProjectProtection.vbext_pp_none)
     {
         OnDispatch(ProjectAdded, VBProject);
     }
 }
 private void OnDispatch(EventHandler<DispatcherEventArgs<VBProject>> dispatched, VBProject project)
 {
     var handler = dispatched;
     if (handler != null)
     {
         handler.Invoke(this, new DispatcherEventArgs<VBProject>(project));
     }
 }
 public void ItemRenamed(VBProject VBProject, string OldName)
 {
     var handler = ProjectRenamed;
     if (handler != null && VBProject.Protection == vbext_ProjectProtection.vbext_pp_none)
     {
         handler.Invoke(this, new DispatcherRenamedEventArgs<VBProject>(VBProject, OldName));
     }
 }
Example #27
0
 public VBProjectParseResult Parse(IRubberduckParser parser, VBProject project)
 {
     using (var view = new ProgressDialog(parser, project))
     {
         view.ShowDialog();
         return(view.Result);
     }
 }
 public VBProjectParseResult Parse(IRubberduckParser parser, VBProject project)
 {
     using (var view = new ProgressDialog(parser, project))
     {
         view.ShowDialog();
         return view.Result;
     }
 }
 public static string GetProjectId(VBProject project)
 {
     if (project == null)
     {
         return string.Empty;
     }
     return string.IsNullOrEmpty(project.HelpFile) ? project.GetHashCode().ToString() : project.HelpFile;
 }
Example #30
0
 public static string GetProjectId(VBProject project)
 {
     if (project == null)
     {
         return(string.Empty);
     }
     return(string.IsNullOrEmpty(project.HelpFile) ? project.GetHashCode().ToString() : project.HelpFile);
 }
Example #31
0
 private void LogVbProject(VBProject vbProject, bool isActiveVbProject)
 {
     Log("Project " + vbProject.Name + ((isActiveVbProject) ? " (active)" : string.Empty));
     foreach (VBComponent vbComponent in vbProject.VBComponents)
     {
         LogVbComponent(vbComponent);
     }
 }
Example #32
0
 public void RemoveProject(VBProject project)
 {
     foreach (var key in ParseResultCache.Keys.Where(k => k.Project.Equals(project)))
     {
         VBComponentParseResult result;
         ParseResultCache.TryRemove(key, out result);
     }
 }
Example #33
0
        /// <summary>
        /// Returns repository settings for project
        /// </summary>
        /// <param name="project">VBProject</param>
        /// <returns></returns>
        public RepositorySettings GetVBProjectRepository(VBProject project)
        {
            var projectRepoPath = GetVBProjectRepoPath(project);

            return(_config.Repositories.Find(r => (r.Name == project.GetRepoName() &&
                                                   NormalizePath(r.LocalPath) == NormalizePath(projectRepoPath) &&
                                                   Directory.Exists(r.LocalPath))));
        }
 public void RemoveProject(VBProject project)
 {
     foreach (var key in ParseResultCache.Keys.Where(k => k.Project.Equals(project)))
     {
         VBComponentParseResult result;
         ParseResultCache.TryRemove(key, out result);
     }
 }
  public QualifiedModuleName(VBProject project)  
  {
      _component = null;
      _componentName = null;
      _project = project;
      _projectName = project.Name;
      _projectHashCode = project.GetHashCode();
      _contentHashCode = 0;  
 }
        public void ItemRenamed(VBProject VBProject, string OldName)
        {
            var handler = ProjectRenamed;

            if (handler != null && VBProject.Protection == vbext_ProjectProtection.vbext_pp_none)
            {
                handler.Invoke(this, new DispatcherRenamedEventArgs <VBProject>(VBProject, OldName));
            }
        }
Example #37
0
 static void include_files(string[] vba_files, ref VBProject project)
 {
     foreach (string source in vba_files)
     {
         var module = project.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);
         module.CodeModule.AddFromFile(source);
         module.Name = Path.GetFileNameWithoutExtension(source);
     }
 }
Example #38
0
 public QualifiedModuleName(VBProject project)
 {
     _component       = null;
     _componentName   = null;
     _project         = project;
     _projectName     = project.Name;
     _projectHashCode = project.GetHashCode();
     _contentHashCode = 0;
 }
        public static void WorkbookGenerateModule(Excel.Workbook wb, string moduleName, string moduleContent)
        {
            VBProject   prj      = wb.VBProject;
            VBComponent xlModule = prj.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);

            xlModule.Name = moduleName;

            xlModule.CodeModule.AddFromString(moduleContent);
        }
 public QualifiedModuleName(VBProject project)
 {
     _component = null;
     _componentName = null;
     _project = project;
     _projectName = project.Name;
     _projectPath = string.Empty;
     _projectId = GetProjectId(project);
     _contentHashCode = 0;
 }
        public static IEnumerable <TestMethod> TestMethods(this VBProject project)
        {
            IHostApplication hostApp = project.VBE.HostApplication();

            return(project.VBComponents
                   .Cast <VBComponent>()
                   .Where(component => component.Type == vbext_ComponentType.vbext_ct_StdModule && component.CodeModule.HasAttribute <TestModuleAttribute>())
                   .Select(component => new { Component = component, Members = component.GetMembers().Where(member => IsTestMethod(member)) })
                   .SelectMany(component => component.Members.Select(method => new TestMethod(project.Name, component.Component.Name, method.Name, hostApp))));
        }
Example #42
0
        public ProgressDialog(IRubberduckParser parser, VBProject project)
            : this()
        {
            _parser = parser;
            _project = project;

            Shown += ProgressDialog_Shown;
            _bgw.WorkerReportsProgress = true;
            _bgw.DoWork += _bgw_DoWork;
            _bgw.RunWorkerCompleted += _bgw_RunWorkerCompleted;
        }
Example #43
0
        public GitProvider(VBProject project, IRepository repository, string userName, string passWord, ICodePaneWrapperFactory wrapperFactory)
            : this(project, repository, wrapperFactory)
        {
            _credentials = new UsernamePasswordCredentials()
            {
                Username = userName,
                Password = passWord
            };

            _credentialsHandler = (url, user, cred) => _credentials;
        }
Example #44
0
        public GitProvider(VBProject project, IRepository repository, ICredentials<SecureString> credentials, ICodePaneWrapperFactory wrapperFactory)
            : this(project, repository, wrapperFactory)
        {
            _credentials = new SecureUsernamePasswordCredentials()
            {
                Username = credentials.Username,
                Password = credentials.Password
            };

            _credentialsHandler = (url, user, cred) => _credentials;
        }
 private Declaration CreateProjectDeclaration(QualifiedModuleName projectQualifiedName, VBProject project)
 {
     var qualifiedName = projectQualifiedName.QualifyMemberName(project.Name);
     var projectId = qualifiedName.QualifiedModuleName.ProjectId;
     var projectDeclaration = new ProjectDeclaration(qualifiedName, project.Name);
     var references = _projectReferences.Where(projectContainingReference => projectContainingReference.ContainsKey(projectId));
     foreach (var reference in references)
     {
         int priority = reference[projectId];
         projectDeclaration.AddProjectReference(reference.ReferencedProjectId, priority);
     }
     return projectDeclaration;
 }
Example #46
0
        public GitProvider(VBProject project, IRepository repository, ICodePaneWrapperFactory wrapperFactory)
            : base(project, repository, wrapperFactory) 
        {
            _unsyncedLocalCommits = new List<ICommit>();
            _unsyncedRemoteCommits = new List<ICommit>();

            try
            {
                _repo = new LibGit2Sharp.Repository(CurrentRepository.LocalLocation);
            }
            catch (RepositoryNotFoundException ex)
            {
                throw new SourceControlException(SourceControlText.GitRepoNotFound, ex);
            }
        }
Example #47
0
        public GitProvider(VBProject project, IRepository repository)
            : base(project, repository)
        {
            _unsyncedLocalCommits = new List<ICommit>();
            _unsyncedRemoteCommits = new List<ICommit>();

            try
            {
                _repo = new LibGit2Sharp.Repository(CurrentRepository.LocalLocation);
            }
            catch (RepositoryNotFoundException ex)
            {
                throw new SourceControlException("Repository not found.", ex);
            }
        }
Example #48
0
        public static void SetSelection(this VBE vbe, VBProject vbProject, Selection selection, string name,
            ICodePaneWrapperFactory wrapperFactory)
        {
            try
            {
                var component = vbProject.VBComponents.Cast<VBComponent>().SingleOrDefault(c => c.Name == name);
                if (component == null)
                {
                    return;
                }

                var codePane = wrapperFactory.Create(component.CodeModule.CodePane);
                codePane.Selection = selection;
            }
            catch (Exception e)
            {
            }
        }
        public VBProjectParseResult Parse(VBProject project, object owner = null)
        {
            if (owner != null)
            {
                OnParseStarted(new[]{project.Name}, owner);
            }

            var results = new List<VBComponentParseResult>();
            if (project.Protection == vbext_ProjectProtection.vbext_pp_locked)
            {
                return new VBProjectParseResult(project, results);
            }

            var modules = project.VBComponents.Cast<VBComponent>();
            var mustResolve = false;
            foreach (var vbComponent in modules)
            {
                OnParseProgress(vbComponent);

                bool fromCache;
                var componentResult = Parse(vbComponent, out fromCache);

                if (componentResult != null)
                {
                    mustResolve = mustResolve || !fromCache;
                    results.Add(componentResult);
                }
            }

            var parseResult = new VBProjectParseResult(project, results);
            if (mustResolve)
            {
                parseResult.Progress += parseResult_Progress;
                parseResult.Resolve();
                parseResult.Progress -= parseResult_Progress;
            }
            if (owner != null)
            {
                OnParseCompleted(new[] {parseResult}, owner);
            }

            return parseResult;
        }
        public ISourceControlProvider CreateGitProvider(VBProject project, ICodePaneWrapperFactory wrapperFactory, [Optional] IRepository repository, [Optional] ICredentials credentials)
        {
            if (credentials != null)
            {
                if (repository == null)
                {
                    throw new ArgumentNullException("Must supply an IRepository if supplying credentials.");
                }

                return new GitProvider(project, repository, credentials, wrapperFactory);
            }

            if (repository != null) 
            {
                return new GitProvider(project, repository, wrapperFactory);
            }

            return new GitProvider(project);
        }
Example #51
0
        public static void SetSelection(this VBE vbe, VBProject vbProject, Selection selection, string name)
        {
            var project = vbe.VBProjects.Cast<VBProject>()
                             .SingleOrDefault(p => p.Protection != vbext_ProjectProtection.vbext_pp_locked 
                                               && ReferenceEquals(p, vbProject));

            VBComponent component = null;
            if (project != null)
            {
                component = project.VBComponents.Cast<VBComponent>()
                    .SingleOrDefault(c => c.Name == name);
            }

            if (component == null)
            {
                return;
            }

            component.CodeModule.CodePane.SetSelection(selection);
        }
        public VBProjectParseResult(VBProject project, IEnumerable<VBComponentParseResult> parseResults)
        {
            _project = project;
            _parseResults = parseResults;
            _declarations = new Declarations();

            var projectIdentifier = project.Name;
            var memberName = new QualifiedMemberName(new QualifiedModuleName(project), projectIdentifier);
            var projectDeclaration = new Declaration(memberName, "VBE", projectIdentifier, false, false, Accessibility.Global, DeclarationType.Project, false);
            _declarations.Add(projectDeclaration);

            foreach (var declaration in VbaStandardLib.Declarations)
            {
                _declarations.Add(declaration);
            }

            foreach (var declaration in _parseResults.SelectMany(item => item.Declarations))
            {
                _declarations.Add(declaration);
            }
        }
 protected SourceControlProviderBase(VBProject project, IRepository repository, ICodePaneWrapperFactory wrapperFactory)
     :this(project)
 {
     CurrentRepository = repository;
     _wrapperFactory = wrapperFactory;
 }
 protected SourceControlProviderBase(VBProject project)
 {
     Project = project;
 }
Example #55
0
 public GitProvider(VBProject project, IRepository repository, ICredentials credentials, ICodePaneWrapperFactory wrapperFactory)
     :base(project, repository, credentials.Username, credentials.Password, wrapperFactory)
 { }
Example #56
0
 public GitProvider(VBProject project, IRepository repository, string userName, string passWord, ICodePaneWrapperFactory wrapperFactory)
     : base(project, repository, userName, passWord, wrapperFactory)
 { }
Example #57
0
 public GitProvider(VBProject project, IRepository repository, ICodePaneWrapperFactory wrapperFactory)
     : base(project, repository, wrapperFactory)
 { }
Example #58
0
 public GitProvider(VBProject project) 
     : base(project)
 { }
Example #59
0
 public GitProvider(VBProject project)
     : base(project)
 {
     _unsyncedLocalCommits = new List<ICommit>();
     _unsyncedRemoteCommits = new List<ICommit>();
 }
 protected SourceControlProviderBase(VBProject project, IRepository repository)
     :this(project)
 {
     this.CurrentRepository = repository;
 }