Ejemplo n.º 1
0
        private List <RegexValues> GetRegex(XmlDocument xmldocument, string xpath)
        {
            string expression = null;
            string replace    = null;

            List <RegexValues> regex = new List <RegexValues>();

            XmlNodeList nodes = xmldocument.SelectNodes(xpath);

            foreach (XmlNode node in nodes)
            {
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    if (childNode.Name == "expression")
                    {
                        expression = childNode.InnerText;
                    }
                    else if (childNode.Name == "operator")
                    {
                        replace = childNode.InnerText;
                    }
                }
                RegexValues rv = new RegexValues();
                rv.expression = expression;
                rv.replace    = replace;
                regex.Add(rv);
            }
            return(regex);
        }
Ejemplo n.º 2
0
 public bool FindNext()
 {
     _found       = false;
     _day         = null;
     _matchValues = null;
     while (_enumerator.MoveNext())
     {
         RegexValues rv          = _enumerator.Current;
         MatchValues matchValues = rv.Match(_text);
         if (matchValues.Success)
         {
             int day;
             if (zDay.TryGetDay(matchValues.GetValues(), out day))
             {
                 //return new FindDay { Found = true, Day = day, MatchValues = matchValues };
                 _found       = true;
                 _day         = day;
                 _matchValues = matchValues;
                 return(true);
             }
         }
     }
     //return new FindDay { Found = false, Day = null, MatchValues = null };
     return(false);
 }
Ejemplo n.º 3
0
        //public PrintIssue Match(RegexValues rv, string filename)
        public GClass2 <PrintIssue, MatchValues> Match(RegexValues rv, string filename)
        {
            //PrintIssue issue = null;
            //Match match = rv.Match_old(filename);
            MatchValues matchValues = rv.Match(filename);

            //if (match.Success)
            if (matchValues.Success)
            {
                Print      print = GetPrint(rv.Name);
                PrintIssue issue = print.NewPrintIssue();
                //NamedValues<ZValue> values = rv.GetValues_old();
                NamedValues <ZValue> values = matchValues.GetValues();
                if (_trace)
                {
                    WriteLine("found {0}", print.Name);
                    WriteLine("pattern \"{0}\"", rv.Pattern);
                    values.zTrace();
                }
                issue.TrySetValues(values);
                return(new GClass2 <PrintIssue, MatchValues> {
                    Value1 = issue, Value2 = matchValues
                });
            }
            else
            {
                //return issue;
                return(null);
            }
        }
Ejemplo n.º 4
0
        //public Print Find2(string filename, out string error)
        //{
        //    error = null;
        //    if (_trace)
        //        Trace.CurrentTrace.WriteLine("search \"{0}\"", filename);
        //    foreach (RegexValues rv in _printRegexList2.Values)
        //    {
        //        Match match = rv.Match(filename);
        //        if (match.Success)
        //        {
        //            Print print = Get(rv.Name);
        //            print.NewIssue();
        //            NamedValues values = rv.GetValues();
        //            if (_trace)
        //            {
        //                Trace.CurrentTrace.WriteLine("found {0}", print.Name);
        //                values.zTrace();
        //            }
        //            if (!print.TrySetValues(values))
        //            {
        //                error = string.Format("find \"{0}\" error \"{1}\"", print.Name, values.Error);
        //                continue;
        //            }

        //            if (MatchRegexValues(print, print.NormalizedFilename, filename, out error))
        //                return print;
        //            if (MatchRegexValues(print, print.NormalizedSpecialFilename, filename, out error))
        //                return print;
        //            string filename2 = filename.Substring(0, match.Index) + filename.Substring(match.Index + match.Length);
        //            if (_trace)
        //                Trace.CurrentTrace.WriteLine("search date \"{0}\" (\"{1}\")", filename2, filename);
        //            foreach (RegexValues rv2 in _dateRegexList.Values)
        //            {
        //                match = rv.Match(filename2);
        //                if (match.Success)
        //                {
        //                    values = rv2.GetValues();
        //                    if (date.IsDateValid(values))
        //                    {
        //                        //print.SetValues(values);
        //                        if (!print.TrySetValues(values))
        //                        {
        //                            error = string.Format("find \"{0}\" error \"{1}\"", print.Name, values.Error);
        //                            continue;
        //                        }
        //                        return print;
        //                    }
        //                }
        //            }
        //            //return print;
        //        }
        //    }
        //    if (_trace)
        //        Trace.CurrentTrace.WriteLine("print not found \"{0}\"", filename);
        //    return null;
        //    //foreach (Print print in _prints.Values)
        //    //{
        //    //    Match match = print.MatchFilename(filename);
        //    //    //if (print.IsMatchFilename(filename))
        //    //    if (match != null && match.Success)
        //    //    {
        //    //        if (_trace)
        //    //            Trace.CurrentTrace.WriteLine("found {0}", print.Name);
        //    //        if (MatchRegexValues(print, print.NormalizedFilename, filename, out error))
        //    //            return print;
        //    //        if (MatchRegexValues(print, print.NormalizedSpecialFilename, filename, out error))
        //    //            return print;
        //    //        string filename2 = filename.Substring(0, match.Index) + filename.Substring(match.Index + match.Length);
        //    //        if (_trace)
        //    //            Trace.CurrentTrace.WriteLine("search date \"{0}\" (\"{1}\")", filename2, filename);
        //    //        //RegexValues rv = _dateRegexList.Find(filename2);
        //    //        foreach (RegexValues rv in _dateRegexList.Values)
        //    //        {
        //    //            match = rv.Match(filename2);
        //    //            if (match.Success)
        //    //            {
        //    //                Dictionary<string, object> values = rv.GetValues();
        //    //                if (date.IsValidDate(values))
        //    //                {
        //    //                    print.SetValues(values);
        //    //                    return print;
        //    //                }
        //    //            }
        //    //        }
        //    //    }
        //    //}
        //    //return null;
        //}

        private bool MatchRegexValues(Print1 print, RegexValues rv, string filename, out string error)
        {
            error = null;
            //Match match = rv.Match_old(filename);
            MatchValues matchValues = rv.Match(filename);

            //if (!match.Success)
            if (!matchValues.Success)
            {
                return(false);
            }
            //NamedValues<ZValue> values = rv.GetValues_old();
            NamedValues <ZValue> values = matchValues.GetValues();

            if (_trace)
            {
                values.zTrace();
            }

            if (!print.TrySetValues(values))
            {
                error = string.Format("find \"{0}\" error \"{1}\"", print.Name, values.Error);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 5
0
 public MainViewModel()
 {
     SettingsClicked = false;
     RegexValues.Add("\".*\"");
 }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        //public Print Find2(string filename, out string error)
        //{
        //    error = null;
        //    if (_trace)
        //        Trace.CurrentTrace.WriteLine("search \"{0}\"", filename);
        //    foreach (RegexValues rv in _printRegexList2.Values)
        //    {
        //        Match match = rv.Match(filename);
        //        if (match.Success)
        //        {
        //            Print print = Get(rv.Name);
        //            print.NewIssue();
        //            NamedValues values = rv.GetValues();
        //            if (_trace)
        //            {
        //                Trace.CurrentTrace.WriteLine("found {0}", print.Name);
        //                values.zTrace();
        //            }
        //            if (!print.TrySetValues(values))
        //            {
        //                error = string.Format("find \"{0}\" error \"{1}\"", print.Name, values.Error);
        //                continue;
        //            }

        //            if (MatchRegexValues(print, print.NormalizedFilename, filename, out error))
        //                return print;
        //            if (MatchRegexValues(print, print.NormalizedSpecialFilename, filename, out error))
        //                return print;
        //            string filename2 = filename.Substring(0, match.Index) + filename.Substring(match.Index + match.Length);
        //            if (_trace)
        //                Trace.CurrentTrace.WriteLine("search date \"{0}\" (\"{1}\")", filename2, filename);
        //            foreach (RegexValues rv2 in _dateRegexList.Values)
        //            {
        //                match = rv.Match(filename2);
        //                if (match.Success)
        //                {
        //                    values = rv2.GetValues();
        //                    if (date.IsDateValid(values))
        //                    {
        //                        //print.SetValues(values);
        //                        if (!print.TrySetValues(values))
        //                        {
        //                            error = string.Format("find \"{0}\" error \"{1}\"", print.Name, values.Error);
        //                            continue;
        //                        }
        //                        return print;
        //                    }
        //                }
        //            }
        //            //return print;
        //        }
        //    }
        //    if (_trace)
        //        Trace.CurrentTrace.WriteLine("print not found \"{0}\"", filename);
        //    return null;
        //    //foreach (Print print in _prints.Values)
        //    //{
        //    //    Match match = print.MatchFilename(filename);
        //    //    //if (print.IsMatchFilename(filename))
        //    //    if (match != null && match.Success)
        //    //    {
        //    //        if (_trace)
        //    //            Trace.CurrentTrace.WriteLine("found {0}", print.Name);
        //    //        if (MatchRegexValues(print, print.NormalizedFilename, filename, out error))
        //    //            return print;
        //    //        if (MatchRegexValues(print, print.NormalizedSpecialFilename, filename, out error))
        //    //            return print;
        //    //        string filename2 = filename.Substring(0, match.Index) + filename.Substring(match.Index + match.Length);
        //    //        if (_trace)
        //    //            Trace.CurrentTrace.WriteLine("search date \"{0}\" (\"{1}\")", filename2, filename);
        //    //        //RegexValues rv = _dateRegexList.Find(filename2);
        //    //        foreach (RegexValues rv in _dateRegexList.Values)
        //    //        {
        //    //            match = rv.Match(filename2);
        //    //            if (match.Success)
        //    //            {
        //    //                Dictionary<string, object> values = rv.GetValues();
        //    //                if (date.IsValidDate(values))
        //    //                {
        //    //                    print.SetValues(values);
        //    //                    return print;
        //    //                }
        //    //            }
        //    //        }
        //    //    }
        //    //}
        //    //return null;
        //}

        private bool MatchRegexValues(Print1 print, RegexValues rv, string filename, out string error)
        {
            error = null;
            //Match match = rv.Match_old(filename);
            MatchValues matchValues = rv.Match(filename);
            //if (!match.Success)
            if (!matchValues.Success)
                return false;
            //NamedValues<ZValue> values = rv.GetValues_old();
            NamedValues<ZValue> values = matchValues.GetValues();

            if (_trace)
                values.zTrace();

            if (!print.TrySetValues(values))
            {
                error = string.Format("find \"{0}\" error \"{1}\"", print.Name, values.Error);
                return false;
            }
            return true;
        }
Ejemplo n.º 8
0
 //public PrintIssue Match(RegexValues rv, string filename)
 public GClass2<PrintIssue, MatchValues> Match(RegexValues rv, string filename)
 {
     //PrintIssue issue = null;
     //Match match = rv.Match_old(filename);
     MatchValues matchValues = rv.Match(filename);
     //if (match.Success)
     if (matchValues.Success)
     {
         Print print = GetPrint(rv.Name);
         PrintIssue issue = print.NewPrintIssue();
         //NamedValues<ZValue> values = rv.GetValues_old();
         NamedValues<ZValue> values = matchValues.GetValues();
         if (_trace)
         {
             WriteLine("found {0}", print.Name);
             WriteLine("pattern \"{0}\"", rv.Pattern);
             values.zTrace();
         }
         issue.TrySetValues(values);
         return new GClass2<PrintIssue, MatchValues> { Value1 = issue, Value2 = matchValues };
     }
     else
         //return issue;
         return null;
 }
Ejemplo n.º 9
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);
            }
        }