Beispiel #1
0
        internal static ParamValuesNode FromXml(XElement element)
        {
            if (element == null)
            {
                return(null);
            }
            ParamValuesNode model = new ParamValuesNode();

            model.Name = element.BaseUri;

            foreach (XElement delm in element.Descendants())
            {
                if (delm.HasElements)
                {
                    continue;
                }
                if (delm.Parent.HasElements && delm.Parent != element)
                {
                    continue;
                }
                if (model.Attributs.ContainsKey(delm.Name.ToString()))
                {
                    continue;                                                    // déja présent (multible attribut interdit)
                }
                model.Attributs.Add(delm.Name.ToString().ToLower(), delm.Value);
            }
            return(model);
        }
Beispiel #2
0
        public int CompareTo(object obj)
        {
            ParamValuesNode Compare = (ParamValuesNode)obj;

            if (!string.IsNullOrEmpty(Compare["dataorder"]) && !string.IsNullOrEmpty(this["dataorder"]))
            {
                try
                {
                    int orderCompare = Convert.ToInt32(Compare["dataorder"]);
                    int orderthis    = Convert.ToInt32(this["dataorder"]);
                    int resulti      = orderthis.CompareTo(orderCompare);
                    if (resulti == 0)
                    {
                        resulti = orderthis.CompareTo(orderCompare);
                    }
                    return(resulti);
                }
                catch (Exception) { }
            }
            int result = this.Name.CompareTo(Compare.Name);

            if (result == 0)
            {
                result = this.Name.CompareTo(Compare.Name);
            }
            return(result);
        }
Beispiel #3
0
        internal static System.Xml.Linq.XElement ToXml(ParamValuesNode model)
        {
            if (model == null)
            {
                return(null);
            }
            XElement element = new XElement(model.Name);

            element.Value = model.GetString(null);
            //if (!string.IsNullOrEmpty(model.IssuerElementId)) element.Add(new XAttribute("id", model.IssuerElementId));
            //element.Add(new XAttribute("type", "ComplexType"));
            if (model.Attributs != null)
            {
                foreach (var attributeKey in model.Attributs.Keys)
                {
                    string val = model.GetString(attributeKey, DataAccessorOptionEnum.None);
                    if (string.IsNullOrEmpty(val))
                    {
                        continue;                            // cela sert à rien d'écrire un attribut vide
                    }
                    XAttribute nodeAttribute = new XAttribute(attributeKey, val);
                    element.Add(nodeAttribute);
                }
            }

            return(element);
        }
Beispiel #4
0
 /// <summary>
 /// Obtient tous les data qui contien l'attribut 'attributname'
 /// </summary>
 /// <param name="attributname"></param>
 /// <param name="replacenameparattribut"></param>
 /// <returns></returns>
 public ParamValues GetDatasWithAttribut(string attributname, bool replacenameparattribut = false)
 {
     try
     {
         ParamValues retour = new ParamValues();
         WaitMutex();
         foreach (ParamValuesNode datb in this.dataStore.Values)
         {
             if (datb[attributname] != "")
             {
                 ParamValuesNode ee = datb.Clone();
                 if (replacenameparattribut)
                 {
                     ee.Name = datb[attributname];
                 }
                 retour.Add(ee);
             }
         }
         return(retour);
     }
     catch (Exception e)
     {
         throw new Exception("Impossible d'obtenir des datas avec l'attribut " + attributname + " " + e.Message);
     }
     finally
     {
         ReleaseMutex();
     }
 }
Beispiel #5
0
 /// <summary>
 /// Obtenir l'Attribut d'un paramètre
 /// </summary>
 /// <param name="ise"></param>
 /// <param name="nameAttribut"></param>
 /// <returns></returns>
 public string this[string ise, string nameAttribut]
 {
     get
     {
         ise = this.PrepareNameNode(ise);
         ParamValuesNode retour = this.Get(ise);
         if (retour == null)
         {
             return(null);
         }
         else
         {
             return(retour[nameAttribut]);
         }
     }
     set
     {
         ise = this.PrepareNameNode(ise);
         ParamValuesNode retour = this.Get(ise);
         if (retour == null)
         {
             retour = new ParamValuesNode(ise);
             Add(retour);
         }
         retour[nameAttribut] = value;
     }
 }
Beispiel #6
0
        /// <summary>
        /// Ajouter un objet
        /// </summary>
        /// <param name="nameValue"></param>
        /// <param name="obj"></param>
        /// <param name="AccesOptions"></param>
        /// <returns></returns>
        public bool SetData(string nameValue, object obj, DataAccessorOptionEnum AccesOptions)
        {
            try
            {
                //if (!AccesOptions.HasFlag(BASICS.DataAccessorOptionEnum.NotReplace)) this.DelData(nameValue);
                // mutex déja pris
                object orgnobj = this.GetObject(nameValue, DataAccessorOptionEnum.None);
                if ((orgnobj == null || (orgnobj is string && string.IsNullOrEmpty(orgnobj.ToString()))) && (obj == null || (obj is string && string.IsNullOrEmpty(obj.ToString()))))
                {
                    return(false);
                }
                if (obj != null && orgnobj != null && obj.Equals(orgnobj))
                {
                    return(false);                                                     // inutile si pas modifié
                }
                nameValue = this.PrepareNameNode(nameValue);
                ParamValuesNode retour = this.Get(nameValue);
                if (retour == null)
                {
                    retour = new ParamValuesNode(nameValue);
                    Add(retour);
                }
                retour.SetObject(null, obj);


                return(true);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private ParamValuesNode GenerateNewNodeFromXML(ParamValues datavalue, string lastpath, XmlNode xChild)
        {
            ParamValuesNode bufliste = new ParamValuesNode();

            try
            {
                bufliste.datavalues_parent = datavalue;
                bufliste.Name = lastpath.ToLower();
                if (bufliste.Name.Substring(bufliste.Name.Length - 1) == "/")
                {
                    bufliste.Name = bufliste.Name.Substring(0, bufliste.Name.Length - 1);
                }
                if (bufliste.Name.Length > 9 && bufliste.Name.Substring(0, 9) == "/noparam/")
                {
                    bufliste.Name.Replace("/noparam/", "");
                }

                // GESTION DES ATTRIBUTS
                // on tente d'obtenir les attributs (Il sont stockées sur le noeud parent)
                XmlAttributeCollection sattributs = null;
                XmlNode xParentElement            = null;
                if (xChild.NodeType == XmlNodeType.Element)
                {
                    xParentElement = xChild;                                         // il n'avait déja pas d'enfant.
                }
                else
                {
                    xParentElement = xChild.ParentNode;
                }

                if (xParentElement != null && xParentElement.NodeType == XmlNodeType.Element)
                {
                    sattributs = xParentElement.Attributes;
                }
                if (sattributs != null && sattributs.Count > 0)
                {
                    foreach (XmlAttribute item in sattributs)
                    {
                        string nameatr = item.LocalName.ToLower();
                        bufliste[nameatr] = item.Value;
                    }
                }


                // dyna
                //if (bufliste.value != null && bufliste.value is string && bufliste.value.ToString().Contains("{!"));

                // Affectation de la données
                bufliste.SetObject(null, xChild.Value);
            }
            catch (Exception)
            {
                bufliste["datatype_error"] = "true";
            }
            return(bufliste);
        }
Beispiel #8
0
        /// <summary>
        /// Clone dans de nouveaux objets
        /// </summary>
        public ParamValuesNode Clone()
        {
            ParamValuesNode clona = new ParamValuesNode();

            clona.Value             = this.Value;
            clona.Name              = this.Name;
            clona.datavalues_parent = this.datavalues_parent;

            foreach (var bifdata in this.Attributs) // cloner dictionary !!!
            {
                clona.Attributs.Add(bifdata.Key, bifdata.Value);
            }
            return(clona);
        }
 private XmlTextWriter savewritenode(XmlTextWriter XmlTextWriter, ParamValuesNode datatab, string item)
 {
     if (datatab.Value == null)
     {
         datatab.Value = "";                        //Attention aux noeuds null...
     }
     XmlTextWriter.WriteStartElement(item);
     foreach (var attribut in datatab.Attributs)
     {
         XmlTextWriter.WriteAttributeString(attribut.Key, Convert.ToString(attribut.Value));
     }
     XmlTextWriter.WriteValue(datatab.GetString(null));
     return(XmlTextWriter);
 }
Beispiel #10
0
        public ParamValuesNode Get(string ise, bool CreateIfNotExist = true)
        {
            ise = this.PrepareNameNode(ise);
            ParamValuesNode retour = null;

            if (!this.dataStore.ContainsKey(ise))
            {
                return(null);
            }
            retour = this.dataStore[ise];
            if (retour == null && CreateIfNotExist)
            {
                retour = new ParamValuesNode(ise);
                Add(retour);
            }
            return(retour);
        }
Beispiel #11
0
 /// <summary>
 /// Attention ne copie pas le nom
 /// </summary>
 /// <param name="dataext"></param>
 /// <param name="ecraser"></param>
 public void Fusion(ParamValuesNode dataext, bool ecraser = false)
 {
     if (ecraser || this._value == null)
     {
         if (ChangedState == System.Data.DataRowState.Unchanged && this._value != dataext._value)
         {
             ChangedState = System.Data.DataRowState.Modified;
         }
         this._value = dataext._value;
     }
     foreach (var itemd in dataext.Attributs)
     {
         if (ecraser || this[itemd.Key] == "")
         {
             this.SetObject(itemd.Key, itemd.Value);
         }
     }
 }
Beispiel #12
0
 public void Fusion(ParamValues dataext, bool ecraser = false)
 {
     foreach (ParamValuesNode itemd in dataext.GetList())
     {
         ParamValuesNode itemsearch = this.Get(itemd.Name);
         if (itemsearch != null && itemsearch.Name != "")
         {
             if (ecraser)
             {
                 this.Add(itemd.Clone());
             }
         }
         else
         {
             this.Add(itemd.Clone());
         }
     }
 }
Beispiel #13
0
 public object GetData(string nameValue, DataAccessorOptionEnum AccesOptions)
 {
     try
     {
         ParamValuesNode dat = this.Get(nameValue);
         if (dat == null)
         {
             return(null);
         }
         else
         {
             return(dat.Value);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Beispiel #14
0
 /// <summary>
 /// ajoute une donnée pure
 /// </summary>
 /// <param name="name">nom de l'élément</param>
 public void Add(ParamValuesNode data)
 {
     try
     {
         WaitMutex();
         data.datavalues_parent = this;
         ParamValuesNode bufliste = this.Get(data.Name);
         if (bufliste != null)
         {
             this.Remove(data.Name);
         }
         this.dataStore.Add(data.Name, data);
     }
     catch (Exception)
     {
     }
     finally
     {
         ReleaseMutex();
     }
 }
Beispiel #15
0
 private void FromJsonSub(ParamValues datavalue, System.Text.Json.JsonProperty elem, string lastpath)
 {
     if (elem.Value.ValueKind == System.Text.Json.JsonValueKind.Array)
     {
         // Array invalids
     }
     else if (elem.Value.ValueKind == System.Text.Json.JsonValueKind.Object)
     {
         string newlastpath = lastpath + elem.Name + "/";
         foreach (var jsubitem in elem.Value.EnumerateObject().ToList())
         {
             FromJsonSub(datavalue, jsubitem, newlastpath);
         }
     }
     else
     {
         string          fullname    = lastpath + elem.Name;
         ParamValuesNode dataelement = new ParamValuesNode();
         dataelement.Name  = fullname;
         dataelement.Value = Nglib.DATA.KEYVALUES.KeyValuesSerializerJson.ReadValue(elem.Value);
         datavalue.Add(dataelement);
     }
 }
Beispiel #16
0
        private void getdataXMLChild(ParamValues datavalue, XmlNode xdot, string pathac, XmlAttributeCollection sattributs)
        {
            string                 lastpath      = pathac;
            ParamValuesNode        bufliste      = new ParamValuesNode();
            XmlAttributeCollection sauvattributs = null;

            foreach (XmlNode xChild in xdot.ChildNodes)
            {
                //System.Console.WriteLine(xChild.Name);
                if (xChild.NodeType == XmlNodeType.Element)
                {
                    lastpath = pathac + xChild.Name.ToLower() + "/";
                    if (xChild.Attributes.Count > 0)
                    {
                        sauvattributs = xChild.Attributes;
                    }
                    else
                    {
                        sauvattributs = null;
                    }
                }

                if (xChild.NodeType == XmlNodeType.Text || (xChild.NodeType == XmlNodeType.Element && !xChild.HasChildNodes && xChild.Value == null))
                {
                    bufliste = GenerateNewNodeFromXML(datavalue, lastpath, xChild); // Ajout d'une nouvelle clef/valeur
                    if (bufliste != null)
                    {
                        datavalue.Add(bufliste);
                    }
                }
                else if (xChild.HasChildNodes)
                {
                    getdataXMLChild(datavalue, xChild, lastpath, sauvattributs);
                }
            }
        }