Advertisement
Guest User

redec

a guest
Feb 12th, 2010
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1.                         String channelName = "PDFChannel_" + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
  2.                         String objectName = "PdfInfo" + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + ".rem";
  3.                         System.Collections.Hashtable properties = new System.Collections.Hashtable();
  4.                         properties["portName"] = channelName;
  5.                         properties["name"] = channelName;
  6.                         properties["exclusiveAddressUse"] = false;
  7.                         Hashtable sinkProps = new Hashtable();
  8.                         sinkProps["typeFilterLevel"] = "Full";
  9.  
  10.                         IpcChannel serverChannel = null;
  11.                         try
  12.                         {
  13.                             serverChannel = (IpcChannel)System.Runtime.Remoting.Channels.ChannelServices.GetChannel(channelName);
  14.                             if (serverChannel == null)
  15.                             {
  16.                                 serverChannel = new IpcChannel(properties, new BinaryClientFormatterSinkProvider(), new BinaryServerFormatterSinkProvider(sinkProps, null));
  17.                                 System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(serverChannel, false);
  18.                                 System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(PdfInfo), objectName, WellKnownObjectMode.Singleton);
  19.                             }
  20.  
  21.                             PdfInfo pdf = (PdfInfo)Activator.GetObject(typeof(PdfInfo), "ipc://" + channelName + "/" + objectName);
  22.                             pdf.ConnectionString = Database.ConnectionString;
  23.                             pdf.Driver = Database.ProviderName;
  24.                             pdf.Config = Config;
  25.                             pdf.Culture = System.Threading.Thread.CurrentThread.CurrentCulture;
  26.                             pdf.Principal = System.Threading.Thread.CurrentPrincipal;
  27.                             ProcessStartInfo start = new ProcessStartInfo("OutOfProcessPDFRunner.exe", "ipc://" + channelName + "/" + objectName);
  28.                             start.CreateNoWindow = true;
  29.                             start.UseShellExecute = false;
  30.  
  31.                             Process pdfProc = Process.Start(start);
  32.                             pdfProc.PriorityClass = ProcessPriorityClass.BelowNormal;
  33.                             if (pdfProc != null)
  34.                                 pdfProc.WaitForExit();
  35.                             pdf.OutputStream.Position = 0;
  36.                             byte[] pdfBuffer = new byte[pdf.OutputStream.Length];
  37.                             pdf.OutputStream.Read(pdfBuffer, 0, pdfBuffer.Length);
  38.                             return pdfBuffer;
  39.                         }
  40.                         finally
  41.                         {
  42.                             if(serverChannel != null)
  43.                                 System.Runtime.Remoting.Channels.ChannelServices.UnregisterChannel(serverChannel);
  44.                         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement