Esempio n. 1
0
        public static void SaveVsComPackages(this SdkInterfaceLibraryEntities entities, Process process, IEnumerable <KeyValuePair <Guid, object> > objects)
        {
            foreach (var pair in objects)
            {
                var obj     = pair.Value;
                var pUnk    = Marshal.GetIUnknownForObject(pair.Value);
                var service = GetServiceFromGuid(pair.Key);

                entities.SaveVsComObjects(process, obj, service, string.Empty, string.Empty);
            }
        }
Esempio n. 2
0
        public static void SaveServices(this SdkInterfaceLibraryEntities entities, Process process, Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider)
        {
            var executingAssembly = Assembly.GetExecutingAssembly();

            foreach (var assemblyRef in executingAssembly.GetReferencedAssemblies())
            {
                if (assemblyRef.Name.StartsWith("Microsoft.VisualStudio.", "EnvDTE."))
                {
                    var assembly = Assembly.Load(assemblyRef);

                    foreach (var refType in assembly.GetTypes().Where(t => t.IsInterface && t.HasCustomAttribute <GuidAttribute>()))
                    {
                        var    attr         = refType.GetCustomAttribute <GuidAttribute>();
                        var    guid         = Guid.Parse(attr.Value);
                        var    IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046");
                        IntPtr pUnk;

                        if (ErrorHandler.Succeeded(serviceProvider.QueryService(ref guid, ref IID_IUnknown, out pUnk)))
                        {
                            var serviceName = GetServiceFromGuid(guid);
                            var obj         = Marshal.GetObjectForIUnknown(pUnk);
                            var tblService  = entities.SaveIfNotExists <tblService>(s => s.ServiceName == serviceName, () =>
                            {
                                return(new tblService
                                {
                                    ServiceId = Guid.NewGuid(),
                                    ServiceName = serviceName,
                                    ComponentId = entities.CreateComponent(refType, Guid.Empty, process, obj).ComponentId
                                });
                            });

                            entities.SaveVsComObjects(process, obj, serviceName, string.Empty, string.Empty);
                        }
                    }
                }
            }
        }