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(MariniGenericObject 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()));
         }
     }
 }
 /// <summary>
 /// Initializes the object path for the MariniGenericObject <see cref="MariniGenericObject"/> class.
 /// </summary>
 /// <param name="node">An Xml node from which to construct the object</param>
 private void SetObjPath(MariniGenericObject parent)
 {
     if (parent == null)
     {
         path = id;
     }
     else
     {
         path = parent.path + "." + id;
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MariniGenericObject"/> class.
        /// </summary>
        /// <param name="parent">MariniGenericObject parent</param>
        /// <param name="type">MariniGenericObject ID</param>
        /// <param name="id">MariniGenericObject ID</param>
        /// <param name="name">MariniGenericObject name</param>
        /// <param name="description">MariniGenericObject description</param>
        /// <param name="handler">MariniGenericObject method name to handle the PropertyChange event</param>
        protected MariniGenericObject(MariniGenericObject 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);
        }
 /// <summary>
 /// Gets a specific object of MariniImpianto.
 /// </summary>
 /// <param name="path">Path of the object</param>
 /// <returns>The <c>MariniGenericObject</c> with the given Path, <c>null</c> if not found.</returns>
 public MariniGenericObject GetObjectByPath(string path)
 {
     MariniGenericObject mgo = null;
     if (this.PathObjectsDictionary.TryGetValue(path, out mgo))
     {
         return mgo;
     }
     else
     {
         return null;
     }
 }
 /// <summary>
 /// Retrieve a dictionary of MariniGenericObject children with Path key
 /// </summary>
 /// <returns>The children dictionary</returns>
 public void _populatePathObjectsDictionary(MariniGenericObject mgo)
 {
     _pathObjectsDictionary.Add(mgo.path, mgo);
     if (mgo.ChildList.Count > 0)
     {
         foreach (MariniGenericObject child in mgo.ChildList)
         {
             _populatePathObjectsDictionary(child);
         }
     }
     return;
 }
Beispiel #6
0
        public MariniProperty(MariniGenericObject 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 = (MariniBindTypeEnum)Enum.Parse(typeof(MariniBindTypeEnum), attr.Value, true);
                        break;

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

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

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

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

                if (!string.IsNullOrEmpty(_s))
                {
                    value = ParsePropertyValue(propertytype, _s);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MariniGenericObject"/> class.
        /// </summary>
        /// <param name="parent">MariniGenericObject parent</param>
        /// <param name="node">An Xml node from which to construct the object</param>
        protected MariniGenericObject(MariniGenericObject 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);
        }
        public static MariniGenericObject CreateMariniObject(MariniGenericObject parent, XmlNode node)
        {
            MariniGenericObject mgo;

            // uso il ToLower percui mettere tutto a minuscolo qui e come si vuole nel file xml
            switch (node.Name)
            {
            //case "Impianto":
            //    mgo = new MariniImpianto(parent, node);
            //    break;
            //case "ZonaPredosaggio":
            //    mgo = new MariniZonaPredosaggio(parent, node);
            //    break;
            //case "Predosatore":
            //    mgo = new MariniPredosatore(parent, node);
            //    break;
            case "Property":
                mgo = new MariniProperty(parent, node);
                break;

            default:
                mgo = new MariniBaseObject(parent, node);
                break;
                //    throw new ApplicationException(string.Format("MariniObject '{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(CreateMariniObject(mgo, child));
                }
            }

            /* restituisco l'oggetto creato: GOF factory pattern */
            return(mgo);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MariniGenericObject"/> class.
 /// </summary>
 /// <param name="parent">MariniGenericObject parent</param>
 protected MariniGenericObject(MariniGenericObject parent)
     : this(parent, "NO_TYPE")
 {
 }
Beispiel #10
0
 public MariniBaseObject(MariniGenericObject parent, string type, string id, string name)
     : base(parent, type, id, name)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MariniGenericObject"/> class.
 /// </summary>
 /// <param name="parent">MariniGenericObject parent</param>
 /// <param name="type">MariniGenericObject ID</param>
 /// <param name="id">MariniGenericObject ID</param>
 /// <param name="name">MariniGenericObject name</param>
 protected MariniGenericObject(MariniGenericObject parent, string type, string id, string name)
     : this(parent, type, id, name, "NO_DESCRIPTION")
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MariniGenericObject"/> class.
 /// </summary>
 /// <param name="parent">MariniGenericObject parent</param>
 /// <param name="type">MariniGenericObject ID</param>
 /// <param name="id">MariniGenericObject ID</param>
 /// <param name="name">MariniGenericObject name</param>
 /// <param name="description"></param>
 protected MariniGenericObject(MariniGenericObject parent, string type, string id, string name, string description)
     : this(parent, type, id, name, description, "NO_HANDLER")
 {
 }
Beispiel #13
0
 public MariniBaseObject(MariniGenericObject parent, XmlNode node)
     : base(parent, node)
 {
 }
Beispiel #14
0
 public MariniBaseObject(MariniGenericObject parent)
     : base(parent)
 {
 }
Beispiel #15
0
 public MariniBaseObject(MariniGenericObject parent, string type)
     : base(parent, type)
 {
 }
Beispiel #16
0
 public MariniProperty(MariniGenericObject parent)
     : base(parent)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MariniGenericObject"/> class.
 /// </summary>
 /// <param name="parent">MariniGenericObject parent</param>
 /// <param name="type">MariniGenericObject ID</param>
 /// <param name="id">MariniGenericObject ID</param>
 protected MariniGenericObject(MariniGenericObject parent, string type, string id)
     : this(parent, type, id, "NO_NAME")
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MariniGenericObject"/> class.
 /// </summary>
 /// <param name="parent">MariniGenericObject parent</param>
 /// <param name="type">MariniGenericObject ID</param>
 protected MariniGenericObject(MariniGenericObject parent, string type)
     : this(parent, type, "NO_ID")
 {
 }
Beispiel #19
0
 public MariniBaseObject(MariniGenericObject parent, string type, string id, string name, string description)
     : base(parent, type, id, name, description)
 {
 }