示例#1
0
 /// <summary>
 ///  Looks for a method with the RegisterFunctionAttribute
 /// </summary>
 /// <param name="type">the type you want looking for the method</param>
 /// <param name="method">the method when its found</param>
 /// <param name="attribute">the attribute when its found</param>
 /// <returns>true when the method was found</returns>
 public static bool GetRegisterAttribute(Type type, ref MethodInfo method, ref RegisterFunctionAttribute attribute)
 {
     foreach (MethodInfo item in type.GetMethods(BindingFlags.Static | BindingFlags.Public))
     {
         object[] array = item.GetCustomAttributes(typeof(RegisterFunctionAttribute), false);
         if (array.Length == 1)
         {
             method    = item;
             attribute = array[0] as RegisterFunctionAttribute;
             return(true);
         }
     }
     return(false);
 }
示例#2
0
 /// <summary>
 ///  Looks for a method with the RegisterFunctionAttribute
 /// </summary>
 /// <param name="type">the type you want looking for the method</param>
 /// <param name="method">the method when its found</param>
 /// <param name="attribute">the attribute when its found</param>
 /// <returns>true when the method was found</returns>
 public static bool GetRegisterAttribute(Type type, ref MethodInfo method, ref RegisterFunctionAttribute attribute)
 {
     foreach (MethodInfo item in type.GetMethods(BindingFlags.Static | BindingFlags.Public))
     {
         object[] array = item.GetCustomAttributes(typeof(RegisterFunctionAttribute), false);
         if (array.Length == 1)
         {
             method = item;
             attribute = array[0] as RegisterFunctionAttribute;
             return true;
         }
     }
     return false;
 }
        /// <summary>
        /// Do register process
        /// </summary>
        /// <param name="type">addin type</param>
        /// <param name="addinOfficeRegistryKey">office application registry path</param>
        /// <param name="scope">the current installation scope</param>
        /// <param name="keyState">the office registry key need to create</param>
        public static void Proceed(Type type, string[] addinOfficeRegistryKey, InstallScope scope, OfficeRegisterKeyState keyState)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }
            if (null == addinOfficeRegistryKey)
            {
                throw new ArgumentNullException("addinOfficeRegistryKey");
            }

            int errorBlock = -1;

            try
            {
                GuidAttribute             guid         = AttributeReflector.GetGuidAttribute(type);
                ProgIdAttribute           progId       = AttributeReflector.GetProgIDAttribute(type);
                RegistryLocationAttribute location     = AttributeReflector.GetRegistryLocationAttribute(type);
                COMAddinAttribute         addin        = AttributeReflector.GetCOMAddinAttribute(type, progId.Value);
                CodebaseAttribute         codebase     = AttributeReflector.GetCodebaseAttribute(type);
                LockbackAttribute         lockBack     = AttributeReflector.GetLockbackAttribute(type);
                ProgrammableAttribute     programmable = AttributeReflector.GetProgrammableAttribute(type);
                TimestampAttribute        timestamp    = AttributeReflector.GetTimestampAttribute(type);
                bool isSystemComponent = location.IsMachineComponentTarget(scope);
                bool isSystemAddin     = location.IsMachineAddinTarget(scope);

                MethodInfo registerMethod = null;
                RegisterFunctionAttribute registerAttribute = null;
                bool registerMethodPresent = false;

                errorBlock = 0;

                try
                {
                    registerMethodPresent = AttributeReflector.GetRegisterAttribute(type, ref registerMethod, ref registerAttribute);
                    if (null != registerAttribute && true == registerMethodPresent && (registerAttribute.Value == RegisterMode.CallBefore || registerAttribute.Value == RegisterMode.CallBeforeAndAfter))
                    {
                        if (!CallDerivedRegisterMethod(registerMethod, type, registerAttribute.Value == RegisterMode.Replace ? RegisterCall.Replace : RegisterCall.CallBefore, scope, keyState))
                        {
                            if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type,
                                                                                    RegisterErrorMethodKind.Register,
                                                                                    new RegisterException(errorBlock)))
                            {
                                return;
                            }
                        }

                        if (registerAttribute.Value == RegisterMode.Replace)
                        {
                            return;
                        }
                    }
                }
                catch (Exception)
                {
                    errorBlock = 1;
                    throw;
                }

                if (null != programmable)
                {
                    try
                    {
                        ProgrammableAttribute.CreateKeys(type.GUID, isSystemComponent);
                    }
                    catch (Exception)
                    {
                        errorBlock = 2;
                        throw;
                    }
                }

                if (null != codebase && codebase.Value)
                {
                    try
                    {
                        Assembly thisAssembly    = Assembly.GetAssembly(type);
                        string   assemblyVersion = thisAssembly.GetName().Version.ToString();
                        CodebaseAttribute.CreateValue(type.GUID, isSystemComponent, assemblyVersion, thisAssembly.CodeBase);
                    }
                    catch (Exception)
                    {
                        errorBlock = 3;
                        throw;
                    }
                }

                if (null != lockBack)
                {
                    if (!LockbackAttribute.CreateKey(isSystemComponent))
                    {
                        NetOffice.DebugConsole.Default.WriteLine("Unable to create lockback bypass.");
                    }
                }

                if (keyState == OfficeRegisterKeyState.NeedToCreate)
                {
                    try
                    {
                        foreach (string item in addinOfficeRegistryKey)
                        {
                            RegistryLocationAttribute.CreateApplicationKey(isSystemAddin, item, progId.Value,
                                                                           addin.LoadBehavior, addin.Name, addin.Description, addin.CommandLineSafe, null != timestamp);
                        }
                    }
                    catch (Exception)
                    {
                        errorBlock = 5;
                        throw;
                    }
                }

                if ((null != registerAttribute && true == registerMethodPresent) && (registerAttribute.Value == RegisterMode.CallAfter || registerAttribute.Value == RegisterMode.CallBeforeAndAfter))
                {
                    if (!CallDerivedRegisterMethod(registerMethod, type, RegisterCall.CallAfter, scope, keyState))
                    {
                        RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Register, new RegisterException(errorBlock));
                    }
                }
            }
            catch (System.Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteLine("RegisterHandler Exception.Block:{0}", errorBlock);
                NetOffice.DebugConsole.Default.WriteException(exception);
                if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Register, exception))
                {
                    throw;
                }
            }
        }
示例#4
0
 /// <summary>
 /// Derived Register Call Helper
 /// </summary>
 /// <param name="type">type for derived class</param>
 /// <param name="registerMethod">the method to call</param>
 /// <param name="registerAttribute">arguments</param>
 private static void CallDerivedRegisterMethod(Type type, MethodInfo registerMethod, RegisterFunctionAttribute registerAttribute)
 {
     if (registerAttribute.Value == RegisterMode.Replace)
         registerMethod.Invoke(null, new object[] { type, RegisterCall.Replace });
     else if (registerAttribute.Value == RegisterMode.CallBeforeAndAfter || registerAttribute.Value == RegisterMode.CallBefore)
         registerMethod.Invoke(null, new object[] { type, RegisterCall.CallBefore });
 }
示例#5
0
        /// <summary>
        /// Do register process
        /// </summary>
        /// <param name="type">addin type</param>
        /// <param name="addinOfficeRegistryKey">office application registry path</param>
        /// <param name="scope">the current installation scope</param>
        /// <param name="keyState">the office registry key need to create</param>
        public static void Proceed(Type type, string[] addinOfficeRegistryKey, InstallScope scope, OfficeRegisterKeyState keyState)
        {
            try
            {
                GuidAttribute             guid         = AttributeReflector.GetGuidAttribute(type);
                ProgIdAttribute           progId       = AttributeReflector.GetProgIDAttribute(type);
                RegistryLocationAttribute location     = AttributeReflector.GetRegistryLocationAttribute(type);
                COMAddinAttribute         addin        = AttributeReflector.GetCOMAddinAttribute(type);
                CodebaseAttribute         codebase     = AttributeReflector.GetCodebaseAttribute(type);
                LockbackAttribute         lockBack     = AttributeReflector.GetLockbackAttribute(type);
                ProgrammableAttribute     programmable = AttributeReflector.GetProgrammableAttribute(type);
                bool isSystem = location.IsMachineTarget(scope);

                MethodInfo registerMethod = null;
                RegisterFunctionAttribute registerAttribute = null;
                bool registerMethodPresent = AttributeReflector.GetRegisterAttribute(type, ref registerMethod, ref registerAttribute);
                if (null != registerAttribute && true == registerMethodPresent &&
                    registerAttribute.Value == RegisterMode.CallBefore || registerAttribute.Value == RegisterMode.CallBeforeAndAfter)
                {
                    if (!CallDerivedRegisterMethod(registerMethod, type, registerAttribute.Value == RegisterMode.Replace ? RegisterCall.Replace : RegisterCall.CallBefore, scope, keyState))
                    {
                        if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Register, new NetOfficeException(ExceptionMessage)))
                        {
                            return;
                        }
                    }
                    if (registerAttribute.Value == RegisterMode.Replace)
                    {
                        return;
                    }
                }

                if (null != programmable)
                {
                    ProgrammableAttribute.CreateKeys(type.GUID, isSystem);
                }

                if (null != codebase && codebase.Value)
                {
                    Assembly thisAssembly    = Assembly.GetAssembly(type);
                    string   assemblyVersion = thisAssembly.GetName().Version.ToString();
                    CodebaseAttribute.CreateValue(type.GUID, location.IsMachineTarget(scope), assemblyVersion, thisAssembly.CodeBase);
                }

                if (null != lockBack)
                {
                    if (!LockbackAttribute.CreateKey(isSystem))
                    {
                        NetOffice.DebugConsole.Default.WriteLine("Unable to create lockback bypass.");
                    }
                }

                if (keyState == OfficeRegisterKeyState.NeedToCreate)
                {
                    foreach (string item in addinOfficeRegistryKey)
                    {
                        RegistryLocationAttribute.CreateApplicationKey(location.IsMachineTarget(scope), item, progId.Value,
                                                                       addin.LoadBehavior, addin.Name, addin.Description, addin.CommandLineSafe);
                    }
                }

                if (null != registerAttribute && true == registerMethodPresent &&
                    registerAttribute.Value == RegisterMode.CallAfter || registerAttribute.Value == RegisterMode.CallBeforeAndAfter)
                {
                    if (!CallDerivedRegisterMethod(registerMethod, type, RegisterCall.CallAfter, scope, keyState))
                    {
                        RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Register, new NetOfficeException(ExceptionMessage));
                    }
                }
            }
            catch (System.Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteException(exception);
                RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Register, exception);
            }
        }