static void DoFileWrite(string path, File.Background b) { CodeTask.RunOneThing(path, b); if (Context.saveAllPngs) { string filename = Path.ChangeExtension(Path.Combine(path, b.Name), ".png"); // we just have one b.Frame.Image.Save(filename); } }
static void DoFileWrite(string path, File.AudioFile s) { CodeTask.RunOneThing(path, s); if (s.Data == null) { return; } string filename = Path.ChangeExtension(Path.Combine(path, s.Name), s.extension); using (FileStream fs = new FileStream(filename, FileMode.Create)) s.Data.CopyTo(fs); }
static void DoFileWrite(string path, File.Font f) { CodeTask.RunOneThing(path, f); if (Context.saveAllPngs) { string filename = Path.ChangeExtension(Path.Combine(path, f.Name), ".fnt"); // we just have one BMFontWriter.SaveAsBMFont(filename, f); // f.Frame.Image.Save(filename); } }
static AllWriter() { chunkActions = new Dictionary <string, Action <List <CodeTask> > >(); chunkActions["code"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.Create("code", File.Codes, DoFileWrite)); chunkActions["textures"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.Create("textures", File.Textures, DoFileWrite)); chunkActions["objects"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.Create("objects", File.Objects, DoFileWrite)); chunkActions["scripts"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.Create("scripts", File.Scripts, DoFileWrite)); chunkActions["sprites"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.Create("sprites", File.Sprites, DoFileWrite)); chunkActions["rooms"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.Create("rooms", File.Rooms, DoFileWrite)); chunkActions["backgrounds"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.Create("backgrounds", File.Backgrounds, DoFileWrite)); chunkActions["sounds"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.Create("sounds", File.Sounds, DoFileWrite)); chunkActions["fonts"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.Create("fonts", File.Fonts, DoFileWrite)); chunkActions["paths"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.Create("fonts", File.Fonts, DoFileWrite)); chunkActions["strings"] = (List <CodeTask> tasks) => tasks.Add(CodeTask.CreateSingle("String List", () => DoStrings("strings"))); }
public static CodeTask CreateSingle <T>(string path_name, string task_name, T o, Action <string, T> action) where T : File.GameMakerStructure { if (Context.doThreads) { CodeTask ct = new CodeTask(); ct.Name = task_name; ct.TotalTasks = 1; ct.Task = new Task(() => action(path_name, o)); return(ct); } else { action(path_name, o); return(null); } }
public static CodeTask CreateSingle(string task_name, Action action) { if (Context.doThreads) { CodeTask ct = new CodeTask(); ct.Name = task_name; ct.TotalTasks = 1; ct.Task = new Task(action); return(ct); } else { action(); return(null); } }
public async Task <CodeTask> CreateAsync(CodeTaskDto model) { var codeTask = new CodeTask { Name = model.Name, Description = model.Description, InitialCode = model.InitialCode, Points = model.Points, Module = await _context.Modules.FindAsync(model.ModuleId) }; _context.CodeTasks.Add(codeTask); await _context.SaveChangesAsync(); return(codeTask); }
public static CodeTask Create <T>(string path_name, string task_name, IReadOnlyList <T> list, Action <string, T> action) where T : File.GameMakerStructure { DateTime start = DateTime.Now; task_name = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(task_name.ToLower()); var path = Context.DeleteAllAndCreateDirectory(path_name); if (Context.doThreads) { CodeTask ct = new CodeTask(); ct.Name = task_name; ct.TotalTasks = list.Count; ct.Task = new Task(() => { int tasksDone = 0; int tasksTotal = list.Count; ParallelOptions opts = new ParallelOptions(); Parallel.ForEach(list, opts, (T o) => { lock (o) action(path, o); Interlocked.Increment(ref tasksDone); ct.Report(tasksDone); }); Context.Message("{0} finished in {1}", task_name, DateTime.Now - start); ct._alldone = true; }, TaskCreationOptions.LongRunning); return(ct); } else { using (var progress = new ProgressBar(task_name)) { ErrorContext.ProgressBar = progress; for (int i = 0; i < list.Count; i++) { var o = list[i]; action(path, o); progress.Report((double)i + 1 / list.Count); } ErrorContext.ProgressBar = null; } Context.Message("{0} finished in {1}", task_name, DateTime.Now - start); return(null); // no task as its done } }
static void DoFileWrite(string path, File.Sprite s) { CodeTask.RunOneThing(path, s); if (Context.saveAllPngs) { if (s.Frames.Length == 0) { return; } else if (s.Frames.Length == 1) { string filename = Path.ChangeExtension(Path.Combine(path, s.Name), ".png"); // we just have one s.Frames[0].Image.Save(filename); } else // we want to cycle though them all { for (int i = 0; i < s.Frames.Length; i++) { string filename = Path.ChangeExtension(Path.Combine(path, s.Name + "_" + i), ".png"); // we just have one s.Frames[i].Image.Save(filename); } } } if (Context.saveAllMasks) { if (s.Masks.Count == 0) { return; } else if (s.Masks.Count == 1) { string filename = Path.ChangeExtension(Path.Combine(path, s.Name + "_mask"), ".png"); // we just have one s.Masks[0].Save(filename); } else { for (int i = 0; i < s.Masks.Count; i++) { string filename = Path.ChangeExtension(Path.Combine(path, s.Name + "_mask_" + i), ".png"); // we just have one s.Masks[i].Save(filename); } } } }
static void DoFileWrite(string path, File.Room room) { if (room.code_offset > 0 && room.Room_Code == null) // fill in room init { room.Room_Code = AllWriter.QuickCodeToLine(File.Codes[room.code_offset]); } foreach (var oi in room.Objects) // fill in instance init { if (oi.Code_Offset > 0 && oi.Room_Code == null) { oi.Room_Code = AllWriter.QuickCodeToLine(File.Codes[oi.Code_Offset]); } if (oi.Object_Index > -1 && oi.Object_Name == null) { oi.Object_Name = File.Objects[oi.Object_Index].Name; } } CodeTask.RunOneThing(path, room); }
public static CodeTask Create <T>(string path_name, string task_name, IReadOnlyList <T> list, Action <string, IReadOnlyList <T>, IProgress <double> > action) where T : File.GameMakerStructure { DateTime start = DateTime.Now; task_name = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(task_name.ToLower()); var path = Context.DeleteAllAndCreateDirectory(path_name); if (Context.doThreads) { CodeTask ct = new CodeTask(); ct.Name = task_name; ct.TotalTasks = 1; ct.Task = new Task(() => { lock (list) { action(path_name, list, ct); ct.Report(1); } Context.Message("{0} finished in {1}", task_name, DateTime.Now - start); ct._alldone = true; }, TaskCreationOptions.LongRunning); return(ct); } else { using (var progress = new ProgressBar(task_name)) { ErrorContext.ProgressBar = progress; action(path, list, progress); ErrorContext.ProgressBar = null; } Context.Message("{0} finished in {1}", task_name, DateTime.Now - start); return(null); // no task as its done } }
public static void AddUpdateLuceneIndex(CodeTask sampleData) { AddUpdateLuceneIndex(new List<CodeTask> { sampleData }); }
private static void _addToLuceneIndex(CodeTask codeTask, IndexWriter writer) { // remove older index entry var searchQuery = new TermQuery(new Term("Id", codeTask.CodeTaskId.ToString())); writer.DeleteDocuments(searchQuery); // add new index entry var doc = new Document(); // add lucene fields mapped to db fields doc.Add(new Field("Id", codeTask.CodeTaskId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field("Name", codeTask.Name, Field.Store.YES, Field.Index.ANALYZED)); // add entry to index writer.AddDocument(doc); }
public void FinishProcessing() { if (Context.oneFile) { CodeTask.RunOneThing("sprites", File.Sprites); CodeTask.RunOneThing("rooms", File.Rooms); CodeTask.RunOneThing("objects", File.Objects); CodeTask.RunOneThing("backgrounds", File.Backgrounds); CodeTask.RunOneThing("sounds", File.Sounds); CodeTask.RunOneThing("paths", File.Paths); CodeTask.RunOneThing("fonts", File.Fonts); CodeTask.RunOneThing("strings", File.Strings); } if (!Context.doThreads) { return; } if (_todo != null && _todo.Count > 0) { // ok, we have the jobs start them all up! foreach (var t in _todo) { t.Task.Start(); } using (var progress = new ProgressBar()) { ErrorContext.ProgressBar = progress; int totalTasks = _todo.Count; int tasksDone = 0; // foreach (var ct in _todo) totalTasks += ct.TotalTasks; while (tasksDone < totalTasks) { totalTasks = 0; tasksDone = 0; for (int i = _todo.Count - 1; i >= 0; i--) { var ct = _todo[i]; if (ct != null) { if (ct.Task.IsFaulted) { ExceptionHandler(ct.Name, ct.Task); Context.FatalError("Fatal exception in task"); } if (ct.Task.IsCompleted) { _todo.RemoveAt(i); } else { totalTasks += ct.TotalTasks; tasksDone += ct.TasksFinished; } } else { _todo.RemoveAt(i); } } if (totalTasks > 0) { progress.Report((double)tasksDone / totalTasks); } Thread.Sleep(50); } ; } ErrorContext.ProgressBar = null; } }
static void DoFileWrite(string path, File.Path p) { CodeTask.RunOneThing(path, p); }
public async Task Remove(CodeTask codeTask) { _context.CodeTasks.Remove(codeTask); await _context.SaveChangesAsync(); }