public void Save(PlotInfo plotInfo) { string filename = GetFilename(plotInfo.Id); string json = JsonConvert.SerializeObject(plotInfo, Formatting.Indented); using (StreamWriter writer = new StreamWriter(filename)) { writer.Write(json); writer.Flush(); writer.Close(); } }
public PlotInfoParser() { PlotInfo = new PlotInfo(); }
private bool CheckShouldStart(List <PlotInfo> allPlotInfos) { var runningPlots = allPlotInfos.Where(p => !p.IsComplete).ToList(); bool tookAction = false; string finalPath = GetFinalDir(runningPlots); Console.WriteLine($"Next final dir to be used: {finalPath}"); int toRemove = _config.CopyPhaseIgnoreCount; for (int i = runningPlots.Count - 1; i >= 0; i--) { if (toRemove == 0) { break; } var cp = runningPlots[i].GetCurrentPlotStatus().CurrentPhase; if (cp == PlotInfo.CopyingStatusText) { Console.WriteLine("Ignoring copying phase for concurrent plot eval"); runningPlots.RemoveAt(i); toRemove--; } } var tempDirs = GetRunningPlotsByTempDir(runningPlots); foreach (var tempDir in tempDirs.OrderBy(p => p.RunningPlotCount).ThenBy(p => p.MostRecentPlotStartDate)) { Console.WriteLine($"{tempDir.TempPath} has {tempDir.RunningPlotCount} running plots (Most recent started at {tempDir.MostRecentPlotStartDate})"); if (tempDir.RunningPlotCount < tempDir.TempDirConfig.ConcurrentPlots) { bool shouldStart = false; PlotInfo mostRecent = null; if (_config.StaggerDelayIsGlobal) { mostRecent = runningPlots.Where(p => p.StartDate.HasValue).OrderByDescending(p => p.StartDate).FirstOrDefault(); } else { mostRecent = tempDir.RunningPlots.Where(p => p.StartDate.HasValue).OrderByDescending(p => p.StartDate).FirstOrDefault(); } if (mostRecent == null) { shouldStart = true; } else { var mostRecentTs = DateTime.Now - mostRecent.StartDate.Value; if (mostRecentTs.TotalSeconds > tempDir.TempDirConfig.StaggerDelaySeconds) { shouldStart = true; } else { var when = new TimeSpan(0, 0, tempDir.TempDirConfig.StaggerDelaySeconds - (int)Math.Round(mostRecentTs.TotalSeconds)); Console.WriteLine($"Will start new plot in {FormatTimespan(when)}"); } } if (IsInMaintenanceWindow()) { return(false); } if (shouldStart) { if (finalPath == null) { Console.WriteLine("No available final dirs with enough space!"); } else { Console.WriteLine("Using final path: " + finalPath); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = tempDir.TempDirConfig.StartCommand; startInfo.Arguments = tempDir.TempDirConfig.StartArgs; startInfo.UseShellExecute = false; startInfo.EnvironmentVariables.Add("TempPath", tempDir.TempDirConfig.Path); startInfo.EnvironmentVariables.Add("LogPath", _config.LogPath); startInfo.EnvironmentVariables.Add("FinalPath", finalPath); Process process = new Process(); process.StartInfo = startInfo; process.Start(); tookAction = true; Thread.Sleep(10000); } } //if (anyInPhase1) //{ // Console.WriteLine("Waiting to start next plot"); //} //else //{ // Console.WriteLine($"Starting plot creation in temp folder: {tempDirConfig.Path}"); // StartPlot(tempDirConfig); //} if (tookAction) { break; // exit loop so currently running plots will be re-evaluated } } else { Console.WriteLine("Concurrent plots met"); } } return(tookAction); }