Example #1
0
        void loadAddInUIMenuItem_Click(object sender, RoutedEventArgs e)
        {
// Get add-in pipeline folder (the folder in which this application was launched from)
            string appPath = Environment.CurrentDirectory;

// Rebuild visual add-in pipeline
            string[] warnings = AddInStore.Rebuild(appPath);
            if (warnings.Length > 0)
            {
                string msg = "Could not rebuild pipeline:";
                foreach (string warning in warnings)
                {
                    msg += "\n" + warning;
                }
                MessageBox.Show(msg);
                return;
            }

// Activate add-in with Internet zone security isolation
            Collection <AddInToken> addInTokens = AddInStore.FindAddIns(typeof(WPFAddInHostView), appPath);
            AddInToken wpfAddInToken            = addInTokens[0];

            this.wpfAddInHostView = wpfAddInToken.Activate <WPFAddInHostView>(AddInSecurityLevel.Internet);

// Display add-in UI
            FrameworkElement addInMainUI = this.wpfAddInHostView;

            this.addInUIHostGrid.Children.Add(addInMainUI);

// Get and display add-in status UI
            FrameworkElement addInStatusUI = this.wpfAddInHostView.GetAddInStatusUI();

            this.addInStatusBar.Items.Add(addInStatusUI);
        }
Example #2
0
        private static void Main(string[] args)
        {
            // Assume that the current directory is the application folder,
            // and that it contains the pipeline folder structure.
            string addInRoot = Environment.CurrentDirectory + "\\Pipeline";

            // Update the cache files of the pipeline segments and add-ins.
            string[] warnings = AddInStore.Rebuild(addInRoot);
            foreach (string warning in warnings)
            {
                Console.WriteLine(warning);
            }

            // Search for add-ins of type ICalculator (the host view of the add-in).
            Collection <AddInToken> tokens = AddInStore.FindAddIns(typeof(IV2), addInRoot);

            AddInToken token = null;

            if (tokens.Count > 1)
            {
                Console.WriteLine("Select a version:");

                for (int i = 0; i < tokens.Count; i++)
                {
                    Console.WriteLine("{0}: {1}", i, tokens[i].Name);
                }

                var key = Console.ReadKey();
                Console.WriteLine();

                if (key.KeyChar == '0')
                {
                    token = tokens[0];
                }
                else
                {
                    token = tokens[1];
                }
            }

            if (token != null)
            {
                // Activate the selected AddInToken in a new application domain
                // with the Internet trust level.
                IV2 v2 = token.Activate <IV2>(AddInSecurityLevel.Internet);
                v2.OnEvent += (sender, message) => { Console.WriteLine("Event Fired: {0}", message); };
                v2.Initialize(new CallbackHandler());

                // Run the add-in.
                v2.WriteToConsole("Hello World From Host!");
                Console.WriteLine(v2.GetName());

                //var test = (Stopwatch)v2.GetSource();

                //Task.Delay(500).Wait();

                //test.Stop();
                //Console.WriteLine(test.ElapsedTicks);
            }
        }
Example #3
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();
        }
Example #4
0
 private void RebuildStore(object sender, RoutedEventArgs e)
 {
     string[] messages = AddInStore.Rebuild(Settings.Default.PipelinePath);
     if (messages.Length != 0)
     {
         MessageBox.Show(string.Join("\n", messages), "AddInStore Warnings", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
Example #5
0
 public static void Rebuild()
 {
     string[] messages = AddInStore.Rebuild(PipelineStoreLocation.ApplicationBase);
     if (messages.Length != 0)
     {
         KryptonMessageBox.Show(string.Join("\n", messages),
                                "AddInStore Warnings", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
     }
 }
        private static AddInToken getRemoteScriptManagerToken(string remoteScriptManagerName)
        {
            string addInRoot = Environment.CurrentDirectory;

            AddInStore.Rebuild(addInRoot);
            Collection <AddInToken> addInTokens = AddInStore.FindAddIns(typeof(IRemoteScriptManager), addInRoot);

            AddInToken token = addInTokens.First <AddInToken>(currentToken => currentToken.Name == remoteScriptManagerName);

            return(token);
        }
Example #7
0
        public void Load()
        {
            // Get add-in pipeline folder (the folder in which this application was launched from)
            var appPath = System.IO.Path.Combine(Environment.CurrentDirectory, "core");

            // Rebuild visual add-in pipeline
            var warnings = AddInStore.Rebuild(appPath);

            if (warnings.Length > 0)
            {
                var msg = warnings.Aggregate(LanguageHelper.ShortNameToString("PipelineRebuildFail"),
                                             (current, warning) => current + ("\n" + warning));
                log.Error(msg);
                MessageBox.Show(msg);
                return;
            }

            //Load the IcyWind.Core add-in
            var addInTokens =
                AddInStore.FindAddIn(typeof(IMainHostView), appPath,
                                     System.IO.Path.Combine(appPath, "AddIns", "IcyWind.Core", "IcyWind.Core.dll"),
                                     "IcyWind.Core.IcyWind");

            //Prevent other add-ins from being loaded and block start if add-ins are in wrong place
            if (addInTokens.Count > 1)
            {
                MessageBox.Show(LanguageHelper.ShortNameToString("MoreOneCore"),
                                "IcyWind Error", MessageBoxButton.OK, MessageBoxImage.Error);
                log.Fatal("More than one IcyWind Core installed.");
                Environment.Exit(1);
            }
            else
            {
                var dirs = System.IO.Directory.GetFiles(System.IO.Path.Combine(appPath, "AddIns"));
                if (dirs.Length > 1)
                {
                    MessageBox.Show(LanguageHelper.ShortNameToString("PluginWrongLocation"));
                    log.Warn("Plugin installed in wrong location.");
                    Environment.Exit(1);
                }
            }
            //Get the addin
            var mainpage = addInTokens.First();
            //Give the add-in full trust to the system
            var hostview = mainpage.Activate <IMainHostView>(AddInSecurityLevel.FullTrust);

            // Get and display add-in UI
            FrameworkElement addInUi = hostview.Run("English");

            //AddInController controller = AddInController.GetAddInController(addInUi);
            MainContent.Content = addInUi;
        }
Example #8
0
        private static AddInToken GetToken()
        {
            String addInRoot = Environment.CurrentDirectory;

            //Check to see if new AddIns have been installed
            AddInStore.Rebuild(addInRoot);

            //Look for Calculator AddIns in our root directory and store the results
            Collection <AddInToken> tokens = AddInStore.FindAddIns(typeof(Calculator), addInRoot);

            //Ask the user which AddIn they would like to use
            AddInToken calcToken = ChooseCalculator(tokens);

            return(calcToken);
        }
Example #9
0
        public static Collection <AddInToken> GetAddInTokens(string addInRoot, string moduleName)
        {
            // rebuild the cache files of the pipeline segments and add-ins.
            string[] warnings = AddInStore.Rebuild(addInRoot);

            foreach (string warning in warnings)
            {
                Console.WriteLine(warning);
            }

            // Search for add-ins of type VModule
            Collection <AddInToken> tokens = AddInStore.FindAddIns(typeof(VModule), addInRoot);

            return(tokens);
        }
        private string[] RebuildPipeline()
        {
            var warnings = AddInStore.Rebuild(_pipelineFolder.FullName);

            if (warnings.Any())
            {
                const string template = "There were {0} warnings rebuilding the Add-In Store.";
                var          message  = String.Format(template, warnings.Length);
                Log.Warn(message);
                foreach (var warning in warnings)
                {
                    Log.Warn(warning);
                }
            }
            return(warnings);
        }
Example #11
0
        private static async Task <IPlugin[]> LoadPlugins()
        {
            async Task <IPlugin> ActivePlugin(AddInToken token)
            {
                AppDomain pluginDomain = CreatePluginDomain(token);

                pluginDomain.SetData(WidgetConst.HANGFIRE, HANGFIRE);
                pluginDomain.DoCallBack(new CrossAppDomainDelegate(PluginCallBackAsync));
                return(await Task.Run(() => {
                    var plugin = token.Activate <IPlugin>(pluginDomain);
                    Logger.LogInformation(token.AddInFullName);
                    return plugin;
                }));
            }

            return(await Task.Run(() => {
                var tasks = new List <Task <IPlugin> >();
                try {
                    var pipeline = Path.Combine(
                        Environment.CurrentDirectory, ContainerConst.PLUGIN_PATH);
                    var warnings = AddInStore.Rebuild(pipeline);
                    var tokens = AddInStore.FindAddIns(typeof(IPlugin), pipeline);

                    foreach (var token in tokens)
                    {
                        tasks.Add(ActivePlugin(token));
                    }
                    Task.WaitAll(tasks.ToArray());

                    return tasks
                    .Select(t => t.Result)
                    .ToArray();
                }
                catch (AggregateException e) {
                    foreach (var ie in e.InnerExceptions)
                    {
                        Console.WriteLine(ie.ToString());
                    }
                    return new IPlugin[0];
                }
            }));
        }
Example #12
0
        public void LoadPlugins()
        {
            // 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(WpfAddinHostView), addinRoot);

            foreach (AddInToken addinToken in addins)
            {
                // Activate the add-in
                WpfAddinHostView addinInstance = addinToken.Activate <WpfAddinHostView>(AddInSecurityLevel.FullTrust);

                FrameworkElement element = addinInstance.RegisterContent();
                m_DockPanel.Children.Add(element);
            }
        }
Example #13
0
        internal void load(string directory)
        {
            string fullpath = System.IO.Path.GetFullPath(directory);

            /* rebuild the plugin cache. */
            string[] errors = AddInStore.Rebuild(PipelineStoreLocation.ApplicationBase);              //fullpath);

            /* grab the list o' addins. */
            Collection <AddInToken> addins = AddInStore.FindAddIns(typeof(StarTree.Host.Database.Plugin), PipelineStoreLocation.ApplicationBase);

            //fullpath);

            foreach (AddInToken token in addins)
            {
                Plugin p = token.Activate <Plugin>(AddInSecurityLevel.Host);

                if (p != null)
                {
                    _plugins.Add(p);
                }
            }
        }
Example #14
0
        public void LoadApplications(Action <HmeServer> serverAction, params string[] applicationDirectories)
        {
            string[] results      = AddInStore.Rebuild(PipelineStoreLocation.ApplicationBase);
            string[] addinResults = AddInStore.RebuildAddIns(applicationDirectories[0]);
            var      addInTokens  = AddInStore.FindAddIns(typeof(IHmeApplicationDriver), PipelineStoreLocation.ApplicationBase,//);
                                                          applicationDirectories);

            foreach (AddInToken token in addInTokens)
            {
                IHmeApplicationDriver driver        = token.Activate <IHmeApplicationDriver>(AddInSecurityLevel.Host);
                Uri assemblyCodeBase                = new Uri(driver.GetType().Assembly.GetName().CodeBase);
                System.IO.FileInfo assemblyFileInfo = new System.IO.FileInfo(assemblyCodeBase.LocalPath);
                foreach (var identity in driver.ApplicationIdentities)
                {
                    HmeServer server = new HmeServer(identity, driver);
                    if (serverAction != null)
                    {
                        serverAction(server);
                    }
                    Add(server, identity, assemblyFileInfo.DirectoryName);
                }
            }
        }
        internal void LoadAddIns()
        {
            _calcs = new List <CalculatorBase>();
            String path = Environment.CurrentDirectory;

            AddInStore.Rebuild(path);
            IList <AddInToken> tokens       = AddInStore.FindAddIns(typeof(Calculator), path);
            IList <AddInToken> visualTokens = AddInStore.FindAddIns(typeof(VisualCalculator), path);

            foreach (AddInToken token in tokens)
            {
                _calcs.Add(token.Activate <CalculatorBase>(AddInSecurityLevel.FullTrust));
            }
            foreach (AddInToken token in visualTokens)
            {
                _calcs.Add(token.Activate <CalculatorBase>(AddInSecurityLevel.FullTrust));
            }
            Actions.Items.Clear();
            foreach (CalculatorBase calc in _calcs)
            {
                InitAddIn(calc, true);
            }
        }
Example #16
0
        void loadUIAddInsMenuItem_Click(object sender, RoutedEventArgs e)
        {
            // Get add-in pipeline folder (the folder in which this application was launched from)
            string appPath = Environment.CurrentDirectory;

            // Rebuild visual add-in pipeline
            string[] warnings = AddInStore.Rebuild(appPath);
            if (warnings.Length > 0)
            {
                string msg = "Could not rebuild pipeline:";
                foreach (string warning in warnings)
                {
                    msg += "\n" + warning;
                }
                MessageBox.Show(msg);
                return;
            }

            // Load add-in with Internet zone security isolation
            Collection <AddInToken> addInTokens = AddInStore.FindAddIns(typeof(IAddInView), appPath);

            foreach (AddInToken addInToken in addInTokens)
            {
                // Get view of add-in
                IAddInView addInView = addInToken.Activate <IAddInView>(AddInSecurityLevel.Internet);

                // Store a reference to it so we can unload it later
                this.addInViews.Add(addInView);

                // Get add-in UI (passing person data to bind to
                FrameworkElement addInUI = addInView.GetAddInUI(this.person);

                // Host add-in
                this.addInUIStackPanel.Children.Add(addInUI);
            }
        }
        public AddInFacade(DirectoryInfo pipelineFolder)
        {
            _pipelineFolder = pipelineFolder;
            if (!pipelineFolder.Exists)
            {
                const string template = "The specified pipeline folder '{0}' does not exist.";
                var message = String.Format(template, pipelineFolder.FullName);
                Log.Error(message);
                throw new ArgumentException(message);
            }

            var warnings = AddInStore.Rebuild(pipelineFolder.FullName);
            if (warnings.Length > 0)
            {
                const string template = "There were {0} warnings rebuilding the Add-In Store.";
                var message = String.Format(template, warnings.Length);
                Log.Warn(message);
                foreach (var warning in warnings)
                {
                    Log.Warn(warning);
                }
            }
            _addInProcesses = new List<AddInProcess>();
        }
Example #18
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            AddInStore.Rebuild(Environment.CurrentDirectory);
        }
Example #19
0
        public void Load(object sender, RoutedEventArgs routedEventArgs)
        {
            Hide();
            var t = new Thread(async() =>
            {
                // Get add-in pipeline folder (the folder in which this application was launched from)
                var appPath = Path.Combine(Environment.CurrentDirectory, "core");

                using (var client = new WebClient())
                {
                    //This handles the IcyWind.Core verification process.
                    if (!Directory.Exists(Path.Combine(Environment.CurrentDirectory, "Certificates")))
                    {
                        Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, "Certificates"));
                    }
                    else if (File.Exists(
                                 Path.Combine(Environment.CurrentDirectory, "Certificates", "IcyWindRootCA.cer")))
                    {
                        File.Delete(Path.Combine(Environment.CurrentDirectory, "Certificates", "IcyWindRootCA.cer"));
                    }
                    //Download the RootCert from the CDN
                    client.DownloadFile("https://cdn.icywindclient.com/IcyWindRootCA.cer", Path.Combine(Environment.CurrentDirectory, "Certificates", "IcyWindRootCA.cer"));

                    //This handles updates and installs. Right now only installs
                    var latest = client.DownloadString("https://cdn.icywindclient.com/latest.txt");
                    var json   = JsonConvert.DeserializeObject <IcyWindVersionJson>(latest);

                    if (!Directory.Exists(appPath))
                    {
                        //Load the installer
                        InstallWindow install = null;
                        await Dispatcher.BeginInvoke(DispatcherPriority.Render, (Action)(() =>
                        {
                            install = new InstallWindow(this);
                            install.Show();
                        }));
                        if (install != null)
                        {
                            var tr = await install.Load(json, true);
                        }
                    }
                }

                //This verifies the certificate that was downloaded. It should not be installed into the
                //user's certificate store for security reasons (It is a root CA)
                var root  = new X509Certificate2(Path.Combine(Environment.CurrentDirectory, "Certificates", "IcyWindRootCA.cer"));
                var chain = new X509Chain();

                var chainPolicy = new X509ChainPolicy
                {
                    RevocationMode = X509RevocationMode.Offline,
                    RevocationFlag = X509RevocationFlag.EntireChain,
                };

                chain.ChainPolicy = chainPolicy;

                var cert = GetAppCertificate(Path.Combine(appPath, "AddIns", "IcyWind.Core", "IcyWind.Core.dll"));
                if (cert != null)
                {
                    chain.ChainPolicy.ExtraStore.Add(cert);
                }
                else
                {
                    ShowUnsignedCore();
                }

                if (!chain.Build(root))
                {
                    //TODO: FIGURE OUT HOW THE F**K TO DO THIS BECAUSE I'M ALMOST ABOUT TO PUT MY OWN CERT IN
                    var data = JsonConvert.SerializeObject(chain.ChainStatus);
                    ShowUnsignedCore();
                }

                await Dispatcher.BeginInvoke(DispatcherPriority.Render, (Action)Show);

                // Rebuild visual add-in pipeline
                var warnings = AddInStore.Rebuild(appPath);
                if (warnings.Length > 0)
                {
                    var msg = warnings.Aggregate(LanguageHelper.ShortNameToString("PipelineRebuildFail"),
                                                 (current, warning) => current + "\n" + warning);
                    Log.Error("Pipeline rebuild failed. Stopping program");
                    MessageBox.Show(msg);
                    Environment.Exit(5);
                }

                //Load the IcyWind.Core add-in
                var addInTokens =
                    AddInStore.FindAddIn(typeof(IMainHostView), appPath,
                                         Path.Combine(appPath, "AddIns", "IcyWind.Core", "IcyWind.Core.dll"),
                                         "IcyWind.Core.IcyWind");
                //Prevent other add-ins from being loaded and block start if add-ins are in wrong place
                if (addInTokens.Count > 1)
                {
                    MessageBox.Show(LanguageHelper.ShortNameToString("MoreOneCore"),
                                    "IcyWind Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Log.Fatal("More than one IcyWind Core installed.");
                    Environment.Exit(1);
                }
                else
                {
                    var dirs = Directory.GetFiles(Path.Combine(appPath, "AddIns"));
                    if (dirs.Length > 1)
                    {
                        MessageBox.Show(LanguageHelper.ShortNameToString("PluginWrongLocation"));
                        Log.Warn("Plugin installed in wrong location.");
                        Environment.Exit(1);
                    }
                }

                //Get the add-in
                var mainPage = addInTokens.First();

                //Give the add-in full trust to the system
                mainHostView = mainPage.Activate <IMainHostView>(AddInSecurityLevel.FullTrust);

                await Dispatcher.BeginInvoke(DispatcherPriority.Render, (Action)(() =>
                {
                    var hwd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
                    var addInUi = mainHostView.Run("English", Assembly.GetEntryAssembly().Location, hwd);
                    //AddInController controller = AddInController.GetAddInController(addInUi);
                    MainContent.Content = addInUi;
                }));
            });

            t.Start();
        }
Example #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            // Get add-in pipeline folder (the folder in which this application was launched from)
            var appPath = Environment.CurrentDirectory;

            Debug.WriteLine($"AppPath: {appPath}");

            // Rebuild visual add-in pipeline
            var warnings = AddInStore.Rebuild(appPath);

            if (warnings.Length > 0)
            {
                var msg = "Could not rebuild pipeline:";
                foreach (var warning in warnings)
                {
                    msg += "\n" + warning;
                }
                MessageBox.Show(msg);
                return;
            }

            AddInGrid.Children.Add(new Button()
            {
                Content = "Test"
            });


            // Activate add-in with Internet zone security isolation
            var addInTokens = AddInStore.FindAddIns(typeof(IWpfAddInHostView1), appPath);
            var addInToken  = addInTokens.FirstOrDefault();

            if (addInToken == null)
            {
                return;
            }

            this._hostView1 = addInToken.Activate <IWpfAddInHostView1>(AddInSecurityLevel.FullTrust);

            // Get and display add-in UI
            var addInUi = _hostView1.GetAddInUi();

            if (addInUi == null)
            {
                return;
            }
            AddInGrid.Children.Add(addInUi);



            var addIn2Tokens = AddInStore.FindAddIns(typeof(IWPFAddInHostView2), appPath);
            var addIn2Token  = addIn2Tokens.FirstOrDefault();

            if (addIn2Token == null)
            {
                return;
            }
            this._hostView2 = addIn2Token.Activate <IWPFAddInHostView2>(AddInSecurityLevel.FullTrust);

            // Get and display add-in UI
            var addIn2Ui = _hostView2.GetAddInUi();

            if (addIn2Ui == null)
            {
                return;
            }
            AddInGrid.Children.Add(addIn2Ui);
        }
Example #21
0
 public void RefreshPluginStore()
 {
     AddInStore.Rebuild(_pipelineRootFolder);
     AddInStore.RebuildAddIns(_pluginRoot);
     _plugins = AddInStore.FindAddIns(typeof(IMyPlugin), _pipelineRootFolder, _pluginRoot);
 }
Example #22
0
        static void Main(string[] args)
        {
            var errors = AddInStore.Rebuild(PipelinePath);

            if (errors.Length > 0)
            {
                foreach (var error in errors)
                {
                    Console.WriteLine(error);
                }
                Console.ReadKey();
                return;
            }

            errors = AddInStore.RebuildAddIns(PluginPath);
            if (errors.Length > 0)
            {
                foreach (var error in errors)
                {
                    Console.WriteLine(error);
                }
                Console.ReadKey();
                return;
            }

            var pluginTokens = AddInStore.FindAddIns(typeof(Plugin), PipelinePath, PluginPath);

            foreach (var token in pluginTokens)
            {
                Console.WriteLine(token.AddInFullName);
                foreach (var item in token)
                {
                    Console.WriteLine($"\t{item.Name}:{item.Value}");
                }
            }


            foreach (var pluginToken in pluginTokens)
            {
                var process = new AddInProcess
                {
                    KeepAlive = false
                };
                //var set = new PermissionSet(PermissionState.Unrestricted);
                //set.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, Path.GetDirectoryName(t.AssemblyName.CodeBase)));
                var plugin = pluginToken.Activate <Plugin>(process, AddInSecurityLevel.Host);
                if (plugin != null)
                {
                    plugin.SetDefaultLog(new FileLog(LogLevelEnum.All));
                    if (plugin.Configuration != null)
                    {
                        foreach (var configuration in plugin.Configuration)
                        {
                            Console.WriteLine(configuration.GetType().FullName);
                        }
                    }

                    plugin.Execute();
                    plugin.Interrupt();

                    var controller = AddInController.GetAddInController(plugin);
                    controller.Shutdown();
                }
            }

            Console.ReadKey();
        }