public Print(XElement xe, string baseDirectory = null, Dictionary <string, RegexValuesModel> regexModels = null) { _name = xe.zXPathValue("Name"); _title = xe.zXPathValue("Title"); _frequency = GetFrequency(xe.zXPathValue("Frequency")); _directory = xe.zXPathValue("Directory").zRootPath(baseDirectory); //if (!Path.IsPathRooted(_directory) && baseDirectory != null) // _directory = Path.Combine(baseDirectory, _directory); SetOption(xe.zXPathValue("Option")); if (!_noDateAndNumberCalculate) { //string dateRef = xe.zXPathValue("DateReference"); //string numberRef = xe.zXPathValue("NumberReference"); //if (dateRef == null && numberRef != null) // throw new PBException("error missing reference number \"{0}\"", _name); //if (dateRef != null && numberRef == null) // throw new PBException("error missing reference date \"{0}\"", _name); //if (dateRef == null) // _noDateAndNumberCalculate = true; //else //{ // _refPrintDate = Date.Parse(dateRef); // _refPrintNumber = int.Parse(numberRef); // GetNoPrintDates(xe.zXPathValues("NoPrintDate")); // GetNoPrintNumbers(xe.zXPathValues("NoPrintNumber")); //} _dateNumberReferences = new PrintDateNumberReferences(xe.Elements("DateNumberReference")); if (_dateNumberReferences.Count == 0) { _noDateAndNumberCalculate = true; } else { GetNoPrintDates(xe.zXPathValues("NoPrintDate").ToArray()); GetNoPrintNumbers(xe.zXPathValues("NoPrintNumber").ToArray()); } } if (_frequency == PrintFrequency.Weekly || _frequency == PrintFrequency.EveryTwoWeek) { _weekday = zdate.GetDayOfWeek(xe.zXPathValue("Weekday")); } if (regexModels != null) { string model; if (_frequency == PrintFrequency.Daily || _frequency == PrintFrequency.Weekly || _frequency == PrintFrequency.EveryTwoWeek) { if (!_noNumber) { model = "name_day_number"; } else { model = "name_day"; } } else { model = "name_month_number"; } RegexValuesModel rvm = regexModels[model]; Dictionary <string, string> textValues = new Dictionary <string, string>(); textValues.Add("v_title", _title); XElement xe2 = xe.zXPathElement("NormalizedFilename"); if (xe2 != null) { //(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa).zAttribs(textValues); textValues.zAdd(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa); } string pattern = rvm.pattern.zSetTextVariables(textValues, true); string values = rvm.values.zSetTextVariables(textValues, true); _normalizedFilename = new RegexValues(rvm.key, rvm.name, pattern, rvm.options, values); if (_specialNoDate) { model = "special_name_number"; } else { model = "special_name_month_number"; } rvm = regexModels[model]; textValues = new Dictionary <string, string>(); textValues.Add("v_title", _title); xe2 = xe.zXPathElement("NormalizedSpecialFilename"); if (xe2 != null) { //(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa).zAttribs(textValues); textValues.zAdd(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa); } pattern = rvm.pattern.zSetTextVariables(textValues, true); values = rvm.values.zSetTextVariables(textValues, true); _normalizedSpecialFilename = new RegexValues(rvm.key, rvm.name, pattern, rvm.options, values); } }
public Print(XElement xe, string baseDirectory = null, Dictionary<string, RegexValuesModel> regexModels = null) { _name = xe.zXPathValue("Name"); _title = xe.zXPathValue("Title"); _frequency = GetFrequency(xe.zXPathValue("Frequency")); _directory = xe.zXPathValue("Directory").zRootPath(baseDirectory); //if (!Path.IsPathRooted(_directory) && baseDirectory != null) // _directory = Path.Combine(baseDirectory, _directory); SetOption(xe.zXPathValue("Option")); if (!_noDateAndNumberCalculate) { //string dateRef = xe.zXPathValue("DateReference"); //string numberRef = xe.zXPathValue("NumberReference"); //if (dateRef == null && numberRef != null) // throw new PBException("error missing reference number \"{0}\"", _name); //if (dateRef != null && numberRef == null) // throw new PBException("error missing reference date \"{0}\"", _name); //if (dateRef == null) // _noDateAndNumberCalculate = true; //else //{ // _refPrintDate = Date.Parse(dateRef); // _refPrintNumber = int.Parse(numberRef); // GetNoPrintDates(xe.zXPathValues("NoPrintDate")); // GetNoPrintNumbers(xe.zXPathValues("NoPrintNumber")); //} _dateNumberReferences = new PrintDateNumberReferences(xe.Elements("DateNumberReference")); if (_dateNumberReferences.Count == 0) _noDateAndNumberCalculate = true; else { GetNoPrintDates(xe.zXPathValues("NoPrintDate").ToArray()); GetNoPrintNumbers(xe.zXPathValues("NoPrintNumber").ToArray()); } } if (_frequency == PrintFrequency.Weekly || _frequency == PrintFrequency.EveryTwoWeek) _weekday = zdate.GetDayOfWeek(xe.zXPathValue("Weekday")); if (regexModels != null) { string model; if (_frequency == PrintFrequency.Daily || _frequency == PrintFrequency.Weekly || _frequency == PrintFrequency.EveryTwoWeek) { if (!_noNumber) model = "name_day_number"; else model = "name_day"; } else model = "name_month_number"; RegexValuesModel rvm = regexModels[model]; Dictionary<string, string> textValues = new Dictionary<string, string>(); textValues.Add("v_title", _title); XElement xe2 = xe.zXPathElement("NormalizedFilename"); if (xe2 != null) //(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa).zAttribs(textValues); textValues.zAdd(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa); string pattern = rvm.pattern.zSetTextVariables(textValues, true); string values = rvm.values.zSetTextVariables(textValues, true); _normalizedFilename = new RegexValues(rvm.key, rvm.name, pattern, rvm.options, values); if (_specialNoDate) model = "special_name_number"; else model = "special_name_month_number"; rvm = regexModels[model]; textValues = new Dictionary<string, string>(); textValues.Add("v_title", _title); xe2 = xe.zXPathElement("NormalizedSpecialFilename"); if (xe2 != null) //(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa).zAttribs(textValues); textValues.zAdd(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa); pattern = rvm.pattern.zSetTextVariables(textValues, true); values = rvm.values.zSetTextVariables(textValues, true); _normalizedSpecialFilename = new RegexValues(rvm.key, rvm.name, pattern, rvm.options, values); } }
private void init(XElement xelement) { _directory = xelement.zXPathValue("Directory"); Dictionary<string, RegexValuesModel> regexModels = new Dictionary<string, RegexValuesModel>(); // zElements("FilenamesModel/FilenameModel") foreach (XElement xe in xelement.zXPathElements("FilenamesModel/FilenameModel")) { RegexValuesModel rvm = new RegexValuesModel(xe); regexModels.Add(rvm.key, rvm); } _regexModels = new Dictionary<string, RegexValuesModel>(); // zElements("FilenameModels/FilenameModel") foreach (XElement xe in xelement.zXPathElements("FilenameModels/FilenameModel")) { RegexValuesModel rvm = new RegexValuesModel(xe); _regexModels.Add(rvm.key, rvm); } // zElements("FilenameDates/FilenameDate") _dateRegexList = new RegexValuesList(xelement.zXPathElements("FilenameDates/FilenameDate")); //if (_trace) // Trace.CurrentTrace.WriteLine("_dateRegexList {0}", _dateRegexList.Count); _printRegexList = new RegexValuesList(); _printRegexList2 = new RegexValuesList(); _prints = new Dictionary<string, Print1>(); // zElements("Prints/Print") foreach (XElement xe in xelement.zXPathElements("Prints/Print")) { Print1 print = null; switch (xe.zXPathValue("Class")) { case "LeMonde": print = new LeMonde(xe, _directory, _regexModels); break; case "LeParisien": print = new LeParisien(xe, _directory, _regexModels); break; case "LeVifExpress": print = new LeVifExpress(xe, _directory, _regexModels); break; default: print = new Print1(xe, _directory, _regexModels); break; } string name = print.Name; _prints.Add(name, print); int n = 1; // zElements("Filenames/Filename") foreach (XElement xe2 in xe.zXPathElements("Filenames/Filename")) { string key = name + n++.ToString(); //string name = xe2.zExplicitAttributeValue("name"); //string model = xe2.zExplicitAttributeValue("model"); string model = xe2.zAttribValue("model"); if (model != null) { if (!regexModels.ContainsKey(model)) throw new PBException("unknow filename model \"{0}\"", model); RegexValuesModel rvm = regexModels[model]; //Dictionary<string, string> attribs = (from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa).zAttribs(); Dictionary<string, string> attribs = new Dictionary<string, string>(); attribs.zAdd(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa); string pattern = rvm.pattern.zSetTextVariables(attribs, true); //Trace.CurrentTrace.WriteLine("\"{0}\" - \"{1}\"", rvm.pattern, pattern); //string values = xe2.zAttribValue("values"); //if (values != null) //{ // if (rvm.values != null && rvm.values != "") // values = rvm.values + ", " + values; //} //else // values = rvm.values; string values = rvm.values; if (values != null) values = values.zSetTextVariables(attribs, true); _printRegexList.Add(key, new RegexValues(key, name, pattern, rvm.options, values)); } else { string regex = xe2.zExplicitAttribValue("regex"); string values = xe2.zExplicitAttribValue("values"); string options = xe2.zAttribValue("options"); _printRegexList.Add(key, new RegexValues(key, name, regex, options, values)); } } n = 1; // zElements("Filenames2/Filename") foreach (XElement xe2 in xe.zXPathElements("Filenames2/Filename")) { string key = name + n++.ToString(); string regex = xe2.zExplicitAttribValue("regex"); string values = xe2.zAttribValue("values"); string options = xe2.zAttribValue("options"); _printRegexList2.Add(key, new RegexValues(key, name, regex, options, values)); } } }
private void init(XElement xelement) { _directory = xelement.zXPathValue("Directory"); Dictionary <string, RegexValuesModel> regexModels = new Dictionary <string, RegexValuesModel>(); // zElements("FilenamesModel/FilenameModel") foreach (XElement xe in xelement.zXPathElements("FilenamesModel/FilenameModel")) { RegexValuesModel rvm = new RegexValuesModel(xe); regexModels.Add(rvm.key, rvm); } _regexModels = new Dictionary <string, RegexValuesModel>(); // zElements("FilenameModels/FilenameModel") foreach (XElement xe in xelement.zXPathElements("FilenameModels/FilenameModel")) { RegexValuesModel rvm = new RegexValuesModel(xe); _regexModels.Add(rvm.key, rvm); } // zElements("FilenameDates/FilenameDate") _dateRegexList = new RegexValuesList(xelement.zXPathElements("FilenameDates/FilenameDate")); //if (_trace) // Trace.CurrentTrace.WriteLine("_dateRegexList {0}", _dateRegexList.Count); _printRegexList = new RegexValuesList(); _printRegexList2 = new RegexValuesList(); _prints = new Dictionary <string, Print1>(); // zElements("Prints/Print") foreach (XElement xe in xelement.zXPathElements("Prints/Print")) { Print1 print = null; switch (xe.zXPathValue("Class")) { case "LeMonde": print = new LeMonde(xe, _directory, _regexModels); break; case "LeParisien": print = new LeParisien(xe, _directory, _regexModels); break; case "LeVifExpress": print = new LeVifExpress(xe, _directory, _regexModels); break; default: print = new Print1(xe, _directory, _regexModels); break; } string name = print.Name; _prints.Add(name, print); int n = 1; // zElements("Filenames/Filename") foreach (XElement xe2 in xe.zXPathElements("Filenames/Filename")) { string key = name + n++.ToString(); //string name = xe2.zExplicitAttributeValue("name"); //string model = xe2.zExplicitAttributeValue("model"); string model = xe2.zAttribValue("model"); if (model != null) { if (!regexModels.ContainsKey(model)) { throw new PBException("unknow filename model \"{0}\"", model); } RegexValuesModel rvm = regexModels[model]; //Dictionary<string, string> attribs = (from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa).zAttribs(); Dictionary <string, string> attribs = new Dictionary <string, string>(); attribs.zAdd(from xa in xe2.Attributes() where xa.Name.ToString().StartsWith("v_") select xa); string pattern = rvm.pattern.zSetTextVariables(attribs, true); //Trace.CurrentTrace.WriteLine("\"{0}\" - \"{1}\"", rvm.pattern, pattern); //string values = xe2.zAttribValue("values"); //if (values != null) //{ // if (rvm.values != null && rvm.values != "") // values = rvm.values + ", " + values; //} //else // values = rvm.values; string values = rvm.values; if (values != null) { values = values.zSetTextVariables(attribs, true); } _printRegexList.Add(key, new RegexValues(key, name, pattern, rvm.options, values)); } else { string regex = xe2.zExplicitAttribValue("regex"); string values = xe2.zExplicitAttribValue("values"); string options = xe2.zAttribValue("options"); _printRegexList.Add(key, new RegexValues(key, name, regex, options, values)); } } n = 1; // zElements("Filenames2/Filename") foreach (XElement xe2 in xe.zXPathElements("Filenames2/Filename")) { string key = name + n++.ToString(); string regex = xe2.zExplicitAttribValue("regex"); string values = xe2.zAttribValue("values"); string options = xe2.zAttribValue("options"); _printRegexList2.Add(key, new RegexValues(key, name, regex, options, values)); } } }