Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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);
            }
        }