private static void Transform_CsvPosition(StringDynamizerContext context) { //chaine = '"' + chaine.Replace("\"", "") + '"'; //string[] chainedec = chaine.Split(';'); //int position = Convert.ToInt32(fcnData["csvposition"]); //if (chainedec.Length < position) throw new Exception("csvposition Ligne CSV invalide, Position : " + position + "/" + chainedec.Length); //chaine = chainedec[position]; //if (chaine.Length > 1 && chaine[0] == '"' && chaine[chaine.Length - 1] == '"') chaine = chaine.Substring(1, chaine.Length - 2); //suppression des guillemets }
private static void Transform_quotation(StringDynamizerContext context) { // met des guillemets : "toto" //string val = "\""; //string daterfg = Convert.ToString(fcnData["guillemets"]).ToLower(); //if (daterfg != "true" || daterfg != "yes") val = daterfg; //chaine = val + chaine.Replace(val, "") + val; // On prend aussi soin de nétoyer la chaine }
private static void Validate_ismodulo(StringDynamizerContext context) { //string[] mrt = Convert.ToString(fcnData["modulo"]).Split('|'); //if (mrt.Length < 2) throw new Exception("DEV param ismodulo invalide"); //int nummodulo = Convert.ToInt32(mrt[0]); //string resmodulochaine = null, resmodulo = null; //if (mrt[1][0] == 'd') //{ // int lastpos = Convert.ToInt32(mrt[1][1]); // resmodulochaine = chaine.Substring(chaine.Length - lastpos - 1, lastpos); // resmodulo = "";// !!!calc //} //if (resmodulochaine != null && resmodulo != resmodulochaine) throw new Exception("Validation MODULO"); }
private static void Transform_substring(StringDynamizerContext context) { //{ // string[] splitsubstringparam = Convert.ToString(fcnData["substring"]).Split(','); // int positionsub = Convert.ToInt32(splitsubstringparam[0]); // int sizesub = Convert.ToInt32(splitsubstringparam[1]); // chaine = DATA.FORMAT.StringUtilities.SubstringSafe(chaine, positionsub, sizesub); //} //if (fcnData.ContainsKey("start")) //{ // chaine = chaine.Substring(Convert.ToInt32(fcnData["start"])); //!!!!! vérifier //} //if (fcnData.ContainsKey("right")) //découpe à partir de la droite //{ // chaine = chaine.Substring(chaine.Length - Convert.ToInt32(fcnData["right"])); //!!!!! vérifier //} //if (fcnData.ContainsKey("left")) //découpe à partir de la gauche //{ // int nb = Convert.ToInt32(fcnData["left"]); // if (nb > chaine.Length) nb = chaine.Length; // chaine = chaine.Substring(0, nb); //} //if (fcnData.ContainsKey("limit")) //Limiter le nombre de caractères sans erreurs //{ // chaine = DATA.FORMAT.StringUtilities.Limit(chaine, Convert.ToInt32(fcnData["limit"])); //} //if (fcnData.ContainsKey("size")) //{ // bool size_forcer = true; if (fcnData.ContainsKey("lengthmax")) size_forcer = false; // si une taille max été défini on ne force pas. // bool size_numerique = false; if (fcnData.ContainsKey("numerique")) size_numerique = true; // chaine = DATA.FORMAT.StringUtilities.Complete(chaine, Convert.ToInt32(fcnData["size"]), size_numerique, size_forcer); //} }
private static void Validate_disallowchar(StringDynamizerContext context) { // if (DATA.FORMAT.StringUtilities.ContainChars(chaine, Convert.ToString(fcnData["disallowchar"]))) throw new Exception("Validation Null Empty WhiteSpace"); }
private static void Validate_isempty(StringDynamizerContext context) { // if (string.IsNullOrWhiteSpace(chaine)) throw new Exception("Validation Null Empty WhiteSpace"); }
private static void Validate_validtype(StringDynamizerContext context) { //if (!System.Text.RegularExpressions.Regex.IsMatch(chaine, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z")) throw new Exception("Validation MAIL"); }
private static void Validate_lengthmax(StringDynamizerContext context) { // if (chaine.Length > Convert.ToInt32(fcnData["lengthmax"])) throw new Exception("Validation lenghtmax"); }
private static void Validate_regex(StringDynamizerContext context) { //System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(Convert.ToString(fcnData["regex"])); //if (!re.IsMatch(chaine)) throw new Exception("Validation REGEX"); }
private static void Transform_atstart(StringDynamizerContext context) { //chaine = fcnData["atstart"] + chaine; }
private static void Transform_atend(StringDynamizerContext context) { // chaine = chaine + fcnData["atend"]; }
private static void Transform_formatdate(StringDynamizerContext context) { DateTime chainedate = ConvertPlus.ToDateTime(context.FinalString); //context.FinalString = DateUtilities.fo(chainedate, Convert.ToString(fcnData["formatdate"])); }
private static void Transform_replace(StringDynamizerContext context) { //chaine = chaine.Replace(Convert.ToString(fcnData["replace"]), Convert.ToString(fcnData["replacevalue"])); }
/// <summary> /// Permet de supprimer les blancs sur la chaine /// </summary> /// <param name="context"></param> private static void Transform_trim(StringDynamizerContext context) { context.FinalString = context.FinalString.Trim(); }
private static void Transform(StringDynamizerContext context) { // chaine_formatdate // l'odre des opérations est très importantes try { if (context.DynFunctions.Keys.Contains("csvposition", true)) // obtient la données dans une ligne csv { Transform_CsvPosition(context); } if (context.DynFunctions.Keys.Contains("trim", true)) { Transform_trim(context); } if (context.DynFunctions.Keys.Contains(new List <string>() { "substring", "start", "right", "left", "limit", "size" })) { Transform_substring(context); } if (context.DynFunctions.Keys.Contains("replace", true)) { Transform_replace(context); } if (context.DynFunctions.Keys.Contains("formatdate", true)) //transforme en date { Transform_formatdate(context); } if (context.DynFunctions.Keys.Contains("atend", true)) //place a la fin { Transform_atend(context); } if (context.DynFunctions.Keys.Contains("atstart", true)) //place au début { Transform_atstart(context); } if (context.DynFunctions.Keys.Contains("quotation", true)) //place au début { Transform_quotation(context); } // ********************************************************************************* // VALIDATEURS if (context.DynFunctions.Keys.Contains("regex")) // Validation { Validate_regex(context); } if (context.DynFunctions.Keys.Contains("ismodulo")) // Validation { Validate_ismodulo(context); } if (context.DynFunctions.Keys.Contains("lengthmax")) // Validation { Validate_lengthmax(context); } if (context.DynFunctions.Keys.Contains("validtype")) // Validation { Validate_validtype(context); } if (context.DynFunctions.Keys.Contains("isempty")) // Validation { Validate_isempty(context); } if (context.DynFunctions.Keys.Contains("disallowchar")) // Validation { Validate_disallowchar(context); } } catch (Exception ex) { throw new Exception("Validate Error: " + ex.Message); } }