コード例 #1
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;
        }
コード例 #2
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>
        }
コード例 #3
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();
        }