static public void SaveAsMd(PetljaTask pt, string rootFolder, string testsFolder) { string folderName; string fileName = "\\text"; if (pt.Id > 50000) { folderName = pt.Id.ToString(); } else { folderName = pt.RefId.ToString(); fileName += pt.Lang; } fileName += ".md"; string cleanFileName = String.Join("", folderName.Split(Path.GetInvalidFileNameChars())); string path = Path.Combine(rootFolder, cleanFileName); bool exists = System.IO.Directory.Exists(path); if (!exists) { System.IO.Directory.CreateDirectory(path); } string destFolder = path; path += fileName; String TextMd = "---\ntitle: " + pt.Title + "\ntimelimit: " + pt.TimeLimit.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture) + "\nmemlimit: " + pt.MemLimit.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture) + "\nowner: " + pt.Owner + "\norigin: " + pt.Origin + "\ntags: " + pt.Tags + "\nsolutions: " + pt.Solutions + "\nstatus: " + pt.Status + "\nstatus-od: " + pt.StatusOd + "\n---\n"; TextMd += pt.Text; if (!File.Exists(path)) { File.WriteAllText(path, TextMd); } CopyTestFiles(pt, destFolder, testsFolder); }
static public void CopyTestFiles(PetljaTask pt, string destFolder, string testsFolder) { if (Directory.Exists(testsFolder + "\\" + pt.Title)) { foreach (string newPath in Directory.GetFiles((testsFolder + "\\" + pt.Title), "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace((testsFolder + "\\" + pt.Title), destFolder), true); } } else if (Directory.Exists(testsFolder + "\\" + "t" + pt.Id)) { foreach (string newPath in Directory.GetFiles((testsFolder + "\\t" + pt.Id), "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace((testsFolder + "\\t" + pt.Id), destFolder), true); } } }
static public PetljaTask ToPetlja(ZTrainingTask ztTask) { PetljaTask pt = new PetljaTask(); pt.Id = ztTask.Id; pt.RefId = ztTask.FullName; pt.Title = ztTask.Name; pt.TimeLimit = ((double)ztTask.TimeLimit) / 1000; //miliS to S pt.MemLimit = ((double)ztTask.MemoryLimit) / 1048576; //B to MB //pt.Owner = pt.Origin = "Z Trening " + ztTask.Source + " URL:" + ztTask.SourceUrl; //pt.Tags = //pt.Solutions = pt.Status = "KANDIDAT"; pt.StatusOd = "Year:" + ztTask.Year; pt.Lang = ztTask.Type_id; pt.Text = ToMdTextFormat(ztTask.Text); return(pt); }