internal ActivationWorker(AddInToken pipeline)
        {
            System.Diagnostics.Contracts.Contract.Requires(pipeline != null);
            System.Diagnostics.Contracts.Contract.Requires(pipeline.PipelineRootDirectory != null);

            _pipeline = pipeline;
        }
Пример #2
0
 public Plugin(AddInToken token)
 {
     _token = token;
     _pluginName = osae.GetPluginName(_token.Name, osae.ComputerName);
     _pluginType = _token.Name;
     _pluginVersion = _token.Version;
     _latestAvailableVersion = "";
 }
        internal AddInControllerImpl(AddInEnvironment environment, bool unloadDomainOnExit, AddInToken token)
        {
            System.Diagnostics.Contracts.Contract.Requires(environment != null);
            System.Diagnostics.Contracts.Contract.Requires(token != null);

            _unloadDomainOnExit = unloadDomainOnExit;
            _token = token;

            _addInEnvironment = environment;
        }
Пример #4
0
        public AddInServerWorker CreateDomain(AddInToken token, PermissionSet permissionSet)
        {
            AppDomain domain;
            AppDomainSetup setup = new AppDomainSetup();
            setup.ApplicationBase = Path.GetDirectoryName(token._addin.Location);
            setup.ConfigurationFile = token._addin.Location + ".config";

            Assembly sysCore = typeof(AddInActivator).Assembly;
            domain = AppDomain.CreateDomain(token.Name,  
                AppDomain.CurrentDomain.Evidence, setup, permissionSet,
                AddInActivator.CreateStrongName(sysCore));  // Grant full trust to System.Core.dll

            // Ensure we load System.Core.dll in this new AD.
            domain.Load(sysCore.FullName);

            ObjectHandle workerHandle = Activator.CreateInstance(domain, sysCore.FullName, typeof(AddInServerWorker).FullName);
            AddInServerWorker server = (AddInServerWorker)workerHandle.Unwrap();

            server.AddInServer = this;

            Interlocked.Increment(ref _addInAppDomains);

            return server;
        }
 void AddTokenToUnreliableList(AddInToken token)
 {
     List<AddInToken> tokens = GetUnreliableTokens();
     tokens.Add(token);
     WriteUnreliableTokens(tokens);
 }
Пример #6
0
 private static Calculator ActivateCalculator(AddInToken calcToken)
 {
     Calculator calculator;
     calculator = calcToken.Activate<Calculator>(AddInSecurityLevel.FullTrust);
     return calculator;
 }
Пример #7
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;
        }
Пример #8
0
        /// <summary>
        /// Activates the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        private void Activate(AddInToken token)
        {
            IPlayer player = token.Activate<IPlayer>(AddInSecurityLevel.Host);
            _loadedPlayers.Add(player);

            player.StartGame(Dictionary, MaxNumberOfChances);
        }
Пример #9
0
 Module(AddInToken t)
 {
     _token = t;
 }
Пример #10
0
        public IContract Activate(AddInToken pipeline, out ActivationWorker worker)
        {
            worker = new ActivationWorker(pipeline);

            IContract contract = worker.Activate();

            return contract;
        }
 protected PluginTokenBase(AddInToken addInToken)
 {
     _addInToken = addInToken;
 }
Пример #12
0
        static void Main()
        {
// <Snippet2>
// Get path for the pipeline root.
// Assumes that the current directory is the
// pipeline directory structure root directory.
            String pipeRoot = Environment.CurrentDirectory;

// <Snippet3>
// Update the cache files of the
// pipeline segments and add-ins.
            string[] warnings = AddInStore.Update(pipeRoot);

            foreach (string warning in warnings)
            {
                Console.WriteLine(warning);
            }
// </Snippet3>

// <Snippet4>
// Search for add-ins of type Calculator (the host view of the add-in)
// specifying the host's application base, instead of a path,
// for the FindAddIns method.

            Collection <AddInToken> tokens =
                AddInStore.FindAddIns(typeof(Calculator), PipelineStoreLocation.ApplicationBase);
// </Snippet4>
// </Snippet2>

// <Snippet5>
//Ask the user which add-in they would like to use.
            AddInToken selectedToken = ChooseAddIn(tokens);

//Activate the selected AddInToken in a new
//application domain with the Internet trust level.
            Calculator CalcAddIn = selectedToken.Activate <Calculator>(AddInSecurityLevel.Internet);

//Run the add-in using a custom method.
            RunCalculator(CalcAddIn);
// </Snippet5>

// <Snippet6>
// Find a specific add-in.

// Construct the path to the add-in.
            string addInFilePath = pipeRoot + @"\AddIns\P3AddIn2\P3AddIn2.dll";

// The fourth parameter, addinTypeName, takes the full name
// of the type qualified by its namespace. Same as AddInToken.AddInFullName.
            Collection <AddInToken> tokenColl = AddInStore.FindAddIn(typeof(Calculator),
                                                                     pipeRoot, addInFilePath, "CalcAddIns.P3AddIn2");

            Console.WriteLine("Found {0}", tokenColl[0].Name);
// </Snippet6>

// <Snippet8>
// Get the AddInController of a
// currently actived add-in (CalcAddIn).
            AddInController aiController = AddInController.GetAddInController(CalcAddIn);

// Select another token.
            AddInToken selectedToken2 = ChooseAddIn(tokens);

// Activate a second add-in, CalcAddIn2, in the same
// appliation domain and process as the first add-in by passing
// the first add-in's AddInEnvironment object to the Activate method.
            AddInEnvironment aiEnvironment = aiController.AddInEnvironment;
            Calculator       CalcAddIn2    =
                selectedToken2.Activate <Calculator>(aiEnvironment);

// Get the AddInController for the second add-in to compare environments.
            AddInController aiController2 = AddInController.GetAddInController(CalcAddIn2);

            Console.WriteLine("Add-ins in same application domain: {0}", aiController.AppDomain.Equals(aiController2.AppDomain));
            Console.WriteLine("Add-ins in same process: {0}", aiEnvironment.Process.Equals(aiController2.AddInEnvironment.Process));
// </Snippet8>


// <Snippet9>
// Get the application domain
// of an existing add-in (CalcAddIn).
            AddInController aiCtrl      = AddInController.GetAddInController(CalcAddIn);
            AppDomain       AddInAppDom = aiCtrl.AppDomain;

// Activate another add-in in the same application domain.
            Calculator CalcAddIn3 =
                selectedToken2.Activate <Calculator>(AddInAppDom);

// Show that CalcAddIn3 was loaded
// into CalcAddIn's application domain.
            AddInController aic = AddInController.GetAddInController(CalcAddIn3);

            Console.WriteLine("Add-in loaded into existing application domain: {0}",
                              aic.AppDomain.Equals(AddInAppDom));
// </Snippet9>

// <Snippet10>
// Create an external process.
            AddInProcess pExternal = new AddInProcess();

// Activate an add-in in the external process
// with a full trust security level.
            Calculator CalcAddIn4 =
                selectedToken.Activate <Calculator>(pExternal,
                                                    AddInSecurityLevel.FullTrust);

// Show that the add-in is an external process
// by verifying that it is not in the current (host's) process.
            AddInController AddinCtl = AddInController.GetAddInController(CalcAddIn4);

            Console.WriteLine("Add-in in host's process: {0}",
                              AddinCtl.AddInEnvironment.Process.IsCurrentProcess);
// </Snippet10>
// <Snippet11>
// Use qualification data to control
// how an add-in should be activated.

            if (selectedToken.QualificationData[AddInSegmentType.AddIn]["Isolation"].Equals("NewProcess"))
            {
                // Create an external process.
                AddInProcess external = new AddInProcess();

                // Activate an add-in in the new process
                // with the full trust security level.
                Calculator CalcAddIn5 =
                    selectedToken.Activate <Calculator>(external,
                                                        AddInSecurityLevel.FullTrust);
                Console.WriteLine("Add-in activated per qualification data.");
            }
            else
            {
                Console.WriteLine("This add-in is not designated to be activated in a new process.");
            }
// </Snippet11>

// <Snippet12>
// Show the qualification data for each
// token in an AddInToken collection.
            foreach (AddInToken token in tokens)
            {
                foreach (QualificationDataItem qdi in token)
                {
                    Console.WriteLine("{0} {1}\n\t QD Name: {2}, QD Value: {3}",
                                      token.Name,
                                      qdi.Segment,
                                      qdi.Name,
                                      qdi.Value);
                }
            }

// </Snippet12>
        }
Пример #13
0
        static void Main(string[] args)
        {
            // <Snippet2>
            // In this example, the pipeline root is the current directory.
            String pipeRoot = Environment.CurrentDirectory;

            // Rebuild the cache of pipeline and add-in information.
            string[] warnings = AddInStore.Update(pipeRoot);
            if (warnings.Length > 0)
            {
                foreach (string one in warnings)
                {
                    Console.WriteLine(one);
                }
            }
            // </Snippet2>

            // <Snippet3>
            // Find add-ins of type LibraryManager under the specified pipeline root directory.
            Collection <AddInToken> tokens = AddInStore.FindAddIns(typeof(LibraryManager), pipeRoot);
            // </Snippet3>
            // Determine which add-in to use.
            AddInToken selectedToken = ChooseAddIn(tokens);

            // <Snippet4>
            // Activate the selected AddInToken in a new
            // application domain with a specified security trust level.
            LibraryManager manager = selectedToken.Activate <LibraryManager>(AddInSecurityLevel.FullTrust);
            // </Snippet4>

            // Create a collection of books.
            IList <BookInfo> books = CreateBooks();

            // Show the collection count.
            Console.WriteLine("Number of books:  {0}", books.Count.ToString());

            // Have the add-in process the books.
            // The add-in will discount computer books by $20
            // and list their before and after prices. It
            // will also remove all horror books.
            manager.ProcessBooks(books);

            // List the genre of each book. There
            // should be no horror books.
            foreach (BookInfo bk in books)
            {
                Console.WriteLine(bk.Genre());
            }

            Console.WriteLine("Number of books: {0}", books.Count.ToString());

            Console.WriteLine();
            // Have the add-in pass a BookInfo object
            // of the best selling book.
            BookInfo bestBook = manager.GetBestSeller();

            Console.WriteLine("Best seller is {0} by {1}", bestBook.Title(), bestBook.Author());

            // Have the add-in show the sales tax rate.
            manager.Data("sales tax");

            // <Snippet6>
            AddInController ctrl = AddInController.GetAddInController(manager);

            ctrl.Shutdown();
            // </Snippet6>
            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }
Пример #14
0
 internal void Init(AddInToken token)
 {
     _token = token;
     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
 }
 internal void Init(AddInToken token)
 {
     _token = token;
     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
 }
Пример #16
0
        /// <summary>
        /// User change select item on listbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 
        
        private void LbxMenu_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (LbxMenu.SelectedIndex != -1)
            {
                
                //Reset Live view tab to unselected
                liveviewtab.Foreground = new SolidColorBrush(Colors.White);
                //End
                if (!ResourceUtil.Tabview.ContainsKey(LbxMenu.SelectedIndex.ToString(CultureInfo.InvariantCulture)))
                {
                    _selectedItem = (AddInToken)LbxMenu.SelectedItem;
                    //Start Busy
                    
                    _busy.Start();
                    #region Test
                    //_backgroundWorker.RunWorkerAsync();
                    //Thread nThread = new Thread(new ParameterizedThreadStart(WorkThreadFunction));
                    //nThread.SetApartmentState(ApartmentState.STA);
                    //nThread.IsBackground = true;
                    //nThread.Start(LbxMenu.SelectedIndex.ToString(CultureInfo.InvariantCulture));
                    //var result = Task<UserControl>.Factory.StartNew(() =>
                    //    {
                    //        AddInToken token = _selectedItem;
                    //        try
                    //        {
                    //            UserControl con = new UserControl();
                    //            con = token.Activate<HostView.WPFAddInHostView>(AddInSecurityLevel.FullTrust);
                    //        }
                    //        catch (Exception ex)
                    //        {
                                
                    //        }

                    //        return null;
                    //    }
                    //);
                    //// Wait for the task opening the file to complete
                    //result.Wait();
                    //userControlview.Content = (result.Result);
                    #endregion

                    _loadready = false;
                    //Main thread create a Usercontrol
                    AddInToken token = _selectedItem;
                    _addin = token.Activate<HostView.IWPFAddInHostView>(AddInSecurityLevel.FullTrust);
                    if(!addInViews.Contains(_addin))
                        addInViews.Add(_addin);

                    FrameworkElement addInUI = this._addin.GetAddInUI();

                    ResourceUtil.Tabview.Add(LbxMenu.SelectedIndex.ToString(CultureInfo.InvariantCulture), addInUI as FrameworkElement);
                    userControlview.Content = addInUI;
                    
                    //End
                    //Stop Busy
                    _busy.Stop();
                    _loadready = true;
                    
                }
                else
                {
                    userControlview.Content = ResourceUtil.Tabview[LbxMenu.SelectedIndex.ToString(CultureInfo.InvariantCulture)];
                }
            }
        }
Пример #17
0
 public Module(AddInToken token)
 {
     _token = token;
 }