예제 #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 static void Test_CalculatePrintDate_01(Print print, string directory, int printNumber, int nb)
        {
            string traceFile = zPath.Combine(directory, @"Print\CalculatePrintDateNumber", string.Format("Print_{0}_Date.txt", print.Name));

            Trace.WriteLine("print {0} frequency {1} calculate date from number {2} nb {3} trace file \"{4}\"", print.Name, print.Frequency, printNumber, nb, zPath.GetFileName(traceFile));
            //Trace.CurrentTrace.DisableBaseLog();
            Trace.CurrentTrace.DisableViewer = true;
            //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Test_CalculatePrintDate_01", WriteToFile.Create(traceFile, FileOption.RazFile).Write);
            try
            {
                Trace.WriteLine("print {0} frequency {1} calculate date from number {2} nb {3}", print.Name, print.Frequency, printNumber, nb);
                Trace.WriteLine();
                for (int i = 0; i < nb; i++)
                {
                    PrintIssue issue = print.NewPrintIssue(printNumber);
                    Trace.WriteLine("{0:yyyy-MM-dd ddd} {1}", issue.Date, printNumber);
                    printNumber++;
                }
            }
            finally
            {
                //Trace.CurrentTrace.EnableBaseLog();
                //Trace.CurrentTrace.RemoveTraceFile(traceFile);
                Trace.CurrentTrace.RemoveOnWrite("Test_CalculatePrintDate_01");
                Trace.CurrentTrace.DisableViewer = false;
            }
        }
예제 #3
0
 private bool FindSpecial(PrintIssue issue, ref string filename)
 {
     foreach (RegexValues rv in _specialRegexList.Values)
     {
         //if (issue.Match(rv, filename))
         MatchValues matchValues = issue.Match(rv, filename);
         if (matchValues != null)
         {
             //filename = rv.MatchReplace_old("_");
             filename = matchValues.Replace("_");
             return(true);
         }
     }
     return(false);
 }
예제 #4
0
 private bool FindDate(PrintIssue issue, ref string filename)
 {
     foreach (RegexValues rv in _dateRegexList.Values)
     {
         //if (issue.Match(rv, filename, v => zdate.IsDateValid(v)))
         MatchValues matchValues = issue.Match(rv, filename, v => zdate.IsDateValid(v));
         if (matchValues != null)
         {
             //filename = rv.MatchReplace_old("_");
             filename = matchValues.Replace("_");
             if (!issue.Special)
             {
                 return(true);
             }
             break;
         }
     }
     return(false);
 }
예제 #5
0
 private bool FindDay(PrintIssue issue, string filename)
 {
     foreach (RegexValues rv in _dayRegexList.Values)
     {
         //Match match = rv.Match_old(filename);
         MatchValues matchValues = rv.Match(filename);
         //while (match.Success)
         while (matchValues.Success)
         {
             //if (issue.MatchSetValues(rv, v => zdate.IsDayValid(v)))
             if (issue.MatchSetValues(matchValues, v => zdate.IsDayValid(v)))
             {
                 return(true);
             }
             //match = rv.Next_old();
             matchValues = matchValues.Next();
         }
     }
     return(false);
 }
예제 #6
0
 private bool FindNumber(PrintIssue issue, string filename)
 {
     foreach (RegexValues rv in _numberRegexList.Values)
     {
         //Match match = rv.Match_old(filename);
         MatchValues matchValues = rv.Match(filename);
         //while (match.Success)
         while (matchValues.Success)
         {
             //if (issue.MatchSetValues(rv, v => PrintIssue.IsNumberValid(v)))
             if (issue.MatchSetValues(matchValues, v => PrintIssue.IsNumberValid(v)))
             {
                 if (issue.Control())
                 {
                     return(true);
                 }
             }
             //match = rv.Next_old();
             matchValues = matchValues.Next();
         }
     }
     return(false);
 }
예제 #7
0
        public static void Test_CalculatePrintNumber_02(Print print, string directory, Date date, int nb)
        {
            string traceFile = zPath.Combine(zPath.Combine(directory, @"Print\CalculatePrintDateNumber"), string.Format("Print_{0}_Number.txt", print.Name));

            Trace.WriteLine("print {0} frequency {1} calculate number from date {2:dd-MM-yyyy} nb {3} trace file \"{4}\"", print.Name, print.Frequency, date, nb, zPath.GetFileName(traceFile));
            //Trace.CurrentTrace.DisableBaseLog();
            //Trace.CurrentTrace.DisableTraceView = true;
            //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Test_CalculatePrintNumber_02", WriteToFile.Create(traceFile, FileOption.RazFile).Write);
            try
            {
                Trace.WriteLine("print {0} frequency {1} calculate number from date {2:dd-MM-yyyy} nb {3}", print.Name, print.Frequency, date, nb);
                Trace.WriteLine();
                if (print.Frequency == PrintFrequency.Daily)
                {
                    for (int i = 0; i < nb; i++)
                    {
                        PrintIssue issue  = print.NewPrintIssue(date);
                        int        number = issue.PrintNumber;
                        Trace.WriteLine("{0:yyyy-MM-dd ddd} {1}", issue.Date, number);
                        date = date.AddDays(1);
                    }
                }
                else if (print.Frequency == PrintFrequency.Weekly)
                {
                    for (int i = 0; i < nb; i++)
                    {
                        PrintIssue issue  = print.NewPrintIssue(date);
                        int        number = issue.PrintNumber;
                        Trace.WriteLine("{0:yyyy-MM-dd ddd} {1}", issue.Date, number);
                        date = date.AddDays(7);
                    }
                }
                else if (print.Frequency == PrintFrequency.Monthly)
                {
                    for (int i = 0; i < nb; i++)
                    {
                        PrintIssue issue  = print.NewPrintIssue(date);
                        int        number = issue.PrintNumber;
                        Trace.WriteLine("{0:yyyy-MM-dd ddd} {1}", issue.Date, number);
                        date = date.AddMonths(1);
                    }
                }
                else if (print.Frequency == PrintFrequency.Bimonthly || print.Frequency == PrintFrequency.Quarterly)
                {
                    int lastNumber = 0;
                    for (int i = 0; i < nb;)
                    {
                        PrintIssue issue  = print.NewPrintIssue(date);
                        int        number = issue.PrintNumber;
                        if (number != lastNumber)
                        {
                            Trace.WriteLine("{0:yyyy-MM-dd ddd} {1}", issue.Date, number);
                            lastNumber = number;
                            i++;
                        }
                        date = date.AddMonths(1);
                    }
                }
            }
            finally
            {
                //Trace.CurrentTrace.EnableBaseLog();
                //Trace.CurrentTrace.RemoveTraceFile(traceFile);
                Trace.CurrentTrace.RemoveOnWrite("Test_CalculatePrintNumber_02");
                Trace.CurrentTrace.DisableViewer = false;
            }
        }
예제 #8
0
 private bool FindNumber(PrintIssue issue, string filename)
 {
     foreach (RegexValues rv in _numberRegexList.Values)
     {
         //Match match = rv.Match_old(filename);
         MatchValues matchValues = rv.Match(filename);
         //while (match.Success)
         while (matchValues.Success)
         {
             //if (issue.MatchSetValues(rv, v => PrintIssue.IsNumberValid(v)))
             if (issue.MatchSetValues(matchValues, v => PrintIssue.IsNumberValid(v)))
             {
                 if (issue.Control())
                 {
                     return true;
                 }
             }
             //match = rv.Next_old();
             matchValues = matchValues.Next();
         }
     }
     return false;
 }
예제 #9
0
 private bool FindDay(PrintIssue issue, string filename)
 {
     foreach (RegexValues rv in _dayRegexList.Values)
     {
         //Match match = rv.Match_old(filename);
         MatchValues matchValues = rv.Match(filename);
         //while (match.Success)
         while (matchValues.Success)
         {
             //if (issue.MatchSetValues(rv, v => zdate.IsDayValid(v)))
             if (issue.MatchSetValues(matchValues, v => zdate.IsDayValid(v)))
             {
                 return true;
             }
             //match = rv.Next_old();
             matchValues = matchValues.Next();
         }
     }
     return false;
 }
예제 #10
0
 private bool FindDate(PrintIssue issue, ref string filename)
 {
     foreach (RegexValues rv in _dateRegexList.Values)
     {
         //if (issue.Match(rv, filename, v => zdate.IsDateValid(v)))
         MatchValues matchValues = issue.Match(rv, filename, v => zdate.IsDateValid(v));
         if (matchValues != null)
         {
             //filename = rv.MatchReplace_old("_");
             filename = matchValues.Replace("_");
             if (!issue.Special)
                 return true;
             break;
         }
     }
     return false;
 }
예제 #11
0
 private bool FindSpecial(PrintIssue issue, ref string filename)
 {
     foreach (RegexValues rv in _specialRegexList.Values)
     {
         //if (issue.Match(rv, filename))
         MatchValues matchValues = issue.Match(rv, filename);
         if (matchValues != null)
         {
             //filename = rv.MatchReplace_old("_");
             filename = matchValues.Replace("_");
             return true;
         }
     }
     return false;
 }
예제 #12
0
        public PrintIssue Find(string filename)
        {
            WriteLine("search \"{0}\"", filename);
            PrintIssue issue          = null;
            PrintIssue lastIssueError = null;
            //List<GClass2<PrintIssue, RegexValues>> issues = new List<GClass2<PrintIssue,RegexValues>>();
            List <GClass2 <PrintIssue, MatchValues> > issues = new List <GClass2 <PrintIssue, MatchValues> >();
            bool foundIssue = false;

            filename = zstr.ReplaceUTF8Code(filename);
            filename = filename.Replace('\u0430', 'a');
            filename = filename.Replace('\u0435', 'e');
            filename = filename.Replace('\u043E', 'o');
            WriteLine("search \"{0}\"", filename);
            foreach (RegexValues rv in _printRegexList.Values)
            {
                //issue = Match(rv, filename);
                GClass2 <PrintIssue, MatchValues> gc = Match(rv, filename);
                //if (issue != null && issue.Error == null)
                if (gc.Value1 != null && gc.Value1.Error == null)
                {
                    Print print = issue.Print;

                    //if (issue.Match(print.NormalizedFilename, filename))
                    MatchValues matchValues = issue.Match(print.NormalizedFilename, filename);
                    if (matchValues != null)
                    {
                        foundIssue = true;
                        break;
                    }
                    //if (issue.Match(print.NormalizedSpecialFilename, filename))
                    matchValues = issue.Match(print.NormalizedSpecialFilename, filename);
                    if (matchValues != null)
                    {
                        foundIssue = true;
                        break;
                    }

                    //issues.Add(new GClass2<PrintIssue, RegexValues>(issue, rv));
                    issues.Add(new GClass2 <PrintIssue, MatchValues>(issue, gc.Value2));
                }

                //if (issue != null && issue.Error != null)
                if (gc.Value1 != null && gc.Value1.Error != null)
                {
                    lastIssueError = issue;
                }
            }

            if (!foundIssue)
            {
                //foreach (GClass2<PrintIssue, RegexValues> issue2 in issues)
                foreach (GClass2 <PrintIssue, MatchValues> issue2 in issues)
                {
                    issue = issue2.Value1;
                    //RegexValues rv = issue2.Value2;
                    MatchValues matchValues = issue2.Value2;
                    Print       print       = issue.Print;
                    //string filename2 = filename = rv.MatchReplace_old("_");
                    string filename2 = filename = matchValues.Replace("_");

                    FindSpecial(issue, ref filename2);

                    if (print.Frequency != PrintFrequency.Daily && print.Frequency != PrintFrequency.Weekly)
                    {
                        if (FindNumber(issue, filename2))
                        {
                            foundIssue = true;
                        }
                        //if (issue.Error != null)
                        //    lastIssueError = issue;
                    }


                    bool foundDate = false;
                    if (!foundIssue)
                    {
                        if (FindDate(issue, ref filename2))
                        {
                            foundDate = true;
                        }
                        //if (issue.Error != null)
                        //    lastIssueError = issue;
                    }

                    if (!foundIssue && print.Frequency != PrintFrequency.Daily)
                    {
                        if (FindNumber(issue, filename2))
                        {
                            foundIssue = true;
                        }
                        //if (issue.Error != null)
                        //    lastIssueError = issue;
                    }

                    if (foundDate)
                    {
                        foundIssue = true;
                    }

                    if (!foundIssue && (print.Frequency == PrintFrequency.Daily || print.Frequency == PrintFrequency.Weekly))
                    {
                        if (FindDay(issue, filename2))
                        {
                            foundIssue = true;
                        }
                        //if (issue.Error != null)
                        //    lastIssueError = issue;
                    }

                    if (issue.Error != null)
                    {
                        lastIssueError = issue;
                    }

                    if (foundIssue)
                    {
                        break;
                    }
                }
            }

            if (!foundIssue)
            {
                if (_trace)
                {
                    WriteLine("print not found \"{0}\"", filename);
                }
                return(lastIssueError);
            }

            issue.Control();
            return(issue);
        }