Beispiel #1
0
        public void MainForm_Load(object sender, EventArgs e)
        {
            // Load the configuration File
            try
            {
                string configData = System.IO.File.ReadAllText(CONFIG_FILE);
                Config = new Configuration(configData);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to read configuration file '" + CONFIG_FILE + "'\n\n" + ex.Message, APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CleanUp();
                Environment.Exit(Environment.ExitCode);
                return;
            }


            // Connect to EM
            try
            {
                if (String.IsNullOrWhiteSpace(Config.EventManagerIP))
                {
                    throw new Exception("No IP specified in Configuration File");
                }
                if (String.IsNullOrWhiteSpace(Config.EventManagerUsername))
                {
                    throw new Exception("No Username specified in Configuration File");
                }
                if (String.IsNullOrWhiteSpace(Config.EventManagerPassword))
                {
                    throw new Exception("No Password specified in Configuration File");
                }

                Service = new CommsService();
                Service.Login(Config.EventManagerIP, Config.EventManagerUsername, Config.EventManagerPassword);

                int i = 1;
                while (!Service.getReceiveFinished())
                {
                    Thread.Sleep(10);

                    if (10 * (i++) > 2000)
                    {
                        throw new Exception("An unknown error occured");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to connect to Event Manager server:\n\n" + ex.Message, APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CleanUp();
                Environment.Exit(Environment.ExitCode);
                return;
            }


            // Connect to Vision
            VisionServices = new List <VisionService>();
            VisionTasks    = new Dictionary <int, Dictionary <int, int> >();
            FoxTasks       = new Dictionary <int, Dictionary <int, Dictionary <bool, int> > >();
            try
            {
                foreach (String VisionMixer in Config.VisionMixers)
                {
                    VisionTasks.Add(VisionServices.Count, new Dictionary <int, int>());
                    FoxTasks.Add(VisionServices.Count, new Dictionary <int, Dictionary <bool, int> >());
                    VisionServices.Add(new VisionService(VisionMixer));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to connect to Vision Mixer #" + (VisionServices.Count + 1) + ":\n\n" + ex.Message, APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CleanUp();
                Environment.Exit(Environment.ExitCode);
                return;
            }


            // Connect to Lighting
            LightingServices = new List <LightingService>();
            LightingTasks    = new Dictionary <int, Dictionary <int, int> >();
            try
            {
                foreach (String LightingServer in Config.LightingServers)
                {
                    LightingTasks.Add(LightingServices.Count, new Dictionary <int, int>());
                    LightingServices.Add(new LightingService(LightingServer));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to connect to Lighting Device #" + (LightingServices.Count + 1) + ":\n\n" + ex.Message, APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CleanUp();
                Environment.Exit(Environment.ExitCode);
                return;
            }


            // Validate Configuration File
            try {
                int i = 1;
                foreach (VisionEntry Entry in Config.VisionEntries)
                {
                    if (Entry.ServerIndex >= VisionServices.Count)
                    {
                        throw new Exception("Invalid Server Index for Vision Entry " + i);
                    }

                    if (!Service.getDivisions().Any(div => div.Equals(Entry.DivisionName)))
                    {
                        throw new Exception("Invalid Division Name for Vision Entry " + i);
                    }

                    if (!Service.getFieldsForDivision(Entry.DivisionName).Any(field => field.Equals(Entry.FieldName)))
                    {
                        throw new Exception("Invalid Field Name for Vision Entry " + i);
                    }

                    int fieldId = Service.getFieldIdForDivisionAndName(Entry.DivisionName, Entry.FieldName);

                    if (VisionTasks[Entry.ServerIndex].ContainsKey(fieldId))
                    {
                        throw new Exception("Vision Entry " + i + " contains a Mixer-Division-Field pair that has already been declared");
                    }

                    VisionTasks[Entry.ServerIndex].Add(fieldId, Entry.MacroNumber);

                    i++;
                }

                i = 1;
                foreach (LightingEntry Entry in Config.LightingEntries)
                {
                    if (Entry.ServerIndex >= LightingServices.Count)
                    {
                        throw new Exception("Invalid Server Index for Lighting Entry " + i);
                    }

                    if (!Service.getDivisions().Any(div => div.Equals(Entry.DivisionName)))
                    {
                        throw new Exception("Invalid Division Name for Lighting Entry " + i);
                    }

                    if (!Service.getFieldsForDivision(Entry.DivisionName).Any(field => field.Equals(Entry.FieldName)))
                    {
                        throw new Exception("Invalid Field Name for Lighting Entry " + i);
                    }

                    int fieldId = Service.getFieldIdForDivisionAndName(Entry.DivisionName, Entry.FieldName);

                    if (LightingTasks[Entry.ServerIndex].ContainsKey(fieldId))
                    {
                        throw new Exception("Lighting Entry " + i + " contains a Server-Division-Field pair that has already been declared");
                    }

                    LightingTasks[Entry.ServerIndex].Add(fieldId, Entry.SequenceNumber);

                    i++;
                }

                i = 1;
                foreach (FoxEntry Entry in Config.FoxEntries)
                {
                    if (Entry.ServerIndex >= VisionServices.Count)
                    {
                        throw new Exception("Invalid Server Index for Vision Entry " + i);
                    }

                    if (!Service.getDivisions().Any(div => div.Equals(Entry.DivisionName)))
                    {
                        throw new Exception("Invalid Division Name for Vision Entry " + i);
                    }

                    int divisionId = Service.getDivisionIdForName(Entry.DivisionName);

                    if (!FoxTasks[Entry.ServerIndex].ContainsKey(divisionId))
                    {
                        FoxTasks[Entry.ServerIndex].Add(divisionId, new Dictionary <bool, int>());
                    }

                    if (FoxTasks[Entry.ServerIndex][divisionId].ContainsKey(Entry.IsShown))
                    {
                        throw new Exception("Fox Entry " + i + " contains a Mixer-Division-Shown pair that has already been declared");
                    }

                    FoxTasks[Entry.ServerIndex][divisionId].Add(Entry.IsShown, Entry.MacroNumber);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Configuration Error:\n\n" + ex.Message, APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CleanUp();
                Environment.Exit(Environment.ExitCode);
                return;
            }

            if (Config.IncludeFox)
            {
                // Start the TCP Server to allow changing of division for Fox
                FoxServer = new TcpServer(new EventHandler(ServiceListener));
                FoxServer.run();
            }

            // Show the form!
            ShowForm();

            Service.AddListener(new EventHandler(ServiceListener));
        }
Beispiel #2
0
        public void MainForm_Load(object sender, EventArgs e)
        {
            // Load the configuration File
            try
            {
                string configData = System.IO.File.ReadAllText(CONFIG_FILE);
                Config = new Configuration(configData);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to read configuration file '" + CONFIG_FILE + "'\n\n" + ex.Message, APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CleanUp();
                Environment.Exit(Environment.ExitCode);
                return;
            }


            // Connect to EM
            try
            {
                if(String.IsNullOrWhiteSpace(Config.EventManagerIP))
                    throw new Exception("No IP specified in Configuration File");
                if(String.IsNullOrWhiteSpace(Config.EventManagerUsername))
                    throw new Exception("No Username specified in Configuration File");
                if(String.IsNullOrWhiteSpace(Config.EventManagerPassword))
                    throw new Exception("No Password specified in Configuration File");

                Service = new CommsService();
                Service.Login(Config.EventManagerIP, Config.EventManagerUsername, Config.EventManagerPassword);

                int i = 1;
                while (!Service.getReceiveFinished())
                {
                    Thread.Sleep(10);

                    if (10 * (i++) > 2000)
                    {
                        throw new Exception("An unknown error occured");
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("Unable to connect to Event Manager server:\n\n" + ex.Message, APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CleanUp();
                Environment.Exit(Environment.ExitCode);
                return;
            }
            

            // Connect to Vision
            VisionServices = new List<VisionService>();
            VisionTasks = new Dictionary<int, Dictionary<int, int>>();
            FoxTasks = new Dictionary<int, Dictionary<int, Dictionary<bool, int>>>();
            try
            {
                foreach (String VisionMixer in Config.VisionMixers)
                {
                    VisionTasks.Add(VisionServices.Count, new Dictionary<int, int>());
                    FoxTasks.Add(VisionServices.Count, new Dictionary<int, Dictionary<bool, int>>());
                    VisionServices.Add(new VisionService(VisionMixer));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to connect to Vision Mixer #" + (VisionServices.Count+1) + ":\n\n" + ex.Message, APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CleanUp();
                Environment.Exit(Environment.ExitCode);
                return;
            }
            

            // Connect to Lighting
            LightingServices = new List<LightingService>();
            LightingTasks = new Dictionary<int, Dictionary<int, int>>();
            try
            {
                foreach (String LightingServer in Config.LightingServers)
                {
                    LightingTasks.Add(LightingServices.Count, new Dictionary<int, int>());
                    LightingServices.Add(new LightingService(LightingServer));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to connect to Lighting Device #" + (LightingServices.Count + 1) + ":\n\n" + ex.Message, APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CleanUp();
                Environment.Exit(Environment.ExitCode);
                return;
            }


            // Validate Configuration File
            try {
                int i = 1;
                foreach (VisionEntry Entry in Config.VisionEntries)
                {
                    if (Entry.ServerIndex >= VisionServices.Count)
                        throw new Exception("Invalid Server Index for Vision Entry " + i);

                    if (!Service.getDivisions().Any(div => div.Equals(Entry.DivisionName)))
                        throw new Exception("Invalid Division Name for Vision Entry " + i);

                    if (!Service.getFieldsForDivision(Entry.DivisionName).Any(field => field.Equals(Entry.FieldName)))
                        throw new Exception("Invalid Field Name for Vision Entry " + i);

                    int fieldId = Service.getFieldIdForDivisionAndName(Entry.DivisionName, Entry.FieldName);

                    if (VisionTasks[Entry.ServerIndex].ContainsKey(fieldId))
                        throw new Exception("Vision Entry " + i + " contains a Mixer-Division-Field pair that has already been declared");

                    VisionTasks[Entry.ServerIndex].Add(fieldId, Entry.MacroNumber);

                    i++;
                }

                i = 1;
                foreach (LightingEntry Entry in Config.LightingEntries)
                {
                    if (Entry.ServerIndex >= LightingServices.Count)
                        throw new Exception("Invalid Server Index for Lighting Entry " + i);

                    if (!Service.getDivisions().Any(div => div.Equals(Entry.DivisionName)))
                        throw new Exception("Invalid Division Name for Lighting Entry " + i);

                    if (!Service.getFieldsForDivision(Entry.DivisionName).Any(field => field.Equals(Entry.FieldName)))
                        throw new Exception("Invalid Field Name for Lighting Entry " + i);

                    int fieldId = Service.getFieldIdForDivisionAndName(Entry.DivisionName, Entry.FieldName);

                    if (LightingTasks[Entry.ServerIndex].ContainsKey(fieldId))
                        throw new Exception("Lighting Entry " + i + " contains a Server-Division-Field pair that has already been declared");

                    LightingTasks[Entry.ServerIndex].Add(fieldId, Entry.SequenceNumber);

                    i++;
                }

                i = 1;
                foreach (FoxEntry Entry in Config.FoxEntries)
                {
                    if (Entry.ServerIndex >= VisionServices.Count)
                        throw new Exception("Invalid Server Index for Vision Entry " + i);

                    if (!Service.getDivisions().Any(div => div.Equals(Entry.DivisionName)))
                        throw new Exception("Invalid Division Name for Vision Entry " + i);

                    int divisionId = Service.getDivisionIdForName(Entry.DivisionName);

                    if (!FoxTasks[Entry.ServerIndex].ContainsKey(divisionId))
                        FoxTasks[Entry.ServerIndex].Add(divisionId, new Dictionary<bool, int>());

                    if (FoxTasks[Entry.ServerIndex][divisionId].ContainsKey(Entry.IsShown))
                        throw new Exception("Fox Entry " + i + " contains a Mixer-Division-Shown pair that has already been declared");

                    FoxTasks[Entry.ServerIndex][divisionId].Add(Entry.IsShown, Entry.MacroNumber);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Configuration Error:\n\n" + ex.Message, APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                CleanUp();
                Environment.Exit(Environment.ExitCode);
                return;
            }

            if(Config.IncludeFox)
            {
                // Start the TCP Server to allow changing of division for Fox
                FoxServer = new TcpServer(new EventHandler(ServiceListener));
                FoxServer.run();
            }

            // Show the form!
            ShowForm();

            Service.AddListener(new EventHandler(ServiceListener));
        }