Last-Modified: Sat, 01 Aug 2026 06:32:03 GMT Expires: Tue, 29 Jul 2036 06:32:03 GMT JobsModule.cs « Tango.PPC.Jobs « Modules « PPC « Visual_Studio « Software - Tango - Twine softwares
aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/JobsModule.cs
blob: 73b0760f23a5189254ec19b97f5ae13666d1361f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using Tango.BL.Enumerations;
using Tango.PPC.Common;
using Tango.PPC.Jobs.Views;
using Tango.SharedUI.Helpers;

namespace Tango.PPC.Jobs
{
    /// <summary>
    /// Represents the PPC jobs module
    /// </summary>
    /// <seealso cref="Tango.PPC.Common.PPCModuleBase" />
    [PPCModule(1, nameof(JobsView))]
    public class JobsModule : PPCModuleBase
    {
        /// <summary>
        /// Gets the module name.
        /// </summary>
        public override string Name
        {
            get
            {
                return "Jobs";
            }
        }

        /// <summary>
        /// Gets the module description.
        /// </summary>
        public override string Description
        {
            get
            {
                return "Manage and run jobs";
            }
        }

        /// <summary>
        /// Gets the module cover image.
        /// </summary>
        public override BitmapSource Image
        {
            get
            {
                return ResourceHelper.GetImageFromResources("Images/jobs-module.png");
            }
        }

        /// <summary>
        /// Gets the module entry point view type.
        /// </summary>
        public override Type MainViewType
        {
            get
            {
                return typeof(MainView);
            }
        }

        /// <summary>
        /// Gets the permission required to see and load this module.
        /// </summary>
        public override Permissions Permission
        {
            get
            {
                return Permissions.RunPPCJobsModule;
            }
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public override void Dispose()
        {

        }
    }
}
>return CreateResult(parsedCommand.Arguments, String.Empty); } else if (Directory.Exists(Path.Combine(request.WorkingFolder, parsedCommand.Arguments))) { return CreateResult(Path.GetFullPath(Path.Combine(request.WorkingFolder, parsedCommand.Arguments)), String.Empty); } else { return CreateResult(null, "The directory does not exists."); } } String output = String.Empty; String error = String.Empty; var process = new Process(); process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; if (request.RunAsAdministrator) { process.StartInfo.Verb = "runas"; } if (request.WorkingFolder != null) { process.StartInfo.WorkingDirectory = request.WorkingFolder; } if (ConsoleDictionary.GetKnownCommands().Exists(x => x.Name.ToLower() == parsedCommand.Command.ToLower())) { process.StartInfo.FileName = "cmd.exe"; process.StartInfo.Arguments = "/C " + request.Command; } else { process.StartInfo.FileName = parsedCommand.Command; process.StartInfo.Arguments = parsedCommand.Arguments; } process.Start(); bool hasGuid = false; try { process.WaitForInputIdle(5000); hasGuid = true; } catch { } if (!hasGuid) { output = process.StandardOutput.ReadToEnd(); error = process.StandardError.ReadToEnd(); } return CreateResult(request.WorkingFolder, String.IsNullOrWhiteSpace(error) ? output.Replace(request.WorkingFolder + ">", "") : error); }); } public static List<ConsoleSuggestion> GetSuggestions(String folder) { List<ConsoleSuggestion> suggestions = new List<ConsoleSuggestion>(); foreach (var dir in Directory.GetDirectories(Path.GetFullPath(folder))) { suggestions.Add(new ConsoleSuggestion() { Type = ConsoleSuggestionType.Folder, Name = Path.GetFileName(dir) }); } foreach (var file in Directory.GetFiles(Path.GetFullPath(folder))) { suggestions.Add(new ConsoleSuggestion() { Type = ConsoleSuggestionType.File, Name = Path.GetFileName(file), }); } return suggestions; } private ConsoleCommandExecutionResult CreateResult(String workingFolder, String output) { ConsoleCommandExecutionResult result = new ConsoleCommandExecutionResult(); result.WorkingFolder = workingFolder; result.Output = output; result.Suggestions.AddRange(GetSuggestions(workingFolder)); return result; } } }