Пример #1
0
        private static RegExport RegExportFunction(Type type, int scope, int keyState)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }
            InstallScope           currentScope    = (InstallScope)scope;
            OfficeRegisterKeyState currentKeyState = (OfficeRegisterKeyState)keyState;

            return(RegExportHandler.Proceed(type, new string[] { _addinOfficeRegistryKey }, currentScope, currentKeyState));
        }
Пример #2
0
        public static void ShowRegister(Type type, RegisterCall registerCall, InstallScope scope, OfficeRegisterKeyState keyState, string from)
        {
            string text = String.Format(
                "Register Type:{1}{0}Assembly Name:{2}{0}Assembly Version:{3}{0}RegisterCall:{4}{0}Scope:{5}{0}KeyState:{6}{0}",
                Environment.NewLine, type, type.Assembly.GetName().Name, type.Assembly.GetName().Version, registerCall, scope, keyState);

            if (_enabled)
                MessageBox.Show(text, "Register " + from);
            else
                Console.WriteLine("Register " + from + " :" + text);
        }
Пример #3
0
        private static void OptimizedRegisterFunction(Type type, int scope, int keyState)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }
            InstallScope           currentScope    = (InstallScope)scope;
            OfficeRegisterKeyState currentKeyState = (OfficeRegisterKeyState)keyState;

            RegisterHandler.Proceed(type, new string[] { _addinOfficeRegistryKey }, currentScope, currentKeyState);
        }
Пример #4
0
        private static void OptimizedRegisterFunction(Type type, int scope, int keyState)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }
            if (null != type.GetCustomAttribute <DontRegisterAddinAttribute>())
            {
                return;
            }

            OfficeRegisterKeyState currentKeyState = (OfficeRegisterKeyState)keyState;

            COMAddinRegisterHandler.ProceedUser(type, new string[] { _addinOfficeRegistryKey, _addinOfficeRegistryKey64 }, currentKeyState);
        }
Пример #5
0
        private static void OptimizedRegisterFunction(Type type, int scope, int keyState)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }
            if (null != type.GetCustomAttribute <DontRegisterAddinAttribute>())
            {
                return;
            }

            InstallScope           currentScope    = (InstallScope)scope;
            OfficeRegisterKeyState currentKeyState = (OfficeRegisterKeyState)keyState;

            COMAddinRegisterHandler.Proceed(type, new string[] { _addinOfficeRegistryKey }, currentScope, currentKeyState);
            RegisterHandleRequireShutdownNotificationAttribute(type);
            RegisterHandleFormRegionAttribute(type);
        }
Пример #6
0
        private static void OptimizedRegisterFunction(Type type, int scope, int keyState)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }
            InstallScope           currentScope    = (InstallScope)scope;
            OfficeRegisterKeyState currentKeyState = (OfficeRegisterKeyState)keyState;

            MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type);

            string[] product = new string[attribute.Products.Length];
            for (int i = 0; i < attribute.Products.Length; i++)
            {
                product[i] = String.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(attribute.Products[i]));
            }

            COMAddinRegisterHandler.Proceed(type, product, currentScope, currentKeyState);
        }
Пример #7
0
        private static RegExport RegExportFunction(Type type, int scope, int keyState)
        {
            if (null == type)
            {
                throw new ArgumentNullException("type");
            }
            InstallScope           currentScope    = (InstallScope)scope;
            OfficeRegisterKeyState currentKeyState = (OfficeRegisterKeyState)keyState;

            MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type);

            string[] product = new string[attribute.Products.Length];
            for (int i = 0; i < attribute.Products.Length; i++)
            {
                product[i] = MultiRegisterAttribute.RegistryEntry(attribute.Products[i]);
            }

            return(RegExportHandler.Proceed(type, new string[] { _addinOfficeRegistryKey }, currentScope, currentKeyState));
        }
Пример #8
0
        /// <summary>
        /// Do register export 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 RegExport Proceed(Type type, string[] addinOfficeRegistryKey, InstallScope scope, OfficeRegisterKeyState keyState)
        {            
            try
            {
                object result = null;
                MethodInfo exportMethod = null;
                RegExportFunctionAttribute registerAttribute = null;
                bool registerMethodPresent = AttributeReflector.GetRegExportAttribute(type, ref exportMethod, ref registerAttribute);
                if (registerMethodPresent)
                {
                    ParameterInfo[] arguments = exportMethod.GetParameters();
                    int argumentCount = arguments.Length;
                    switch (argumentCount)
                    {
                        case 0:
                            result = exportMethod.Invoke(null, new object[0]);
                            break;
                        case 1:
                            result = exportMethod.Invoke(null, new object[] { scope });
                            break;
                        case 2:
                            result = exportMethod.Invoke(null, new object[] { scope, keyState});
                            break;
                        case 3:
                            exportMethod.Invoke(null, new object[] { type, scope, keyState });
                            break;
                        default:
                            break;
                    }

                    return result as RegExport;
                }
                else
                    return null;
            }
            catch (System.Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteException(exception);
                RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Export, exception);
                return null;
            }
        }
Пример #9
0
        private static RegExport CreateExport(InstallScope scope, OfficeRegisterKeyState keyState)
        {
            Console.WriteLine("ExcelConnect::CreateExport");
            RegExport export = new RegExport();

            export.Add("Software\\Microsoft\\Office\\Excel\\Addins\\ClientAddin.ExcelConnect",
                new RegExportValue[] {
                                       new RegExportValue("Value 1", Microsoft.Win32.RegistryValueKind.DWord, 144),
                                       new RegExportValue("Value 2", Microsoft.Win32.RegistryValueKind.QWord, 1433689),
                                       new RegExportValue("Value 3", Microsoft.Win32.RegistryValueKind.String,"Hello Excel"),
                                       new RegExportValue("Value 4", Microsoft.Win32.RegistryValueKind.ExpandString, "Hello World"),
                                       new RegExportValue("Value 5", Microsoft.Win32.RegistryValueKind.MultiString, new string[] { "Item 1","Item 2","Item 3"}),
                                       new RegExportValue("Value 6", Microsoft.Win32.RegistryValueKind.Binary,new byte[] { 1, 2, 3, 4, 0, 7, 15, 31, 127, 255}),
                                    });

            IList<RegExportValue> settings = export.Add("Software\\Microsoft\\Office\\Excel\\Addins\\ClientAddin.ExcelConnect\\Settings");
            settings.Add(new RegExportValue("", "I was here"));
            settings.Add(new RegExportValue("Setting 1", "Enabled"));
            settings.Add(new RegExportValue("Setting 2", "Disabled"));
            
            return export;
        }
Пример #10
0
        private static RegExport CreateExport(InstallScope scope, OfficeRegisterKeyState keyState)
        {
            Console.WriteLine("ExcelConnect::CreateExport");
            RegExport export = new RegExport();

            export.Add("Software\\Microsoft\\Office\\Excel\\Addins\\ClientAddin.ExcelConnect",
                       new RegExportValue[] {
                new RegExportValue("Value 1", Microsoft.Win32.RegistryValueKind.DWord, 144),
                new RegExportValue("Value 2", Microsoft.Win32.RegistryValueKind.QWord, 1433689),
                new RegExportValue("Value 3", Microsoft.Win32.RegistryValueKind.String, "Hello Excel"),
                new RegExportValue("Value 4", Microsoft.Win32.RegistryValueKind.ExpandString, "Hello World"),
                new RegExportValue("Value 5", Microsoft.Win32.RegistryValueKind.MultiString, new string[] { "Item 1", "Item 2", "Item 3" }),
                new RegExportValue("Value 6", Microsoft.Win32.RegistryValueKind.Binary, new byte[] { 1, 2, 3, 4, 0, 7, 15, 31, 127, 255 }),
            });

            IList <RegExportValue> settings = export.Add("Software\\Microsoft\\Office\\Excel\\Addins\\ClientAddin.ExcelConnect\\Settings");

            settings.Add(new RegExportValue("", "I was here"));
            settings.Add(new RegExportValue("Setting 1", "Enabled"));
            settings.Add(new RegExportValue("Setting 2", "Disabled"));

            return(export);
        }
Пример #11
0
 [RegisterFunction(RegisterMode.CallAfter)]  // We want that NetOffice call this method after register
 private static void Register(Type type, RegisterCall registerCall, InstallScope scope, OfficeRegisterKeyState keyState)
 {
 }
Пример #12
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);
            }
        }
        /// <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;
                }
            }
        }
 /// <summary>
 /// Do register process per user installation
 /// </summary>
 /// <param name="type">addin type</param>
 /// <param name="addinOfficeRegistryKey">office application registry path</param>
 /// <param name="keyState">the office registry key need to create</param>
 public static void ProceedUser(Type type, string[] addinOfficeRegistryKey, OfficeRegisterKeyState keyState)
 {
     Proceed(type, addinOfficeRegistryKey, InstallScope.User, keyState);
 }
        /// <summary>
        /// Derived Register Call Helper
        /// </summary>
        /// <param name="registerMethod">the method to call</param>
        /// <param name="type">type for derived class</param>
        /// <param name="callType">kind of call, defined in Register attribute</param>
        /// <param name="scope">current register scope</param>
        /// <param name="keyState">office reg key state</param>
        /// <returns>true if no exception occurs, otherwise false</returns>
        public static bool CallDerivedRegisterMethod(MethodInfo registerMethod, Type type,
                                                     RegisterCall callType, InstallScope scope, OfficeRegisterKeyState keyState)
        {
            try
            {
                ParameterInfo[] arguments      = registerMethod.GetParameters();
                int             argumentsCount = arguments.Length;
                switch (argumentsCount)
                {
                case 0:
                    registerMethod.Invoke(null, new object[0]);
                    break;

                case 1:
                    if (arguments[0].ParameterType.GUID == typeof(InstallScope).GUID)
                    {
                        registerMethod.Invoke(null, new object[] { scope });
                    }
                    else if (arguments[0].ParameterType.GUID == typeof(RegisterCall).GUID)
                    {
                        registerMethod.Invoke(null, new object[] { callType });
                    }
                    else
                    {
                        registerMethod.Invoke(null, new object[] { type });
                    }
                    break;

                case 2:
                    registerMethod.Invoke(null, new object[] { type, callType });
                    break;

                case 3:
                    registerMethod.Invoke(null, new object[] { type, callType, scope });
                    break;

                case 4:
                    registerMethod.Invoke(null, new object[] { type, callType, scope, keyState });
                    break;

                default:
                    break;
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #16
0
 private static void UnRegister(Type type, RegisterCall registerCall, InstallScope scope, OfficeRegisterKeyState keyState)
 {
     try
     {
         using (CdeclHandle libray = CdeclHandle.LoadLibrary <Addin>("Excel06AddinCS4.Shim.dll"))
         {
             SayHello hello = libray.GetDelegateForFunctionPointer <SayHello>("SayHelloToTheWorld");
             hello("Unregister Excel06AddinCS4");
         }
     }
     catch (Exception ex)
     {
         Office.Tools.Contribution.DialogUtils.ShowMessageBox(ex.ToString());
     }
 }
Пример #17
0
 private static void Register(Type type, RegisterCall registerCall, InstallScope scope, OfficeRegisterKeyState keyState)
 {
     MessageDialog.ShowRegister(type, registerCall, scope, keyState, "Excel");
 }
Пример #18
0
 /// <summary>
 /// Derived Register Call Helper
 /// </summary>
 /// <param name="registerMethod">the method to call</param>
 /// <param name="type">type for derived class</param>
 /// <param name="callType">kind of call, defined in Register attribute</param>
 /// <param name="scope">current register scope</param>
 /// <param name="keyState">office reg key state</param>
 /// <returns>true if no exception occurs</returns>
 private static bool CallDerivedRegisterMethod(MethodInfo registerMethod, Type type, 
     RegisterCall callType, InstallScope scope, OfficeRegisterKeyState keyState)
 {
     try
     {
         ParameterInfo[] arguments = registerMethod.GetParameters();
         int argumentsCount = arguments.Length;
         switch (argumentsCount)
         {
             case 0:
                 registerMethod.Invoke(null, new object[0]);
                 break;
             case 1:
                 if(arguments[0].ParameterType.GUID == typeof(InstallScope).GUID)
                     registerMethod.Invoke(null, new object[] { scope });
                 else if (arguments[0].ParameterType.GUID == typeof(RegisterCall).GUID)
                     registerMethod.Invoke(null, new object[] { callType });
                 else
                     registerMethod.Invoke(null, new object[] { type });
                 break;
             case 2:
                 registerMethod.Invoke(null, new object[] { type, callType });
                 break;
             case 3:
                 registerMethod.Invoke(null, new object[] { type, callType, scope });
                 break;
             case 4:
                 registerMethod.Invoke(null, new object[] { type, callType, scope, keyState });
                 break;
             default:
                 break;
         }
         return true;
     }
     catch (Exception)
     {
         return true;
     }          
 }        
Пример #19
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);
            }
        }
Пример #20
0
        /// <summary>
        /// Do register export 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 RegExport Proceed(Type type, string[] addinOfficeRegistryKey, InstallScope scope, OfficeRegisterKeyState keyState)
        {
            try
            {
                object     result       = null;
                MethodInfo exportMethod = null;
                RegExportFunctionAttribute registerAttribute = null;
                bool registerMethodPresent = AttributeReflector.GetRegExportAttribute(type, ref exportMethod, ref registerAttribute);
                if (registerMethodPresent)
                {
                    ParameterInfo[] arguments     = exportMethod.GetParameters();
                    int             argumentCount = arguments.Length;
                    switch (argumentCount)
                    {
                    case 0:
                        result = exportMethod.Invoke(null, new object[0]);
                        break;

                    case 1:
                        result = exportMethod.Invoke(null, new object[] { scope });
                        break;

                    case 2:
                        result = exportMethod.Invoke(null, new object[] { scope, keyState });
                        break;

                    case 3:
                        exportMethod.Invoke(null, new object[] { type, scope, keyState });
                        break;

                    default:
                        break;
                    }

                    return(result as RegExport);
                }
                else
                {
                    return(null);
                }
            }
            catch (System.Exception exception)
            {
                NetOffice.DebugConsole.Default.WriteException(exception);
                RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Export, exception);
                return(null);
            }
        }
Пример #21
0
        public static void ShowRegister(Type type, RegisterCall registerCall, InstallScope scope, OfficeRegisterKeyState keyState, string from)
        {
            string text = String.Format(
                "Register Type:{1}{0}Assembly Name:{2}{0}Assembly Version:{3}{0}RegisterCall:{4}{0}Scope:{5}{0}KeyState:{6}{0}",
                Environment.NewLine, type, type.Assembly.GetName().Name, type.Assembly.GetName().Version, registerCall, scope, keyState);

            if (_enabled)
            {
                MessageBox.Show(text, "Register " + from);
            }
            else
            {
                Console.WriteLine("Register " + from + " :" + text);
            }
        }
Пример #22
0
 private static void Register(Type type, RegisterCall registerCall, InstallScope scope, OfficeRegisterKeyState keyState)
 {
     MessageDialog.ShowRegister(type, registerCall, scope, keyState, "Excel");
 }
Пример #23
0
 private static void Register(Type type, RegisterCall registerCall, InstallScope scope, OfficeRegisterKeyState keyState)
 {
     try
     {
         // requires NetOffice 1.7.4.2+
         using (CdeclHandle libray = CdeclHandle.LoadLibrary(typeof(Addin), "Excel06AddinCS4.Shim.dll"))
         {
             SayHello hello = libray.GetDelegateForFunctionPointer("SayHelloToTheWorld", typeof(SayHello)) as SayHello;
             hello("Excel06AddinCS4");
         }
     }
     catch (Exception ex)
     {
         Office.Tools.Contribution.DialogUtils.ShowMessageBox(ex.ToString());
     }
 }
Пример #24
0
 /// <summary>
 /// Do register export process per user
 /// </summary>
 /// <param name="type">addin type</param>
 /// <param name="addinOfficeRegistryKey">office application registry path</param>
 /// <param name="keyState">the office registry key need to create</param>
 public static RegExport ProceedUser(Type type, string[] addinOfficeRegistryKey, OfficeRegisterKeyState keyState)
 {
     return(Proceed(type, addinOfficeRegistryKey, InstallScope.User, keyState));
 }