Exemplo n.º 1
0
        private static void SetupUnmanagedAssembly(string fileName, byte[] assemblyRaw)
        {
            var assemblyName = Assembly.GetExecutingAssembly().GetName();

            var basePath = Path.Combine(
                Path.GetTempPath(),
                String.Format(
                    "{0}{1}_{2}_{3}",
                    assemblyName.Name.ToString(),
                    assemblyName.Version.ToString(),
                    IntPtr.Size == 8 ? "x64" : "x86",
                    String.Join(String.Empty, AppDomain.CurrentDomain.BaseDirectory.Split(Path.GetInvalidFileNameChars()))));

            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
            }

            fileName = Path.Combine(basePath, fileName);

            WriteStreamToFile(fileName, () => new GZipStream(new MemoryStream(assemblyRaw), CompressionMode.Decompress));

            TocXslFilename = Path.Combine(basePath, "toc.xsl");

            WriteStreamToFile(TocXslFilename, () => new MemoryStream(Resources.toc));

            WinApiHelper.LoadLibrary(fileName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Unloads the private AppDomain and the wkhtmltopdf library, and if applicable, destroys
        /// the synchronization thread.
        /// </summary>
        /// <param name="sender">Typically a null value, not used in the method.</param>
        /// <param name="e">Typically EventArgs.Empty, not used in the method.</param>
        private static void TearDownAppDomain(object sender, EventArgs e)
        {
            if (Factory.operatingDomain != null)
            {
                Func <object> del = () =>
                {
                    Factory.operatingDomain.DoCallBack(() => PechkinBindings.wkhtmltopdf_deinit());

                    return(null);
                };

                SynchronizedDispatcher.Invoke(del);

                AppDomain.Unload(Factory.operatingDomain);

                foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
                {
                    if (module.ModuleName == "wkhtmltox.dll")
                    {
                        while (WinApiHelper.FreeLibrary(module.BaseAddress))
                        {
                        }
                    }
                }

                Factory.operatingDomain = null;
            }

            SynchronizedDispatcher.Terminate();
        }
Exemplo n.º 3
0
        private void TearDownAppDomain(object sender, EventArgs e)
        {
            if (remoteDomain == null)
            {
                return;
            }

            OnBeforeUnload((ActionShim)(() => NestedToolset.Unload()));

            AppDomain.Unload(remoteDomain);

            var expected = Path.Combine(
                Deployment.Path,
                WkhtmltoxBindings.DLLNAME);

            foreach (ProcessModule module in Process.GetCurrentProcess().Modules)
            {
                if (module.FileName == expected)
                {
                    while (WinApiHelper.FreeLibrary(module.BaseAddress))
                    {
                    }

                    break;
                }
            }

            remoteDomain = null;
            Loaded       = false;

            if (Unloaded != null)
            {
                Unloaded(this, EventArgs.Empty);
            }
        }
Exemplo n.º 4
0
        public void Load(IDeployment deployment = null)
        {
            if (Loaded)
            {
                return;
            }

            if (deployment != null)
            {
                Deployment = deployment;
            }

            WinApiHelper.SetDllDirectory(Deployment.Path);
            WkhtmltoxBindings.wkhtmltoimage_init(0);

            Loaded = true;
        }