Пример #1
0
        protected List <Declaration> LoadDeclarationsFromComProject(ComProject type)
        {
            var declarations = new List <Declaration>();

            var projectName = new QualifiedModuleName(type.Name, type.Path, type.Name);
            var project     = new ProjectDeclaration(type, projectName);

            declarations.Add(project);

            foreach (var alias in type.Aliases.Select(item => new AliasDeclaration(item, project, projectName)))
            {
                declarations.Add(alias);
            }

            foreach (var module in type.Members)
            {
                var moduleIdentifier = module.Type == DeclarationType.Enumeration || module.Type == DeclarationType.UserDefinedType
                    ? $"_{module.Name}"
                    : module.Name;
                var moduleName = new QualifiedModuleName(type.Name, type.Path, moduleIdentifier);

                var moduleDeclarations = GetDeclarationsForModule(module, moduleName, project);
                declarations.AddRange(moduleDeclarations);
            }

            return(declarations);
        }
Пример #2
0
        private List <Declaration> LoadDeclarationsFromLibrary(ReferenceInfo reference)
        {
            var libraryPath = reference.FullPath;
            // Failure to load might mean that it's a "normal" VBProject that will get parsed by us anyway.
            var typeLibrary = GetTypeLibrary(libraryPath);

            if (typeLibrary == null)
            {
                return(new List <Declaration>());
            }

            var type         = new ComProject(typeLibrary, libraryPath);
            var declarations = LoadDeclarationsFromComProject(type);

            return(declarations);
        }
        private IReadOnlyCollection <Declaration> LoadDeclarationsFromLibrary(ReferenceInfo reference)
        {
            var libraryPath = reference.FullPath;
            // Failure to load might mean that it's a "normal" VBProject that will get loaded through a different channel.
            var typeLibrary = GetTypeLibrary(libraryPath);

            if (typeLibrary == null)
            {
                return(new List <Declaration>());
            }

            var type         = new ComProject(typeLibrary, libraryPath);
            var declarations = LoadDeclarationsFromComProject(type);

            return(declarations);
        }
Пример #4
0
        [SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times")] //This is fine. XmlWriter disposes the FileStream, but calling twice is a NOP.
        public void SerializeProject(ComProject project)
        {
            var filepath = _fileSystem.Path.Combine(Target, FileName(project));

            using (var stream = _fileSystem.FileStream.Create(filepath, FileMode.Create, FileAccess.Write))
                using (var xmlWriter = XmlWriter.Create(stream, WriterSettings))
                    using (var writer = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter))
                    {
                        writer.WriteStartDocument();
                        var settings = new DataContractSerializerSettings
                        {
                            RootNamespace            = XmlDictionaryString.Empty,
                            PreserveObjectReferences = true
                        };
                        var serializer = new DataContractSerializer(typeof(ComProject), settings);
                        serializer.WriteObject(writer, project);
                    }
        }
        /// <summary>
        /// Use only on the UI thread!
        /// </summary>
        /// <remarks>
        ///This method uses the typeLib API, which is only safe to use on the UI thread.
        /// </remarks>
        private bool TryLoadProject(string projectId, IVBProject project, out ComProject comProject)
        {
            if (!project.TryGetFullPath(out var path))
            {
                //Only debug because this will always happen for unsaved projects.
                _logger.Debug($"Unable to get project path for project with projectId {projectId} when loading the COM project.");
                path = string.Empty;
            }

            using (var typeLib = _typeLibWrapperProvider.TypeLibWrapperFromProject(project))
            {
                comProject = typeLib != null
                    ? new ComProject(typeLib, path)
                    : null;
            }

            return(comProject != null);
        }
        private List <Declaration> LoadDeclarationsFromLibrary(ReferenceInfo reference)
        {
            var libraryPath = reference.FullPath;
            // Failure to load might mean that it's a "normal" VBProject that will get parsed by us anyway.
            var typeLibrary = GetTypeLibrary(libraryPath);

            if (typeLibrary == null)
            {
                return(new List <Declaration>());
            }

            var declarations = new List <Declaration>();

            var type = new ComProject(typeLibrary, libraryPath);

            var projectName = new QualifiedModuleName(type.Name, libraryPath, type.Name);
            var project     = new ProjectDeclaration(type, projectName);

            declarations.Add(project);

            foreach (var alias in type.Aliases.Select(item => new AliasDeclaration(item, project, projectName)))
            {
                declarations.Add(alias);
            }

            foreach (var module in type.Members)
            {
                var moduleIdentifier = module.Type == DeclarationType.Enumeration || module.Type == DeclarationType.UserDefinedType
                                        ? $"_{module.Name}"
                                        : module.Name;
                var moduleName = new QualifiedModuleName(reference.Name, libraryPath, moduleIdentifier);

                var moduleDeclarations = GetDeclarationsForModule(module, moduleName, project);
                declarations.AddRange(moduleDeclarations);
            }

            return(declarations);
        }
Пример #7
0
 private static string FileName(ComProject project)
 {
     return($"{project.Name}.{project.MajorVersion}.{project.MinorVersion}.xml");
 }
Пример #8
0
 public ComTypeName(ComProject project, string name, Guid enumGuid, Guid aliasGuid) : this(project, name)
 {
     EnumGuid  = enumGuid;
     AliasGuid = aliasGuid;
 }
Пример #9
0
 public ComTypeName(ComProject project, string name)
 {
     Project  = project;
     _rawName = name;
 }
Пример #10
0
        public List <Declaration> LoadDeclarationsFromLibrary()
        {
            ITypeLib typeLibrary;

            // Failure to load might mean that it's a "normal" VBProject that will get parsed by us anyway.
            LoadTypeLibEx(_path, REGKIND.REGKIND_NONE, out typeLibrary);
            if (typeLibrary == null)
            {
                return(_declarations);
            }

            var type = new ComProject(typeLibrary)
            {
                Path = _path
            };

            var projectName = new QualifiedModuleName(type.Name, _path, type.Name);
            var project     = new ProjectDeclaration(type, projectName);

            _serialized = new SerializableProject(project);
            _declarations.Add(project);

            foreach (var alias in type.Aliases.Select(item => new AliasDeclaration(item, project, projectName)))
            {
                _declarations.Add(alias);
                _serialized.AddDeclaration(new SerializableDeclarationTree(alias));
            }

            foreach (var module in type.Members)
            {
                var moduleName = new QualifiedModuleName(_referenceName, _path,
                                                         module.Type == DeclarationType.Enumeration || module.Type == DeclarationType.UserDefinedType
                        ? string.Format("_{0}", module.Name)
                        : module.Name);

                var declaration = CreateModuleDeclaration(module, moduleName, project, GetModuleAttributes(module));
                var moduleTree  = new SerializableDeclarationTree(declaration);
                _declarations.Add(declaration);
                _serialized.AddDeclaration(moduleTree);

                var membered = module as IComTypeWithMembers;
                if (membered != null)
                {
                    CreateMemberDeclarations(membered.Members, moduleName, declaration, moduleTree, membered.DefaultMember);
                    var coClass = membered as ComCoClass;
                    if (coClass != null)
                    {
                        CreateMemberDeclarations(coClass.SourceMembers, moduleName, declaration, moduleTree, coClass.DefaultMember, true);
                    }
                }

                var enumeration = module as ComEnumeration;
                if (enumeration != null)
                {
                    var enumDeclaration = new Declaration(enumeration, declaration, moduleName);
                    _declarations.Add(enumDeclaration);
                    var members = enumeration.Members.Select(e => new Declaration(e, enumDeclaration, moduleName)).ToList();
                    _declarations.AddRange(members);

                    var enumTree = new SerializableDeclarationTree(enumDeclaration);
                    moduleTree.AddChildTree(enumTree);
                    enumTree.AddChildren(members);
                }

                var structure = module as ComStruct;
                if (structure != null)
                {
                    var typeDeclaration = new Declaration(structure, declaration, moduleName);
                    _declarations.Add(typeDeclaration);
                    var members = structure.Fields.Select(f => new Declaration(f, typeDeclaration, moduleName)).ToList();
                    _declarations.AddRange(members);

                    var typeTree = new SerializableDeclarationTree(typeDeclaration);
                    moduleTree.AddChildTree(typeTree);
                    typeTree.AddChildren(members);
                }

                var fields = module as IComTypeWithFields;
                if (fields == null || !fields.Fields.Any())
                {
                    continue;
                }
                var declarations = fields.Fields.Select(f => new Declaration(f, declaration, projectName)).ToList();
                _declarations.AddRange(declarations);
                moduleTree.AddChildren(declarations);
            }
            _state.BuiltInDeclarationTrees.TryAdd(_serialized);
            return(_declarations);
        }
 protected IReadOnlyCollection <Declaration> LoadDeclarationsFromComProject(ComProject type, string projectId = null)
 {
     return(_declarationsFromComProjectLoader.LoadDeclarations(type, projectId));
 }