private static void RegisterHandleDocumentInspector(Type type) { try { DocumentInspectorAttribute[] attributes = DocumentInspectorAttribute.GetAttributes(type); if (attributes.Length > 0) { GuidAttribute typeid = AttributeReflector.GetGuidAttribute(type); foreach (var attribute in attributes) { foreach (var version in attribute.ProcessedApplicationVersion) { DocumentInspectorAttribute.CreateKey("Word", attribute.Name, version, attribute.Selected, typeid.Value); } } } } catch (NetRuntimeSystem.Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Register, exception)) { throw; } } }
private static void UnregisterHandleDocumentInspector(Type type) { try { DocumentInspectorAttribute[] attributes = DocumentInspectorAttribute.GetAttributes(type); if (attributes.Length > 0) { RegistryLocationAttribute location = AttributeReflector.GetRegistryLocationAttribute(type); GuidAttribute typeid = AttributeReflector.GetGuidAttribute(type); foreach (var attribute in attributes) { foreach (var version in attribute.ProcessedApplicationVersion) { DocumentInspectorAttribute.TryDeleteKey("Word", attribute.Name, version); } } } } catch (Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, exception)) { throw; } } }
private void ProceedCustomPaneAttributes() { CustomPaneAttribute[] paneAttributes = AttributeReflector.GetCustomPaneAttributes(Type); foreach (CustomPaneAttribute itemPane in paneAttributes) { if (null != itemPane) { TaskPaneInfo item = TaskPanes.Add(itemPane.PaneType, itemPane.PaneType.Name); item.Title = itemPane.Title; item.Visible = itemPane.Visible; item.DockPosition = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), itemPane.DockPosition.ToString()); item.DockPositionRestrict = (Office.Enums.MsoCTPDockPositionRestrict)Enum.Parse(typeof(Office.Enums.MsoCTPDockPositionRestrict), itemPane.DockPositionRestrict.ToString()); item.Width = itemPane.Width; item.Height = itemPane.Height; item.Arguments = new object[] { this }; if (CallOnCreateTaskPaneInfo(item)) { item.VisibleStateChange += new NetOffice.OfficeApi.CustomTaskPane_VisibleStateChangeEventHandler(AttributePane_VisibleStateChange); item.DockPositionStateChange += new Office.CustomTaskPane_DockPositionStateChangeEventHandler(AttributePane_DockPositionStateChange); } else { TaskPanes.Remove(item); } } } }
/// <summary> /// Analyze COMAddin custom taskpane attributes /// </summary> /// <param name="taskPanes">taskpanes you want to create</param> /// <param name="addinType">addin class type informations</param> /// <param name="addin">addin instance</param> /// <param name="callOnCreateTaskPaneInfo">callback to manipulate the process dynamicly</param> /// <param name="visibleStateChange">visible changed event handler</param> /// <param name="dockPositionStateChange">dock state changed event handler</param> public void ProceedCustomPaneAttributes(OfficeApi.Tools.CustomTaskPaneCollection taskPanes, Type addinType, COMAddinBase addin, CallOnCreateTaskPaneInfoHandler callOnCreateTaskPaneInfo, CustomTaskPane_VisibleStateChangeEventHandler visibleStateChange, CustomTaskPane_DockPositionStateChangeEventHandler dockPositionStateChange) { CustomPaneAttribute[] paneAttributes = AttributeReflector.GetCustomPaneAttributes(addinType); foreach (CustomPaneAttribute itemPane in paneAttributes) { if (null != itemPane) { TaskPaneInfo item = taskPanes.Add(itemPane.PaneType, itemPane.PaneType.Name); item.Title = itemPane.Title; item.Visible = itemPane.Visible; item.DockPosition = (OfficeApi.Enums.MsoCTPDockPosition)Enum.Parse(typeof(OfficeApi.Enums.MsoCTPDockPosition), itemPane.DockPosition.ToString()); item.DockPositionRestrict = (OfficeApi.Enums.MsoCTPDockPositionRestrict)Enum.Parse(typeof(OfficeApi.Enums.MsoCTPDockPositionRestrict), itemPane.DockPositionRestrict.ToString()); item.Width = itemPane.Width; item.Height = itemPane.Height; item.Arguments = new object[] { addin, this }; if (callOnCreateTaskPaneInfo(item)) { item.VisibleStateChange += visibleStateChange; item.DockPositionStateChange += dockPositionStateChange; } else { taskPanes.Remove(item); } } } }
public static void UnregisterFunction(Type type) { if (null == type) { throw new ArgumentNullException("type"); } if (null != type.GetCustomAttribute <DontRegisterAddinAttribute>()) { return; } UnregisterHandleProgrammable(type, InstallScope.System); UnregisterHandleCodebase(type, InstallScope.System); MethodInfo registerMethod = null; UnRegisterFunctionAttribute registerAttribute = null; bool registerMethodPresent = AttributeReflector.GetUnRegisterAttribute(type, ref registerMethod, ref registerAttribute); if (null != registerAttribute && true == registerMethodPresent) { if (!TryCallDerivedUnRegisterMethod(registerMethod, type, InstallScope.System)) { if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, new UnregisterException())) { return; } } } }
public virtual string GetCustomUI(string RibbonID) { try { OlCustomUIAttribute olRibbon = GetOlRibbonAttribute(Type, RibbonID); if (null != olRibbon) { return(Utils.Resource.ReadString(OlCustomUIAttribute.BuildPath(olRibbon.Value, olRibbon.UseAssemblyNamespace, Type.Namespace))); } else { CustomUIAttribute ribbon = AttributeReflector.GetRibbonAttribute(Type, RibbonID); if (null != ribbon) { return(Utils.Resource.ReadString(CustomUIAttribute.BuildPath(ribbon.Value, ribbon.UseAssemblyNamespace, Type.Namespace))); } else { return(String.Empty); } } } catch (NetRuntimeSystem.Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); OnError(ErrorMethodKind.GetCustomUI, exception); return(String.Empty); } }
void NetOffice.Tools.Native.IDTExtensibility2.OnConnection(object application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom) { try { if (AttributeReflector.GetTweakAttribute(Type).Enabled == true) { string registryEndPoint = TryDetectHostRegistryKey(Application); if (null != registryEndPoint) { Tweaks.ApplyTweaks(Factory, this, Type, registryEndPoint, IsLoadedFromSystem); } } if (custom.Length > 0) { object firstCustomItem = custom.GetValue(1); string tryString = null != firstCustomItem?firstCustomItem.ToString() : String.Empty; System.Int32.TryParse(tryString, out _automationCode); } this.Application = Factory.CreateObjectFromComProxy(null, application, true); Utils = OnCreateUtils(); TryCreateCustomObject(AddInInst); RaiseOnConnection(Application, ConnectMode, AddInInst, ref custom); } catch (NetRuntimeSystem.Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); OnError(ErrorMethodKind.OnConnection, exception); } }
/// <summary> /// Checks for a static method, signed with the ErrorHandlerAttribute and call them if its available /// </summary> /// <param name="type">type information for the class wtih static method </param> /// <param name="methodKind">origin method where the error comes from</param> /// <param name="exception">occured exception</param> private static void RaiseStaticErrorHandlerMethod(Type type, RegisterErrorMethodKind methodKind, NetRuntimeSystem.Exception exception) { MethodInfo errorMethod = AttributeReflector.GetRegisterErrorMethod(type); if (null != errorMethod) { errorMethod.Invoke(null, new object[] { methodKind, exception }); } }
/// <summary> /// Creates an registry tweak entry in the current addin key /// </summary> /// <param name="applicationType">target office application</param> /// <param name="addinType">addin class type informations</param> /// <param name="name">name for the tweak</param> /// <param name="value">value for the tweak</param> /// <param name="throwException">throw exception on error</param> /// <returns>true if value was stored otherwise false</returns> public static bool SetTweakPersistenceEntry(ApplicationIdentifiers.ApplicationType applicationType, Type addinType, string name, string value, bool throwException) { try { if (null == addinType) { return(false); } RegistryLocationAttribute location = AttributeReflector.GetRegistryLocationAttribute(addinType); ProgIdAttribute progID = AttributeReflector.GetProgIDAttribute(addinType); OfficeApi.Tools.Contribution.RegistryLocationResult addinLocation = Tools.Contribution.CommonUtils.TryFindAddinLoadLocation(addinType, applicationType); if (addinLocation == Office.Tools.Contribution.RegistryLocationResult.Unknown) { return(false); } RegistryKey regKey = null; switch (addinLocation) { case Office.Tools.Contribution.RegistryLocationResult.User: regKey = Registry.LocalMachine.OpenSubKey(_addinOfficeRegistryKey + progID.Value, true); break; case Office.Tools.Contribution.RegistryLocationResult.System: regKey = Registry.CurrentUser.OpenSubKey(_addinOfficeRegistryKey + progID.Value, true); break; } if (null == regKey) { return(false); } regKey.SetValue(name, value); regKey.Close(); return(true); } catch (Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); if (throwException) { throw; } else { return(false); } } }
/// <summary> /// Create the used factory. The method was called as first in the base ctor /// </summary> /// <returns>new Settings instance</returns> protected virtual Core CreateFactory() { Core core = new Core(); ForceInitializeAttribute attribute = AttributeReflector.GetForceInitializeAttribute(Type); if (null != attribute) { core.Settings.EnableMoreDebugOutput = attribute.EnableMoreDebugOutput; core.CheckInitialize(); } return(core); }
public void Returns_specified_url_for_area_url_when_both_subdomain_is_specified_and_area_url_is_specified() { var configuration = new Configuration(); configuration.AddRoutesFromController <SubdomainWithAreaUrlController>(); var reflector = new AttributeReflector(configuration); var specs = reflector.BuildRouteSpecifications().ToList(); Assert.That(specs.Count, Is.EqualTo(1)); Assert.That(specs.Single().Subdomain, Is.EqualTo("private")); Assert.That(specs.Single().AreaUrl, Is.EqualTo("admin")); }
/// <summary> /// Create the used factory. The method was called as first in the base ctor /// </summary> /// <returns>new Settings instance</returns> protected virtual Core CreateFactory() { Core core = new Core(); ForceInitializeAttribute attribute = AttributeReflector.GetForceInitializeAttribute(Type); if (null != attribute) { core.Settings.EnableMoreDebugOutput = attribute.EnableMoreDebugOutput; core.CheckInitialize(); } else { core.Settings.MessageFilter.Enabled = true; // MSProject has known issues without } return(core); }
public void Returns_null_area_url_when_controller_configured_with_subdomain_only_via_configuration_object() { var configuration = new Configuration(); configuration.AddRoutesFromController <SubdomainControllerWithoutSubdomainInAttribute>(); configuration.MapArea("NoSubdomain").ToSubdomain("subdomain"); var reflector = new AttributeReflector(configuration); var specs = reflector.BuildRouteSpecifications().ToList(); var spec = specs.SingleOrDefault(); Assert.That(spec, Is.Not.Null); Assert.That(spec.Subdomain, Is.EqualTo("subdomain")); Assert.That(spec.AreaName, Is.EqualTo("NoSubdomain")); Assert.That(spec.AreaUrl, Is.EqualTo(null)); }
public void Returns_subdomain_specified_for_area_via_configuration_object() { var configuration = new Configuration(); configuration.AddRoutesFromController <SubdomainController>(); configuration.MapArea("Users").ToSubdomain("override"); var reflector = new AttributeReflector(configuration); var specs = reflector.BuildRouteSpecifications().ToList(); var spec = specs.SingleOrDefault(); Assert.That(spec, Is.Not.Null); Assert.That(spec.Subdomain, Is.EqualTo("override")); Assert.That(spec.AreaName, Is.EqualTo("Users")); Assert.That(spec.AreaUrl, Is.EqualTo(null)); }
private static void RegisterHandleRequireShutdownNotificationAttribute(Type type) { try { if (null != RequireShutdownNotificationAttribute.GetAttribute(type)) { RegistryLocationAttribute location = AttributeReflector.GetRegistryLocationAttribute(type); bool isSystem = location.IsMachineAddinTarget(); ProgIdAttribute progId = AttributeReflector.GetProgIDAttribute(type); RequireShutdownNotificationAttribute.CreateApplicationKey(isSystem, _addinOfficeRegistryKey, progId.Value); } } catch (System.Exception exception) { DebugConsole.Default.WriteException(exception); if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Register, exception)) { throw; } } }
private static void UnregisterHandleProgrammable(Type type, InstallScope scope) { try { ProgrammableAttribute programmable = AttributeReflector.GetProgrammableAttribute(type); if (null != programmable) { RegistryLocationAttribute location = AttributeReflector.GetRegistryLocationAttribute(type); bool isSystemComponent = location.IsMachineComponentTarget(scope); ProgrammableAttribute.DeleteKeys(type.GUID, isSystemComponent, false); } } catch (Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, exception)) { throw; } } }
private static void UnregisterHandleFormRegionAttribute(Type type) { try { var formAttributes = FormRegionAttribute.GetAttributes(type); foreach (var item in formAttributes) { RegistryLocationAttribute location = AttributeReflector.GetRegistryLocationAttribute(type); bool isSystem = location.IsMachineAddinTarget(); ProgIdAttribute progId = AttributeReflector.GetProgIDAttribute(type); FormRegionAttribute.TryDeleteKey(isSystem, _formRegionsOfficeRegistryKey, progId.Value, item.Category, item.Name); } } catch (System.Exception exception) { DebugConsole.Default.WriteException(exception); if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Register, exception)) { throw; } } }
private static void UnregisterHandleCodebase(Type type, InstallScope scope) { try { CodebaseAttribute codebase = AttributeReflector.GetCodebaseAttribute(type); if (null != codebase && codebase.Value == true) { RegistryLocationAttribute location = AttributeReflector.GetRegistryLocationAttribute(type); bool isSystemComponent = location.IsMachineComponentTarget(scope); Assembly thisAssembly = Assembly.GetAssembly(type); string assemblyVersion = thisAssembly.GetName().Version.ToString(); CodebaseAttribute.DeleteValue(type.GUID, isSystemComponent, assemblyVersion, false); } } catch (Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, exception)) { throw; } } }