/// <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; } }
/// <summary> /// Obtenir/Convertir en INT Nullable /// </summary> /// <param name="dataAccessor"></param> /// <param name="nameValue"></param> /// <param name="AccesOptions"></param> /// <param name="defaultvalue"></param> /// <returns></returns> public static int?GetInt(this IDataAccessor dataAccessor, string nameValue, DataAccessorOptionEnum AccesOptions, int?defaultvalue) { try { object obj = dataAccessor.GetObject(nameValue, AccesOptions); if (obj == DBNull.Value || obj == null) { return(null); } else if (AccesOptions.HasFlag(DataAccessorOptionEnum.AdvancedConverter)) { return(ConvertPlus.ToInt(obj)); } else { return(Convert.ToInt32(obj)); } } catch (Exception ex) { if (!AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { throw new DataAccessorException("GetString " + ex.Message, ex); } throw; } }
/// <summary> /// Obtenir une valeur, methode standard DataAccessor /// </summary> public object GetObject(string nameValue, DataAccessorOptionEnum AccesOptions) { try { if (string.IsNullOrWhiteSpace(nameValue)) { return(null); } //int positionPartWant = GetPosition(nameValue); if (!this.ContainsKey(nameValue)) { return(null); } object valstring = base[nameValue]; // if(AccesOptions.HasFlag( BASICS.DataAccessorOptionEnum.Dynamise)) return(valstring); } catch (Exception) { if (AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { return(null); } throw; } }
/// <summary> /// Définir une valeur, methode standard DataAccessor /// </summary> public bool SetObject(string nameValue, object obj, DataAccessorOptionEnum AccesOptions) { try { if (string.IsNullOrWhiteSpace(nameValue)) { return(false); } //int positionPartWant = GetPosition(nameValue); if (!this.ContainsKey(nameValue)) { this.Add(nameValue, Convert.ToString(obj)); } else { base[nameValue] = Convert.ToString(obj); } return(true); } catch (Exception ex) { throw new Exception(string.Format("SetObject({0}){1}", nameValue, ex.Message), ex); } }
public bool SetData(object obj, DataAccessorOptionEnum AccesOptions) { if (!AccesOptions.HasFlag(DataAccessorOptionEnum.IgnoreChange)) { this.isChangedValue = true; } this.Value = obj; return(true); }
/// <summary> /// Accessor sur les attributs /// </summary> /// <param name="nameValue"></param> /// <param name="AccesOptions"></param> /// <returns></returns> public object GetData(string nameValue, DataAccessorOptionEnum AccesOptions) { if (string.IsNullOrWhiteSpace(nameValue)) { return(this._value); } if (this.Attributs.ContainsKey(nameValue)) { return(this.Attributs[nameValue]); } return(null); }
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); } }
public static void FromDictionaryValues(this IDataAccessor dataAccessor, Dictionary <string, object> Values, DataAccessorOptionEnum AccesOptions = 0) { try { DataAccessorOptionEnum options = DataAccessorOptionEnum.None; foreach (string itemkey in Values.Keys) { dataAccessor.SetObject(itemkey, Values[itemkey], options); } } catch (Exception) { if (AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { return; } else { throw; } } }
public bool SetData(string nameValue, object obj, DataAccessorOptionEnum AccesOptions) { if (ChangedState == System.Data.DataRowState.Unchanged) { ChangedState = System.Data.DataRowState.Modified; // !!! améliorer pour gérer les cas ou la valeur est identique et donc ne change pas vraiement } if (string.IsNullOrWhiteSpace(nameValue)) { this._value = obj; } // Si vide, c'est qu'il s'agit de l'objet principal else { // sinon il s'agit d'un attributxml if (this.Attributs.ContainsKey(nameValue)) { this.Attributs[nameValue] = obj; } else { this.Attributs.Add(nameValue.ToLowerInvariant(), obj); } } return(true); }
protected virtual object EncryptArrayValue(IDataAccessor dataAccessor, string nameValue, object value, DataAccessorOptionEnum options) { if (!options.HasFlag(DataAccessorOptionEnum.Encrypted) || dataAccessor == null || value == null) return value; // rien à faire if (this.OptionForEncrypt == null) throw new NullReferenceException($"DataAccessorEncrypt OptionForEncrypt NULL (objectType: {dataAccessor.GetType().Name})"); string[] adata = DataAccessorTools.ConvertoArrayString(value); for (int i = 0; i < adata.Length; i++) // on encrypte les valeurs une par une adata[i] = Nglib.FORMAT.CryptHashTools.Encrypt(adata[i], this.OptionForEncrypt); return adata; }
/// <summary> /// Obtient un Objet (du datarow, fluxxml ou des objets liés) /// méthode principale /// </summary> /// <returns></returns> public object GetData(string nameValue, DataAccessorOptionEnum AccesOptions) { if (this.localRow == null) { return(null); // vraiement innutile, y'a aucune données } try { if (string.IsNullOrWhiteSpace(nameValue)) { return(null); } nameValue = nameValue.Trim(); // ----------------------------- if (nameValue.Contains(":")) // Il s'agit d'un champ provenant d'un autre datapo incorporé { string[] fieldsPO = nameValue.Split(':'); if (fieldsPO.Length < 2 || string.IsNullOrWhiteSpace(fieldsPO[0]) || string.IsNullOrWhiteSpace(fieldsPO[1])) { return(null); } System.Reflection.PropertyInfo pi = this.GetType().GetProperty(fieldsPO[0]); if (pi == null || !pi.CanRead) { return(null); } object ObjfieldIn = pi.GetValue(this, null); if (ObjfieldIn == null) { return(null); } if (ObjfieldIn is DATAPO.DataPO) { DATAPO.DataPO dpo = (DATAPO.DataPO)ObjfieldIn; return(dpo.GetObject(fieldsPO[1], AccesOptions)); } else if (pi.PropertyType.IsClass) { System.Reflection.PropertyInfo subpi = pi.PropertyType.GetProperty(fieldsPO[1]); if (subpi == null) { return(null); } else { return(subpi.GetValue(ObjfieldIn, null)); } // !!! ajouter la recherche dans une liste ou dictionary : 'documents[monchamp="valeur",monchamp2="valeur"]:monchamp3' } } // ----------------------------- else if (nameValue.StartsWith("/")) // Il s'agit du flux de données nosql { //string fieldName = nameValue.Split('/')[1]; // le nom du champ est équivalent au nom du root //IDataPOFlow flow = this.GetFlow(fieldName); //// IDataAccessor flowdata = this.GetFlow(fieldName) as IDataAccessor; // On converti le //if (flow == null ||) return null; //return flow.GetObject(nameValue, AccesOptions); //!!!!!!!!! } // ----------------------------- else // sinon c'est un champdu datarow { System.Data.DataColumn realColumn = DataSetTools.GetColumn(this.localRow.Table, nameValue); if (realColumn != null) { return(this.localRow[realColumn]); } } return(null); } catch (Exception) { return(null); } }
protected virtual object DecryptArrayValue(IDataAccessor dataAccessor, string nameValue, object valuecc, DataAccessorOptionEnum options) { if (!options.HasFlag(DataAccessorOptionEnum.Encrypted) || dataAccessor == null || valuecc == null) return valuecc; // rien à faire if (this.OptionForDecrypt == null) throw new NullReferenceException($"DataAccessorDecrypt OptionForDecrypt NULL (objectType: {dataAccessor.GetType().Name})"); if (valuecc == null) return null; string[] adata = valuecc as string[]; if (adata == null) throw new Exception("DecryptArrayValue Only string[] input allowed"); for (int i = 0; i < adata.Length; i++) //une par une adata[i] = Nglib.FORMAT.CryptHashTools.Decrypt(adata[i], this.OptionForDecrypt); return adata; }
public virtual object EncryptObjectValue(IDataAccessor dataAccessor, string nameValue, object value, DataAccessorOptionEnum options) { if (!options.HasFlag(DataAccessorOptionEnum.Encrypted) || dataAccessor == null || value == null) return value; // rien à faire if (this.OptionForEncrypt == null) throw new NullReferenceException($"DataAccessorEncrypt OptionForEncrypt NULL (objectType: {dataAccessor.GetType().Name})"); if (value.GetType().IsArray) return EncryptArrayValue(dataAccessor, nameValue, value, options); // spécifique pour gérer les array string strvalue = value.ToString(); // la valeur en base sera forcément un string string encryptedVal = Nglib.FORMAT.CryptHashTools.Encrypt(strvalue, this.OptionForEncrypt); return encryptedVal; }
public static bool[] GetBooleanArray(this IDataAccessor dataAccessor, string nameValue, DataAccessorOptionEnum AccesOptions = DataAccessorOptionEnum.None, bool defaultvalue = false) { if (AccesOptions.HasFlag(DataAccessorOptionEnum.Safe) && dataAccessor == null) { return(null); } object obj = dataAccessor.GetObject(nameValue, AccesOptions); bool[] retour = obj as bool[]; if (retour == null && obj is string[]) { retour = (obj as string[]).Select(item => (string.IsNullOrWhiteSpace(item)) ? defaultvalue : Convert.ToBoolean(item)).ToArray(); } return(retour); }
public static DateTime[] GetDateTimeArray(this IDataAccessor dataAccessor, string nameValue, DataAccessorOptionEnum AccesOptions = DataAccessorOptionEnum.None) { if (AccesOptions.HasFlag(DataAccessorOptionEnum.Safe) && dataAccessor == null) { return(null); } object obj = dataAccessor.GetObject(nameValue, AccesOptions); DateTime[] retour = obj as DateTime[]; if (retour == null && obj is string[]) { retour = (obj as string[]).Select(item => (string.IsNullOrWhiteSpace(item)) ? new DateTime() : Convert.ToDateTime(item)).ToArray(); } return(retour); }
/// <summary> /// Obtient les données d'un autre objet par la reflexion /// </summary> /// <param name="objetSource"></param> /// <param name="replaceifnotnull"></param> /// <param name="safe"></param> /// <returns></returns> public static bool FromObject(this IDataAccessor dataAccessor, object objetSource, bool replaceifnotnull = true, DataAccessorOptionEnum AccesOptions = 0) { try { Dictionary <string, object> vals = Nglib.APP.CODE.PropertiesTools.GetValuesReflexion(objetSource); vals.Keys.ToList().ForEach(k => dataAccessor.SetObject(k, vals[k])); return(false); } catch (Exception ex) { throw new Exception("FromObject " + ex.Message, ex); } }
public static string DynamicValues(this IDataAccessor dataAccessor, string formatingValues, Dictionary <string, string> transformFuctions = null, DataAccessorOptionEnum AccesOptions = DataAccessorOptionEnum.None) { try { // dynamisation de la chaine de caratère string retour = FORMAT.StringTransform.DynamiseWithAccessor(formatingValues, dataAccessor); // Transformation de la chaine finale selon une série d'instruction de transformation if (transformFuctions != null) { retour = FORMAT.StringTransform.Transform(retour, transformFuctions); } return(retour); } catch (Exception ex) { if (!AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { throw new DataAccessorException("FormatingMultiValues " + ex.Message, ex); } return(string.Empty); } }
public static long[] GetLongArray(this IDataAccessor dataAccessor, string nameValue, DataAccessorOptionEnum AccesOptions = DataAccessorOptionEnum.None, long DefaultValue = 0) { if (AccesOptions.HasFlag(DataAccessorOptionEnum.Safe) && dataAccessor == null) { return(null); } object obj = dataAccessor.GetObject(nameValue, AccesOptions); long[] retour = obj as long[]; if (retour == null && obj is string[]) { retour = (obj as string[]).Select(item => (string.IsNullOrWhiteSpace(item)) ? DefaultValue : Convert.ToInt64(item)).ToArray(); } return(retour); }
public static string[] GetStringArray(this IDataAccessor dataAccessor, string nameValue, DataAccessorOptionEnum AccesOptions = DataAccessorOptionEnum.None) { if (AccesOptions.HasFlag(DataAccessorOptionEnum.Safe) && dataAccessor == null) { return(null); } object obj = dataAccessor.GetObject(nameValue, AccesOptions); string[] retour = obj as string[]; return(retour); }
/// <summary> /// Obtenir/Convertir en Double NULLABLE /// </summary> /// <param name="dataAccessor"></param> /// <param name="nameValue"></param> /// <param name="AccesOptions"></param> /// <param name="defaultvalue"></param> /// <returns></returns> public static double?GetDouble(this IDataAccessor dataAccessor, string nameValue, DataAccessorOptionEnum AccesOptions, double?defaultvalue) { try { object obj = dataAccessor.GetObject(nameValue, AccesOptions); if (obj == DBNull.Value || obj == null) { return(null); } else { return(Convert.ToDouble(obj)); } } catch (Exception ex) { if (!AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { throw new DataAccessorException("GetString " + ex.Message, ex); } throw; } }
public static Dictionary <string, string> ToDictionaryString(this IDataAccessor dataAccessor, DataAccessorOptionEnum AccesOptions = DataAccessorOptionEnum.None) { Dictionary <string, string> retour = new Dictionary <string, string>(); foreach (string item in dataAccessor.ListFieldsKeys()) { retour.Add(item, dataAccessor.GetString(item, AccesOptions)); } return(retour); }
/// <summary> /// Obtenir les données dans un dictionary /// </summary> /// <param name="dataAccessor"></param> /// <param name="AccesOptions"></param> /// <returns></returns> public static Dictionary <string, object> ToDictionaryValues(this IDataAccessor dataAccessor, DataAccessorOptionEnum AccesOptions = 0) { Dictionary <string, object> retour = new Dictionary <string, object>(); foreach (string item in dataAccessor.ListFieldsKeys()) { retour.Add(item, dataAccessor.GetObject(item, AccesOptions)); } return(retour); }
/// <summary> /// Défini un objet /// </summary> /// <returns></returns> public bool SetData(string nameValue, object obj, DataAccessorOptionEnum AccesOptions) { try { if (string.IsNullOrWhiteSpace(nameValue)) { return(false); } nameValue = nameValue.Trim(); if (nameValue.Contains(":")) { // Obtenir la valeur dans un datapo join à celui-ci throw new Exception("DataPo In SubObject non géré"); } else if (nameValue.StartsWith("/")) { // Obtenir la valeur dans le flux nosql lié string fieldName = nameValue.Split('/')[1]; // le nom du champ est équivalent au nom du root IDataPOFlow flow = this.GetFlow(fieldName); if (flow == null) { return(false); } //bool iset = flow.SetObject(nameValue, obj, AccesOptions); //if (iset) this.localRow.SetModified(); //return iset; //!!!!!!!!!!!! return(false); } else { // Obtien la valeur normalement dans le datarow local if (this.localRow == null) { this.DefineSchemaPO(); // si pas de datarow, on l'initialiser (identique à GetRow()) } System.Data.DataColumn realColumn = this.localRow.Table.Columns[nameValue]; if (realColumn == null) { if (AccesOptions.HasFlag(DataAccessorOptionEnum.NotCreateColumn)) // création de la colonne interdite { if (AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { return(false); } else { throw new Exception("Colonne Introuvable dans le DataRow (NotCreateColumn = true)"); } } else if (obj == null || obj == DBNull.Value) // si la valeur est null et que la valeur existe pas c'est pas la peine de créer une colone { return(false); //if (AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) return false; //else throw new Exception("Colonne Introuvable dans le DataRow (Impossible de déterminer le type à partir d'un null pour créer la colonne)"); } // Création de la colone Type typetocreate = obj.GetType(); realColumn = this.localRow.Table.CreateColumn(nameValue.ToLower(), typetocreate); // Création d'une nouvelle colonne dans la table pour stoker la valeur (toujours en minuscule) } object orgnobj = this.localRow[realColumn]; if (obj == null && orgnobj == null) { return(false); // inutile si pas modifié } if (obj != null && obj.Equals(orgnobj)) { return(false); // inutile si pas modifié } if (AccesOptions.HasFlag(DataAccessorOptionEnum.IgnoreChange)) // il faut tromper le datarow pour lui faire croire que la donnée n'a pas été modifié { Dictionary <string, object> prechanged = DataSetTools.GetChangedValues(this.localRow); // on obtien les changements précédents if (prechanged.Count > 0) { this.localRow.RejectChanges(); // on les rejetents pour les remettre après } this.localRow[realColumn] = obj; // on met à jours la données this.localRow.AcceptChanges(); // on approuve la mise à jours if (prechanged.Count > 0) { prechanged.Keys.ToList().ForEach(k => this.localRow[k] = prechanged[k]); // on remet les anciennes modifications } } else { this.localRow[realColumn] = obj; // on met à jours la données dans le datarow , l'objet passera au statut modified } return(true); } } catch (Exception ex) { if (AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { return(false); } else { throw new Exception("SetObject DataRow " + nameValue + " : " + ex.Message, ex); } } finally { } }
public static TEnum[] GetEnumArray <TEnum>(this IDataAccessor dataAccessor, string nameValue, DataAccessorOptionEnum AccesOptions = DataAccessorOptionEnum.None) { throw new NotImplementedException(); // !!! }
/// <summary> /// Obtenir la données /// </summary> public static object GetObject(this IDataAccessor dataAccessor, string nameValue, DataAccessorOptionEnum AccesOptions) { //Obtenir la données la donnée object adata = dataAccessor.GetData(nameValue, AccesOptions); //Cryptage if (adata != null && AccesOptions.HasFlag(DataAccessorOptionEnum.Encrypted)) { var cryptoctx = dataAccessor.GetCryptoContext(); if (cryptoctx != null) { adata = cryptoctx.DecryptObjectValue(dataAccessor, nameValue, adata, AccesOptions); } } return(adata); }
/// <summary> /// Définir une donnée /// </summary> public static bool SetObject(this IDataAccessor dataAccessor, string nameValue, object obj, DataAccessorOptionEnum AccesOptions) { object adata = obj; // Cryptage if (obj != null && AccesOptions.HasFlag(DataAccessorOptionEnum.Encrypted)) { var cryptoctx = dataAccessor.GetCryptoContext(); if (cryptoctx != null) { adata = cryptoctx.EncryptObjectValue(dataAccessor, nameValue, adata, AccesOptions); } } if (adata == null) { adata = DBNull.Value; // les nul son interdit en base } return(dataAccessor.SetData(nameValue, adata, AccesOptions)); }
public static TEnum GetEnum <TEnum>(this IDataAccessor dataAccessor, string fieldname, DataAccessorOptionEnum AccesOptions = 0) where TEnum : struct { TEnum defaultValue = DataAccessorTools.GetEnumDefaultValue <TEnum>(); return(GetEnum <TEnum>(dataAccessor, fieldname, defaultValue, AccesOptions).Value); }
/// <summary> /// Obtenir/Convertir en Bool /// </summary> /// <param name="dataAccessor"></param> /// <param name="nameValue"></param> /// <param name="DefaultValue"></param> /// <param name="AccesOptions"></param> /// <returns></returns> public static bool GetBoolean(this IDataAccessor dataAccessor, string nameValue, bool DefaultValue, DataAccessorOptionEnum AccesOptions = 0) { try { object obj = dataAccessor.GetObject(nameValue, AccesOptions); if (obj == DBNull.Value || obj == null) { return(DefaultValue); } if (obj is string && string.IsNullOrWhiteSpace((string)obj)) { return(DefaultValue); } else if (AccesOptions.HasFlag(DataAccessorOptionEnum.AdvancedConverter)) { return(ConvertPlus.ToBoolean(obj)); } else { return(Convert.ToBoolean(obj)); } } catch (Exception ex) { if (!AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { throw new DataAccessorException("GetString " + ex.Message, ex); } throw; } }
public static TEnum?GetEnum <TEnum>(this IDataAccessor dataAccessor, string fieldname, TEnum?defaultValue, DataAccessorOptionEnum AccesOptions = 0) where TEnum : struct { TEnum? foo = defaultValue; Object obj = dataAccessor.GetObject(fieldname, AccesOptions); try { if (obj == null || obj == DBNull.Value || obj is System.DBNull) { foo = defaultValue; } else if (obj is string) { string objTypeIn = obj.ToString(); if (!string.IsNullOrWhiteSpace(objTypeIn)) { foo = (TEnum)Enum.Parse(typeof(TEnum), objTypeIn); if (!Enum.IsDefined(typeof(TEnum), foo) && !foo.ToString().Contains(",")) { throw new InvalidOperationException(string.Format("{0} is not an underlying value of the YourEnum enumeration.", objTypeIn)); } } } else if (obj is int || obj is short) { foo = (TEnum)obj; } else { throw new NotImplementedException(string.Format("Type {0} non géré", obj.GetType().ToString())); } } catch (Exception ex) { if (!AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { throw new Exception("GetEnum " + ex.Message, ex); } } return(foo); }
/// <summary> /// Obtenir un string /// </summary> /// <param name="dataAccessor"></param> /// <param name="nameValue"></param> /// <param name="AccesOptions"></param> /// <returns></returns> public static string GetString(this IDataAccessor dataAccessor, string nameValue, DataAccessorOptionEnum AccesOptions) { try { if (AccesOptions.HasFlag(DataAccessorOptionEnum.Safe) && dataAccessor == null) { return(null); } object obj = dataAccessor.GetObject(nameValue, AccesOptions); if ((obj == null || obj == DBNull.Value)) // retourne pas null par default { if (AccesOptions.HasFlag(DataAccessorOptionEnum.Nullable)) { return(null); } else { return(string.Empty); } } return(obj.ToString()); //DATA.MANIPULATE.TEXT.TextTreatment.Transform //return str; } catch (Exception ex) { if (!AccesOptions.HasFlag(DataAccessorOptionEnum.Safe)) { throw new DataAccessorException("GetString " + ex.Message, ex); } return(string.Empty); } }