コード例 #1
0
ファイル: Updater.cs プロジェクト: puri232/f5-irule-editor
        public void launchProgramUpdater()
        {
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetCallingAssembly();
            System.Reflection.Module   module   = assembly.GetModule("iRuler.exe");
            string updater = System.IO.Path.GetDirectoryName(module.FullyQualifiedName) + "\\iRulerUpdater.exe";

            if (!System.IO.File.Exists(updater))
            {
                updater = updater.Replace("iRulerUpdater.exe", "iRulerUpdater2.exe");
            }

            String sVersion = assembly.GetName().Version.ToString();

            try
            {
                //System.Diagnostics.Process proc = System.Diagnostics.Process.Start(updater);
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName  = updater;
                proc.StartInfo.Arguments = sVersion;
                proc.Start();
                proc.WaitForExit(300 * 1000);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message.ToString());
            }
        }
コード例 #2
0
        /// <summary>
        /// Executes an assembly in a different and permission restricted app domain.
        /// </summary>
        /// <param name="assemblyPath">Assembly path.</param>
        /// <param name="typeName">Type name.</param>
        /// <param name="method">Method.</param>
        ///
        public string ExecuteAssembly(string assemblyPath, string typeName, string method)
        {
            System.Reflection.Assembly a      = System.Reflection.Assembly.LoadFrom(assemblyPath);
            System.Reflection.Module   module = a.GetModule("<Module>");
            Type namespaceType = module.GetType(typeName);

            System.Reflection.MethodInfo      methodToExecute = namespaceType.GetMethod(method);
            System.Reflection.ParameterInfo[] parameters      = methodToExecute.GetParameters();

            Random        r          = new Random();
            List <object> sampleArgs = new List <object>();

            // Only int parameters are supported for now
            foreach (System.Reflection.ParameterInfo param in parameters)
            {
                switch (Type.GetTypeCode(param.ParameterType))
                {
                case TypeCode.Int16:
                    sampleArgs.Add(r.Next(Int16.MinValue, Int16.MaxValue));
                    break;

                case TypeCode.Int32:
                case TypeCode.Int64:
                    sampleArgs.Add(r.Next(Int32.MinValue, Int32.MaxValue));
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false, "Not supported: " + param.ParameterType.ToString());
                    break;
                }
            }
            object[] sampleArgsArray = sampleArgs.ToArray();
            if (methodToExecute.Invoke(null, sampleArgsArray) != null)
            {
                return(methodToExecute.Invoke(null, sampleArgsArray).ToString());
            }
            return("Nothing to return.");
        }