コード例 #1
0
        private void StartPlot(TempDirConfig tempDirConfig)
        {
            RunningPlot runningPlot = new RunningPlot()
            {
                InternalId = Guid.NewGuid(),
                TempDir    = tempDirConfig.Path
            };

            //runningPlot.Temp2Path = tempDirConfig.Temp2Path;
            //runningPlot.FinalPath = tempDirConfig.FinalPath;
            runningPlot.LogPath = _config.LogPath;
            //runningPlot.PlotSize = tempDirConfig.PlotSize ??_config.DefaultPlotSize ?? null;
            //runningPlot.Buffer = tempDirConfig.Buffer ??_config.DefaultBuffer ?? null;
            //runningPlot.NumThreads = tempDirConfig.NumThreads ?? _config.DefaultNumThreads ?? null;
            //runningPlot.Buckets = tempDirConfig.Buckets ?? _config.DefaultBuckets ?? null;



            _runningPlots.Add(runningPlot);

            _plotInfos.TryAdd(runningPlot.InternalId, new PlotInfo());

            Thread t = new Thread(new ParameterizedThreadStart(ExecutePlotThread));

            t.Start(runningPlot);

            _threads.Add(runningPlot.InternalId, t);
        }
コード例 #2
0
        private void ExecutePlotThread(object prms)
        {
            RunningPlot runningPlot = (RunningPlot)prms;

            string cmd = @"C:\code\plottracker\src\PlotTracker\MockPlot\bin\Debug\net5.0\MockPlot.exe";

            StringBuilder sbArgs = new StringBuilder();

            sbArgs.Append("plots create ");

            if (runningPlot.PlotSize.HasValue)
            {
                sbArgs.Append($"-k {runningPlot.PlotSize} ");
            }

            if (runningPlot.Buffer.HasValue)
            {
                sbArgs.Append($"-b {runningPlot.Buffer} ");
            }

            if (runningPlot.Buckets.HasValue)
            {
                sbArgs.Append($"-u {runningPlot.Buckets} ");
            }

            if (runningPlot.NumThreads.HasValue)
            {
                sbArgs.Append($"-u {runningPlot.NumThreads} ");
            }

            sbArgs.Append($"-t \"{runningPlot.TempDir}\" ");
            Directory.CreateDirectory(runningPlot.TempDir);

            if (!string.IsNullOrWhiteSpace(runningPlot.Temp2Path))
            {
                sbArgs.Append($"-2 \"{runningPlot.Temp2Path}\" ");
                Directory.CreateDirectory(runningPlot.Temp2Path);
            }

            sbArgs.Append($"-d \"{runningPlot.FinalPath}\" ");
            Directory.CreateDirectory(runningPlot.FinalPath);

            Directory.CreateDirectory(runningPlot.LogPath);

            Process p = new Process();

            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName  = cmd;
            p.StartInfo.Arguments = sbArgs.ToString().Trim();

            p.OutputDataReceived += new DataReceivedEventHandler((s, e) =>
            {
                if (string.IsNullOrWhiteSpace(e.Data))
                {
                    return;
                }

                PlotInfo plotInfo;
                _plotInfos.TryGetValue(runningPlot.InternalId, out plotInfo);

                //LogParser.ParseLine(e.Data, ref plotInfo);

                _plotInfos.AddOrUpdate(runningPlot.InternalId, plotInfo, (key, existingVal) =>
                {
                    return(plotInfo);
                });

                if (!string.IsNullOrEmpty(plotInfo.Id))
                {
                    string logFilename = Path.Combine(runningPlot.LogPath, $"{plotInfo.Id}.log");
                    using (StreamWriter writer = new StreamWriter(logFilename, true))
                    {
                        writer.WriteLine(e.Data);
                    }
                }
            });

            p.Start();
            p.BeginOutputReadLine();
            p.WaitForExit();
        }