Beispiel #1
0
 /// <summary>
 /// Serialize a specific object of MariniImpianto.
 /// </summary>
 /// <param name="path">the path of the object.</param>
 /// <returns>A string that contains the serialized object</returns>
 public string Serialize(GenericObject mgo)
 {
     if (mgo == null)
     {
         Console.WriteLine("\nOggetto null!!!");
         return("NN");
     }
     else
     {
         _xmlSerializer = new XmlSerializer(mgo.GetType());
         using (StringWriter stringWriter = new StringWriter())
         {
             using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings()
             {
                 OmitXmlDeclaration = true
                 , ConformanceLevel = ConformanceLevel.Auto
                                      //, ConformanceLevel = ConformanceLevel.Document
                                      //, NewLineOnAttributes = true
                 , Indent = true
             }))
             {
                 // Build Xml with xw.
                 _xmlSerializer.Serialize(xmlWriter, mgo);
             }
             // rielaboro lo streaming per convertire in un formato compatibile con HTTP/HTML
             // ad esempio la codifica di < e > diventa &lt; and &gt;
             return(WebUtility.HtmlDecode(stringWriter.ToString()));
         }
     }
 }
Beispiel #2
0
        public static GenericObject CreateObject(GenericObject parent, XmlNode node)
        {
            GenericObject mgo;

            /* uso il ToLower percui mettere tutto a minuscolo qui e come si vuole nel file xml */
            switch (node.Name)
            {
            case "Property":
                mgo = new PropertyObject(parent, node);
                break;

            default:
                mgo = new BaseObject(parent, node);
                break;
                //    throw new ApplicationException(string.Format("Object '{0}' cannot be created", mgo));
            }

            /* Riempio la lista oggetti con i nodi figli */
            XmlNodeList children = node.ChildNodes;

            foreach (XmlNode child in children)
            {
                if (children.Count > 0)
                {
                    //Console.WriteLine("Parent id: {0} node.childnodes = {1}", mgo.id, node.ChildNodes.Count);
                    mgo.ChildList.Add(CreateObject(mgo, child));
                }
            }

            /* restituisco l'oggetto creato: GOF factory pattern */
            return(mgo);
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericObject"/> class.
        /// </summary>
        /// <param name="parent">GenericObject parent</param>
        /// <param name="type">GenericObject ID</param>
        /// <param name="id">GenericObject ID</param>
        /// <param name="name">GenericObject name</param>
        /// <param name="description">GenericObject description</param>
        /// <param name="handler">GenericObject method name to handle the PropertyChange event</param>
        protected GenericObject(GenericObject parent, string type, string id, string name, string description, string handler)
        {
            this.parent      = parent;
            this.type        = type;
            this.id          = id;
            this.name        = name;
            this.description = description;
            this.handler     = handler;

            SetObjPath(parent);
        }
Beispiel #4
0
 /// <summary>
 /// Initializes the object path for the GenericObject <see cref="GenericObject"/> class.
 /// </summary>
 /// <param name="node">An Xml node from which to construct the object</param>
 private void SetObjPath(GenericObject parent)
 {
     if (parent == null)
     {
         path = id;
     }
     else
     {
         path = parent.path + "." + id;
     }
 }
Beispiel #5
0
 /// <summary>
 /// Retrieve a dictionary of GenericObject children with Path key
 /// </summary>
 /// <returns>The children dictionary</returns>
 public void _populatePathObjectsDictionary(GenericObject mgo)
 {
     _pathObjectsDictionary.Add(mgo.path, mgo);
     if (mgo.ChildList.Count > 0)
     {
         foreach (GenericObject child in mgo.ChildList)
         {
             _populatePathObjectsDictionary(child);
         }
     }
     return;
 }
Beispiel #6
0
        public override bool Equals(Object o)
        {
            GenericObject mgo = o as GenericObject;

            if (mgo == null)
            {
                return(false);
            }
            else
            {
                return(path.Equals(mgo.path));
            }
        }
Beispiel #7
0
        /// <summary>
        /// Gets a specific object of Datamodel.
        /// </summary>
        /// <param name="path">Path of the object</param>
        /// <returns>The <c>GenericObject</c> with the given Path, <c>null</c> if not found.</returns>
        public GenericObject GetObjectByPath(string path)
        {
            GenericObject mgo = null;

            if (this.PathObjectsDictionary.TryGetValue(path, out mgo))
            {
                return(mgo);
            }
            else
            {
                return(null);
            }
        }
Beispiel #8
0
        public PropertyObject(GenericObject parent, XmlNode node)
            : base(parent, node)
        {
            if (node.Attributes != null)
            {
                // per gestire value devo fare un doppio passaggio, perche' altrimenti se viene scritta nell'XML prima del propertytype
                // (di default a Int) si rischia di falire il Parse
                string _s = "";
                XmlAttributeCollection attrs = node.Attributes;
                value = null;
                foreach (XmlAttribute attr in attrs)
                {
                    //Console.WriteLine("Attribute Name = " + attr.Name + "; Attribute Value = " + attr.Value);
                    switch (attr.Name)
                    {
                    case "bind":
                        bind = attr.Value;
                        break;

                    case "bindtype":
                        bindtype = (BindType)Enum.Parse(typeof(BindType), attr.Value, true);
                        break;

                    case "binddirection":
                        binddirection = (BindDirection)Enum.Parse(typeof(BindDirection), attr.Value, true);
                        break;

                    case "persistence":
                        persistence = (PersistenceType)Enum.Parse(typeof(PersistenceType), attr.Value, true);
                        break;

                    case "propertytype":
                        propertytype = (PropertyObjectType)Enum.Parse(typeof(PropertyObjectType), attr.Value, true);
                        break;

                    case "value":
                        _s = attr.Value;
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(_s))
                {
                    value = ParsePropertyValue(propertytype, _s);
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenericObject"/> class.
        /// </summary>
        /// <param name="parent">GenericObject parent</param>
        /// <param name="node">An Xml node from which to construct the object</param>
        protected GenericObject(GenericObject parent, XmlNode node)
            : this(parent)
        {
            // L'attributo type viene ricavato dal nome del nodo
            type = node.Name;
            // Gli altri attributi della classe li ricavo dalle altri attributi dell'XML
            if (node.Attributes != null)
            {
                XmlAttributeCollection attrs = node.Attributes;
                foreach (XmlAttribute attr in attrs)
                {
                    //Console.WriteLine("Attribute Name = " + attr.Name + "; Attribute Value = " + attr.Value);

                    switch (attr.Name)
                    {
                    //case "type":
                    //    type = attr.Value;
                    //    break;
                    case "id":
                        id = attr.Value;
                        break;

                    case "name":
                        name = attr.Value;
                        break;

                    case "description":
                        description = attr.Value;
                        break;

                    case "handler":
                        handler = attr.Value;
                        break;
                        // default:
                        // throw new ApplicationException(string.Format("MariniObject '{0}' cannot be created", mgo));
                    }
                }
            }
            // calcolo il path dell'oggetto
            SetObjPath(parent);
        }
Beispiel #10
0
 public BaseObject(GenericObject parent, string type, string id, string name, string description)
     : base(parent, type, id, name, description)
 {
 }
Beispiel #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericObject"/> class.
 /// </summary>
 /// <param name="parent">GenericObject parent</param>
 protected GenericObject(GenericObject parent)
     : this(parent, "NO_TYPE")
 {
 }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericObject"/> class.
 /// </summary>
 /// <param name="parent">GenericObject parent</param>
 /// <param name="type">GenericObject ID</param>
 protected GenericObject(GenericObject parent, string type)
     : this(parent, type, "NO_ID")
 {
 }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericObject"/> class.
 /// </summary>
 /// <param name="parent">GenericObject parent</param>
 /// <param name="type">GenericObject ID</param>
 /// <param name="id">GenericObject ID</param>
 protected GenericObject(GenericObject parent, string type, string id)
     : this(parent, type, id, "NO_NAME")
 {
 }
Beispiel #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericObject"/> class.
 /// </summary>
 /// <param name="parent">GenericObject parent</param>
 /// <param name="type">GenericObject ID</param>
 /// <param name="id">GenericObject ID</param>
 /// <param name="name">GenericObject name</param>
 protected GenericObject(GenericObject parent, string type, string id, string name)
     : this(parent, type, id, name, "NO_DESCRIPTION")
 {
 }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericObject"/> class.
 /// </summary>
 /// <param name="parent">GenericObject parent</param>
 /// <param name="type">GenericObject ID</param>
 /// <param name="id">GenericObject ID</param>
 /// <param name="name">GenericObject name</param>
 /// <param name="description"></param>
 protected GenericObject(GenericObject parent, string type, string id, string name, string description)
     : this(parent, type, id, name, description, "NO_HANDLER")
 {
 }
Beispiel #16
0
 public BaseObject(GenericObject parent, string type, string id, string name)
     : base(parent, type, id, name)
 {
 }
Beispiel #17
0
 public BaseObject(GenericObject parent, string type)
     : base(parent, type)
 {
 }
Beispiel #18
0
 public BaseObject(GenericObject parent)
     : base(parent)
 {
 }
Beispiel #19
0
 public PropertyObject(GenericObject parent)
     : base(parent)
 {
 }
Beispiel #20
0
 public BaseObject(GenericObject parent, XmlNode node)
     : base(parent, node)
 {
 }