/// <include file='doc\ProvideEditorFactoryAttribute.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_NotifyEditorFactory, FactoryType.Name));

            using (Key childKey = context.CreateKey(EditorRegKey))
            {
                childKey.SetValue(string.Empty, FactoryType.Name);
                childKey.SetValue("DisplayName", string.Format(CultureInfo.InvariantCulture, "#{0}", NameResourceID));
                childKey.SetValue("Package", context.ComponentType.GUID.ToString("B"));
                childKey.SetValue("EditorTrustLevel", (int)_trustLevel);

                // Now report logical views for the editor factory.
                //
                using (Key viewKey = childKey.CreateSubkey("LogicalViews"))
                {
                    TypeConverter converter = TypeDescriptor.GetConverter(typeof(LogicalView));
                    foreach (ProvideViewAttribute pva in FactoryType.GetCustomAttributes(typeof(ProvideViewAttribute), true))
                    {
                        if (pva.LogicalView != LogicalView.Primary)
                        {
                            context.Log.WriteLine(SR.GetString(SR.Reg_NotifyEditorView, converter.ConvertToString(pva.LogicalView)));
                            Guid   logicalView  = (Guid)converter.ConvertTo(pva.LogicalView, typeof(Guid));
                            string physicalView = pva.PhysicalView;
                            if (physicalView == null)
                            {
                                physicalView = string.Empty;
                            }
                            viewKey.SetValue(logicalView.ToString("B"), physicalView);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public override void Register(RegistrationContext context)
 {
     using (Key key = context.CreateKey(EditorRegKey))
     {
         key.SetValue(string.Empty, FactoryType.Name);
         key.SetValue("DisplayName", string.Format(CultureInfo.InvariantCulture, "#{0}", NameResourceID));
         key.SetValue("Package", context.ComponentType.GUID.ToString("B"));
         key.SetValue("CommonPhysicalViewAttributes", (int)_commonPhysicalViewAttributes);
         key.SetValue("EditorTrustLevel", (int)_trustLevel);
         using (Key key2 = key.CreateSubkey("LogicalViews"))
         {
             TypeConverter converter        = TypeDescriptor.GetConverter(typeof(LogicalView));
             object[]      customAttributes = FactoryType.GetCustomAttributes(typeof(ProvideViewAttribute), true);
             foreach (ProvideViewAttribute attribute in customAttributes)
             {
                 if (attribute.LogicalView != LogicalView.Primary)
                 {
                     Guid   guid         = (Guid)converter.ConvertTo(attribute.LogicalView, typeof(Guid));
                     string physicalView = attribute.PhysicalView ?? string.Empty;
                     key2.SetValue(guid.ToString("B"), physicalView);
                 }
             }
         }
     }
 }