Exemple #1
0
        private ClusterTemplate LoadClusterTemplate(XElement xElement)
        {
            string name = null;
            var xmlName = xElement.Attribute("Name");
            if (xmlName != null)
            {
                name = xmlName.Value;
            }

            var clusterTemplate = new ClusterTemplate(name);
            clusterTemplate.Hardware = LoadHardwareTemplates(xElement.Elements("Hardware"));
            return clusterTemplate;
        }
Exemple #2
0
        private ClusterConfig CreateClusterConfig(ClusterTemplate template)
        {
            ClusterConfig config = new ClusterConfig();

            foreach (var hwTemplate in template.Hardware)
            {
                var hw = CreateHardware(hwTemplate.Type);

                try
                {
                    hw.SetParameters(hwTemplate.Parameters);
                    Logger.Instance.Write(String.Format("[ClusterFactory] Initializing {0}", hw.Name), LogType.Message);
                    hw.Initialise();
                }
                catch(Exception ex)
                {
                    var outer = new InvalidOperationException(
                        String.Format("Failed to initialise hardware item Type: {0}, Name: {1}",
                        hw.GetType().ToString(), hw.Name), ex);

                    Logger.Instance.Write(new LogEntry(outer));
                    throw outer;
                }

                if (hw is IRobot)
                {
                    config.Robots.Add(hw.GetType(), hw as IRobot);
                }
                else if (hw is IConveyor)
                {
                    config.Conveyors.Add(hw.GetType(), hw as IConveyor);
                }
                else if (hw is ISensor)
                {
                    config.Sensors.Add(hw.Name, hw as ISensor);
                }
                else if (hw is ICamera)
                {
                    config.Cameras.Add(hw.Name, hw as ICamera);
                }
                else if (hw is IPlc)
                {
                    config.Plcs.Add(hw.Name, hw as IPlc);
                }

                Logger.Instance.Write(String.Format("[ClusterFactory] {0} initialization completed", hw.Name), LogType.Message);
            }

            config.Controllers = CreateControllers(config);

            return config;
        }