Ejemplo n.º 1
0
 public void RegisterMaster(IScanMaster scanMaster)
 {
     scanMaster.pong();
     mainForm.Invoke((MethodInvoker) delegate {
         mainForm.RegisterMaster(scanMaster);
     });
 }
Ejemplo n.º 2
0
        public ScannerController(ScannerControllerWidget scanControllerWidget)
        {
            this.scanControllerWidget = scanControllerWidget;

            // connect to the scanner controller
            var serverProvider = new BinaryServerFormatterSinkProvider();
            var clientProvider = new BinaryClientFormatterSinkProvider();

            serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            var props = new Hashtable();

            props["name"]     = "ipc";
            props["portName"] = ScanWorker.Program.APP_NAME + "_CLIENT";

            IpcChannel clientChannel = new IpcChannel(props, clientProvider, serverProvider);

            ChannelServices.RegisterChannel(clientChannel);

            scanWorker =
                (IScanWorker)Activator.GetObject(
                    typeof(ScanWorker.ScanWorker),
                    "ipc://ScanSimple/ScanWorker");

            try {
                // try to connect to existing scan worker process first (for debugging)
                bool alive = scanWorker.ping();
                Console.WriteLine("scanworker ping() output = " + alive);
            } catch (System.Runtime.Remoting.RemotingException e) {
                // if we fail, launch a scan worker...
                LaunchScanWorker();
                for (int i = 0; i < 10; i++)
                {
                    Thread.Sleep(50);
                    // and try to connect again
                    try {
                        bool alive2 = scanWorker.ping();
                        Console.WriteLine("scanworker ping() output = " + alive2);
                        break;
                    } catch (System.Runtime.Remoting.RemotingException e2) {
                        // try again.
                        Console.WriteLine("failed to connect to ScanWorker, trying again...");
                    }
                }

                // if we didn't connect, this will throw an exception
                bool alive = scanWorker.ping();

                // now create our scan master listener, and send it over
                scanMaster = new ScanMaster(scanControllerWidget.mainWindow, scanControllerWidget);
                scanWorker.RegisterMaster(scanMaster);
            }
        }
Ejemplo n.º 3
0
 public void RegisterMaster(IScanMaster scanMaster)
 {
     this.scanMaster       = scanMaster;
     _twain.TransferImage += delegate(Object sender, TransferImageEventArgs args) {
         Console.WriteLine("sending Scanned Image...");
         if (args.Image != null)
         {
             if (scanMaster != null)
             {
                 MemoryStream ms = new MemoryStream();
                 args.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                 scanMaster.ScanDataTransfer(ms.ToArray());
             }
         }
     };
 }