Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String channelName = "PDFChannel_" + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
- String objectName = "PdfInfo" + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + ".rem";
- System.Collections.Hashtable properties = new System.Collections.Hashtable();
- properties["portName"] = channelName;
- properties["name"] = channelName;
- properties["exclusiveAddressUse"] = false;
- Hashtable sinkProps = new Hashtable();
- sinkProps["typeFilterLevel"] = "Full";
- IpcChannel serverChannel = null;
- try
- {
- serverChannel = (IpcChannel)System.Runtime.Remoting.Channels.ChannelServices.GetChannel(channelName);
- if (serverChannel == null)
- {
- serverChannel = new IpcChannel(properties, new BinaryClientFormatterSinkProvider(), new BinaryServerFormatterSinkProvider(sinkProps, null));
- System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(serverChannel, false);
- System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(PdfInfo), objectName, WellKnownObjectMode.Singleton);
- }
- PdfInfo pdf = (PdfInfo)Activator.GetObject(typeof(PdfInfo), "ipc://" + channelName + "/" + objectName);
- pdf.ConnectionString = Database.ConnectionString;
- pdf.Driver = Database.ProviderName;
- pdf.Config = Config;
- pdf.Culture = System.Threading.Thread.CurrentThread.CurrentCulture;
- pdf.Principal = System.Threading.Thread.CurrentPrincipal;
- ProcessStartInfo start = new ProcessStartInfo("OutOfProcessPDFRunner.exe", "ipc://" + channelName + "/" + objectName);
- start.CreateNoWindow = true;
- start.UseShellExecute = false;
- Process pdfProc = Process.Start(start);
- pdfProc.PriorityClass = ProcessPriorityClass.BelowNormal;
- if (pdfProc != null)
- pdfProc.WaitForExit();
- pdf.OutputStream.Position = 0;
- byte[] pdfBuffer = new byte[pdf.OutputStream.Length];
- pdf.OutputStream.Read(pdfBuffer, 0, pdfBuffer.Length);
- return pdfBuffer;
- }
- finally
- {
- if(serverChannel != null)
- System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(serverChannel);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement