Ejemplo n.º 1
0
        public HResult Register(INiRegistrationContext registrationContext)
        {
            try
            {
                if (registrationContext == null)
                {
                    throw new ArgumentNullException("registrationContext");
                }

                var packageGuid = GetType().GUID.ToString("B").ToUpperInvariant();

                var    descriptionAttribute = GetType().GetCustomAttributes(typeof(DescriptionAttribute), true).Cast <DescriptionAttribute>().SingleOrDefault();
                string description          = descriptionAttribute != null ? descriptionAttribute.Description : registrationContext.PackageId;

                using (var key = registrationContext.CreateKey("Packages\\" + packageGuid))
                {
                    key.SetValue(null, this.ResolveStringResource(description));

                    foreach (var type in GetType().Assembly.GetTypes())
                    {
                        foreach (RegistrationAttribute attribute in type.GetCustomAttributes(typeof(RegistrationAttribute), true))
                        {
                            attribute.Register(this, registrationContext, key);
                        }
                    }
                }

                using (var key = registrationContext.CreateKey("InstalledProducts\\" + registrationContext.PackageId))
                {
                    key.SetValue(null, description);
                    key.SetValue("Package", packageGuid);
                    key.SetValue("Version", GetType().Assembly.GetName().Version.ToString());
                }

                // Add the installed products key.

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Ejemplo n.º 2
0
        public HResult Unregister(INiRegistrationContext registrationContext)
        {
            try
            {
                if (registrationContext == null)
                {
                    throw new ArgumentNullException("registrationContext");
                }

                var packageGuid = GetType().GUID.ToString("B").ToUpperInvariant();

                using (var key = registrationContext.CreateKey("Packages\\" + packageGuid))
                {
                    foreach (var type in GetType().Assembly.GetTypes())
                    {
                        foreach (RegistrationAttribute attribute in type.GetCustomAttributes(typeof(RegistrationAttribute), true))
                        {
                            attribute.Unregister(this, registrationContext, key);
                        }
                    }
                }

                // Un-registration allows attributes to perform cleanup other
                // than from inside the package namespace. The package namespace
                // itself is unconditionally deleted anyway, so the attributes
                // don't have to clean up that.

                registrationContext.RemoveKey("Packages\\" + packageGuid);
                registrationContext.RemoveKey("InstalledProducts\\" + registrationContext.PackageId);

                return(HResult.OK);
            }
            catch (Exception ex)
            {
                return(ErrorUtil.GetHResult(ex));
            }
        }
Ejemplo n.º 3
0
        public HResult Unregister(INiRegistrationContext registrationContext)
        {
            try
            {
                if (registrationContext == null)
                    throw new ArgumentNullException("registrationContext");

                var packageGuid = GetType().GUID.ToString("B").ToUpperInvariant();

                using (var key = registrationContext.CreateKey("Packages\\" + packageGuid))
                {
                    foreach (var type in GetType().Assembly.GetTypes())
                    {
                        foreach (RegistrationAttribute attribute in type.GetCustomAttributes(typeof(RegistrationAttribute), true))
                        {
                            attribute.Unregister(this, registrationContext, key);
                        }
                    }
                }

                // Un-registration allows attributes to perform cleanup other
                // than from inside the package namespace. The package namespace
                // itself is unconditionally deleted anyway, so the attributes
                // don't have to clean up that.

                registrationContext.RemoveKey("Packages\\" + packageGuid);
                registrationContext.RemoveKey("InstalledProducts\\" + registrationContext.PackageId);

                return HResult.OK;
            }
            catch (Exception ex)
            {
                return ErrorUtil.GetHResult(ex);
            }
        }
Ejemplo n.º 4
0
        public HResult Register(INiRegistrationContext registrationContext)
        {
            try
            {
                if (registrationContext == null)
                    throw new ArgumentNullException("registrationContext");

                var packageGuid = GetType().GUID.ToString("B").ToUpperInvariant();

                var descriptionAttribute = GetType().GetCustomAttributes(typeof(DescriptionAttribute), true).Cast<DescriptionAttribute>().SingleOrDefault();
                string description = descriptionAttribute != null ? descriptionAttribute.Description : registrationContext.PackageId;

                using (var key = registrationContext.CreateKey("Packages\\" + packageGuid))
                {
                    key.SetValue(null, this.ResolveStringResource(description));

                    foreach (var type in GetType().Assembly.GetTypes())
                    {
                        foreach (RegistrationAttribute attribute in type.GetCustomAttributes(typeof(RegistrationAttribute), true))
                        {
                            attribute.Register(this, registrationContext, key);
                        }
                    }
                }

                using (var key = registrationContext.CreateKey("InstalledProducts\\" + registrationContext.PackageId))
                {
                    key.SetValue(null, description);
                    key.SetValue("Package", packageGuid);
                    key.SetValue("Version", GetType().Assembly.GetName().Version.ToString());
                }

                // Add the installed products key.

                return HResult.OK;
            }
            catch (Exception ex)
            {
                return ErrorUtil.GetHResult(ex);
            }
        }