Beispiel #1
0
        public static void Control_RegexValues_02()
        {
            string file    = @"control\print_filenames_01.txt";
            string logFile = @"control\print_filenames_01_regex.txt";

            logFile = zPath.Combine(XmlConfig.CurrentConfig.GetExplicit("DataDir"), logFile);
            Trace.WriteLine("write to file \"{0}\"", logFile);
            //Trace.CurrentTrace.AddTraceFile(logFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Print_Exe", WriteToFile.Create(logFile, FileOption.RazFile).Write);
            Trace.WriteLine("Control RegexValues :");
            Trace.WriteLine("  file : \"{0}\"", file);
            Trace.WriteLine("  log  : \"{0}\"", logFile);
            Trace.WriteLine();
            IEnumerable <XElement> els = XmlConfig.CurrentConfig.GetElements("Print/Filenames/Filename");

            string[] lines = zfile.ReadAllLines(zPath.Combine(XmlConfig.CurrentConfig.GetExplicit("DataDir"), file));
            foreach (string line in lines)
            {
                if (line != "")
                {
                    Test_Exe.Test_RegexValues(els, line);
                }
                //else
                //    Trace.WriteLine();
            }
            //Trace.CurrentTrace.RemoveTraceFile(logFile);
            Trace.CurrentTrace.RemoveOnWrite("Print_Exe");
        }
Beispiel #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;
            }
        }
Beispiel #3
0
        static void Main()
        {
            try
            {
                object runSourceRestartParameters = null;
                while (true)
                {
                    __config = new XmlConfig(__configFile);
                    TraceManager.Current.AddTrace(Trace.Current);
                    //TraceManager.Current.SetWriter(__config.Get("Log").zRootPath(zapp.GetAppDirectory()), __config.Get("Log/@option").zTextDeserialize(FileOption.None));
                    TraceManager.Current.SetWriter(WriteToFile.Create(__config.Get("Log").zRootPath(zapp.GetAppDirectory()), __config.Get("Log/@option").zTextDeserialize(FileOption.None)));
                    //__traceUpdate = __config.Get("UpdateRunSource/TraceUpdate").zTryParseAs(false);
                    zUpdateFiles.Trace = __config.Get("UpdateRunSource/TraceUpdate").zTryParseAs(false);

                    UpdateRunSourceFiles();
                    Run(runSourceRestartParameters);
                    // attention récupérer RunSourceRestartParameters avant UpdateRunSourceFiles(), UpdateRunSourceFiles() fait AppDomain.Unload()
                    runSourceRestartParameters = __domain.GetData(__domainRestartParametersName);
                    if (runSourceRestartParameters == null)
                    {
                        break;
                    }
                    //__domain.DomainUnload += domain_DomainUnload;
                    //Trace.WriteLine("__domain.IsFinalizingForUnload() : {0}", __domain.IsFinalizingForUnload());
                    //Trace.WriteLine("AppDomain.Unload(__domain)");
                    AppDomain.Unload(__domain);
                    __domain = null;
                    //Trace.WriteLine("__domain.IsFinalizingForUnload() : {0}", __domain.IsFinalizingForUnload());
                }
            }
            catch (Exception ex)
            {
                zerrf.ErrorMessageBox(ex);
            }
        }
Beispiel #4
0
        //private static XmlConfig _config = new XmlConfig("pt_config.xml");

        public static void Main(string[] args)
        {
            try
            {
                //Trace.CurrentTrace.SetLogFile(null, LogOptions.LogToConsole);
                Trace.CurrentTrace.SetViewer(Console.Out.Write);
                //string log = _config.Get("Log").zRootPath(zapp.GetEntryAssemblyDirectory());
                //if (log != null)
                //{
                //    //Trace.WriteLine("log to \"{0}\"", log);
                //    //Trace.AddTraceFile(log, LogOptions.IndexedFile);
                //    Trace.CurrentTrace.AddTraceFile(log);
                //}
                Trace.CurrentTrace.SetWriter(WriteToFile.Create(_config.Get("Log").zRootPath(zapp.GetEntryAssemblyDirectory()), _config.Get("Log/@option").zTextDeserialize(FileOption.None)));
                string path = _config.Get("PrintConfig");
                if (path != null)
                {
                    //Trace.WriteLine("load print config \"{0}\"", path);
                    _printConfig = new XmlConfig(path);
                }
                pt(args);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
                Trace.WriteLine(ex.StackTrace);
            }
        }
Beispiel #5
0
        public static void Test_FindDate_03(FindDateManager_v1 findDateManager, string file)
        {
            file = zPath.Combine(GetDirectoryDate(), file);
            int year = Date.Today.Year;

            findDateManager.DateRegexList.Add("year", new RegexValues("year", "year", string.Format(@"(?:^|[_\s])({0}|{1}|{2})(?:$|[_\s])", year - 1, year, year + 1), "IgnoreCase", "year", compileRegex: true));

            string traceFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_out");

            Trace.WriteLine("Test_FindDate \"{0}\" (nb date regex {1})", file, findDateManager.DateRegexList.Count);
            //Trace.CurrentTrace.DisableBaseLog();
            Trace.CurrentTrace.DisableViewer = true;
            //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Test_FindDate_03", WriteToFile.Create(traceFile, FileOption.RazFile).Write);

            try
            {
                DateTime dt = DateTime.Now;
                TraceRegexValuesList(findDateManager.DateRegexList);
                Trace.WriteLine();

                string bsonFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_bson");
                zMongo.BsonRead <TestText>(file).zFindDate(findDateManager).zSave(bsonFile);
                zMongo.BsonRead <TestFindDate>(bsonFile).zTraceFindDate();
                Trace.WriteLine("test duration {0}", DateTime.Now - dt);
            }
            finally
            {
                //Trace.CurrentTrace.EnableBaseLog();
                //Trace.CurrentTrace.RemoveTraceFile(traceFile);
                Trace.CurrentTrace.RemoveOnWrite("Test_FindDate_03");
                Trace.CurrentTrace.DisableViewer = false;
            }
        }
Beispiel #6
0
        public static void Test_FindDate_04(FindDateManager findDateManager, string file)
        {
            file = zPath.Combine(GetDirectoryDate(), file);

            string traceFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_new_out");
            string bsonFile  = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_new_bson");

            Trace.WriteLine("Test_FindDate \"{0}\" (nb date regex {1})", file, findDateManager.DateRegexList.Count);
            //Trace.CurrentTrace.DisableBaseLog();
            Trace.CurrentTrace.DisableViewer = true;
            //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Test_FindDate_04", WriteToFile.Create(traceFile, FileOption.RazFile).Write);

            try
            {
                DateTime dt = DateTime.Now;
                TraceRegexValuesList(findDateManager.DateRegexList);
                Trace.WriteLine();

                zMongo.BsonRead <TestText>(file).zFindDateNew(findDateManager).zSave(bsonFile);
                zMongo.BsonRead <TestFindDate>(bsonFile).zTraceFindDate();
                Trace.WriteLine("test duration {0}", DateTime.Now - dt);
            }
            finally
            {
                //Trace.CurrentTrace.EnableBaseLog();
                //Trace.CurrentTrace.RemoveTraceFile(traceFile);
                Trace.CurrentTrace.RemoveOnWrite("Test_FindDate_04");
                Trace.CurrentTrace.DisableViewer = false;
            }
        }
Beispiel #7
0
        public static void Test_FindDate_01(RegexValuesList dateRegexList, string file)
        {
            file = zPath.Combine(GetDirectoryDate(), file);
            string traceFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_out");

            Trace.WriteLine("Test_FindDate \"{0}\" (nb date regex {1})", file, dateRegexList.Count);
            //Trace.CurrentTrace.DisableBaseLog();
            Trace.CurrentTrace.DisableViewer = true;
            //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Test_FindDate_01", WriteToFile.Create(traceFile, FileOption.RazFile).Write);
            try
            {
                TraceRegexValuesList(dateRegexList);
                Trace.WriteLine();
                foreach (BsonDocument document in zMongo.BsonRead <BsonDocument>(file))
                {
                    FindDate(dateRegexList, document["text"].AsString);
                }
            }
            finally
            {
                //Trace.CurrentTrace.EnableBaseLog();
                //Trace.CurrentTrace.RemoveTraceFile(traceFile);
                Trace.CurrentTrace.RemoveOnWrite("Test_FindDate_01");
                Trace.CurrentTrace.DisableViewer = false;
            }
        }
Beispiel #8
0
 public static void InitAlways()
 {
     XmlConfig.CurrentConfig = new XmlConfig(RunSourceCommand.GetFilePath("anki.config.xml"));
     //XmlConfig config = XmlConfig.CurrentConfig;
     //TraceManager.Current.SetWriter(WriteToFile.Create(@"log\log.txt", FileOption.None));
     RunSourceCommand.TraceManager.SetWriter(WriteToFile.Create(RunSourceCommand.GetFilePath(@"log\log.txt"), FileOption.None));
     Trace.WriteLine($"set log file to \"{RunSourceCommand.TraceManager.GetWriter().File}\"");
 }
Beispiel #9
0
        static void Main()
        {
            try
            {
                // load runsource.runsource.config.xml (config of runsource.runsource.exe)
                XmlConfig config = new XmlConfig();
                FormatInfo.SetInvariantCulture();
                Application.CurrentCulture = FormatInfo.CurrentFormat.CurrentCulture;
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                RemoteRunSource remoteRunSource = new RemoteRunSource();
                remoteRunSource.RunsourceDllFilename  = config.GetExplicit("RunsourceDllFilename");
                remoteRunSource.RunsourceClassName    = config.GetExplicit("RunsourceClassName");
                remoteRunSource.TraceManagerClassName = config.GetExplicit("TraceManagerClassName");
                remoteRunSource.TraceClassName        = config.GetExplicit("TraceClassName");
                // ATTENTION si CreateRunSourceDomain = true runsource.launch.exe ne peut pas mettre à jour runsource.runsource.exe
                remoteRunSource.CreateRunSourceDomain = config.Get("CreateRunSourceDomain").zTryParseAs <bool>(false);
                IRunSource runSource = remoteRunSource.GetRunSource();
                //remoteRunSource.LoadRunsourceCommand();
                //runSource.AllowMultipleExecution = config.Get("AllowMultipleExecution").zTryParseAs(false);
                ///////////////////////// donc il faut utiliser RemoteRunSource.GetTrace()
                //ITrace trace = remoteRunSource.GetTrace();
                //trace.SetWriter(config.Get("Log"), config.Get("Log/@option").zTextDeserialize(FileOption.None));

                // ATTENTION Trace exists in both 'runsource.runsource.exe' and 'runsource.dll'
                // both Trace are connected to TraceManager and can be used
                string     logFile       = config.Get("Log");
                FileOption logFileOption = config.Get("Log/@option").zTextDeserialize(FileOption.None);
                TraceManager.Current.AddTrace(Trace.Current);
                //TraceManager.Current.SetWriter(logFile, logFileOption);
                TraceManager.Current.SetWriter(WriteToFile.Create(logFile, logFileOption));

                ITraceManager remoteTraceManager = remoteRunSource.GetTraceManager();
                remoteTraceManager.AddTrace(remoteRunSource.GetTrace());
                //remoteTraceManager.SetWriter(logFile, logFileOption);
                remoteTraceManager.SetWriter(WriteToFile.Create(logFile, logFileOption));

                // ATTENTION appeler DeleteGeneratedAssemblies() après SetRunSourceConfig()
                //RunSourceForm form = new RunSourceForm(runSource, trace, config, GetRunSourceRestartParameters());
                //RunSourceForm_v3 form = new RunSourceForm_v3(runSource, trace, config, GetRunSourceRestartParameters());
                //RunSourceFormExe form = new RunSourceFormExe(runSource, trace, config, GetRunSourceRestartParameters());
                RunSourceFormExe form = new RunSourceFormExe(runSource, config, remoteRunSource, GetRunSourceRestartParameters());
                RunSourceFormExe.Current = form;

                form.SetRestartRunsource += FormSetRestartRunsource;
                Application.Run(form);

                TraceManager.Current.RemoveTrace(Trace.Current);
                TraceManager.Current.RemoveTrace(remoteRunSource.GetTrace());
                SetRunSourceRestartParameters();
            }
            catch (Exception ex)
            {
                zerrf.ErrorMessageBox(ex);
            }
        }
Beispiel #10
0
        public static void Test_FindNumber_02(FindNumberManager findNumberManager, string file)
        {
            file = zPath.Combine(GetDirectoryNumber(), file);
            string traceFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_out");

            Trace.WriteLine("Test_FindNumber \"{0}\" (nb number regex {1})", file, findNumberManager.NumberRegexList.Count);
            //Trace.CurrentTrace.DisableBaseLog();
            Trace.CurrentTrace.DisableViewer = true;
            //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Test_FindNumber_02", WriteToFile.Create(traceFile, FileOption.RazFile).Write);
            try
            {
                TraceRegexValuesList(findNumberManager.NumberRegexList);
                Trace.WriteLine();
                foreach (BsonDocument document in zMongo.BsonRead <BsonDocument>(file))
                {
                    string title = document["title"].AsString;
                    //FindNumber_old findNumber = findNumberManager.Find_old(title);
                    FindNumber findNumber = findNumberManager.Find(title);

                    Trace.WriteLine("search number in   : \"{0}\"", title);
                    if (findNumber.found)
                    {
                        //Trace.WriteLine("    found number : \"{0}\"", findNumber.regexValues.MatchValue_old);
                        Trace.WriteLine("    found number : \"{0}\"", findNumber.matchValues.Match.Value);
                        //Trace.WriteLine("    remain text  : \"{0}\"", findNumber.regexValues.MatchReplace_old("_"));
                        Trace.WriteLine("    remain text  : \"{0}\"", findNumber.matchValues.Replace("_"));

                        Trace.WriteLine("    number       : {0}", findNumber.number);
                        //Trace.Write("not found ");

                        Trace.Write("    values      : ");
                        //findNumber.regexValues.GetValues_old().zTrace();
                        findNumber.matchValues.GetValues().zTrace();
                        Trace.WriteLine();
                    }
                    else
                    {
                        Trace.WriteLine("    number not found ");
                    }
                    Trace.WriteLine();
                }
            }
            finally
            {
                //Trace.CurrentTrace.EnableBaseLog();
                //Trace.CurrentTrace.RemoveTraceFile(traceFile);
                Trace.CurrentTrace.RemoveOnWrite("Test_FindNumber_02");
                Trace.CurrentTrace.DisableViewer = false;
            }
        }
Beispiel #11
0
        public static void Test_FindDate_02(FindDateManager_v1 findDateManager, string file)
        {
            file = zPath.Combine(GetDirectoryDate(), file);
            int year = Date.Today.Year;

            findDateManager.DateRegexList.Add("year", new RegexValues("year", "year", string.Format(@"(?:^|[_\s])({0}|{1}|{2})(?:$|[_\s])", year - 1, year, year + 1), "IgnoreCase", "year", compileRegex: true));
            string traceFile = zpath.PathSetFileNameWithoutExtension(file, zPath.GetFileNameWithoutExtension(file) + "_out");

            Trace.WriteLine("Test_FindDate \"{0}\" (nb date regex {1})", file, findDateManager.DateRegexList.Count);
            //Trace.CurrentTrace.DisableBaseLog();
            Trace.CurrentTrace.DisableViewer = true;
            //Trace.CurrentTrace.AddTraceFile(traceFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Test_FindDate_02", WriteToFile.Create(traceFile, FileOption.RazFile).Write);
            try
            {
                DateTime dt = DateTime.Now;
                TraceRegexValuesList(findDateManager.DateRegexList);
                Trace.WriteLine();
                int nb          = 0;
                int nbDateFound = 0;
                foreach (BsonDocument document in zMongo.BsonRead <BsonDocument>(file))
                {
                    string text = document["text"].AsString;

                    //FindDate_old findDate = FindDate(findDateManager, text);
                    FindDate findDate = FindDate(findDateManager, text);

                    if (findDate.Found)
                    {
                        nbDateFound++;
                    }

                    nb++;
                }
                Trace.WriteLine();
                Trace.WriteLine();
                Trace.WriteLine("search date in {0} text", nb);
                Trace.WriteLine("found date in {0} text", nbDateFound);
                Trace.WriteLine("test duration {0}", DateTime.Now - dt);
            }
            finally
            {
                //Trace.CurrentTrace.EnableBaseLog();
                //Trace.CurrentTrace.RemoveTraceFile(traceFile);
                Trace.CurrentTrace.RemoveOnWrite("Test_FindDate_02");
                Trace.CurrentTrace.DisableViewer = false;
            }
        }
Beispiel #12
0
 public async Task <object> SetLogFile(object file)
 {
     Try(
         () =>
     {
         if (file != null)
         {
             TraceManager.Current.SetWriter(WriteToFile.Create((string)file, FileOption.None), "_default");
         }
         else
         {
             TraceManager.Current.RemoveWriter("_default");
         }
     });
     return(null);
 }
Beispiel #13
0
        public static void Test_AddTraceFile_01()
        {
            Trace.WriteLine("Test_AddTraceFile_01");
            string logFile = zPath.Combine(XmlConfig.CurrentConfig.GetExplicit("DataDir"), @"test_log_01.txt");

            Trace.WriteLine("add trace file to \"{0}\"", logFile);
            //Trace.CurrentTrace.AddTraceFile(logFile, LogOptions.RazLogFile);
            if (logFile != null)
            {
                Trace.CurrentTrace.AddOnWrite("Test_Exe", WriteToFile.Create(logFile, FileOption.RazFile).Write);
            }
            Trace.WriteLine("Test trace");
            Trace.WriteLine("Test trace");
            Trace.WriteLine("Test trace");
            Trace.WriteLine("Test trace");
            //Trace.CurrentTrace.RemoveTraceFile(logFile);
            if (logFile != null)
            {
                Trace.CurrentTrace.RemoveOnWrite("Test_Exe");
            }
            Trace.WriteLine("remove trace file to \"{0}\"", logFile);
        }
Beispiel #14
0
        //public static XmlConfig GetPrintConfig()
        //{
        //    string file = zpath.GetPathFile(XmlConfig.CurrentConfig.GetExplicit("PrintConfig"));
        //    //Trace.WriteLine("current directory \"{0}\"", Directory.GetCurrentDirectory());
        //    //Trace.WriteLine("print config \"{0}\"", file);
        //    XmlConfig config = new XmlConfig(file);
        //    //Trace.WriteLine("print config path \"{0}\"", config.ConfigPath);
        //    return config;
        //}

        //public static PrintManager_v1 GetPrintManager_v1()
        //{
        //    return new PrintManager_v1(GetPrintConfig().GetElement("Print"));
        //}

        //public static PrintManager_v2 GetPrintManager_v2()
        //{
        //    return new PrintManager_v2(GetPrintConfig().GetElement("Print"));
        //}

        //public static void Test_PrintManager_01()
        //{
        //    //string file = "Le monde - 2013-07-07 - no 21295 _quo+éco.pdf";
        //    //string file = "Le monde - 2013-07-07 - no 21295 -éco.pdf";
        //    //string file = "Le parisien - 2013-05-24 - no 21369 -mag.pdf";
        //    //string file = "Le monde - 2013-05-30 - no 21262 _quo.pdf";
        //    //string file = "Le monde - 2013-05-30 - no 21262 -éco.pdf";
        //    //string file = "LeVifWeekEnd20130607.pdf";
        //    //string file = "325_AltertvEc0nomik325bkf.pdf";
        //    //string file = "L'Humanite du Vendredi 19 & Samedi 20 & Dimanche 21 Juillet 2013.pdf";
        //    //string file = "Sud0ues20.pdf";
        //    string file = "ECHOS du mardi 23 juillet 2013.pdf";
        //    //PrintManager pm = new PrintManager(XmlConfig.CurrentConfig.GetElement("Print"));
        //    PrintManager_v1 pm = GetPrintManager_v1();
        //    RegexValuesList rvl = pm.PrintRegexList;
        //    //RegexValues rv = rvl.Find(file);
        //    //FindText_old findText = rvl.Find_old(file);
        //    FindText findText = rvl.Find(file);
        //    Trace.WriteLine("search print \"{0}\"", file);
        //    //if (rv == null)
        //    if (!findText.found)
        //    {
        //        Trace.WriteLine("not found");
        //        return;
        //    }
        //    //Trace.WriteLine("found {0} - {1}", findText.regexValues.Name, findText.regexValues.Key);
        //    Trace.WriteLine("found {0} - {1}", findText.matchValues.Name, findText.matchValues.Key);
        //    //Trace.WriteLine("pattern \"{0}\"", findText.regexValues.Pattern);
        //    Trace.WriteLine("pattern \"{0}\"", findText.matchValues.Pattern);
        //    //RunSource.CurrentRunSource.View(findText.regexValues.GetValues_old());
        //    RunSource.CurrentRunSource.View(findText.matchValues.GetValues());
        //    //Print print = pm.Find(file);
        //    //if (print == null)
        //    //    Trace.WriteLine("print not found");
        //    //else
        //    //    Trace.WriteLine("print file \"{0}\"", print.GetFilename());
        //    //RunSource.CurrentRunSource.View(rv.GetValues());
        //}

        //public static void Test_PrintManager_02()
        //{
        //    //string file = "01Net N°778 Du 11 Juillet au 07 Aout 2013.pdf";
        //    //string file = "Le point - 2013-07-11 - no 2130_2.pdf";
        //    //string file = "LeVifWeekEnd20130607.pdf";
        //    //string file = "Psychologies magazine - 2013-07 - no 331.pdf";
        //    //string file = "L'Humanite du Vendredi 19 & Samedi 20 & Dimanche 21 Juillet 2013.pdf";
        //    string file = "Sud0ues20.pdf";
        //    //string file = "";
        //    //string file = "";
        //    //string file = "";
        //    //string file = "";

        //    //string key = "01_net2";
        //    PrintManager_v1 pm = GetPrintManager_v1();
        //    Trace.WriteLine("Find \"{0}\"", file);
        //    string error;
        //    Print1 print = pm.Find(file, out error);
        //    if (print == null)
        //        Trace.WriteLine("not found, error \"{0}\"", error);
        //    else
        //        Trace.WriteLine("found \"{0}\"", print.Name);
        //    //RegexValues rv = pm.PrintRegexList[key];
        //    //PB_Tools.Test.Test_Regex(rv.Pattern, file, rv.Options);
        //}

        //public static void Test_PrintManager_03()
        //{
        //    //string file = "01Net N°778 Du 11 Juillet au 07 Aout 2013.pdf";
        //    //string file = "Le point - 2013-07-11 - no 2130_2.pdf";
        //    //string file = "LeVifWeekEnd20130607.pdf";
        //    string file = "Psychologies magazine - 2013-07 - no 331.pdf";
        //    //string file = "L'Humanite du Vendredi 19 & Samedi 20 & Dimanche 21 Juillet 2013.pdf";
        //    //string file = "";
        //    //string file = "";
        //    //string file = "";
        //    //string file = "";
        //    //string file = "";

        //    //string key = "01_net2";
        //    PrintManager_v1 pm = GetPrintManager_v1();
        //    Trace.WriteLine("Find \"{0}\"", file);
        //    string error;
        //    Print1 print = pm.Find(file, out error);
        //    if (print == null)
        //        Trace.WriteLine("not found, error \"{0}\"", error);
        //    else
        //        Trace.WriteLine("found \"{0}\"", print.Name);
        //    //RegexValues rv = pm.PrintRegexList[key];
        //    //PB_Tools.Test.Test_Regex(rv.Pattern, file, rv.Options);
        //}

        //public static void Test_PrintManager_04()
        //{
        //    //string file = "01Net N°778 Du 11 Juillet au 07 Aout 2013.pdf";
        //    //string file = "Le point - 2013-07-11 - no 2130_2.pdf";
        //    //string key = "01_net2";
        //    //string name = "l_equipe";
        //    //string name = "l_humanite";
        //    //string name = "l_expansion";
        //    string name = "les_cahiers_de_science_et_vie";
        //    bool regexValues = false;
        //    PrintManager_v2 pm = GetPrintManager_v2();
        //    global::Print.Print print = pm.GetPrint(name);
        //    Trace.WriteLine("print \"{0}\"", name);
        //    Trace.WriteLine("  NoPrintMonths \"{0}\"", print.NoPrintMonths);
        //    foreach (int date in print.NoPrintDates.Values)
        //    {
        //        Trace.WriteLine("  NoPrintDate {0} - {1}", date, Date.CreateDateFromAbsoluteDay(date));
        //    }
        //    if (regexValues)
        //    {
        //        Trace.WriteLine("GetRegexValuesListByName \"{0}\"", name);
        //        RegexValues[] rvList = pm.PrintRegexList.GetRegexValuesListByName(name);
        //        Trace.WriteLine("found {0}", rvList.Length);
        //        foreach (RegexValues rv in rvList)
        //        {
        //            Trace.WriteLine("pattern \"{0}\"", rv.Pattern);
        //        }
        //    }
        //}

        //public static void Test_PrintManager_05()
        //{
        //    //string file = "01Net N°778 Du 11 Juillet au 07 Aout 2013.pdf";
        //    //string file = "Le point - 2013-07-11 - no 2130_2.pdf";
        //    //string file = "LeVifWeekEnd20130607.pdf";
        //    //string file = "Psychologies magazine - 2013-07 - no 331.pdf";
        //    //string file = "L'Humanite du Vendredi 19 & Samedi 20 & Dimanche 21 Juillet 2013.pdf";
        //    //string file = "Psychologies magazine - hors-série - 2012-10 - no 19.pdf";
        //    //string file = "20130720_ARH.pdf";
        //    //string file = "Figa20.pdf";
        //    //string file = "La croix du Mercredi 24 Juillet  2013.pdf";
        //    //string file = "merlib.240713.pdf";
        //    //string file = "SciencVi1151.pdf";
        //    //string file = "Psychologies_Magazine_Hors_S_rie_N_22_Juillet_Aout_Septembre_2013.pdf";
        //    //string file = "38CI1186.pdf";
        //    //string file = "Le_Nouvel_Observateur_2542_Juillet_2013.pdf";
        //    //string file = "Le Nouvel Observateur N°2542 Du 25 au 31 Juillet 2013.pdf";
        //    //string file = "36517Marion.846.pdf";
        //    //string file = "Invest27Juill02A0u.pdf";
        //    //string file = "L'express - hors-série - 2012-04 - no 13.pdf";
        //    //string file = "Dossier pour la science - 2013-01 - no 78 - vents et nuages, la physique du ciel.pdf";
        //    //string file = "36DossPolaScien_80.pdf";
        //    //string file = "Invest27Juill02A0u.pdf";
        //    //string file = "34665IntelligenceMonde31.pdf";
        //    //string file = "Le monde de l'intelligence - 2013-07 - no 31.pdf";
        //    //string file = "36571Ccervv0.PPssyycc0.58.pdf";
        //    //string file = "L'équipe - 2013-07-31 - no 21564.pdf";
        //    //string file = "L'essentiel cerveau et psycho - 2012-05 - no 10.pdf";
        //    //string file = "Le Figaro - Vendredi 2 Août 2013.pdf";
        //    //string file = "Archéothéma - 2013-07 - no 29_2.pdf";
        //    //string file = "Fémina n°32 du 04 aout 2013.pdf";
        //    //string file = "Rep_D0_BEns_D0_B5s_Photo_Decembre_249_2012.pdf";
        //    //string file = "LeFigaroHistoire8.pdf";
        //    //string file = "Cinema_Teaser_13_Avril_2012_28Collector_Avengers_29.pdf";
        //    //string file = "Trek Magazine N°149 Juin Juillet 2013.pdf";
        //    //string file = "Ciel_26_Espace_Hors_S_C3_A9rie_19_Juillet_2012.pdf";
        //    //string file = "Ciel_et_Esp_D0_B0ce_510_2012.pdf";
        //    //string file = "Montagnes_Magazine_Hors_S_C3_A9ie_380_Et_C3_A9_2012.pdf";
        //    //string file = "Bateaux Hors-Série N°2 (2010).pdf";
        //    string file = "Le monde - 2013-08-11 - no 21325 _quo+sport+tv.txt";
        //    //string file = "";
        //    //string file = "";
        //    //string file = "";
        //    //string file = "";
        //    //string file = "";
        //    //string file = "";

        //    //string key = "01_net2";
        //    PrintManager_v2.Trace = true;
        //    global::Print.Print.Trace = true;
        //    PrintIssue.Trace = true;
        //    PrintManager_v2 pm = GetPrintManager_v2();
        //    Trace.WriteLine("Create PrintManager ({0})", pm.PrintRegexList.Count);

        //    Trace.WriteLine("Find \"{0}\"", file);
        //    //string error;
        //    //PrintIssue issue = pm.Find(file, out error);
        //    PrintIssue issue = pm.Find(file);
        //    if (issue == null)
        //    {
        //        Trace.WriteLine("not found");
        //        return;
        //    }
        //    if (issue.Error != null)
        //    {
        //        Trace.WriteLine("not found, error \"{0}\"", issue.Error);
        //        return;
        //    }
        //    Trace.WriteLine("found \"{0}\"", issue.Print.Name);
        //    issue.PrintValues.zTrace();
        //    Trace.WriteLine("filename \"{0}\"", issue.GetFilename());
        //    Trace.WriteLine("SpecialMonth {0}", issue.SpecialMonth);
        //    //RegexValues rv = pm.PrintRegexList[key];
        //    //PB_Tools.Test.Test_Regex(rv.Pattern, file, rv.Options);
        //}

        //public static void Test_PrintManager_06()
        //{
        //    string name = "le_monde";
        //    Trace.WriteLine("Create PrintManager");
        //    PrintManager_v2 pm = GetPrintManager_v2();
        //    Trace.WriteLine("search pattern \"{0}\"", name);
        //    for (int i = 1; ; i++)
        //    {
        //        string key = name + i.ToString();
        //        if (!pm.PrintRegexList.ContainsKey(key))
        //            break;
        //        RegexValues rv = pm.PrintRegexList[key];
        //        Trace.WriteLine("{0} - \"{1}\"", key, rv.Pattern);
        //    }
        //    Trace.WriteLine("date patterns");
        //    foreach (RegexValues rv in pm.DateRegexList.Values)
        //    {
        //        Trace.WriteLine("\"{0}\"", rv.Pattern);
        //    }
        //}

        //public static void Test_LeParisien_01()
        //{
        //    LeParisien pari = new LeParisien("le_parisien", "Le parisien", PrintFrequency.Daily, null, null, new Date(2013, 5, 9), 21356, SpecialDay.Sunday);
        //    pari.NewIssue(new Date(2013, 6, 9));
        //    Trace.WriteLine(pari.GetFilename());

        //    Print1 print = new LeParisien("le_parisien", "Le parisien", PrintFrequency.Daily, null, null, new Date(2013, 5, 9), 21356, SpecialDay.Sunday);
        //    print.NewIssue(new Date(2013, 6, 9));
        //    Trace.WriteLine(print.GetFilename());

        //    Print1 print2 = print;
        //    Trace.WriteLine(print2.GetFilename());

        //    //PrintManager pm = new PrintManager(XmlConfig.CurrentConfig.GetElement("Print"));
        //    PrintManager_v1 pm = GetPrintManager_v1();
        //    print2 = pm.Get("le_parisien");
        //    print2.NewIssue(new Date(2013, 6, 9));
        //    Trace.WriteLine(print2.GetFilename());
        //}

        public static void Control_RegexValues_01()
        {
            Trace.WriteLine("Control_RegexValues_01");
            string logFile = zPath.Combine(XmlConfig.CurrentConfig.GetExplicit("DataDir"), @"control\ctrl_RegexValues_01.txt");

            Trace.WriteLine("write to file \"{0}\"", logFile);
            //Trace.CurrentTrace.AddTraceFile(logFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Print_Exe", WriteToFile.Create(logFile, FileOption.RazFile).Write);
            //_wr.DisableMessage = true;
            IEnumerable <XElement> els = XmlConfig.CurrentConfig.GetElements("Print/Filenames/Filename");

            //Test_RegexValues(els, "Le monde - 2013-02-01 - no 21162 _quo.pdf");
            //Test_RegexValues(els, "Le monde - 2013-02-03 - no 21164 _quo+tv.pdf");
            Test_Exe.Test_RegexValues(els, "Le monde - 2013-02-03 - no 21164 _quo+tv+argent.pdf");
            //Test_RegexValues(els, "Le monde - 2013-03-01 - no 21186 -livres.pdf");
            //Test_RegexValues(els, "La Croix du vendredi 24 Mai 2013.pdf");
            //Test_RegexValues(els, "20130315_LIV.pdf");
            //Test_RegexValues(els, );
            //_wr.DisableMessage = false;
            //Trace.CurrentTrace.RemoveTraceFile(logFile);
            Trace.CurrentTrace.RemoveOnWrite("Print_Exe");
        }
Beispiel #15
0
        public static void InitAlways()
        {
            XmlConfig.CurrentConfig = new XmlConfig(RunSourceCommand.GetFilePath("hts.config.xml"));
            XmlConfig config = XmlConfig.CurrentConfig;

            string logFile = config.Get("Log").zRootPath(zapp.GetAppDirectory());

            //Trace.WriteLine($"set log file \"{logFile}\"");
            //RunSourceCommand.SetWriter(logFile, config.Get("Log/@option").zTextDeserialize(FileOption.None));
            //RunSourceCommand.TraceSetWriter(WriteToFile.Create(logFile, config.Get("Log/@option").zTextDeserialize(FileOption.None)));
            RunSourceCommand.TraceManager.SetWriter(WriteToFile.Create(logFile, config.Get("Log/@option").zTextDeserialize(FileOption.None)));

            AppData.DataDirectory = config.GetExplicit("DataDir");
            //string httpExportDirectory = config.Get("HttpExportDirectory").zRootPath(zapp.GetEntryAssemblyDirectory());
            //if (httpExportDirectory != null)
            //{
            //    //Trace.WriteLine($"http export directory \"{httpExportDirectory}\"");
            //    HttpRun.HttpManager.UrlCache = new UrlCache(httpExportDirectory);
            //    HttpRun.HttpManager.UrlCache.UrlFileNameType = UrlFileNameType.Host | UrlFileNameType.Path | UrlFileNameType.Ext | UrlFileNameType.Query;
            //    HttpRun.HttpManager.UrlCache.IndexedFile = true;
            //    HttpRun.HttpManager.UrlCache.SaveRequest = true;
            //}
            HttpRun.HttpManager.UrlCache = UrlCache.CreateIndexedCache(config.Get("HttpExportDirectory").zRootPath(zapp.GetEntryAssemblyDirectory()));
            MongoLog.CurrentMongoLog.SetLogFile(config.Get("MongoLog").zRootPath(zapp.GetEntryAssemblyDirectory()), config.Get("MongoLog/@option").zTextDeserialize(FileOption.None));
            string mongoCache = config.Get("MongoCache").zRootPath(zapp.GetEntryAssemblyDirectory());

            if (mongoCache != null)
            {
                MongoCursorCache.CacheFile = mongoCache;
            }
            //TraceMongoCommand.ResultToGrid = true;
            //DefaultMongoSerialization.SetDefaultMongoSerializationOptions();
            //DefaultMongoSerialization.RegisterDefaultMongoSerializer();
            //HtmlRun.SetResult = dt => RunSource.CurrentRunSource.SetResult(dt);

            //pb.Web.Html.HtmlToXmlManager.Current.ExportXml = true;
        }
Beispiel #16
0
        public static void Test_SpecialDays_01()
        {
            string logFile = zPath.Combine(XmlConfig.CurrentConfig.GetExplicit("DataDir"), @"control\ctrl_SpecialDays_01.txt");

            Trace.WriteLine("write to file \"{0}\"", logFile);
            //Trace.CurrentTrace.AddTraceFile(logFile, LogOptions.RazLogFile);
            Trace.CurrentTrace.AddOnWrite("Print_Exe", WriteToFile.Create(logFile, FileOption.RazFile).Write);

            //_wr.DisableMessage = true;
            CultureInfo culture = new CultureInfo("fr-FR");

            Trace.WriteLine("Mardi gras          Dimanche des        Dimanche de         Jeudi de            Dimanche de");
            Trace.WriteLine("                    Rameaux             Pâques              l'Ascension         Pentecôte");
            for (int year = 2013; year <= 2035; year++)
            {
                Date   dateMardiGras       = SpecialDayTools.GetMardiGrasDate(year);
                string dateMardiGrasString = string.Format(culture, "{0:dd}  {0,-7:MMMM} {0:yyyy}", dateMardiGras);

                Date   datePalmSunday       = SpecialDayTools.GetPalmSundayDate(year);
                string datePalmSundayString = string.Format(culture, "{0:dd}  {0,-7:MMMM} {0:yyyy}", datePalmSunday);

                Date   dateEasterSunday       = SpecialDayTools.GetEasterSundayDate(year);
                string dateEasterSundayString = string.Format(culture, "{0:dd}  {0,-7:MMMM} {0:yyyy}", dateEasterSunday);

                Date   dateAscensionThursday       = SpecialDayTools.GetAscensionThursdayDate(year);
                string dateAscensionThursdayString = string.Format(culture, "{0:dd}  {0,-7:MMMM} {0:yyyy}", dateAscensionThursday);

                Date   datePentecostSunday       = SpecialDayTools.GetPentecostSundayDate(year);
                string datePentecostSundayString = string.Format(culture, "{0:dd}  {0,-7:MMMM} {0:yyyy}", datePentecostSunday);

                Trace.WriteLine("{0}    {1}    {2}    {3}    {4}", dateMardiGrasString, datePalmSundayString, dateEasterSundayString, dateAscensionThursdayString, datePentecostSundayString);
            }
            //_wr.DisableMessage = false;
            //Trace.CurrentTrace.RemoveTraceFile(logFile);
            Trace.CurrentTrace.RemoveOnWrite("Print_Exe");
        }
Beispiel #17
0
        public static void InitAlways()
        {
            XmlConfig.CurrentConfig = new XmlConfig(RunSourceCommand.GetFilePath("download.config.xml"));
            XmlConfig config = XmlConfig.CurrentConfig;

            //RunSourceCommand.SetWriter(config.Get("Log").zRootPath(zapp.GetAppDirectory()), config.Get("Log/@option").zTextDeserialize(FileOption.None));
            //RunSourceCommand.TraceSetWriter(WriteToFile.Create(config.Get("Log").zRootPath(zapp.GetAppDirectory()), config.Get("Log/@option").zTextDeserialize(FileOption.None)));
            RunSourceCommand.TraceManager.SetWriter(WriteToFile.Create(config.Get("Log").zRootPath(zapp.GetAppDirectory()), config.Get("Log/@option").zTextDeserialize(FileOption.None)));

            string dataDir = config.GetExplicit("DataDir");

            AppData.DataDirectory = dataDir;

            //HttpManager.CurrentHttpManager.ExportDirectory = config.Get("HttpExportDirectory").zRootPath(zapp.GetEntryAssemblyDirectory());
            HttpRun.HttpManager.UrlCache = UrlCache.CreateIndexedCache(config.Get("HttpExportDirectory").zRootPath(zapp.GetEntryAssemblyDirectory()));

            MongoLog.CurrentMongoLog.SetLogFile(config.Get("MongoLog").zRootPath(zapp.GetEntryAssemblyDirectory()), config.Get("MongoLog/@option").zTextDeserialize(FileOption.None));
            string mongoCache = config.Get("MongoCache").zRootPath(zapp.GetEntryAssemblyDirectory());

            if (mongoCache != null)
            {
                MongoCursorCache.CacheFile = mongoCache;
            }

            // export data of PrintTextValuesManager
            bool exportData = config.Get("TextInfos/ExportData").zParseAs <bool>();

            if (exportData)
            {
                string exportDataFile = config.Get("TextInfos/ExportDataFile");
                if (exportDataFile != null)
                {
                    DownloadPrint.PrintTextValuesManager.SetExportDataFile(exportDataFile);
                }
            }
        }
Beispiel #18
0
        //public Log_v1 Log { get { return _log; } set { _log = value; } }

        //public void SetLogFile(string file, LogOptions_v1 options)
        //{
        //    _log = new Log_v1(file, options);
        //    //Trace.WriteLine("set mongo log file to \"{0}\"", _log.File);
        //}

        public void SetLogFile(string file, FileOption option, Encoding encoding = null)
        {
            _writeToFile = WriteToFile.Create(file, option, encoding);
            //Trace.WriteLine("set mongo log file to \"{0}\"", _log.File);
        }
Beispiel #19
0
        // PrintManager_v2 pm
        public static void RenameFile(PrintManager pm, string path, bool simulate = false, bool moveFile = false, string printFile = null)
        {
            string fmt1             = "file {0,-70}";
            string fmt2             = " {0,-30}";
            string fmt3             = " {0,-60}";
            bool   writeFilenameOk  = true;
            bool   writeUnknowPrint = true;
            bool   logFileInDestinationDirectory = false;
            bool   debug = false;

            //Trace.WriteLine("path \"{0}\"", path);
            if (!zPath.IsPathRooted(path))
            {
                path = zPath.GetFullPath(path);
            }
            //Trace.WriteLine("path \"{0}\"", path);
            string file = zPath.GetFileName(path);

            if (!zFile.Exists(path))
            {
                Trace.WriteLine("file dont exists \"{0}\"", file);
                return;
            }
            PrintIssue issue;

            if (printFile != null)
            {
                issue = pm.Find(printFile + ".pdf");
            }
            else
            {
                issue = pm.Find(file);
            }
            string msgFile = "\"" + file + "\"";

            if (printFile != null)
            {
                msgFile += " (\"" + printFile + "\")";
            }
            if (issue == null || issue.Error != null)
            {
                if (writeUnknowPrint)
                {
                    Trace.Write(fmt1, msgFile);
                    if (issue == null)
                    {
                        Trace.Write(" unknow print");
                    }
                    else
                    {
                        Trace.Write(" {0}", issue.Print.Name);
                    }
                    if (issue != null && issue.Error != null)
                    {
                        Trace.Write(" " + issue.Error);
                    }
                    Trace.WriteLine();
                }
                return;
            }
            if (debug)
            {
                Trace.Write(fmt1, msgFile);
                Trace.WriteLine(fmt2, issue.Print.Name);
                issue.PrintValues.zTrace();
            }
            string file2 = issue.GetFilename();

            //Trace.WriteLine("zPath.GetDirectoryName(path) \"{0}\"", zPath.GetDirectoryName(path));
            //Trace.WriteLine("issue.Print.Directory       \"{0}\"", issue.Print.Directory);
            if (file == file2 && (!moveFile || zPath.GetDirectoryName(path).Equals(issue.Print.Directory, StringComparison.InvariantCultureIgnoreCase)))
            {
                if (writeFilenameOk)
                {
                    Trace.Write(fmt1, msgFile);
                    Trace.Write(fmt2, issue.Print.Name);
                    Trace.Write(" filename ok");
                    if (moveFile)
                    {
                        Trace.Write(" move to same directory");
                    }
                    Trace.WriteLine();
                }
                return;
            }

            if (moveFile && !simulate && !zDirectory.Exists(issue.Print.Directory))
            {
                zDirectory.CreateDirectory(issue.Print.Directory);
            }
            string traceFile = null;

            if (moveFile && !simulate && logFileInDestinationDirectory)
            {
                traceFile = zPath.Combine(issue.Print.Directory, "log.txt");
                //_tr.AddTraceFile(traceFile);
                //_tr.AddTraceFile(traceFile, LogOptions.None);
                if (traceFile != null)
                {
                    Trace.CurrentTrace.AddOnWrite("zprint", WriteToFile.Create(traceFile, FileOption.None).Write);
                }
            }
            try
            {
                Trace.Write(fmt1, msgFile);
                Trace.Write(fmt2, issue.Print.Name);
                string path2;
                bool   fileExists  = false;
                bool   filesEquals = false;
                if (moveFile)
                {
                    path2 = zPath.Combine(issue.Print.Directory, file2);
                }
                else
                {
                    path2 = zpath.PathSetFileName(path, file2);
                }
                int index = 2;
                while (zFile.Exists(path2))
                {
                    fileExists = true;
                    if (path == path2)
                    {
                        break;
                    }
                    //filesEquals = zfile.FilesEquals(path, path2);
                    filesEquals = zfile.AreFileEqual(path, path2);
                    if (filesEquals)
                    {
                        break;
                    }
                    file2 = issue.GetFilename(index++);
                    path2 = zpath.PathSetFileName(path2, file2);
                }
                Trace.Write(fmt3, "\"" + file2 + "\"");
                if (simulate)
                {
                    Trace.Write(" simulate");
                }
                if (fileExists)
                {
                    Trace.Write(" file exists");
                    if (filesEquals)
                    {
                        Trace.Write(" and is equals");
                    }
                    else
                    {
                        Trace.Write(" and is different");
                    }
                }
                if (filesEquals)
                {
                    Trace.Write(" delete file");
                }
                else
                {
                    Trace.Write(" rename");
                    if (moveFile)
                    {
                        Trace.Write(" and move");
                    }
                    Trace.Write(" file");
                }
                Trace.WriteLine();
                if (!simulate)
                {
                    if (filesEquals)
                    {
                        zFile.Delete(path);
                    }
                    else if (!zFile.Exists(path2))
                    {
                        zFile.Move(path, path2);
                    }
                }
            }
            finally
            {
                if (traceFile != null)
                {
                    //_tr.RemoveTraceFile(traceFile);
                    Trace.CurrentTrace.RemoveOnWrite("zprint");
                }
            }
        }
Beispiel #20
0
        //private static ITrace _tr = Trace.CurrentTrace;

        public static void RenameFile(PrintManager_v1 pm, string path, bool simulate = false, bool moveFile = false, string printFile = null)
        {
            string fmt1             = "file {0,-70}";
            string fmt2             = " {0,-30}";
            string fmt3             = " {0,-60}";
            bool   writeFilenameOk  = true;
            bool   writeUnknowPrint = true;
            bool   logFileInDestinationDirectory = false;
            bool   debug = false;
            string file  = zPath.GetFileName(path);

            if (!zFile.Exists(path))
            {
                Trace.WriteLine("file dont exists \"{0}\"", file);
                return;
            }
            Print1 print;
            //Trace.WriteLine("search print start");
            string error;

            if (printFile != null)
            {
                print = pm.Find(printFile + ".pdf", out error);
            }
            else
            {
                print = pm.Find(file, out error);
            }
            //Trace.WriteLine("search print end");
            string msgFile = "\"" + file + "\"";

            if (printFile != null)
            {
                msgFile += " (\"" + printFile + "\")";
            }
            if (print == null)
            {
                if (writeUnknowPrint)
                {
                    Trace.Write(fmt1, msgFile);
                    Trace.Write(" unknow print");
                    if (error != null)
                    {
                        Trace.Write(" " + error);
                    }
                    Trace.WriteLine();
                }
                return;
            }
            if (debug)
            {
                Trace.Write(fmt1, msgFile);
                Trace.WriteLine(fmt2, print.Name);
                //foreach (KeyValuePair<string, object> value in print.PrintValues)
                foreach (KeyValuePair <string, ZValue> value in print.PrintValues)
                {
                    Trace.WriteLine("  {0} = {1}", value.Key, value.Value);
                }
            }
            string file2 = print.GetFilename();

            if (file == file2 && (!moveFile || zPath.GetDirectoryName(path) == print.Directory))
            {
                if (writeFilenameOk)
                {
                    Trace.Write(fmt1, msgFile);
                    Trace.Write(fmt2, print.Name);
                    Trace.Write(" filename ok");
                    if (moveFile)
                    {
                        Trace.Write(" move to same directory");
                    }
                    Trace.WriteLine();
                }
                return;
            }

            if (moveFile && !simulate && !zDirectory.Exists(print.Directory))
            {
                zDirectory.CreateDirectory(print.Directory);
            }
            string traceFile = null;

            if (moveFile && !simulate && logFileInDestinationDirectory)
            {
                traceFile = zPath.Combine(print.Directory, "log.txt");
                //_tr.AddTraceFile(traceFile, LogOptions.None);
                if (traceFile != null)
                {
                    Trace.CurrentTrace.AddOnWrite("pu1", WriteToFile.Create(traceFile, FileOption.None).Write);
                }
            }
            try
            {
                Trace.Write(fmt1, msgFile);
                Trace.Write(fmt2, print.Name);
                string path2;
                bool   fileExists  = false;
                bool   filesEquals = false;
                if (moveFile)
                {
                    //if (!simulate && !Directory.Exists(print.Directory))
                    //    Directory.CreateDirectory(print.Directory);
                    path2 = zPath.Combine(print.Directory, file2);
                }
                else
                {
                    path2 = zpath.PathSetFileName(path, file2);
                }
                int index = 2;
                while (zFile.Exists(path2))
                {
                    fileExists = true;
                    if (path == path2)
                    {
                        break;
                    }
                    //filesEquals = zfile.FilesEquals(path, path2);
                    filesEquals = zfile.AreFileEqual(path, path2);
                    if (filesEquals)
                    {
                        break;
                    }
                    file2 = print.GetFilename(index++);
                    //path2 = path.PathSetFileWithExt(path, file2);
                    path2 = zpath.PathSetFileName(path2, file2);
                }
                //if (simulate)
                //    Trace.Write(" simulate");
                //Trace.Write(" rename");
                //if (moveFile)
                //    Trace.Write(" and move");
                //Trace.WriteLine(" \"{0}\"", file2);
                Trace.Write(fmt3, "\"" + file2 + "\"");
                if (simulate)
                {
                    Trace.Write(" simulate");
                }
                if (fileExists)
                {
                    Trace.Write(" file exists");
                    if (filesEquals)
                    {
                        Trace.Write(" and is equals");
                    }
                    else
                    {
                        Trace.Write(" and is different");
                    }
                }
                if (filesEquals)
                {
                    Trace.Write(" delete file");
                }
                else
                {
                    Trace.Write(" rename");
                    if (moveFile)
                    {
                        Trace.Write(" and move");
                    }
                    Trace.Write(" file");
                }
                Trace.WriteLine();
                if (!simulate)
                {
                    if (filesEquals)
                    {
                        zFile.Delete(path);
                    }
                    else if (!zFile.Exists(path2))
                    {
                        zFile.Move(path, path2);
                    }
                }
            }
            finally
            {
                if (traceFile != null)
                {
                    //_tr.RemoveTraceFile(traceFile);
                    Trace.CurrentTrace.RemoveOnWrite("pu1");
                }
            }
        }
Beispiel #21
0
 public void SetWriter(string file, FileOption option, Encoding encoding = null)
 {
     SetWriter(WriteToFile.Create(file, option, encoding));
 }
Beispiel #22
0
        public static void TraceVSProject(string vsProject = null)
        {
            if (vsProject != null)
            {
                vsProject = RunSourceCommand.GetFilePath(RunSourceCommand.GetProjectVariableValue(vsProject));
            }
            else
            {
                vsProject = GetVSProject(RunSourceCommand.GetCurrentProject());
            }

            if (!zFile.Exists(vsProject))
            {
                Trace.WriteLine($"visual studio project not found \"{vsProject}\"");
                return;
            }

            try
            {
                //RunSourceCommand.TraceDisableViewer();
                ////RunSourceCommand.TraceSetWriter(WriteToFile.Create(zPath.Combine(zPath.GetDirectoryName(vsProject), zPath.GetFileName(vsProject) + ".trace.txt"), FileOption.RazFile), "trace");
                //RunSourceCommand.TraceSetWriter(WriteToFile.Create(vsProject + ".trace.txt", FileOption.RazFile), "trace");
                RunSourceCommand.TraceManager.DisableViewer();
                RunSourceCommand.TraceManager.SetWriter(WriteToFile.Create(vsProject + ".trace.txt", FileOption.RazFile), "trace");

                Trace.WriteLine($"visual studio project \"{vsProject}\"");
                VSProjectManager vsProjectManager = new VSProjectManager(vsProject);
                Trace.WriteLine("  sources");
                foreach (VSSource source in vsProjectManager.GetSources().Where(source => source.Link == null).OrderBy(source => source.File))
                {
                    //Trace.WriteLine($"    file \"{sourceLink.File}\" link \"{sourceLink.Link}\"");
                    //if (source.Link == null)
                    Trace.WriteLine($"    \"{source.File}\"");
                }
                Trace.WriteLine("  sources links");
                foreach (VSSource source in vsProjectManager.GetSources().Where(source => source.Link != null).OrderBy(source => source.File))
                {
                    //Trace.WriteLine($"    file \"{sourceLink.File}\" link \"{sourceLink.Link}\"");
                    //if (source.Link != null)
                    Trace.WriteLine($"    \"{source.File}\"");
                }
                Trace.WriteLine("  framework references");
                foreach (VSReference reference in vsProjectManager.GetReferences().Where(reference => reference.File == null).OrderBy(reference => reference.Name))
                {
                    Trace.WriteLine($"    \"{reference.Name}\"");
                }
                Trace.WriteLine("  dll references");
                foreach (VSReference reference in vsProjectManager.GetReferences().Where(reference => reference.File != null && !reference.ProjectReference).OrderBy(reference => reference.Name))
                {
                    Trace.WriteLine($"    {("\"" + reference.Name + "\""),-70} \"{reference.File}\"");
                    //if (reference.File == null)
                    //    Trace.WriteLine($"    \"{reference.Name}\"");
                    //else if (reference.ProjectReference)
                    //    //Trace.WriteLine($"    \"{reference.Name}\" \"{reference.File}\" project \"{reference.ProjectReference}\"");
                    //    Trace.WriteLine($"    \"{reference.Name,-70}\" \"{reference.File}\"");
                    //else
                    //    Trace.WriteLine($"    \"{reference.Name,-70}\" \"{reference.File}\"");
                }
                Trace.WriteLine("  project references");
                foreach (VSReference reference in vsProjectManager.GetReferences().Where(reference => reference.ProjectReference).OrderBy(reference => reference.Name))
                {
                    Trace.WriteLine($"    {("\"" + reference.Name + "\""),-70} \"{reference.File}\"");
                }
            }
            finally
            {
                //RunSourceCommand.TraceRemoveWriter("trace");
                //RunSourceCommand.TraceEnableViewer();
                RunSourceCommand.TraceManager.RemoveWriter("trace");
                RunSourceCommand.TraceManager.EnableViewer();
            }
        }
Beispiel #23
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;
            }
        }
Beispiel #24
0
        //public static void UpdateVSProject(string runsourceProject = null, string vsProject = null, VSProjectUpdateOptions options = VSProjectUpdateOptions.None)
        //public static void UpdateVSProject(string runsourceProject = null, VSProjectUpdateOptions options = VSProjectUpdateOptions.None)
        //{
        //    //if (runsourceProjects != null)
        //    //{
        //    //    //runsourceProject = RunSourceCommand.GetFilePath(RunSourceCommand.GetProjectVariableValue(runsourceProject));
        //    //    List<string> projects = new List<string>();
        //    //    foreach (string runsourceProject in runsourceProjects)
        //    //        projects.Add(RunSourceCommand.GetFilePath(RunSourceCommand.GetProjectVariableValue(runsourceProject)));
        //    //    runsourceProjects = projects;
        //    //}
        //    //else
        //    //    runsourceProjects = new string[] { RunSourceCommand.GetCurrentProject() };

        //    if (runsourceProject != null)
        //        runsourceProject = RunSourceCommand.GetFilePath(RunSourceCommand.GetProjectVariableValue(runsourceProject));
        //    else
        //        runsourceProject = RunSourceCommand.GetCurrentProject();


        //    //string vsProject = GetVSProject(runsourceProject);
        //    //if (vsProject != null)
        //    //    vsProject = RunSourceCommand.GetFilePath(RunSourceCommand.GetProjectVariableValue(vsProject));
        //    //else
        //    //    vsProject = GetVSProject(runsourceProjects.First());

        //    options |= VSProjectUpdateOptions.BackupVSProject;


        //    //RunSourceVSProjectManager.UpdateVSProject(vsProject, runsourceProjects, options);
        //    //RunSourceVSProjectManager.UpdateVSProject(runsourceProject, options);
        //    new RunSourceVSProjectManager().UpdateVSProject(runsourceProject, options);
        //}

        //public static void TraceRunSourceProject(string runsourceProject = null, bool traceProjectName = false)
        public static void TraceRunSourceProject(IEnumerable <string> runsourceProjects = null, bool traceProjectName = false)
        {
            if (runsourceProjects != null)
            {
                //runsourceProject = RunSourceCommand.GetFilePath(RunSourceCommand.GetProjectVariableValue(runsourceProject));
                List <string> projects = new List <string>();
                foreach (string runsourceProject in runsourceProjects)
                {
                    projects.Add(RunSourceCommand.GetFilePath(RunSourceCommand.GetProjectVariableValue(runsourceProject)));
                }
                runsourceProjects = projects;
            }
            else
            {
                runsourceProjects = new string[] { RunSourceCommand.GetCurrentProject() }
            };

            foreach (string runsourceProject in runsourceProjects)
            {
                if (!zFile.Exists(runsourceProject))
                {
                    Trace.WriteLine($"runsource project not found \"{runsourceProject}\"");
                    return;
                }
            }

            try
            {
                //RunSourceCommand.TraceDisableViewer();
                //RunSourceCommand.TraceSetWriter(WriteToFile.Create(zPath.Combine(zPath.GetDirectoryName(runsourceProject), zPath.GetFileNameWithoutExtension(runsourceProject) + ".trace.txt"), FileOption.RazFile), "trace");
                RunSourceCommand.TraceManager.DisableViewer();
                string project = runsourceProjects.First();
                RunSourceCommand.TraceManager.SetWriter(WriteToFile.Create(zPath.Combine(zPath.GetDirectoryName(project), zPath.GetFileNameWithoutExtension(project) + ".trace.txt"), FileOption.RazFile), "trace");

                //Trace.WriteLine($"runsource project \"{runsourceProject}\"");
                Trace.WriteLine($"runsource project {runsourceProjects.zToStringValues(runsourceProject => "\"" + zPath.GetFileName(runsourceProject) + "\"")}");

                //CompilerProjectReader runsourceProjectReader = CompilerProjectReader.Create(new XmlConfig(runsourceProject).GetConfigElement("/AssemblyProject"));
                List <CompilerProjectReader> runsourceProjectsReaders = new List <CompilerProjectReader>();
                foreach (string runsourceProject in runsourceProjects)
                {
                    runsourceProjectsReaders.Add(CompilerProjectReader.Create(new XmlConfig(runsourceProject).GetConfigElement("/AssemblyProject")));
                }

                Trace.WriteLine("  sources");
                foreach (RunSourceSource source in RunSourceVSProjectManager.GetRunSourceSources(runsourceProjectsReaders).OrderBy(source => source.RelativePath))
                {
                    //Trace.WriteLine($"    file \"{sourceLink.File}\" link \"{sourceLink.Link}\"");
                    //Trace.WriteLine($"    file \"{source.File}\" relative path \"{source.RelativePath}\" ({zPath.GetFileName(source.ProjectFile)})");
                    if (traceProjectName)
                    {
                        Trace.WriteLine($"    {("\"" + source.RelativePath + "\""),-140} ({zPath.GetFileName(source.ProjectFile)})");
                    }
                    else
                    {
                        Trace.WriteLine($"    {("\"" + source.RelativePath + "\"")}");
                    }
                }
                Trace.WriteLine("  sources links");
                foreach (RunSourceSource source in RunSourceVSProjectManager.GetRunSourceSourcesLinks(runsourceProjectsReaders).OrderBy(source => source.RelativePath))
                {
                    //Trace.WriteLine($"    file \"{sourceLink.File}\" link \"{sourceLink.Link}\"");
                    //Trace.WriteLine($"    file \"{source.File}\" relative path \"{source.RelativePath}\" ({zPath.GetFileName(source.ProjectFile)})");
                    if (traceProjectName)
                    {
                        Trace.WriteLine($"    {("\"" + source.RelativePath + "\""),-140} ({zPath.GetFileName(source.ProjectFile)})");
                    }
                    else
                    {
                        Trace.WriteLine($"    {("\"" + source.RelativePath + "\"")}");
                    }
                }
                Trace.WriteLine("  framework references");
                foreach (RunSourceReference reference in RunSourceVSProjectManager.GetRunSourceAssemblies(runsourceProjectsReaders).Where(reference => reference.FrameworkAssembly).OrderBy(reference => reference.Name))
                {
                    //Trace.WriteLine($"    file \"{assembly.File}\"{(assembly.FrameworkAssembly ? " (framework assembly)" : "")}{(assembly.RunSourceAssembly ? " (runsource assembly)" : "")} ({zPath.GetFileName(assembly.Project.ProjectFile)})");
                    //Trace.WriteLine($"    {("\"" + assembly.Name + "\""),-70} {(assembly.RelativePath != null ? "\"" + assembly.RelativePath + "\"" : ""),-140} {(assembly.FrameworkAssembly ? " (framework assembly)" : "")}{(assembly.RunSourceAssembly ? " (runsource assembly)" : "")} ({zPath.GetFileName(assembly.ProjectFile)})");
                    if (traceProjectName)
                    {
                        Trace.WriteLine($"    {("\"" + reference.Name + "\""),-70} ({zPath.GetFileName(reference.ProjectFile)})");
                    }
                    else
                    {
                        Trace.WriteLine($"    {("\"" + reference.Name + "\"")}");
                    }
                }
                Trace.WriteLine("  dll references");
                foreach (RunSourceReference assembly in RunSourceVSProjectManager.GetRunSourceAssemblies(runsourceProjectsReaders).Where(reference => !reference.FrameworkAssembly && !reference.RunSourceAssembly).OrderBy(reference => reference.Name))
                {
                    if (traceProjectName)
                    {
                        Trace.WriteLine($"    {("\"" + assembly.Name + "\""),-70} {("\"" + assembly.RelativePath + "\""),-140} ({zPath.GetFileName(assembly.ProjectFile)})");
                    }
                    else
                    {
                        Trace.WriteLine($"    {("\"" + assembly.Name + "\""),-70} {("\"" + assembly.RelativePath + "\"")}");
                    }
                }
                Trace.WriteLine("  runsource references");
                foreach (RunSourceReference assembly in RunSourceVSProjectManager.GetRunSourceAssemblies(runsourceProjectsReaders).Where(reference => reference.RunSourceAssembly).OrderBy(reference => reference.Name))
                {
                    if (traceProjectName)
                    {
                        Trace.WriteLine($"    {("\"" + assembly.Name + "\""),-70} {("\"" + assembly.RelativePath + "\""),-140} ({zPath.GetFileName(assembly.ProjectFile)})");
                    }
                    else
                    {
                        Trace.WriteLine($"    {("\"" + assembly.Name + "\""),-70} {("\"" + assembly.RelativePath + "\"")}");
                    }
                }
            }
            finally
            {
                //RunSourceCommand.TraceRemoveWriter("trace");
                //RunSourceCommand.TraceEnableViewer();
                RunSourceCommand.TraceManager.RemoveWriter("trace");
                RunSourceCommand.TraceManager.EnableViewer();
            }
        }
Beispiel #25
0
 public static WriteToFile GetLogWriter()
 {
     return(WriteToFile.Create(@"c:\pib\dev_data\exe\runsource\test\_log\_log.txt", FileOption.IndexedFile));
 }