示例#1
0
        static void Main(string[] args)
        {
            // Set the add-ins discovery root directory to be the current directory
            string addinRoot = Environment.CurrentDirectory;

            // Rebuild the add-ins cache and pipeline components cache.
            AddInStore.Rebuild(addinRoot);

            // Get registerd add-ins of type SimpleAddInHostView
            Collection<AddInToken> addins = AddInStore.FindAddIns(typeof(SayHelloHostView), addinRoot);

            Console.WriteLine("Main AppDomain: " + AppDomain.CurrentDomain.FriendlyName);

            AddInProcess process = new AddInProcess();
            process.Start();

            Console.WriteLine("External AddIn ProcessID=" + process.ProcessId);

            foreach (AddInToken addinToken in addins)
            {
                // Activate the add-in
                //SayHelloHostView addinInstance = addinToken.Activate<SayHelloHostView>(AddInSecurityLevel.Host);
                SayHelloHostView addinInstance = addinToken.Activate<SayHelloHostView>(process, AddInSecurityLevel.Host);

                // Use the add-in
                Console.WriteLine();
                Console.WriteLine(String.Format("Add-in {0} Version {1}",
                     addinToken.Name, addinToken.Version));

                Console.WriteLine(addinInstance.SayHello("Hello World from Plugin ;-)"));
            }

            Console.ReadKey();
        }
        internal AddInEnvironment(AppDomain appDomain, bool skipDomainCheck)
        {
            if (appDomain == null)
                throw new ArgumentNullException("appDomain");
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            _appDomain = appDomain;
            _process = AddInProcess.Current;
        }
示例#3
0
        internal AddInEnvironment(AppDomain appDomain, bool skipDomainCheck)
        {
            if (appDomain == null)
            {
                throw new ArgumentNullException("appDomain");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            _appDomain = appDomain;
            _process   = AddInProcess.Current;
        }
        public AddInEnvironment(AppDomain appDomain)
        {
            if (appDomain == null)
                throw new ArgumentNullException("appDomain");
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            if (appDomain != AppDomain.CurrentDomain && !Utils.HasFullTrust()) {
                throw new SecurityException(Res.PartialTrustCannotActivate); 
            }

            _appDomain = appDomain;
            _process = AddInProcess.Current;
        }
示例#5
0
        public AddInEnvironment(AppDomain appDomain)
        {
            if (appDomain == null)
            {
                throw new ArgumentNullException("appDomain");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            if (appDomain != AppDomain.CurrentDomain && !Utils.HasFullTrust())
            {
                throw new SecurityException(Res.PartialTrustCannotActivate);
            }

            _appDomain = appDomain;
            _process   = AddInProcess.Current;
        }
        public MainWindow()
        {
            InitializeComponent();

            var currentDireory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var addinsFolder = Path.Combine(currentDireory, "Addins");
            AddInStore.Update(PipelineStoreLocation.ApplicationBase);
            AddInStore.RebuildAddIns(addinsFolder);

            speakers = new List<ISpeaker>();
            var addins = AddInStore.FindAddIns(typeof(Contracts.HostViews.ISpeaker), PipelineStoreLocation.ApplicationBase);
            foreach (var addin in addins)
            {
                AddInProcess addinProcess = new AddInProcess();
                var speaker = addin.Activate<ISpeaker>(addinProcess, AddInSecurityLevel.FullTrust);
                speakers.Add(speaker);
            }
        }
示例#7
0
        internal static T Activate <T>(AddInToken token, AddInProcess process, PermissionSet permissionSet)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }
            if (permissionSet == null)
            {
                throw new ArgumentNullException("permissionSet");
            }
            if (process == null)
            {
                throw new ArgumentNullException("process");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            // check that they have ExecutionPermission.  Otherwise OOP remoting fails
            // by shutting down the pipe, leaving the user scratching his head.
            if (!permissionSet.IsUnrestricted())
            {
                SecurityPermission     p             = (SecurityPermission)permissionSet.GetPermission(typeof(SecurityPermission));
                SecurityPermissionFlag requiredFlags = SecurityPermissionFlag.Execution;
                if (p == null || (p.Flags & requiredFlags) != requiredFlags)
                {
                    throw new ArgumentException(Res.NeedSecurityFlags);
                }
            }

            RemotingHelper.InitializeClientChannel();

            AddInServer addInServer = process.GetAddInServer();

            AddInServerWorker addInServerWorker = addInServer.CreateDomain(token, permissionSet);
            AddInEnvironment  fullEnvironment   = new AddInEnvironment(process, addInServerWorker);

            return(ActivateOutOfProcess <T>(token, fullEnvironment, true));
        }
示例#8
0
        public bool ActivatePlugin()
        {
            try
            {
                osae.AddToLog("Activating Plugin: " + PluginName, true);
                // Create application domain setup information.
                AppDomainSetup domaininfo = new AppDomainSetup();
                domaininfo.ApplicationBase = osae.APIpath;
                //domaininfo.ApplicationTrust = AddInSecurityLevel.Host;

                // Create the application domain.
                AppDomain domain = AppDomain.CreateDomain(PluginName + "_Domain", null, domaininfo);
                // Write application domain information to the console.
                osae.AddToLog("Host domain: " + AppDomain.CurrentDomain.FriendlyName, true);
                osae.AddToLog("child domain: " + domain.FriendlyName, true);
                osae.AddToLog("Application base is: " + domain.SetupInformation.ApplicationBase, true);

                //_addin = _token.Activate<IOpenSourceAutomationAddIn>(domain);
                _process = new AddInProcess(Platform.AnyCpu);
                _addin = _token.Activate<IOpenSourceAutomationAddInv2>(process,AddInSecurityLevel.FullTrust);
                _enabled = true;
                return true;
            }
            catch(Exception ex)
            {
                osae.AddToLog("Error activating plugin (" + _pluginName + "): " + ex.Message + " - " + ex.InnerException, true);
                _enabled = false;
                return false;
            }
            catch
            {
                osae.AddToLog("Error activating plugin", true);
                return false;
            }
        }
示例#9
0
        /// <summary>
        /// Starts a module given its token
        ///    We don't do this anymore: Has the side effect of updating the moduleInfo object's version to what was exactly ran
        /// </summary>
        /// <param name="moduleInfo"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private VModule StartModule(ModuleInfo moduleInfo, AddInToken token)
        {
            VModule startedModule = null;

            string moduleVersion = Utils.GetHomeOSUpdateVersion(Utils.GetAddInConfigFilepath(moduleInfo.BinaryName()), logger);
            if (!CompareModuleVersions(moduleInfo.GetDesiredVersion(), moduleVersion))
            {
                logger.Log("WARNING: Starting an inexact match for {0}", moduleInfo.FriendlyName());                
            }

            moduleInfo.SetRunningVersion(moduleVersion);

            switch (Constants.ModuleIsolationLevel)
            {
                case ModuleIsolationModes.AppDomain:
                    //     AppDomain addInAppDomain = AppDomain.CreateDomain(moduleInfo.BinaryName());
                    //    startedModule = token.Activate<VModule>(addInAppDomain);

                    // Adding upfront, to check if the module is already running.
                    // So that token is not re-activated if not needed - rayman
                    if (runningModules.Values.Contains(moduleInfo))
                        throw new Exception(string.Format("Attempted to run duplicate module. New = {0}. Old = {1}", moduleInfo, moduleInfo));

                    startedModule = token.Activate<VModule>(AddInSecurityLevel.FullTrust);

                    //AddInController ainController = AddInController.GetAddInController(startedModule);
                    //AppDomain domain = ainController.AppDomain;

                    break;
                case ModuleIsolationModes.Process:
                    AddInProcess addInProc = new AddInProcess();
                    startedModule = token.Activate<VModule>(addInProc, AddInSecurityLevel.FullTrust);
                    break;
                case ModuleIsolationModes.NoAddInAppDomain:
                    //this requires putting Views.dll in the directory with AppBenchmarker.dll
                    //the simplest way to do that is to just add AppBenchmarker as a reference
                    //AppDomainSetup ads = new AppDomainSetup();
                    //ads.ApplicationBase = Environment.CurrentDirectory;//AddInRoot + "\\AddIns\\" + "AppBenchmarker";
                    var ad = AppDomain.CreateDomain(moduleInfo.FriendlyName());//, null, ads);
                    startedModule = (VModule)ad.CreateInstanceAndUnwrap("AppBenchmarker", "AppBenchmarker.Benchmarker");
                    break;
                case ModuleIsolationModes.None:
                    //this requires adding AppBenchmarker and ModuleBase projects as References
                    //startedModule = (VModule)new AppBenchmarker.Benchmarker();
                    //if (moduleInfo.BinaryName().Equals("AppCamera"))
                    //    startedModule = (VModule)new AppCamera.CameraController();
                    //else if (moduleInfo.BinaryName().Equals("DriverFoscam"))
                    //    startedModule = (VModule)new DriverFoscam.DriverFoscam();
                    //else
                    //    logger.Log("Unknown module: {0}", moduleInfo.BinaryName());
                    break;
            }

            if (moduleInfo.WorkingDir() == null)
                moduleInfo.SetWorkingDir(Settings.ModuleWorkingDirBase + "\\" + moduleInfo.FriendlyName());

            if (String.IsNullOrEmpty(moduleInfo.BaseURL()))
                moduleInfo.SetBaseURL(GetBaseUrl() + "/" + moduleInfo.FriendlyName());

            if (string.IsNullOrEmpty(moduleInfo.BinaryDir()))
                moduleInfo.SetBinaryDir(Constants.AddInRoot + "\\AddIns\\" + moduleInfo.BinaryName());

            int secret = GetNewSecret();
            startedModule.Initialize(this, logger, moduleInfo, secret);

            lock (this)
            {
                //check if we already have this module running
                foreach (ModuleInfo runningModuleInfo in runningModules.Values)
                {
                    if (runningModuleInfo.Equals(moduleInfo))
                    {
                        //moduleThread.Abort();
                        throw new Exception(string.Format("Attempted to run duplicate module. New = {0}. Old = {1}", moduleInfo, moduleInfo));
                    }
                }

                runningModules[startedModule] = moduleInfo;
            }

            SafeThread moduleThread = new SafeThread(delegate() { startedModule.Start(); }, moduleInfo.FriendlyName(), logger);
            moduleThread.Start();

            return startedModule;
        }
 internal AddInEnvironment(AddInProcess process, AddInServerWorker worker)
 {
     _addInServerWorker = worker;
     _process = process;
 }
示例#11
0
        private void startGame(String gameFullName)
        {
            //if (gameControl1.Running)
            //    gameControl1.Stop();

            AddInToken a = getAddIn(gameFullName);
            AddInProcess process = new AddInProcess();
            process.KeepAlive = false;

            activeGame = a.Activate<LPView.LPView>(process, AddInSecurityLevel.FullTrust);

            // Register delegate
            //gameControl1.OnStart += activeGame.OnStart;
            //gameControl1.OnUpdate += activeGame.OnUpdate;
            //gameControl1.OnDraw += activeGame.OnDraw;
            //gameControl1.OnStop += activeGame.OnStop;

            // Start!
            //gameControl1.Start();
        }
 public EventWorker(AddInProcess process)
 {
     _process = process;
 }
 public T Activate <T>(AddInProcess process, AddInSecurityLevel level)
 {
     return(AddInActivator.Activate <T>(this, process, level));
 }
示例#14
0
 public static void LoadAddins()
 {
     try
     {
         string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
         AddInStore.Rebuild(baseDirectory);
         IList<AddInToken> list = (IList<AddInToken>)AddInStore.FindAddIns(typeof(CustomAddIn), baseDirectory, new string[0]);
         App.addIns = new List<CustomAddIn>();
         foreach (AddInToken addInToken in (IEnumerable<AddInToken>)list)
         {
             AddInProcess process = new AddInProcess(Platform.X86);
             process.Start();
             AddInStore.FindAddIns(typeof(CustomAddIn), PipelineStoreLocation.ApplicationBase);
             CustomAddIn customAddIn = addInToken.Activate<CustomAddIn>(process, AddInSecurityLevel.Host);
             App.addIns.Add(customAddIn);
         }
     }
     catch
     {
     }
 }
示例#15
0
 public EventWorker(AddInProcess process)
 {
     _process = process;
 }
示例#16
0
文件: Program.cs 项目: Giten2004/MAF
        static void Main(string[] args)
        {
            //Init pipline, create PipelineSegments.store and AddIns.store
            string path = Environment.CurrentDirectory;
            AddInStore.Update(path);

            //string[] warnings = AddInStore.Update(path);
            //foreach (var tmp in warnings)
            //{
            //    Console.WriteLine(tmp);
            //}

            //发现, used the host side view(without attribute)
            var tokens = AddInStore.FindAddIns(typeof(HostSideView.HostSideView), path);
            Console.WriteLine("当前共有{0}个插件可以选择。它们分别为:", tokens.Count);

            var index = 1;
            foreach (var tmp in tokens)
            {
                Console.WriteLine(string.Format("[{4}]名称:{0},描述:{1},版本:{2},发布者:{3}", tmp.Name, tmp.Description, tmp.Version, tmp.Publisher, index++));
            }

            //[[ find addin in the another folder
            string anotherAddInPath = @"C:\OutPutForAddIn\Test";
            AddInStore.RebuildAddIns(anotherAddInPath);

            //todo: why there find the addin in the fist folder????
            IList<AddInToken> PluginList = AddInStore.FindAddIns(typeof(HostSideView.HostSideView), PipelineStoreLocation.ApplicationBase, anotherAddInPath);
            //]]

            var token = ChooseCalculator(tokens);

            //隔离和激活插件
            AddInProcess process = new AddInProcess();//(Platform.X64);
            process.Start();

            var addin = token.Activate<HostSideView.HostSideView>(process, AddInSecurityLevel.FullTrust);

            Console.WriteLine("PID:{0}", process.ProcessId);

            //调用插件
            Console.WriteLine(addin.Say());

            Console.ReadKey();
        }
示例#17
0
        internal static T Activate <T>(AddInToken token, AddInProcess process, AddInSecurityLevel level)
        {
            PermissionSet permissionSet = GetPermissionSetForLevel(level);

            return(Activate <T>(token, process, permissionSet));
        }
示例#18
0
 internal AddInEnvironment(AddInProcess process, AddInServerWorker worker)
 {
     _addInServerWorker = worker;
     _process           = process;
 }
 public T Activate <T>(AddInProcess process, PermissionSet permissionSet)
 {
     return(AddInActivator.Activate <T>(this, process, permissionSet));
 }