private string GetNextTestModuleName(IVBProject project) { var names = project.ComponentNames(); var index = names.Count(n => n.StartsWith(TestModuleBaseName)) + 1; return(string.Concat(TestModuleBaseName, index)); }
private void EnsureValidProjectId(IVBProject project) { if (string.IsNullOrEmpty(project.ProjectId) || _projects.Keys.Contains(project.ProjectId)) { project.AssignProjectId(); } }
public ProjectDeclaration( QualifiedMemberName qualifiedName, string name, bool isUserDefined, IVBProject project) : base( qualifiedName, null, (Declaration)null, name, null, false, false, Accessibility.Implicit, DeclarationType.Project, null, null, Selection.Home, false, null, isUserDefined) { _project = project; _projectReferences = new List <ProjectReference>(); }
private void AddReferenceIfNeeded(IVBProject project, IUnitTestSettings settings) { switch (settings.BindingMode) { case BindingMode.EarlyBinding: _interaction.EnsureProjectReferencesUnitTesting(project); return; case BindingMode.LateBinding: return; case BindingMode.DualBinding: var precompile = _argumentsProvider.UserDefinedCompilationArguments(project.ProjectId); if (precompile is null) { return; } var setting = precompile.FirstOrDefault(option => option.Key.Equals(LateBindDirectiveName, StringComparison.CurrentCultureIgnoreCase)); if (!string.IsNullOrEmpty(setting.Key) && setting.Value != 0) { _interaction.EnsureProjectReferencesUnitTesting(project); } return; default: throw new ArgumentOutOfRangeException(); } }
public void SetModuleState(QualifiedModuleName module, ParserState state, SyntaxErrorException parserError = null, bool evaluateOverallState = true) { if (AllUserDeclarations.Any()) { var projectId = module.ProjectId; IVBProject project = GetProject(projectId); if (project == null) { // ghost component shouldn't even exist ClearStateCache(module); EvaluateParserState(); return; } } var oldState = GetModuleState(module); _moduleStates.AddOrUpdate(module, new ModuleState(state), (c, e) => e.SetState(state)); _moduleStates.AddOrUpdate(module, new ModuleState(parserError), (c, e) => e.SetModuleException(parserError)); Logger.Debug("Module '{0}' state is changing to '{1}' (thread {2})", module.ComponentName, state, Thread.CurrentThread.ManagedThreadId); OnModuleStateChanged(module, state, oldState); if (evaluateOverallState) { EvaluateParserState(); } }
protected override void OnExecute(object parameter) { var projectNode = parameter as CodeExplorerProjectViewModel; var vbproject = parameter as IVBProject; IVBProject project = projectNode?.Declaration.Project ?? vbproject ?? _vbe.ActiveVBProject; var desc = string.Format(RubberduckUI.ExportAllCommand_SaveAsDialog_Title, project.Name); // If .GetDirectoryName is passed an empty string for a RootFolder, // it defaults to the Documents library (Win 7+) or equivalent. var path = string.Empty; if (!string.IsNullOrWhiteSpace(project.FileName)) { path = Path.GetDirectoryName(project.FileName); } using (var _folderBrowser = _factory.CreateFolderBrowser(desc, true, path)) { var result = _folderBrowser.ShowDialog(); if (result == DialogResult.OK) { project.ExportSourceFiles(_folderBrowser.SelectedPath); } } }
private bool UserConfirmsToReplaceProjectContents(IVBProject project) { var projectName = project.Name; var message = string.Format(RubberduckUI.ReplaceProjectContentsFromFilesCommand_DialogCaption, projectName); return(MessageBox.ConfirmYesNo(message, DialogsTitle, false)); }
private void RegisterProjectHandlers(IVBProject project) { if (project.IsWrappingNullReference || project.Protection != ProjectProtection.Unprotected) { return; } project.AssignProjectId(); var components = project.VBComponents; _components.Add(project.ProjectId, components); components.AttachEvents(); components.ComponentAdded += ComponentAddedHandler; components.ComponentRemoved += ComponentRemovedHandler; components.ComponentRenamed += ComponentRenamedHandler; components.ComponentActivated += ComponentActivatedHandler; components.ComponentSelected += ComponentSelectedHandler; components.ComponentReloaded += ComponentReloadedHandler; var references = project.References; _references.Add(project.ProjectId, references); references.AttachEvents(); references.ItemAdded += ProjectReferenceAddedHandler; references.ItemRemoved += ProjectReferenceRemovedHandler; }
private string GetReferenceProjectId(IReference reference, IReadOnlyList <IVBProject> projects) { IVBProject project = null; foreach (var item in projects) { try { // check the name not just the path, because path is empty in tests: if (item.Name == reference.Name && item.FileName == reference.FullPath) { project = item; break; } } catch (IOException) { // Filename throws exception if unsaved. } catch (COMException e) { Logger.Warn(e); } } if (project != null) { if (string.IsNullOrEmpty(project.ProjectId)) { project.AssignProjectId(); } return(project.ProjectId); } return(QualifiedModuleName.GetProjectId(reference)); }
public void Remove(IVBProject project) { if (IsWrappingNullReference) { return; } Target.Remove((VB.VBProject)project.Target); }
public QualifiedModuleName(IVBProject project) { _componentName = null; ComponentType = ComponentType.Undefined; _projectName = project.Name; ProjectPath = string.Empty; ProjectId = GetProjectId(project); }
internal static ITypeLibWrapper FromVBProject(IVBProject vbProject) { using (var references = vbProject.References) { // Now we've got the references object, we can read the internal object structure to grab the ITypeLib var internalReferencesObj = StructHelper.ReadComObjectStructure <VBEReferencesObj>(references.Target); return(TypeApiFactory.GetTypeLibWrapper(internalReferencesObj._typeLib, addRef: true)); } }
public static void AddComponent(this IVBProject vbProject, string name, ComponentType type, string content, Selection selection = new Selection()) { var component = new VbComponent(vbProject.VBE, name, type, vbProject.VBComponents); var codePane = new CodePane(vbProject.VBE, new Window(name), selection, component); vbProject.VBE.ActiveCodePane = codePane; component.CodeModule = codePane.CodeModule = new CodeModule(vbProject.VBE, name, content, component, codePane); ((VbComponents)vbProject.VBComponents).Add(component); }
public QualifiedModuleName(IVBProject project) { _componentName = null; ComponentType = ComponentType.Undefined; _projectName = project.Name; ProjectPath = string.Empty; ProjectId = GetProjectId(project); ModuleContentHashOnCreation = GetModuleContentHash(null); }
public ReferenceModel(IVBProject project, int priority) : this() { Name = project.Name ?? string.Empty; Priority = priority; Guid = Guid.Empty; Description = project.Description ?? project.Name; FullPath = project.FileName ?? string.Empty; IsBuiltIn = false; Type = ReferenceKind.Project; }
private static void AddProject(this IVBE vbe, IVBProject project) { ((VbProjects)vbe.VBProjects).Projects.Add(project); foreach (IVBComponent component in ((VbProjects)vbe.VBProjects).Projects.SelectMany(x => x.VBComponents)) { ((CodePanes)vbe.CodePanes).Panes.Add(component.CodeModule.CodePane); } vbe.ActiveVBProject = project; vbe.ActiveCodePane = project.VBComponents[0].CodeModule.CodePane; }
public void EnsureProjectReferencesUnitTesting(IVBProject project) { if (project == null || project.IsWrappingNullReference) { return; } var libFolder = IntPtr.Size == 8 ? "win64" : "win32"; const string libGuid = RubberduckGuid.RubberduckTypeLibGuid; var pathKey = Registry.ClassesRoot.OpenSubKey( $@"TypeLib\{{{libGuid}}}\{_rubberduckVersion.Major}.{_rubberduckVersion.Minor}\0\{libFolder}"); if (pathKey != null) { var referencePath = pathKey.GetValue(string.Empty, string.Empty) as string; string name = null; if (!string.IsNullOrWhiteSpace(referencePath)) { var tlbKey = Registry.ClassesRoot.OpenSubKey( $@"TypeLib\{{{libGuid}}}\{_rubberduckVersion.Major}.{_rubberduckVersion.Minor}"); if (tlbKey != null) { name = tlbKey.GetValue(string.Empty, string.Empty) as string; tlbKey.Dispose(); } } if (string.IsNullOrWhiteSpace(referencePath) || string.IsNullOrWhiteSpace(name)) { throw new InvalidOperationException( "Cannot locate the tlb in the registry or the entry may be corrupted. Therefore early binding is not possible"); } using (var references = project.References) { var reference = FindReferenceByName(references, name); if (reference != null) { references.Remove(reference); reference.Dispose(); } if (!ReferenceWithPathExists(references, referencePath)) { // AddFromFile returns a new wrapped reference so we must // ensure it is disposed properly. using (references.AddFromFile(referencePath)) { } } } pathKey.Dispose(); } }
public GitProvider(IVBProject project, IRepository repository, string userName, string passWord) : this(project, repository) { _credentials = new UsernamePasswordCredentials() { Username = userName, Password = passWord }; _credentialsHandler = (url, user, cred) => _credentials; }
public GitProvider(IVBProject project, IRepository repository, ICredentials <SecureString> credentials) : this(project, repository) { _credentials = new SecureUsernamePasswordCredentials() { Username = credentials.Username, Password = credentials.Password }; _credentialsHandler = (url, user, cred) => _credentials; }
private Declaration CreateProjectDeclaration(IVBProject project) { var qualifiedModuleName = new QualifiedModuleName(project); var qualifiedName = qualifiedModuleName.QualifyMemberName(project.Name); var projectId = qualifiedModuleName.ProjectId; var projectDeclaration = new ProjectDeclaration(qualifiedName, qualifiedName.MemberName, true, project); var references = ProjectReferences(projectId); AddReferences(projectDeclaration, references); return(projectDeclaration); }
private bool Evaluate(IVBProject project) { if (project == null || project.IsWrappingNullReference) { return(false); } using (var compontents = project.VBComponents) { return(compontents.Count > 0); } }
private bool TryStoreLockedProject(IVBProject project) { if (!project.TryGetFullPath(out var path)) { _logger.Warn("Path of locked project could not be read."); } var projectName = project.Name; var projectId = QualifiedModuleName.GetProjectId(projectName, path); _lockedProjects.Add(projectId, project); return(true); }
private string GetNextTestModuleName(IVBProject project) { var names = new HashSet <string>(project.ComponentNames().Where(module => module.StartsWith(TestModuleBaseName))); var index = 1; while (names.Contains($"{TestModuleBaseName}{index}")) { index++; } return($"{TestModuleBaseName}{index}"); }
public static string GetProjectId(IVBProject project) { if (project.IsWrappingNullReference) { return(string.Empty); } if (string.IsNullOrEmpty(project.HelpFile)) { project.HelpFile = project.GetHashCode().ToString(CultureInfo.InvariantCulture); } return(project.HelpFile); }
public static void SetSelection(IVBProject vbProject, Selection selection, string name) { var components = vbProject.VBComponents; var component = components.SingleOrDefault(c => c.Name == name); if (component == null || component.IsWrappingNullReference) { return; } var module = component.CodeModule; var pane = module.CodePane; pane.Selection = selection; }
public GitProvider(IVBProject 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(SourceControlText.GitRepoNotFound, ex); } }
/// <summary> /// Imports all source code files from target directory into project. /// </summary> /// <remarks> /// Only files with extensions "cls", "bas, "frm", and "doccls" are imported. /// It is the callers responsibility to remove any existing components prior to importing. /// </remarks> /// <param name="project"></param> /// <param name="filePath">Directory path containing the source files.</param> public static void ImportDocumentTypeSourceFiles(this IVBProject project, string filePath) { var dirInfo = new DirectoryInfo(filePath); var files = dirInfo.EnumerateFiles() .Where(f => f.Extension == ComponentTypeExtensions.DocClassExtension); foreach (var file in files) { try { project.VBComponents.ImportSourceFile(file.FullName); } catch (IndexOutOfRangeException) { } // component didn't exist } }
private void ImportFilesWithSuspension(ICollection <string> filesToImport, IVBProject targetProject) { var suspendResult = _parseManager.OnSuspendParser(this, new[] { ParserState.Ready }, () => ImportFiles(filesToImport, targetProject)); var suspendOutcome = suspendResult.Outcome; if (suspendOutcome != SuspensionOutcome.Completed) { if (suspendOutcome == SuspensionOutcome.UnexpectedError || suspendOutcome == SuspensionOutcome.Canceled) { //This rethrows the exception with the original stack trace. ExceptionDispatchInfo.Capture(suspendResult.EncounteredException).Throw(); return; } Logger.Warn("File import failed due to suspension failure."); } }
public static string GetProjectId(IVBProject project) { if (project.IsWrappingNullReference) { return(string.Empty); } var projectId = project.ProjectId; if (string.IsNullOrEmpty(projectId)) { project.AssignProjectId(); projectId = project.ProjectId; } return(projectId); }
private void AddTestModule(IVBProject project, Declaration stubSource) { if (project == null || project.IsWrappingNullReference) { return; } var settings = _settings.Create(); AddReferenceIfNeeded(project, settings); try { using (var components = project.VBComponents) using (var component = components.Add(ComponentType.StandardModule)) using (var module = component.CodeModule) { component.Name = GetNextTestModuleName(project); // Test modules always have appropriate options so remove any pre-generated code. if (module.CountOfLines > 0) { module.DeleteLines(1, module.CountOfLines); } if (stubSource != null) { var code = GetNewTestModuleCode(component, GetDeclarationsToStub(stubSource).ToList()); module.AddFromString(code); } else { module.AddFromString(GetNewTestModuleCode(component)); } component.Activate(); } } catch (Exception ex) { _messageBox.Message(TestExplorer.Command_AddTestModule_Error); Logger.Warn("Unable to add test module. An exception was thrown."); Logger.Warn(ex); } }