Пример #1
0
        /// <summary>
        /// Deserializes the ShapeDefinition objects in the XmlReader
        /// The ShapeDefinition objects are deserialized using the object name in the enclosing tags.
        /// ReadXml is part of the IXmlSerializable interface.
        /// </summary>
        public void ReadXml(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                reader.ReadStartElement();
                return;
            }
            General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(Shape).IsAssignableFrom(p) && !p.IsAbstract));

            reader.Read();

            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                Type T = Types[reader.LocalName];

                if (T != null)
                {
                    XmlSerializer serializer = new XmlSerializer(T);
                    Shape         Shape      = (Shape)serializer.Deserialize(reader);
                    if (!Contains(Shape.Name))
                    {
                        Add(Shape);
                    }
                }
                else
                {
                    Log.Warning("ShapeDefinition type {0} not found during deserialization of cabinet data.".Build(reader.LocalName));
                    reader.Skip();
                }
            }
            reader.ReadEndElement();
        }
Пример #2
0
        /// <summary>
        /// Deserializes the IOutput objects in the XmlReader.<br/>
        /// The IOutput objects are deserialized using the object name in the enclosing tags.<br/>
        /// ReadXml is part of the IXmlSerializable interface.
        /// </summary>
        public void ReadXml(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                reader.ReadStartElement();
                return;
            }
            General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(IOutput).IsAssignableFrom(p) && !p.IsAbstract));

            reader.Read();

            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                Type T = Types[reader.LocalName];
                if (T != null)
                {
                    XmlSerializer serializer = new XmlSerializer(T);
                    IOutput       O          = (IOutput)serializer.Deserialize(reader);
                    if (!Contains(O.Name))
                    {
                        Add(O);
                    }
                }
                else
                {
                    reader.Skip();
                }
            }

            reader.ReadEndElement();
        }
Пример #3
0
        /// <summary>
        /// This method finds all classes implementing the IAutoConfigOutputController interface and uses the member of this interface to detect and configure IOutputController objects automatically.
        /// </summary>
        public void AutoConfig()
        {
            Log.Write("Cabinet auto configuration started");

            General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(IAutoConfigOutputController).IsAssignableFrom(p) && !p.IsAbstract));
            foreach (Type T in Types)
            {
                IAutoConfigOutputController AutoConfig = (IAutoConfigOutputController)Activator.CreateInstance(T);
                AutoConfig.AutoConfig(this);
            }



            Log.Write("Cabinet auto configuration finished");
        }
Пример #4
0
        /// <summary>
        /// This method finds all classes implementing the IAutoConfigOutputController interface and uses the member of this interface to detect and configure IOutputController objects automatically.
        /// </summary>
        public void AutoConfig()
        {
            Log.Write("Cabinet auto configuration started");

            General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(IAutoConfigOutputController).IsAssignableFrom(p) && !p.IsAbstract));
            foreach (Type T in Types)
            {
                IAutoConfigOutputController AutoConfig = (IAutoConfigOutputController)Activator.CreateInstance(T);
                AutoConfig.AutoConfig(this);
            }



            Log.Write("Cabinet auto configuration finished");
        }
Пример #5
0
        /// <summary>
        /// Deserializes the IOutputController objects in the XmlReader.<br/>
        /// The IOutputController objects are deserialized using the object name in the enclosing tags.<br/>
        /// ReadXml is part of the IXmlSerializable interface.
        /// </summary>
        public void ReadXml(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                reader.ReadStartElement();
                return;
            }

            General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(IOutputController).IsAssignableFrom(p) && !p.IsAbstract));

            reader.Read();

            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    Type T = Types[reader.LocalName];
                    if (T != null)
                    {
                        XmlSerializer     serializer = new XmlSerializer(T);
                        IOutputController O          = null;
                        try {
                            O = (IOutputController)serializer.Deserialize(reader);
                        } catch (Exception E) {
                            Log.Exception("DirectOutput framework has encountered a exception during initialization.", E);
                            throw new Exception("DirectOutput framework has encountered a exception during initialization.\n Inner exception: {0}".Build(E.Message), E);
                        }
                        if (!Contains(O.Name))
                        {
                            //Log.Write("OutputControlleRList.ReadXml...adding: " + O.Name);
                            Add(O);
                        }
                    }
                    else
                    {
                        Log.Warning("Output controller type {0} not found during deserialization of data.".Build(reader.LocalName));
                        reader.Skip();
                    }
                }
                else
                {
                    //Not a xml element. Probably a comment. Skip.
                    reader.Skip();
                }
            }

            reader.ReadEndElement();
        }
Пример #6
0
        /// <summary>
        /// Deserializes the IOutputController objects in the XmlReader.<br/>
        /// The IOutputController objects are deserialized using the object name in the enclosing tags.<br/>
        /// ReadXml is part of the IXmlSerializable interface.
        /// </summary>
        public void ReadXml(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                reader.ReadStartElement();
                return;
            }

            General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(IOutputController).IsAssignableFrom(p) && !p.IsAbstract));

            reader.Read();

            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    Type T = Types[reader.LocalName];
                    if (T != null)
                    {
                        XmlSerializer     serializer = new XmlSerializer(T);
                        IOutputController O          = (IOutputController)serializer.Deserialize(reader);
                        if (!Contains(O.Name))
                        {
                            Add(O);
                        }
                    }
                    else
                    {
                        Log.Warning("Output controller type {0} not found during deserialization of data.".Build(reader.LocalName));
                        reader.Skip();
                    }
                }
                else
                {
                    //Not a xml element. Probably a comment. Skip.
                    reader.Skip();
                }
            }

            reader.ReadEndElement();
        }
Пример #7
0
        /// <summary>
        /// This method finds all classes implementing the IAutoConfigOutputController interface and uses the member of this interface to detect and configure IOutputController objects automatically.
        /// </summary>
        public void AutoConfig()
        {
            Log.Write("Cabinet auto configuration started");

            General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(IAutoConfigOutputController).IsAssignableFrom(p) && !p.IsAbstract));
            foreach (Type T in Types)
            {
                try
                {
                    IAutoConfigOutputController AutoConfig = (IAutoConfigOutputController)Activator.CreateInstance(T);
                    AutoConfig.AutoConfig(this);
                }
                catch (Exception E)
                {
                    Log.Exception("A exception occured during auto configuration for output controller(s) of type {0}.".Build(T.Name), E);
                }
            }



            Log.Write("Cabinet auto configuration finished");
        }
Пример #8
0
        private void UpdateTypeXml()
        {
            string S = "";

            if (ScriptTypes.SelectedRows.Count > 0)
            {
                string           N     = ScriptTypes.SelectedRows[0].Cells[0].Value.ToString();
                General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => (typeof(IEffect).IsAssignableFrom(p) || typeof(IToy).IsAssignableFrom(p)) && !p.IsAbstract));
                if (Types.Contains(N))
                {
                    Type   T = Types[N];
                    object O = Activator.CreateInstance(T);


                    foreach (PropertyInfo PI in T.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        if (PI.CanWrite)
                        {
                            if (PI.PropertyType == typeof(string) && PI.Name == "Name")
                            {
                                if (typeof(IEffect).IsAssignableFrom(T))
                                {
                                    PI.SetValue(O, "Effect Name", null);
                                }
                                else if (typeof(IToy).IsAssignableFrom(T))
                                {
                                    PI.SetValue(O, "Toy Name", null);
                                }
                                else
                                {
                                    PI.SetValue(O, "Name", null);
                                }
                            }
                            else if (PI.PropertyType.IsNumber())
                            {
                            }
                            else if (PI.PropertyType == typeof(bool))
                            {
                                PI.SetValue(O, false, null);
                            }
                            else if (PI.PropertyType == typeof(string) && PI.Name.ToLower().Contains("output"))
                            {
                                PI.SetValue(O, "Name of a output", null);
                            }
                            else if (PI.PropertyType == typeof(string) && PI.Name.ToLower().Contains("toy"))
                            {
                                PI.SetValue(O, "Name of a toy", null);
                            }
                            else if (PI.PropertyType == typeof(string))
                            {
                                string V = (string)PI.GetValue(O, null);
                                if (V.IsNullOrWhiteSpace())
                                {
                                    PI.SetValue(O, "{0} value".Build(PI.Name), null);
                                }
                            }
                            else if (PI.PropertyType == typeof(DateTime))
                            {
                                PI.SetValue(O, DateTime.MaxValue, null);
                            }
                        }
                    }

                    try
                    {
                        XmlSerializerNamespaces EmptyNamepsaces = new XmlSerializerNamespaces(new[] { System.Xml.XmlQualifiedName.Empty });
                        var Serializer = new XmlSerializer(T);
                        var Settings   = new System.Xml.XmlWriterSettings();
                        Settings.Indent             = true;
                        Settings.OmitXmlDeclaration = true;

                        using (var Stream = new StringWriter())
                            using (var Writer = System.Xml.XmlWriter.Create(Stream, Settings))
                            {
                                Serializer.Serialize(Writer, O, EmptyNamepsaces);
                                S = Stream.ToString();
                            }
                    }
                    catch (Exception E)
                    {
                        S = "XML Serialization failed.\nException:\n{0}".Build(E.Message);
                    }
                }
                else
                {
                    S = "Type not found";
                }
            }
            TypeXml.Text = S;
        }
Пример #9
0
        private void UpdateTypeXml()
        {
            string S = "";
            if (AvailableToys.SelectedRows.Count > 0)
            {
                string N = AvailableToys.SelectedRows[0].Cells[0].Value.ToString();
                General.TypeList Types = new General.TypeList(AppDomain.CurrentDomain.GetAssemblies().ToList().SelectMany(s => s.GetTypes()).Where(p => typeof(IToy).IsAssignableFrom(p) && !p.IsAbstract));
                if (Types.Contains(N))
                {
                    Type T = Types[N];


                    object O = Activator.CreateInstance(T);


                    foreach (PropertyInfo PI in T.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        if (PI.CanWrite)
                        {
                            if (PI.PropertyType == typeof(string) && PI.Name == "Name")
                            {
                                PI.SetValue(O, "Toy name", null);
                            }
                            else if (PI.PropertyType.IsNumber())
                            {
                                //                               PI.SetValue(O, 0, null);
                            }
                            else if (PI.PropertyType == typeof(bool))
                            {
                                PI.SetValue(O, false, null);
                            }
                            else if (PI.PropertyType == typeof(string) && PI.Name.ToLower().Contains("output"))
                            {
                                PI.SetValue(O, "Name of a output", null);
                            }
                            else if (PI.PropertyType == typeof(string))
                            {
                                string V = (string)PI.GetValue(O, null);
                                if (V.IsNullOrWhiteSpace())
                                {
                                    PI.SetValue(O, "{0} value".Build(PI.Name), null);
                                }
                            }
                            else if (PI.PropertyType == typeof(DateTime))
                            {
                                PI.SetValue(O, DateTime.MaxValue, null);
                            }
                        }
                    }

                    try
                    {
                        XmlSerializerNamespaces EmptyNamepsaces = new XmlSerializerNamespaces(new[] { System.Xml.XmlQualifiedName.Empty });
                        var Serializer = new XmlSerializer(T);
                        var Settings = new System.Xml.XmlWriterSettings();
                        Settings.Indent = true;
                        Settings.OmitXmlDeclaration = true;


                        using (var Stream = new StringWriter())
                        using (var Writer = System.Xml.XmlWriter.Create(Stream, Settings))
                        {
                            Serializer.Serialize(Writer, O, EmptyNamepsaces);
                            S = Stream.ToString();
                        }

                    }
                    catch (Exception E)
                    {
                        S = "XML Serialization failed.\nException:\n{0}".Build(E.Message);
                    }

                }
                else
                {
                    S = "Type not found";
                }

            }
            TypeXml.Text = S;
        }