Ejemplo n.º 1
0
        /// <summary>
        /// Launches the data server asynchronously, and optionally waits until it is ready to serve requests before returning
        /// </summary>
        public Task LaunchServer(string coordName, CancellationToken cancelToken, bool blockUntilReady, bool restartOnDisconnect)
        {
            Semaphore s = blockUntilReady ? DataServer.BuildNamedSingletonSemaphore(coordName) : null;
            Task      t = RunServerAsync(coordName, cancelToken, restartOnDisconnect);

            if (blockUntilReady)
            {
                s.WaitOne();
            }
            return(t);
        }
Ejemplo n.º 2
0
        public CcdCam(string pipeName)
        {
            if (!DataServer.IsRunning(pipeName))
            {
                this.externalDataServer = DataServer.LaunchExternal(pipeName, waitUntilReady: true);
            }

            cameraReader = new CameraReader <ICameraFlow, RemoteClientCameraFlow>(pipeName, new AcqProtoSerializer());

            // ensure we stop the server, if we're the ones who started it
            cameraReader.TerminateServerOnStop = (this.externalDataServer != null);

            cameraReader.DataSource.NewData += DataSource_NewData;
        }
Ejemplo n.º 3
0
        public void StandaloneServerMain(string[] args)
        {
            Trace.Listeners.Add(new SimpleConsoleTraceListener());

            string coordName = DefaultCoordinationName;

            if (args.Length > 0)
            {
                coordName = args[0];
            }

            Trace.TraceInformation("Standalone data server using coordination name '{0}'", coordName);

            CancellationTokenSource cancel = new CancellationTokenSource();
            string suffix   = "";
            string procName = Process.GetCurrentProcess().ProcessName;

            if (procName.ToLower().Contains("fake"))
            {
                suffix = " (FAKE)";
            }
            Console.Title = string.Format("{0}{1} standalone data server.  Press ESC to quit", coordName, suffix);
            Task serverTask = LaunchServer(coordName, cancel.Token, blockUntilReady: false, restartOnDisconnect: true);

            serverTask.ContinueWith(t =>
            {
                AggregateException e = t.Exception;
                if (e == null)
                {
                    cancel.Cancel();
                }
                else
                {
                    Console.WriteLine(" = = = = =  E R R O R  = = = = = ");
                    foreach (var ee in e.InnerExceptions)
                    {
                        Trace.TraceError(ee.Message);
                    }
                    if (e.InnerExceptions.Count > 0)
                    {
                        Lab.UI.Balloon.ShowBalloon("Data server error", e.InnerExceptions[0].Message);
                    }
                    Console.WriteLine("Press ESC to quit");
                }
            });
            DataServer.ConsoleWait(cancel);
            Trace.TraceInformation("Standalone server will terminate.");
            this.Dispose();
        }