/// <include file='doc\ProvideObjectAttribute.uex' path='docs/doc[@for="Register"]' />
        /// <devdoc>
        ///     Called to register this attribute with the given context.  The context
        ///     contains the location where the registration inforomation should be placed.
        ///     it also contains such as the type being registered, and path information.
        ///
        ///     This method is called both for registration and unregistration.  The difference is
        ///     that unregistering just uses a hive that reverses the changes applied to it.
        /// </devdoc>
        public override void Register(RegistrationContext context)
        {
            context.Log.WriteLine(SR.GetString(SR.Reg_NotifyToolboxItemConfiguration, ObjectType.Name));

            using (Key childKey = context.CreateKey(CLSIDRegKey))
            {
                childKey.SetValue(string.Empty, ObjectType.FullName);
                childKey.SetValue("InprocServer32", context.InprocServerPath);
                childKey.SetValue("Class", ObjectType.FullName);
                if (context.RegistrationMethod == RegistrationMethod.CodeBase)
                {
                    childKey.SetValue("Codebase", context.CodeBase);
                }
                else
                {
                    childKey.SetValue("Assembly", ObjectType.Assembly.FullName);
                }
                childKey.SetValue("ThreadingModel", "Both");
            }

            string guid = ObjectType.GUID.ToString("B");

            // Now, look up the object type and look for assembly filters.
            foreach (object attr in ObjectType.GetCustomAttributes(typeof(ProvideAssemblyFilterAttribute), true))
            {
                ProvideAssemblyFilterAttribute filter = (ProvideAssemblyFilterAttribute)attr;
                context.Log.WriteLine(SR.GetString(SR.Reg_NotifyToolboxItemFilter, filter.AssemblyFilter));
                using (Key itemCfgKey = context.CreateKey(GetItemCfgFilterKey(filter.AssemblyFilter)))
                {
                    itemCfgKey.SetValue(ObjectType.FullName, guid);
                }
            }
        }
예제 #2
0
        // Check to ensure we've loaded the cache policy.
        //
        private void EnsureCachePolicy()
        {
            if (_cachePolicy == null || _cacheTime == null)
            {
                Debug.Assert(ObjectType != null, "Can't get policy before debug type is set.");
                CachePolicyAttribute cpa;
                if (!_cachedPolicies.TryGetValue(ObjectType, out cpa))
                {
                    // check the cache policy
                    //
                    var cpattributes = ObjectType.GetCustomAttributes(typeof(CachePolicyAttribute), true);

                    cpa = (CachePolicyAttribute)cpattributes.FirstOrDefault();

                    if (cpa == null)
                    {
                        cpa = CachePolicyAttribute.Default;
                    }
                    _cachedPolicies[ObjectType] = cpa;
                }

                _cachePolicy = cpa.CachePolicy;

                if (_cachePolicy == CachePolicy.NoCache)
                {
                    _cacheTime = TimeSpan.Zero;
                }
                else
                {
                    _cacheTime = TimeSpan.FromSeconds(cpa.CacheTimeInSeconds);
                }
            }
        }
        public override void Unregister(RegistrationContext context)
        {
            context.RemoveKey(CLSIDRegKey);

            // Now, look up the object type and remove assembly filters.
            foreach (object attr in ObjectType.GetCustomAttributes(typeof(ProvideAssemblyFilterAttribute), true))
            {
                ProvideAssemblyFilterAttribute filter = (ProvideAssemblyFilterAttribute)attr;
                context.RemoveKey(GetItemCfgFilterKey(filter.AssemblyFilter));
            }
        }