Пример #1
0
        protected internal void RunJob(Job job, int stepNumber = 0)
        {
            lock (_runningLock)
            {
                if (Running.Count >= MaxConcurrentJobs)
                {
                    _runCompleteSignal.WaitOne();
                }

                job.WorkerException += (o, a) =>
                {
                    OnWorkerException(job.CurrentWorkState);
                };
                job.WorkerStarting += (o, a) =>
                {
                    OnWorkerStarting(job.CurrentWorkState);
                };
                job.WorkerFinished += (o, a) =>
                {
                    OnWorkerFinished(job.CurrentWorkState);
                };
                job.JobFinished += (o, a) =>
                {
                    OnJobFinished(job.CurrentWorkState);
                };
                Running.Add(job);
            }

            job.StepNumber = stepNumber;
            job.Run();
        }
Пример #2
0
        public void ReadyToRunning()
        {
            Process p = this.HighestPriority();

            if (p == null || Ready.Count == 0)
            {
                //Console.WriteLine("No ready process.");
            }
            else
            {
                p.Status = "Running";
                p.CPU_usage++;
                Ready.Remove(p);
                Running.Add(p);
                //Console.WriteLine("ReadyToRunning");
                //Console.WriteLine("Process status: " + p.Status);
                //Console.WriteLine("Running count: "+Running.Count);
            }
        }
Пример #3
0
        async void doStart(CommandArgs e)
        {
            if (e.Parameters.Count == 0)
            {
                e.Player.SendErrorMessage($"Invalid syntax! Proper syntax: {Commands.Specifier}timeline start <file> [params...]");
                return;
            }

            string filePath = e.Parameters[0];

            if (!e.Player.CanUseTimeline(filePath))
            {
                e.Player.SendErrorMessage("You don't have access to this timeline.");
                return;
            }

            string path = Path.Combine(TShock.SavePath, filePath.EndsWith(".txt") ? filePath : $"{filePath}.txt");

            if (!File.Exists(path))
            {
                e.Player.SendErrorMessage($"'{filePath}' doesn't exist.");
                return;
            }

            string name = Path.GetFileNameWithoutExtension(filePath);

            if (Running.Exists(t => t.Name.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                e.Player.SendErrorMessage($"'{name}' is already running.");
                return;
            }

            string data;

            try
            {
                data = File.ReadAllText(path);
            }
            catch (Exception ex)
            {
                e.Player.SendErrorMessage($"Timeline loading failed: {ex.Message}");
                return;
            }

            // Remove the file name
            e.Parameters.RemoveAt(0);
            Timeline timeline = new Timeline(name, data, e.Parameters);

            try
            {
                // Process the timeline and handle all exceptions
                e.Player.SendInfoMessage("Processing timeline...");
                await timeline.Start();

                timeline.Finished += (o, a) => Running.Remove(timeline);
                Running.Add(timeline);

                e.Player.SendSuccessMessage($"{name} started.");
            }
            catch (EmptyTimelineException)
            {
                e.Player.SendErrorMessage($"'{name}' must contain at least one command.");
            }
            catch (MissingParameterException ex)
            {
                e.Player.SendInfoMessage($"'{name}' syntax: {Commands.Specifier}timeline start {name} {ex.Message}");
            }
            catch (CannotRunException ex)
            {
                e.Player.SendErrorMessage(
                    $"Error processing timeline '{name}' at line {ex.Line}: Cannot run {Commands.Specifier}{ex.Command} as the server.");
            }
            catch (TimelineException ex)
            {
                e.Player.SendErrorMessage($"Error processing timeline '{name}' at line {ex.Line}: {ex.Message}");
            }
        }