Esempio n. 1
0
        //----------------------------------------------------------------------------
        // ExecuteApplication
        //----------------------------------------------------------------------------
        public void ExecuteApplication(PolicyLevel AppPolicy, Evidence securityEvidence)
        {
            Console.WriteLine("Executing Application...");

            // setup object for new domain
            AppDomainSetup appDomainSetup = new AppDomainSetup();

            // app base, config file name and friendly name = host name.
            appDomainSetup.ApplicationBase   = _sAppBase;
            appDomainSetup.ConfigurationFile = GetConfigFileName();
            AppDomain dom = AppDomain.CreateDomain(GetHostName(), securityEvidence, appDomainSetup);

            // Set the policy level on the domain.
            dom.SetAppDomainPolicy(AppPolicy);

            // Normal exe case.
            if (_sAsmMethod == "")
            {
                Console.WriteLine("\nRunning ExecuteAssembly in: " + GetExeFilePath());
                // bugbug - question security guys on whether or not useful to have evidence passed in.
                dom.ExecuteAssembly(GetExeFilePath());
            }
            // Library entry case.
            else
            {
                Console.WriteLine("\nRunning " + _sAsmMethod + " in Assembly: " + _sAsmName);

                // Hosted code metadata must be present in both default app domain
                // and remote app domain.  Load NDPHost assembly into remote domain.
                AssemblyName asmName = Assembly.GetExecutingAssembly().GetName();

                // Instance the NDPHost class with default constructor.
                ObjectHandle objhNDP = dom.CreateInstanceFrom(asmName.CodeBase, "Microsoft.Fusion.ADF.NDPHost");

                // Unwrap the handle.
                NDPHost objNDP = (NDPHost)objhNDP.Unwrap();

                // Get a string array representation of this object in the current app domain.
                string[] s = this.LoadToStrings();

                // Do the real construction in the remote domain.
                objNDP.LoadFromStrings(s);

                // Load the assembly resolve handler in the remote domain.
                objNDP.LoadResolveEventHandler();

                // Run the method.
                objNDP.ExecMethod();

                // NOTE: why doesn't the following construction work?
                // ObjectHandle objhNDP = dom.CreateInstanceFrom(asmName.CodeBase, "NDPHost", true,
                //	BindingFlags.Instance|BindingFlags.Public|BindingFlags.DeclaredOnly,
                //  null, (object[]) s, null, null, null);
            }
        }
Esempio n. 2
0
        //----------------------------------------------------------------------------
        // Main
        //----------------------------------------------------------------------------
        public static void Main(string[] sCmdLine)
        {
            NDPHost ndpHost = new NDPHost();

            try
            {
                ndpHost.ParseCmdLine(sCmdLine);
                ndpHost.ParseManifest();
                ndpHost.LaunchApp();
            }
            catch (ArgumentException e)
            {
                if ((e.Message == "Invalid Command Line"))
                {
                    Usage();
                }
                else
                {
                    throw(e);
                }
            }
        }