예제 #1
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);
            }
        }
예제 #2
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);
        }
예제 #3
0
        public static void FindDate(RegexValuesList dateRegexList, string title)
        {
            bool found = false;

            foreach (RegexValues rv in dateRegexList.Values)
            {
                //rv.Match_old(title);
                MatchValues matchValues = rv.Match(title);
                //if (rv.Success_old)
                if (matchValues.Success)
                {
                    //NamedValues<ZValue> values = rv.GetValues_old();
                    NamedValues <ZValue> values = matchValues.GetValues();
                    Date     date;
                    DateType dateType;
                    //Trace.Write(" date ");
                    //found = zdate.TryCreateDate(values, out date);
                    //if (found)
                    //    Trace.Write("{0:dd-MM-yyyy}", date);
                    //else
                    //    Trace.Write("not found ");
                    //Trace.Write("   ");
                    //values.zTrace();

                    //Trace.WriteLine("    found date  : {0}", rv.MatchValue_old);
                    Trace.WriteLine("    found date  : {0}", matchValues.Match.Value);

                    //Trace.WriteLine("    remain text : {0}", rv.MatchReplace_old("_"));
                    Trace.WriteLine("    remain text : {0}", matchValues.Replace("_"));

                    Trace.Write("    date        : ");
                    found = zdate.TryCreateDate(values, out date, out dateType);
                    if (found)
                    {
                        Trace.Write("{0:dd-MM-yyyy} type {1}", date, dateType);
                    }
                    else
                    {
                        Trace.Write("not found ");
                    }
                    Trace.WriteLine();

                    Trace.Write("    values      : ");
                    values.zTrace();
                    Trace.WriteLine();

                    if (found)
                    {
                        break;
                    }
                }
            }
            if (!found)
            {
                Trace.WriteLine("    date not found ");
            }
        }
예제 #4
0
        public Print1 Find(string filename, out string error)
        {
            error = null;
            if (_trace)
            {
                Trace.CurrentTrace.WriteLine("search \"{0}\"", filename);
            }
            foreach (RegexValues rv in _printRegexList.Values)
            {
                //Match match = rv.Match_old(filename);
                MatchValues matchValues = rv.Match(filename);
                //if (match.Success)
                if (matchValues.Success)
                {
                    Print1 print = Get(rv.Name);
                    print.NewIssue();
                    //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);
                        continue;
                    }
                    return(print);
                }
            }

            if (_trace)
            {
                Trace.CurrentTrace.WriteLine("print not found \"{0}\"", filename);
            }
            return(null);
        }