Start() public method

Starts the gateway
public Start ( ) : void
return void
        private static void SimpleServer()
        {
            Console.WindowWidth = 120;
            Console.BufferWidth = 120;
            Console.WindowHeight = 60;
            Console.BufferHeight = 3000;

            server = new CAServer(IPAddress.Parse(ip), 5777, 5777);
            CAIntRecord record = server.CreateRecord<CAIntRecord>("MXI1:ILOG:2");
            record.Value = 5;

            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = ip + ":5432";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = ip + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = ip + ":5777";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();

            Gateway.AutoCreateChannel = false;
            Gateway.RestoreCache = false;
            gateway.Start();
            Console.ReadKey();
            gateway.Dispose();
        }
        static void ReconnectIoc()
        {
            InitServer();

            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = ip + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = ip + ":5777";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();

            Gateway.AutoCreateChannel = false;
            Gateway.RestoreCache = false;
            gateway.Start();

            client = new EpicsClient();
            client.Configuration.SearchAddress = ip + ":5555";
            client.Configuration.WaitTimeout = 200;
            chans = new List<EpicsChannel>();

            for (int i = 0; i < 1; i++)
            {
                EpicsChannel<int> intChan = client.CreateChannel<int>("PCT:INT-" + i);
                chans.Add(intChan);
                intChan.MonitorChanged += new EpicsDelegate<int>(intChan_MonitorChanged);
            }

            Thread t = new Thread(ChanToGet);
            t.IsBackground = true;
            t.Start();

            //Thread.Sleep(2000);
            //chans[0].Get<int>();

            //for (int i = 0; i < 100; i++)
            while(true)
            {
                Thread.Sleep(5000);
                server.Dispose();
                Thread.Sleep(2000);
                InitServer();
            }

            Console.ReadKey();
        }
        static void ReconnectProscan()
        {
            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();
            gateway.Start();

            client = new EpicsClient();
            client.Configuration.WaitTimeout = 2000;
            client.Configuration.SearchAddress = ip + ":5555";

            EpicsChannel<ExtGraphic<string>> ch = client.CreateChannel<ExtGraphic<string>>("MMAP10Y:CMODE:1");
            ch.StatusChanged += new EpicsStatusDelegate(ch_StatusChanged);
            ch.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(ch_MonitorChangedView);

            EpicsChannel<ExtGraphic<string>> ch2 = client.CreateChannel<ExtGraphic<string>>("MMAP12Y:CNSAMPLES:1");
            ch2.StatusChanged += new EpicsStatusDelegate(ch_StatusChanged);
            ch2.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(ch_MonitorChangedView);

            Thread.Sleep(1000);

            Console.WriteLine("------------------------------------------------------------------------");
            gateway.Dispose();
            //Thread.Sleep(5000);

            gateway = new Gateway();
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.Start();

            /*EpicsChannel restart = client.CreateChannel("TESTGW:RESTART");
            try
            {
                restart.Put<int>(2);
            }
            catch
            {
            }*/

            Thread.Sleep(5000);
            Console.ReadKey();
        }
        static void ProscanWave()
        {
            PBCaGw.Services.Log.Enabled = false;
            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();
            gateway.Start();

            Console.WriteLine("Gateway up");
            //gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.BIDIRECTIONAL;

            client = new EpicsClient();
            client.Configuration.WaitTimeout = 2000;
            client.Configuration.SearchAddress = ip + ":5555";
            List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
            foreach (string i in channelsToConnect)
            {
                EpicsChannel<ExtGraphic<string>> ch = client.CreateChannel<ExtGraphic<string>>(i);
                ch.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(ch_MonitorChanged);
                channels.Add(ch);
            }
            Thread.Sleep(2000);

            gateway.Dispose();
            PBCaGw.Services.Log.Enabled = true;
            //Thread.Sleep(5000);

            gateway = new Gateway();
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.Start();

            Thread.Sleep(5000);

            foreach (var i in channels)
            {
                if (i.Status != ChannelStatus.CONNECTED)
                {
                    Console.WriteLine(i.ChannelName + " not connected.");
                }
            }
            //client.Dispose();

            Console.ReadKey();
            //Console.WriteLine(ch.Get<string>());
        }
        private static void QuickMonitor()
        {
            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = "127.0.0.1:5432";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = "127.0.0.1:5552";
            gateway.Configuration.LocalAddressSideB = "129.129.130.87:5064";
            //gateway.Configuration.LocalAddressSideB = "172.22.200.116:5432";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            //gateway.Configuration.RemoteAddressSideB = "172.22.255.255:5064";
            gateway.Configuration.RemoteAddressSideB = "172.22.200.117:5062";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();
            gateway.Start();

            Thread.Sleep(1000);

            EpicsClient client = new EpicsClient();
            string clientConfig = "127.0.0.1:5432";
            //string clientConfig="172.22.100.101:5064";
            client.Configuration.SearchAddress = clientConfig;

            //string[] channelNames = { "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL", "ZPSAF101-VME:CALNCONN.EGU", "ZPSAF101-VME:CALDCONN.EGU", "ZPSAF101-VME:LOAD", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:HBT" };
            //string[] channelNames = { "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CALNCONN.EGU", "ZPSAF101-VME:CALDCONN.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU" };
            string[] channelNames = { "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CALNCONN.EGU", "ZPSAF101-VME:CALDCONN.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:CAL.EGU", "ZPSAF101-VME:HBT.EGU", "ZPSAF101-VME:HBT.EGU", "ZPSAF101-VME:LOAD.EGU" };
            //string[] channelNames = { "ZPSAF101-VME:CAL.EGU" };
            while (true)
            {
                for (int l = 0; l < 10; l++)
                {
                    List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
                    foreach (var i in channelNames)
                    {
                        EpicsChannel<ExtGraphic<string>> c = client.CreateChannel<ExtGraphic<string>>(i);
                        c.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(QuickMonitor);
                        channels.Add(c);
                    }
                    foreach (var i in channels)
                        i.Dispose();
                    client.Dispose();
                    client = new EpicsClient();
                    client.Configuration.SearchAddress = clientConfig;
                }

                if (true)
                {
                    bool gotError = false;
                    List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
                    foreach (var i in channelNames)
                    {
                        EpicsChannel<ExtGraphic<string>> c = client.CreateChannel<ExtGraphic<string>>(i);
                        channels.Add(c);
                    }

                    CountdownEvent multiActionCountDown = new CountdownEvent(channelNames.Count());
                    Dictionary<uint, bool> gotMonitor = new Dictionary<uint, bool>();

                    foreach (EpicsChannel<ExtGraphic<string>> c in channels)
                    {
                        c.MonitorChanged += delegate(EpicsChannel<ExtGraphic<string>> sender, ExtGraphic<string> newValue)
                        {
                            if ((newValue.Value != "#" && sender.ChannelName.Contains(":CAL")) ||
                                (newValue.Value != "%" && sender.ChannelName.Contains(":LOAD")) ||
                                (newValue.Value != "ticks" && sender.ChannelName.Contains(":HBT")))
                            {
                                Console.WriteLine("Wrong data on CID (" + sender.ChannelName + "): " + sender.CID + ", " + newValue.Value);
                                gotError = true;
                            }
                            lock (gotMonitor)
                            {
                                if (!gotMonitor.ContainsKey(sender.CID))
                                {
                                    gotMonitor.Add(sender.CID, true);
                                    multiActionCountDown.Signal();
                                }
                            }
                        };

                        c.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(QuickMonitor);
                    }

                    multiActionCountDown.Wait(2500);

                    bool allConnected = true;
                    foreach (var i in channels)
                    {
                        if (i.Status != ChannelStatus.CONNECTED)
                        {
                            allConnected = false;
                            Console.WriteLine(i.ChannelName + " not connected.");
                            //gotError = true;
                        }
                    }

                    if (!allConnected)
                    {
                        needToShow = false;
                        //gotError = true;
                        Console.WriteLine("Not all connected!!!!!");
                    }

                    foreach (var i in channels)
                        i.Dispose();
                    client.Dispose();
                    client = new EpicsClient();
                    client.Configuration.SearchAddress = clientConfig;
                    multiActionCountDown.Dispose();

                    if (gotError)
                    {
                        Console.Beep();
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey();
                        needToShow = true;
                    }
                }
            }
        }
        private static void MultipleCreate()
        {
            Console.WindowWidth = 120;
            Console.BufferWidth = 120;
            Console.WindowHeight = 60;
            Console.BufferHeight = 3000;

            server = new CAServer(IPAddress.Parse(ip), 5777, 5777);
            CAStringRecord record = server.CreateRecord<CAStringRecord>("PCTEST:STR");
            record.Value = "Hello there!";

            gateway = new Gateway();
            gateway.Configuration.GatewayName = "TESTGW";
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = ip + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.RemoteAddressSideB = ip + ":5777";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            gateway.SaveConfig();

            Gateway.AutoCreateChannel = false;
            Gateway.RestoreCache = false;
            gateway.Start();

            Thread.Sleep(2000);

            EpicsClient c1 = new EpicsClient();
            c1.Configuration.SearchAddress = ip + ":5555";
            EpicsClient c2 = new EpicsClient();
            c2.Configuration.SearchAddress = ip + ":5555";

            EpicsChannel ca1 = c1.CreateChannel("PCTEST:STR");
            EpicsChannel ca2 = c2.CreateChannel("PCTEST:STR");

            Console.WriteLine("Reading...");

            ca1.MonitorChanged += new EpicsDelegate(ca1_MonitorChanged);
            ca2.MonitorChanged += new EpicsDelegate(ca2_MonitorChanged);

            Console.ReadKey();
        }
        static void MonAll()
        {
            //PBCaGw.Services.Log.Enabled = false;
            Stopwatch sw = new Stopwatch();
            for (int loop = 0; loop < 10; loop++)
            {
                gateway = new Gateway();
                gateway.Configuration.GatewayName = "TESTGW";
                gateway.Configuration.LocalAddressSideA = ip + ":5555";
                //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
                gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
                gateway.Configuration.LocalAddressSideB = ip + ":5888";
                //gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
                gateway.Configuration.RemoteAddressSideB = "172.25.60.67:5062";
                gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
                gateway.SaveConfig();
                gateway.Start();

                Console.WriteLine("Gateway up");
                //gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.BIDIRECTIONAL;

                Gateway.BufferedSockets = false;

                Thread.Sleep(1000);
                multiActionCountDown = new CountdownEvent(channelsToConnect.Count(row => !row.Contains("TRACE")));
                hadValue = new Dictionary<string, bool>();
                sw.Start();
                client = new EpicsClient();
                client.Configuration.WaitTimeout = 2000;
                client.Configuration.SearchAddress = ip + ":5555";
                List<EpicsChannel<ExtGraphic<string>>> channels = new List<EpicsChannel<ExtGraphic<string>>>();
                foreach (string i in channelsToConnect.Where(row => !row.Contains("TRACE")))
                {
                    EpicsChannel<ExtGraphic<string>> ch = client.CreateChannel<ExtGraphic<string>>(i);
                    ch.MonitorChanged += new EpicsDelegate<ExtGraphic<string>>(ch_MonitorChangedGotValue);
                    channels.Add(ch);
                }
                if (multiActionCountDown.Wait(5000) == false)
                    Console.WriteLine("Didn't got it...");
                client.Dispose();
                sw.Stop();
                gateway.Dispose();
            }

            Console.WriteLine("Time: " + sw.Elapsed.ToString());
            Console.ReadKey();
        }
        static void InternTest()
        {
            InitServer();

            gateway = new Gateway();
            gateway.Configuration.LocalAddressSideA = ip + ":5555";
            //gateway.Configuration.LocalAddressSideA = "129.129.130.87:5555";
            gateway.Configuration.RemoteAddressSideA = remoteIp + ":5552";
            gateway.Configuration.LocalAddressSideB = ip + ":5888";
            gateway.Configuration.RemoteAddressSideB = remoteIp + ":5777";
            gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.UNIDIRECTIONAL;
            //gateway.Configuration.ConfigurationType = PBCaGw.Configurations.ConfigurationType.BIDIRECTIONAL;
            gateway.Start();

            client = new EpicsClient();
            client.Configuration.SearchAddress = ip + ":5555";
            //client.Configuration.SearchAddress = "129.129.130.255:5555";
            //client.Configuration.SearchAddress = "127.0.0.1:5777";

            //MultiConnect();
            //Checks2();

            EpicsChannel ca = client.CreateChannel("PCT:INT-1");
            Console.WriteLine(ca.Get<string>());

            //GetDisconnect();

            Console.WriteLine("Press a key to continue...");
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            Console.WriteLine("PBCaGW " + Gateway.Version);
            Console.WriteLine("Build on " + DiagnosticServer.BuildTime.ToString(CultureInfo.InvariantCulture));
            Console.WriteLine("(c) Paul Scherrer Institute - GFA IT - 2012");

            // Setup the console look
            try
            {
                Console.Title = "PBCaGW - " + System.Configuration.ConfigurationManager.AppSettings["gatewayName"];
                Console.WindowWidth = 120;
                Console.BufferWidth = 120;
                Console.WindowHeight = 60;
                Console.BufferHeight = 3000;
            }
            catch
            {
            }

            if (System.Diagnostics.Debugger.IsAttached)
            {
                Console.WriteLine("Press return to stop the gateway...");
            }
            else
            {
                Console.WriteLine("Press Ctrl+C to stop the gateway...");
                Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
            }
            Console.WriteLine("");

            /*Gateway.AutoCreateChannel = false;
            Gateway.RestoreCache = false;*/

            /*Gateway.AutoCreateChannel = false;
            Gateway.RestoreCache = false;*/
            //Gateway.AutoCreateChannel = false;
            //Gateway.BufferedSockets = false;

            gateway = new Gateway();
            gateway.LoadConfig();
            gateway.Start();

            while (true)
            {
                ConsoleKeyInfo k = Console.ReadKey();
                switch (k.Key)
                {
                    case ConsoleKey.Spacebar:
                        DataPacket.ShowPools();
                        break;
                    case ConsoleKey.L:
                        Log.ShowAll = !Log.ShowAll;
                        break;
                    default:
                        if (System.Diagnostics.Debugger.IsAttached)
                        {
                            gateway.Dispose();
                            return;
                        }
                        break;
                }
            }

            /*if (System.Diagnostics.Debugger.IsAttached)
            {
                while (true)
                {
                    ConsoleKeyInfo k = Console.ReadKey();
                    switch (k.Key)
                    {
                        case ConsoleKey.Spacebar:
                            DataPacket.ShowPools();
                            break;
                        default:
                            gateway.Dispose();
                            return;
                    }
                }
            }
            else
            {
                while (true)
                    Console.ReadKey();
            }*/
        }
 protected override void OnStart(string[] args)
 {
     gateway = new Gateway();
     gateway.LoadConfig();
     gateway.Start();
 }