Esempio n. 1
0
            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
                }
            }
Esempio n. 2
0
            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
                }
            }