//NamedValues1 public override bool TrySetValues(NamedValues <ZValue> values) { if (!base.TrySetValues(values)) { return(false); } _weekEnd = false; _extra = false; _focus = false; if (values.ContainsKey("we")) { _weekEnd = true; } if (values.ContainsKey("extra")) { _extra = true; } if (values.ContainsKey("focus")) { _focus = true; } if (values.ContainsKey("type_code")) { SetType((string)values["type_code"]); } return(true); }
//NamedValues1 public static LeMondeType GetType(NamedValues<ZValue> values) { LeMondeType type = LeMondeType.Unknow; if (values.ContainsKey("type_code")) { type = GetTypeCode((string)values["type_code"]); } else if (values.ContainsKey("type_quo") && values["type_quo"] != null) { type = LeMondeType.Quotidien; if (values.ContainsKey("types_quo_sup")) { object o = values["types_quo_sup"]; if (o != null && !(o is string[])) throw new PBException("error creating LeMonde value types_quo_sup should be a string array : {0}", o); foreach (string s in (string[])o) type |= GetTypeSup(s); } } else { if (!values.ContainsKey("type_sup")) throw new PBException("error creating LeMonde unknow type_sup"); object o = values["type_sup"]; if (!(o is string)) throw new PBException("error creating LeMonde value type_sup should be a string : {0}", o); type = GetTypeSup((string)o); } return type; }
//NamedValues1 public LeMonde0(NamedValues <ZValue> values) { // year : mandatory, int or numeric string // day : mandatory, int or numeric string // month : mandatory, int or numeric string // type_quo : optional, string null, "_quo" // types_quo_sup : optional, string[], "tv", "argent" // type_sup : optional, string null, "livres" // number : not used, int or numeric string // type : not used, string "_quo", "-livres", "_quo+tv", "_quo+tv+argent" if (!values.ContainsKey("year")) { throw new PBException("error creating LeMonde unknow year"); } if (!values.ContainsKey("month")) { throw new PBException("error creating LeMonde unknow month"); } if (!values.ContainsKey("day")) { throw new PBException("error creating LeMonde unknow day"); } _date = zdate.CreateDate(values); _type = GetType(values); }
//NamedValues1 public LeFigaro(NamedValues<ZValue> values) { if (!values.ContainsKey("day_near_current_date")) { if (!values.ContainsKey("year")) throw new PBException("error creating LeFigaro unknow year"); if (!values.ContainsKey("month")) throw new PBException("error creating LeFigaro unknow month"); if (!values.ContainsKey("day")) throw new PBException("error creating LeFigaro unknow day"); } _date = zdate.CreateDate(values); }
//NamedValues1 public override bool TrySetValues(NamedValues<ZValue> values) { if (!base.TrySetValues(values)) return false; if (values.ContainsKey("es")) _es = true; if (values.ContainsKey("styles")) _styles = true; if (values.ContainsKey("type_code")) //string SetType((string)values["type_code"]); return true; }
//NamedValues1 public override bool TrySetValues(NamedValues<ZValue> values) { if (!base.TrySetValues(values)) return false; _eco = false; _mag = false; if (values.ContainsKey("eco")) _eco = true; if (values.ContainsKey("mag")) _mag = true; if (values.ContainsKey("type_code")) SetType((string)values["type_code"]); return true; }
protected virtual bool TryGetPrintNumber(NamedValues <ZValue> values, out int number) { number = 0; if (!values.ContainsKey("number")) { SetError("error print number not found"); return(false); } int number2; if (!int.TryParse((string)values["number"], out number2)) { SetError("error invalid print number \"{0}\"", values["number"]); return(false); } if (_print.Frequency != PrintFrequency.Daily && !_special) { //Date date = _print.GetPrintDate(number2); Date date; DateType dateType; _print.GetPrintDate(number2, out date, out dateType); string error; if (!ControlDate(date, out error)) { return(false); } } number = number2; return(true); }
protected virtual bool TryGetIndex(NamedValues <ZValue> values, out int index) { index = 0; if (!values.ContainsKey("index")) { SetError("error index not found"); return(false); } //string string s = (string)values["index"]; if (s == null) { return(true); } int index2; if (!int.TryParse(s, out index2)) { SetError("error invalid index \"{0}\"", s); return(false); } index = index2; return(true); }
public static object[] GetParameters(MethodInfo methodInfo, NamedValues <ZValue> namedParameters, ErrorOptions option = ErrorOptions.None) { if (methodInfo == null) { return(null); } List <object> parameters = new List <object>(); //ParameterInfo[] methodParameters = methodInfo.GetParameters(); foreach (ParameterInfo parameter in methodInfo.GetParameters()) { object value; if (namedParameters != null && namedParameters.ContainsKey(parameter.Name)) { // no control between parameter type and named parameter type value = namedParameters[parameter.Name].ToObject(); } else if (parameter.HasDefaultValue) { value = parameter.DefaultValue; } else { Error.WriteMessage(option, $"no value for parameter \"{parameter.Name}\" of method \"{methodInfo.zGetName()}\", use default value"); value = zReflection.GetDefaultValue(parameter.ParameterType); } parameters.Add(value); } return(parameters.ToArray()); }
public static object[] GetParameters(MethodInfo methodInfo, NamedValues<ZValue> namedParameters, ErrorOptions option = ErrorOptions.None) { if (methodInfo == null) return null; List<object> parameters = new List<object>(); //ParameterInfo[] methodParameters = methodInfo.GetParameters(); foreach (ParameterInfo parameter in methodInfo.GetParameters()) { object value; if (namedParameters != null && namedParameters.ContainsKey(parameter.Name)) { // no control between parameter type and named parameter type value = namedParameters[parameter.Name].ToObject(); } else if (parameter.HasDefaultValue) { value = parameter.DefaultValue; } else { Error.WriteMessage(option, $"no value for parameter \"{parameter.Name}\" of method \"{methodInfo.zGetName()}\", use default value"); value = zReflection.GetDefaultValue(parameter.ParameterType); } parameters.Add(value); } return parameters.ToArray(); }
// type_dossier : name public override bool TrySetValues(NamedValues <ZValue> values) { if (!base.TrySetValues(values)) { return(false); } LeMondeType type; if (!TryGetType(values, out type)) { return(false); } if (type != LeMondeType.Unknow) { _type = type; } if (values.ContainsKey("type_dossier")) { ZValue v = values["type_dossier"]; if (v != null && v is ZString) { _dossier = (string)v; } } _typeCode = null; return(true); }
//NamedValues1 public override bool TrySetValues(NamedValues<ZValue> values) { if (!base.TrySetValues(values)) return false; _weekEnd = false; _extra = false; _focus = false; if (values.ContainsKey("we")) _weekEnd = true; if (values.ContainsKey("extra")) _extra = true; if (values.ContainsKey("focus")) _focus = true; if (values.ContainsKey("type_code")) SetType((string)values["type_code"]); return true; }
//NamedValues1 public LaCroix(NamedValues<ZValue> values) { // year : mandatory, int or numeric string // day : mandatory, int or numeric string // month : mandatory, int or numeric string // number : not used, int or numeric string if (!values.ContainsKey("day_near_current_date")) { if (!values.ContainsKey("year")) throw new PBException("error creating LaCroix unknow year"); if (!values.ContainsKey("month")) throw new PBException("error creating LaCroix unknow month"); if (!values.ContainsKey("day")) throw new PBException("error creating LaCroix unknow day"); } _date = zdate.CreateDate(values); }
public static bool GetTestValue(NamedValues <ZValue> parameters) { if (parameters.ContainsKey("test")) { return((bool)parameters["test"]); } return(false); }
//NamedValues1 public LeMonde0(NamedValues<ZValue> values) { // year : mandatory, int or numeric string // day : mandatory, int or numeric string // month : mandatory, int or numeric string // type_quo : optional, string null, "_quo" // types_quo_sup : optional, string[], "tv", "argent" // type_sup : optional, string null, "livres" // number : not used, int or numeric string // type : not used, string "_quo", "-livres", "_quo+tv", "_quo+tv+argent" if (!values.ContainsKey("year")) throw new PBException("error creating LeMonde unknow year"); if (!values.ContainsKey("month")) throw new PBException("error creating LeMonde unknow month"); if (!values.ContainsKey("day")) throw new PBException("error creating LeMonde unknow day"); _date = zdate.CreateDate(values); _type = GetType(values); }
//NamedValues1 public LeFigaro(NamedValues <ZValue> values) { if (!values.ContainsKey("day_near_current_date")) { if (!values.ContainsKey("year")) { throw new PBException("error creating LeFigaro unknow year"); } if (!values.ContainsKey("month")) { throw new PBException("error creating LeFigaro unknow month"); } if (!values.ContainsKey("day")) { throw new PBException("error creating LeFigaro unknow day"); } } _date = zdate.CreateDate(values); }
//NamedValues1 public override bool TrySetValues(NamedValues <ZValue> values) { if (!base.TrySetValues(values)) { return(false); } if (values.ContainsKey("es")) { _es = true; } if (values.ContainsKey("styles")) { _styles = true; } if (values.ContainsKey("type_code")) { //string SetType((string)values["type_code"]); } return(true); }
//NamedValues1 public static LeMondeType GetType(NamedValues <ZValue> values) { LeMondeType type = LeMondeType.Unknow; if (values.ContainsKey("type_code")) { type = GetTypeCode((string)values["type_code"]); } else if (values.ContainsKey("type_quo") && values["type_quo"] != null) { type = LeMondeType.Quotidien; if (values.ContainsKey("types_quo_sup")) { object o = values["types_quo_sup"]; if (o != null && !(o is string[])) { throw new PBException("error creating LeMonde value types_quo_sup should be a string array : {0}", o); } foreach (string s in (string[])o) { type |= GetTypeSup(s); } } } else { if (!values.ContainsKey("type_sup")) { throw new PBException("error creating LeMonde unknow type_sup"); } object o = values["type_sup"]; if (!(o is string)) { throw new PBException("error creating LeMonde value type_sup should be a string : {0}", o); } type = GetTypeSup((string)o); } return(type); }
//NamedValues1 public override bool TrySetValues(NamedValues <ZValue> values) { if (!base.TrySetValues(values)) { return(false); } _eco = false; _mag = false; if (values.ContainsKey("eco")) { _eco = true; } if (values.ContainsKey("mag")) { _mag = true; } if (values.ContainsKey("type_code")) { SetType((string)values["type_code"]); } return(true); }
//NamedValues1 public LaCroix(NamedValues <ZValue> values) { // year : mandatory, int or numeric string // day : mandatory, int or numeric string // month : mandatory, int or numeric string // number : not used, int or numeric string if (!values.ContainsKey("day_near_current_date")) { if (!values.ContainsKey("year")) { throw new PBException("error creating LaCroix unknow year"); } if (!values.ContainsKey("month")) { throw new PBException("error creating LaCroix unknow month"); } if (!values.ContainsKey("day")) { throw new PBException("error creating LaCroix unknow day"); } } _date = zdate.CreateDate(values); }
public static bool TryGetDay(NamedValues<ZValue> values, out int day) { day = 0; if (values.ContainsKey("day")) { ZValue v = values["day"]; if (v is ZString) { day = GetDayNumber((string)v); if (day != 0) return true; } else Trace.WriteLine("error day should be a string : {0}", v); } return false; }
//NamedValues1 protected virtual bool TryGetPrintNumber(NamedValues <ZValue> values, out int number) { number = 0; if (!values.ContainsKey("number")) { //throw new PBException("error print number not found"); values.SetError("error print number not found"); return(false); } int number2; if (!int.TryParse((string)values["number"], out number2)) { //throw new PBException("error invalid print number \"{0}\"", values["number"]); values.SetError("error invalid print number \"{0}\"", values["number"]); return(false); } //return printNumber; number = number2; return(true); }
public static bool TryGetDay(NamedValues <ZValue> values, out int day) { day = 0; if (values.ContainsKey("day")) { ZValue v = values["day"]; if (v is ZString) { day = GetDayNumber((string)v); if (day != 0) { return(true); } } else { Trace.WriteLine("error day should be a string : {0}", v); } } return(false); }
public FindNumber Find(string text) { foreach (RegexValues rv in _numberRegexList.Values) { MatchValues matchValues = rv.Match(text); if (matchValues.Success) { NamedValues <ZValue> values = matchValues.GetValues(); if (values.ContainsKey("number")) { int number; ZValue value = values["number"]; if (value is ZString) { if (!int.TryParse((string)value, out number)) { throw new PBException("error finding number text is'nt a number : \"{0}\"", (string)value); } } else if (value is ZInt) { number = (int)value; } else { throw new PBException("error finding number value is'nt a number : {0}", value); } //return new FindNumber { found = true, number = number, remainText = rv.MatchReplace("_"), regexValues = rv }; return(new FindNumber { found = true, number = number, matchValues = matchValues }); } } } return(new FindNumber { found = false }); }
public virtual bool TrySetValues(NamedValues <ZValue> values) { //_error = null; //_printValues.SetValues(values); bool special = _special; if (values.ContainsKey("special")) { special = true; _printValues.SetValues(values, "special"); } bool specialMonth = _specialMonth; if (values.ContainsKey("special_month")) { specialMonth = true; _printValues.SetValues(values, "special_month"); } Date? date = _date; DateType dateType = _dateType; if (values.ContainsKey("day_near_current_date") || values.ContainsKey("month")) { Date date2; DateType dateType2; if (!zdate.TryCreateDate(values, out date2, out dateType2)) { //if (values.Error != null) // _error = values.Error; return(false); } string error; if (!ControlDate(date2, out error)) { return(false); } date = date2; dateType = dateType2; _printValues.SetValues(values, "day_near_current_date", "day", "month", "year"); } int printNumber = _printNumber; if (values.ContainsKey("number")) { if (!TryGetPrintNumber(values, out printNumber)) { return(false); } _printValues.SetValues(values, "number"); } if (date != null && printNumber != 0 && !_print.NoDateAndNumberCalculate && !special && !specialMonth) { if (_print.Frequency == PrintFrequency.Daily) { printNumber = 0; } else { date = null; dateType = pb.DateType.Unknow; } } string label = _label; if (values.ContainsKey("label")) { label = (string)values["label"]; _printValues.SetValues(values, "label"); } int index = _index; if (values.ContainsKey("index")) { if (!TryGetIndex(values, out index)) { return(false); } _printValues.SetValues(values, "index"); } _error = null; _special = special; _specialMonth = specialMonth; _date = date; _dateType = dateType; _printNumber = printNumber; _label = label; _index = index; return(true); }
//NamedValues1 public static bool TryGetType(NamedValues<ZValue> values, out LeMondeType type) { type = LeMondeType.Unknow; if (values.ContainsKey("type_code")) { type = GetTypeCode((string)values["type_code"]); if (type == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", (string)values["type_code"]); return false; } } else if ((values.ContainsKey("type_quo") && values["type_quo"] != null) || values.ContainsKey("fix_type_quo")) //else if (values.ContainsKey("type_quo")) { type = LeMondeType.Quotidien; if (values.ContainsKey("types_quo_sup")) { object o = values["types_quo_sup"]; if (o != null && !(o is string[])) { //throw new PBException("error creating LeMonde value types_quo_sup should be a string array : {0}", o); values.SetError("error creating LeMonde value types_quo_sup should be a string array : {0}", o); return false; } foreach (string s in (string[])o) { //type |= GetTypeSup(s); LeMondeType type2 = GetTypeSup(s); if (type2 == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", s); return false; } type |= type2; } } } else if (values.ContainsKey("type_sup")) { //if (!values.ContainsKey("type_sup")) // throw new PBException("error creating LeMonde unknow type_sup"); object o = values["type_sup"]; if (!(o is string)) { //throw new PBException("error creating LeMonde value type_sup should be a string : {0}", o); values.SetError("error creating LeMonde value type_sup should be a string : {0}", o); return false; } type = GetTypeSup((string)o); if (type == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", o); return false; } } else if (values.ContainsKey("fix_type_eco")) type = LeMondeType.Economie; else if (values.ContainsKey("fix_type_tv")) type = LeMondeType.TV; else { //throw new PBException("error creating LeMonde unknow type"); values.SetError("error creating LeMonde unknow type"); return false; } //return type; return true; }
public void SetTextValues(IEnumerable <string> texts) { string name = null; string text = null; foreach (string s in texts) { // PDF | 116 pages | 53 Mb | French //Trace.CurrentTrace.WriteLine("SetTextValues : \"{0}\"", s); if (s == "\r\n") { if (text != null) { if (name != null) { infos.SetValue(name, new ZString(text)); } else { description.Add(text); } text = null; } name = null; } else { //string s2 = TelechargementPlus.TrimString(TelechargementPlus.ExtractTextValues(infos, s)); string s2 = TelechargementPlus.TrimFunc1(TelechargementPlus.ExtractTextValues(infos, s)); if (infos.ContainsKey("language")) { language = (string)infos["language"]; infos.Remove("language"); } else if (infos.ContainsKey("size")) { size = (string)infos["size"]; infos.Remove("size"); } else if (infos.ContainsKey("page_nb")) { nbPages = int.Parse((string)infos["page_nb"]); infos.Remove("page_nb"); } //Trace.WriteLine("text \"{0}\" => \"{1}\"", s, s2); bool foundName = false; if (s2.EndsWith(":")) { string s3 = s2.Substring(0, s2.Length - 1).Trim(); if (s3 != "") { name = s3; foundName = true; } } //else if (s2 != "" && s2 != title) if (!foundName && s2 != "" && s2 != title) { if (text == null) { text = s2; } else { text += " " + s2; } } } } if (text != null) { if (name != null) { infos.SetValue(name, new ZString(text)); } else { description.Add(text); } } }
// type_code : quo, arg, arh, dos, mde, edu, aut, peh, liv, mag, mdv, sch, scq, sph, sty, nyt, tel // type_quo : // fix_type_quo : // types_quo_sup : argent, culture, dossier, éco, eco, édu, edu, festival, géo, geo, livres, mag, mode, science, sport, style, nyt, tv, document, élection, election, hebdo, sup // type_sup : argent, culture, dossier, éco, eco, édu, edu, festival, géo, geo, livres, mag, mode, science, sport, style, nyt, tv, document, élection, election, hebdo, sup // type_sups : argent, culture, dossier, éco, eco, édu, edu, festival, géo, geo, livres, mag, mode, science, sport, style, nyt, tv, document, élection, election, hebdo, sup // fix_type_eco : // fix_type_tv : public static bool TryGetType(NamedValues<ZValue> values, out LeMondeType type) { type = LeMondeType.Unknow; if (values.ContainsKey("type_code")) { type = GetTypeCode((string)values["type_code"]); if (type == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", values["type_code"]); return false; } } else if ((values.ContainsKey("type_quo") && values["type_quo"] != null) || values.ContainsKey("fix_type_quo")) { type = LeMondeType.Quotidien; if (values.ContainsKey("types_quo_sup")) { ZValue v = values["types_quo_sup"]; if (v != null && !(v is ZStringArray)) { values.SetError("error creating LeMonde value types_quo_sup should be a string array : {0}", v); return false; } foreach (string s in (string[])v) { LeMondeType type2 = GetTypeSup(s); if (type2 == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", s); return false; } type |= type2; } } } else if (values.ContainsKey("type_sup")) { ZValue v = values["type_sup"]; if (!(v is ZString)) { values.SetError("error creating LeMonde value type_sup should be a string : {0}", v); return false; } type = GetTypeSup((string)v); if (type == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", v); return false; } } else if (values.ContainsKey("type_sups")) { ZValue v = values["type_sups"]; if (v != null) { if (v is ZString) { LeMondeType type2 = GetTypeSup((string)v); if (type2 == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", (string)v); return false; } type = type2; } else if (v is ZStringArray) { type = LeMondeType.Unknow; foreach (string s in (string[])v) { LeMondeType type2 = GetTypeSup(s); if (type2 == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", s); //return false; } else type |= type2; } } else { values.SetError("error creating LeMonde value type_sups should be a string or string array : {0}", v); return false; } } } else if (values.ContainsKey("fix_type_eco")) type = LeMondeType.Economie; else if (values.ContainsKey("fix_type_tv")) type = LeMondeType.TV; return true; }
public static bool GetTestValue(NamedValues<ZValue> parameters) { if (parameters.ContainsKey("test")) return (bool)parameters["test"]; return false; }
// type_dossier : name public override bool TrySetValues(NamedValues<ZValue> values) { if (!base.TrySetValues(values)) return false; LeMondeType type; if (!TryGetType(values, out type)) return false; if (type != LeMondeType.Unknow) _type = type; if (values.ContainsKey("type_dossier")) { ZValue v = values["type_dossier"]; if (v != null && v is ZString) { _dossier = (string)v; } } _typeCode = null; return true; }
protected virtual bool TryGetPrintNumber(NamedValues<ZValue> values, out int number) { number = 0; if (!values.ContainsKey("number")) { SetError("error print number not found"); return false; } int number2; if (!int.TryParse((string)values["number"], out number2)) { SetError("error invalid print number \"{0}\"", values["number"]); return false; } if (_print.Frequency != PrintFrequency.Daily && !_special) { //Date date = _print.GetPrintDate(number2); Date date; DateType dateType; _print.GetPrintDate(number2, out date, out dateType); string error; if (!ControlDate(date, out error)) { return false; } } number = number2; return true; }
public static DateValues GetDateValues(NamedValues<ZValue> values) { DateValues dateValues = new DateValues(); ZValue v; if (values.ContainsKey("day_near_current_date")) { v = values["day_near_current_date"]; //if (v is ZStringArray) // v = ((ZStringArray)v).SelectArrayValue(); if (v is ZString) { string s = (string)v; s = s.Replace('o', '0'); s = s.Replace('O', '0'); int day; if (int.TryParse(s, out day)) dateValues.dayNearCurrentDate = day; else { //values.SetError("error creating Date day_near_current_date is'nt a number : \"{0}\"", v); Trace.WriteLine("error creating Date day_near_current_date is'nt a number : \"{0}\"", v); //return false; } } else if (v is ZInt) //day = (int)v; dateValues.dayNearCurrentDate = (int)v; else { //values.SetError("error creating Date day_near_current_date should be a string number or an int : {0}", v); Trace.WriteLine("error creating Date day_near_current_date should be a string number or an int : {0}", v); //return false; } } //string name = null; //if (values.ContainsKey("year")) // name = "year"; //else if (values.ContainsKey("year1")) // name = "year1"; //else if (values.ContainsKey("year2")) // name = "year2"; v = null; if (values.ContainsKey("year1")) { v = values["year1"]; if (v is ZString && string.IsNullOrEmpty((string)v)) v = null; } if (v == null && values.ContainsKey("year2")) { v = values["year2"]; if (v is ZString && string.IsNullOrEmpty((string)v)) v = null; } if (v == null && values.ContainsKey("year")) { v = values["year"]; if (v is ZString && string.IsNullOrEmpty((string)v)) v = null; } if (v != null) { //if (v is ZStringArray) // v = ((ZStringArray)v).SelectArrayValue(); if (v is ZString) { int year; if (int.TryParse((string)v, out year)) dateValues.year = year; else { //values.SetError("error creating Date year is'nt a number : \"{0}\"", v); Trace.WriteLine("error creating Date year is'nt a number : \"{0}\"", v); //return false; } } else if (v is ZInt) dateValues.year = (int)v; else if (v != null) { //values.SetError("error creating Date year should be a string number or an int : {0}", v); Trace.WriteLine("error creating Date year should be a string number or an int : {0}", v); //return false; } } v = null; if (values.ContainsKey("month1")) { v = values["month1"]; if (v is ZString && string.IsNullOrEmpty((string)v)) v = null; } if (v == null && values.ContainsKey("month2")) { v = values["month2"]; if (v is ZString && string.IsNullOrEmpty((string)v)) v = null; } if (v == null && values.ContainsKey("month")) { v = values["month"]; if (v is ZString && string.IsNullOrEmpty((string)v)) v = null; } if (v != null) { //if (v is ZStringArray) // v = ((ZStringArray)v).SelectArrayValue(); if (v is ZString) { int month; if (int.TryParse((string)v, out month)) dateValues.month = month; else { month = zdate.GetMonthNumber((string)v); if (month != 0) dateValues.month = month; else { //values.SetError("error creating Date invalid month : \"{0}\"", v); Trace.WriteLine("error creating Date invalid month : \"{0}\"", v); //return false; } } } else if (v is ZInt) dateValues.month = (int)v; else if (v != null) { //values.SetError("error creating Date month should be a string number or an int : {0}", v); Trace.WriteLine("error creating Date month should be a string number or an int : {0}", v); //return false; } } if (values.ContainsKey("day")) { v = values["day"]; //if (v is ZStringArray) // v = ((ZStringArray)v).SelectArrayValue(); if (v is ZString) { int day; //if ((string)v == "1er") if (string.Equals((string)v, "1er", StringComparison.InvariantCultureIgnoreCase)) dateValues.day = 1; else if (int.TryParse((string)v, out day)) dateValues.day = day; else { //values.SetError("error creating Date day is'nt a number : \"{0}\"", v); Trace.WriteLine("error creating Date day is'nt a number : \"{0}\"", v); //return false; } } else if (v is ZInt) { dateValues.day = (int)v; } else if (v != null) { //values.SetError("error creating Date day should be a string number or an int : {0}", v); //Trace.WriteLine("error creating Date day should be a string number or an int : value {0} type {1}", v != null ? v : "(null)", v != null ? v.GetType().zName() : "(null)"); Trace.WriteLine("error creating Date day should be a string number or an int : value {0} type {1}", v, v.GetType().zGetTypeName()); //return false; } } return dateValues; }
public static DateValues GetDateValues(NamedValues <ZValue> values) { DateValues dateValues = new DateValues(); ZValue v; if (values.ContainsKey("day_near_current_date")) { v = values["day_near_current_date"]; //if (v is ZStringArray) // v = ((ZStringArray)v).SelectArrayValue(); if (v is ZString) { string s = (string)v; s = s.Replace('o', '0'); s = s.Replace('O', '0'); int day; if (int.TryParse(s, out day)) { dateValues.dayNearCurrentDate = day; } else { //values.SetError("error creating Date day_near_current_date is'nt a number : \"{0}\"", v); Trace.WriteLine("error creating Date day_near_current_date is'nt a number : \"{0}\"", v); //return false; } } else if (v is ZInt) { //day = (int)v; dateValues.dayNearCurrentDate = (int)v; } else { //values.SetError("error creating Date day_near_current_date should be a string number or an int : {0}", v); Trace.WriteLine("error creating Date day_near_current_date should be a string number or an int : {0}", v); //return false; } } //string name = null; //if (values.ContainsKey("year")) // name = "year"; //else if (values.ContainsKey("year1")) // name = "year1"; //else if (values.ContainsKey("year2")) // name = "year2"; v = null; if (values.ContainsKey("year1")) { v = values["year1"]; if (v is ZString && string.IsNullOrEmpty((string)v)) { v = null; } } if (v == null && values.ContainsKey("year2")) { v = values["year2"]; if (v is ZString && string.IsNullOrEmpty((string)v)) { v = null; } } if (v == null && values.ContainsKey("year")) { v = values["year"]; if (v is ZString && string.IsNullOrEmpty((string)v)) { v = null; } } if (v != null) { //if (v is ZStringArray) // v = ((ZStringArray)v).SelectArrayValue(); if (v is ZString) { int year; if (int.TryParse((string)v, out year)) { dateValues.year = year; } else { //values.SetError("error creating Date year is'nt a number : \"{0}\"", v); Trace.WriteLine("error creating Date year is'nt a number : \"{0}\"", v); //return false; } } else if (v is ZInt) { dateValues.year = (int)v; } else if (v != null) { //values.SetError("error creating Date year should be a string number or an int : {0}", v); Trace.WriteLine("error creating Date year should be a string number or an int : {0}", v); //return false; } } v = null; if (values.ContainsKey("month1")) { v = values["month1"]; if (v is ZString && string.IsNullOrEmpty((string)v)) { v = null; } } if (v == null && values.ContainsKey("month2")) { v = values["month2"]; if (v is ZString && string.IsNullOrEmpty((string)v)) { v = null; } } if (v == null && values.ContainsKey("month")) { v = values["month"]; if (v is ZString && string.IsNullOrEmpty((string)v)) { v = null; } } if (v != null) { //if (v is ZStringArray) // v = ((ZStringArray)v).SelectArrayValue(); if (v is ZString) { int month; if (int.TryParse((string)v, out month)) { dateValues.month = month; } else { month = zdate.GetMonthNumber((string)v); if (month != 0) { dateValues.month = month; } else { //values.SetError("error creating Date invalid month : \"{0}\"", v); Trace.WriteLine("error creating Date invalid month : \"{0}\"", v); //return false; } } } else if (v is ZInt) { dateValues.month = (int)v; } else if (v != null) { //values.SetError("error creating Date month should be a string number or an int : {0}", v); Trace.WriteLine("error creating Date month should be a string number or an int : {0}", v); //return false; } } if (values.ContainsKey("day")) { v = values["day"]; //if (v is ZStringArray) // v = ((ZStringArray)v).SelectArrayValue(); if (v is ZString) { int day; //if ((string)v == "1er") if (string.Equals((string)v, "1er", StringComparison.InvariantCultureIgnoreCase)) { dateValues.day = 1; } else if (int.TryParse((string)v, out day)) { dateValues.day = day; } else { //values.SetError("error creating Date day is'nt a number : \"{0}\"", v); Trace.WriteLine("error creating Date day is'nt a number : \"{0}\"", v); //return false; } } else if (v is ZInt) { dateValues.day = (int)v; } else if (v != null) { //values.SetError("error creating Date day should be a string number or an int : {0}", v); //Trace.WriteLine("error creating Date day should be a string number or an int : value {0} type {1}", v != null ? v : "(null)", v != null ? v.GetType().zName() : "(null)"); Trace.WriteLine("error creating Date day should be a string number or an int : value {0} type {1}", v, v.GetType().zGetTypeName()); //return false; } } return(dateValues); }
//NamedValues1 protected virtual bool TryGetIndex(NamedValues<ZValue> values, out int index) { index = 0; if (!values.ContainsKey("index")) { //throw new PBException("error index not found"); values.SetError("error index not found"); return false; } string s = (string)values["index"]; if (s == null) //return 0; return true; int index2; if (!int.TryParse(s, out index2)) { //throw new PBException("error invalid index \"{0}\"", s); values.SetError("error invalid index \"{0}\"", s); return false; } //return index; index = index2; return true; }
// type_code : quo, arg, arh, dos, mde, edu, aut, peh, liv, mag, mdv, sch, scq, sph, sty, nyt, tel // type_quo : // fix_type_quo : // types_quo_sup : argent, culture, dossier, éco, eco, édu, edu, festival, géo, geo, livres, mag, mode, science, sport, style, nyt, tv, document, élection, election, hebdo, sup // type_sup : argent, culture, dossier, éco, eco, édu, edu, festival, géo, geo, livres, mag, mode, science, sport, style, nyt, tv, document, élection, election, hebdo, sup // type_sups : argent, culture, dossier, éco, eco, édu, edu, festival, géo, geo, livres, mag, mode, science, sport, style, nyt, tv, document, élection, election, hebdo, sup // fix_type_eco : // fix_type_tv : public static bool TryGetType(NamedValues <ZValue> values, out LeMondeType type) { type = LeMondeType.Unknow; if (values.ContainsKey("type_code")) { type = GetTypeCode((string)values["type_code"]); if (type == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", values["type_code"]); return(false); } } else if ((values.ContainsKey("type_quo") && values["type_quo"] != null) || values.ContainsKey("fix_type_quo")) { type = LeMondeType.Quotidien; if (values.ContainsKey("types_quo_sup")) { ZValue v = values["types_quo_sup"]; if (v != null && !(v is ZStringArray)) { values.SetError("error creating LeMonde value types_quo_sup should be a string array : {0}", v); return(false); } foreach (string s in (string[])v) { LeMondeType type2 = GetTypeSup(s); if (type2 == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", s); return(false); } type |= type2; } } } else if (values.ContainsKey("type_sup")) { ZValue v = values["type_sup"]; if (!(v is ZString)) { values.SetError("error creating LeMonde value type_sup should be a string : {0}", v); return(false); } type = GetTypeSup((string)v); if (type == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", v); return(false); } } else if (values.ContainsKey("type_sups")) { ZValue v = values["type_sups"]; if (v != null) { if (v is ZString) { LeMondeType type2 = GetTypeSup((string)v); if (type2 == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", (string)v); return(false); } type = type2; } else if (v is ZStringArray) { type = LeMondeType.Unknow; foreach (string s in (string[])v) { LeMondeType type2 = GetTypeSup(s); if (type2 == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", s); //return false; } else { type |= type2; } } } else { values.SetError("error creating LeMonde value type_sups should be a string or string array : {0}", v); return(false); } } } else if (values.ContainsKey("fix_type_eco")) { type = LeMondeType.Economie; } else if (values.ContainsKey("fix_type_tv")) { type = LeMondeType.TV; } return(true); }
//NamedValues1 public static bool TryGetType(NamedValues <ZValue> values, out LeMondeType type) { type = LeMondeType.Unknow; if (values.ContainsKey("type_code")) { type = GetTypeCode((string)values["type_code"]); if (type == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", (string)values["type_code"]); return(false); } } else if ((values.ContainsKey("type_quo") && values["type_quo"] != null) || values.ContainsKey("fix_type_quo")) //else if (values.ContainsKey("type_quo")) { type = LeMondeType.Quotidien; if (values.ContainsKey("types_quo_sup")) { object o = values["types_quo_sup"]; if (o != null && !(o is string[])) { //throw new PBException("error creating LeMonde value types_quo_sup should be a string array : {0}", o); values.SetError("error creating LeMonde value types_quo_sup should be a string array : {0}", o); return(false); } foreach (string s in (string[])o) { //type |= GetTypeSup(s); LeMondeType type2 = GetTypeSup(s); if (type2 == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", s); return(false); } type |= type2; } } } else if (values.ContainsKey("type_sup")) { //if (!values.ContainsKey("type_sup")) // throw new PBException("error creating LeMonde unknow type_sup"); object o = values["type_sup"]; if (!(o is string)) { //throw new PBException("error creating LeMonde value type_sup should be a string : {0}", o); values.SetError("error creating LeMonde value type_sup should be a string : {0}", o); return(false); } type = GetTypeSup((string)o); if (type == LeMondeType.Unknow) { values.SetError("error unknow le monde type sup : \"{0}\"", o); return(false); } } else if (values.ContainsKey("fix_type_eco")) { type = LeMondeType.Economie; } else if (values.ContainsKey("fix_type_tv")) { type = LeMondeType.TV; } else { //throw new PBException("error creating LeMonde unknow type"); values.SetError("error creating LeMonde unknow type"); return(false); } //return type; return(true); }
//NamedValues1 public virtual bool TrySetValues(NamedValues<ZValue> values) { //_special //NewIssue(); //if (values.ContainsKey("special_month")) //{ // _special_month = true; // _date = date.CreateDate(values); // _printNumber = GetPrintNumber(values); //} //else //{ // if (values.ContainsKey("day_near_current_date") || values.ContainsKey("year") || values.ContainsKey("month") || values.ContainsKey("day")) // _date = date.CreateDate(values); // if (values.ContainsKey("number")) // { // _printNumber = GetPrintNumber(values); // } //} //_printValues = values; if (values.ContainsKey("special")) _special = true; if (values.ContainsKey("special_month")) _specialMonth = true; //bool setDate = false; //if (values.ContainsKey("day_near_current_date") || values.ContainsKey("year") || values.ContainsKey("month") || values.ContainsKey("day")) if (values.ContainsKey("day_near_current_date") || values.ContainsKey("month")) { //_date = date.CreateDate(values); //setDate = true; Date date; DateType dateType; if (!zdate.TryCreateDate(values, out date, out dateType)) return false; _date = date; } if (values.ContainsKey("number")) { //if (!setDate || _noDateAndNumberCalculate) //_printNumber = GetPrintNumber(values); if (!TryGetPrintNumber(values, out _printNumber)) return false; } if (_date != null && _printNumber != 0 && !_noDateAndNumberCalculate && !_special && !_specialMonth) { if (_frequency == PrintFrequency.Daily) _printNumber = 0; else _date = null; } if (values.ContainsKey("label")) _label = (string)values["label"]; if (values.ContainsKey("index")) { //_index = GetIndex(values); if (!TryGetIndex(values, out _index)) return false; } _printValues.SetValues(values); return true; }
public virtual bool TrySetValues(NamedValues<ZValue> values) { //_error = null; //_printValues.SetValues(values); bool special = _special; if (values.ContainsKey("special")) { special = true; _printValues.SetValues(values, "special"); } bool specialMonth = _specialMonth; if (values.ContainsKey("special_month")) { specialMonth = true; _printValues.SetValues(values, "special_month"); } Date? date = _date; DateType dateType = _dateType; if (values.ContainsKey("day_near_current_date") || values.ContainsKey("month")) { Date date2; DateType dateType2; if (!zdate.TryCreateDate(values, out date2, out dateType2)) { //if (values.Error != null) // _error = values.Error; return false; } string error; if (!ControlDate(date2, out error)) return false; date = date2; dateType = dateType2; _printValues.SetValues(values, "day_near_current_date", "day", "month", "year"); } int printNumber = _printNumber; if (values.ContainsKey("number")) { if (!TryGetPrintNumber(values, out printNumber)) return false; _printValues.SetValues(values, "number"); } if (date != null && printNumber != 0 && !_print.NoDateAndNumberCalculate && !special && !specialMonth) { if (_print.Frequency == PrintFrequency.Daily) printNumber = 0; else { date = null; dateType = pb.DateType.Unknow; } } string label = _label; if (values.ContainsKey("label")) { label = (string)values["label"]; _printValues.SetValues(values, "label"); } int index = _index; if (values.ContainsKey("index")) { if (!TryGetIndex(values, out index)) return false; _printValues.SetValues(values, "index"); } _error = null; _special = special; _specialMonth = specialMonth; _date = date; _dateType = dateType; _printNumber = printNumber; _label = label; _index = index; return true; }
//NamedValues1 protected virtual bool TryGetPrintNumber(NamedValues<ZValue> values, out int number) { number = 0; if (!values.ContainsKey("number")) { //throw new PBException("error print number not found"); values.SetError("error print number not found"); return false; } int number2; if (!int.TryParse((string)values["number"], out number2)) { //throw new PBException("error invalid print number \"{0}\"", values["number"]); values.SetError("error invalid print number \"{0}\"", values["number"]); return false; } //return printNumber; number = number2; return true; }
//NamedValues1 public virtual bool TrySetValues(NamedValues <ZValue> values) { //_special //NewIssue(); //if (values.ContainsKey("special_month")) //{ // _special_month = true; // _date = date.CreateDate(values); // _printNumber = GetPrintNumber(values); //} //else //{ // if (values.ContainsKey("day_near_current_date") || values.ContainsKey("year") || values.ContainsKey("month") || values.ContainsKey("day")) // _date = date.CreateDate(values); // if (values.ContainsKey("number")) // { // _printNumber = GetPrintNumber(values); // } //} //_printValues = values; if (values.ContainsKey("special")) { _special = true; } if (values.ContainsKey("special_month")) { _specialMonth = true; } //bool setDate = false; //if (values.ContainsKey("day_near_current_date") || values.ContainsKey("year") || values.ContainsKey("month") || values.ContainsKey("day")) if (values.ContainsKey("day_near_current_date") || values.ContainsKey("month")) { //_date = date.CreateDate(values); //setDate = true; Date date; DateType dateType; if (!zdate.TryCreateDate(values, out date, out dateType)) { return(false); } _date = date; } if (values.ContainsKey("number")) { //if (!setDate || _noDateAndNumberCalculate) //_printNumber = GetPrintNumber(values); if (!TryGetPrintNumber(values, out _printNumber)) { return(false); } } if (_date != null && _printNumber != 0 && !_noDateAndNumberCalculate && !_special && !_specialMonth) { if (_frequency == PrintFrequency.Daily) { _printNumber = 0; } else { _date = null; } } if (values.ContainsKey("label")) { _label = (string)values["label"]; } if (values.ContainsKey("index")) { //_index = GetIndex(values); if (!TryGetIndex(values, out _index)) { return(false); } } _printValues.SetValues(values); return(true); }