public void TestProcessMockSession() { var objDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); var startup = new ProcessConfig { ProcessName = Path.Combine(objDir, "MockWs3270.exe"), ConnectRetryMsec = 50 }; // Try a successful start. var session = new ProcessSession(startup); var result = session.Start(); Assert.AreEqual(true, result.Success); session.Close(); // Exercise some bad command-line options. startup.TestFirstOptions = "-baz"; result = session.Start(); Assert.AreEqual(false, result.Success); startup.TestFirstOptions = "-scriptport 12345678"; result = session.Start(); Assert.AreEqual(false, result.Success); }
public InstructionItem(ProcessSession processSession, UInt64 BaseAddress, String moduleName, String instruction, Byte[] instructionBytes) : base(processSession, DataTypeBase.ByteArray, "New Instruction") { this.ModuleOffset = BaseAddress; this.ModuleName = moduleName; this.Instruction = instruction; this.InstructionBytes = instructionBytes; }
public ProcessSession GetSession(long id) { ProcessSession processSession = (from session in dbContext.ProcessSessions.Include(s => s.WorkerConnection) where session.Id == id select session).SingleOrDefault(); return(processSession); }
public void TestEmptyHistory() { var session = new ProcessSession(); Assert.AreEqual(null, session.LastCommand); var emptyIoResult = new IoResult[0]; Assert.AreEqual(emptyIoResult, session.RecentCommands); Assert.AreEqual(null, session.StatusLine); }
public void TestArgsTooLong() { var config = new ProcessConfig { ProcessName = "MockWs3270.exe", ExtraOptions = Enumerable.Range(1, 11000).Select(x => new ProcessOptionWithoutValue("x")) }; var session = new ProcessSession(config); Assert.Throws <InvalidOperationException>(() => session.Start()); }
public UserActivity Create(ProcessSession processSession, IGame game) { return(new UserActivity { UserActivityId = Guid.Id <UserActivity> .NewId(), GameId = game.GameId, AssignedToDate = AssignDateRangeToDateStrategy.DetermineAssignedDate(processSession.StartTime, processSession.EndTime), StartTime = processSession.StartTime, EndTime = processSession.EndTime, ProcessSessionId = processSession.ProcessSessionId, }); }
public void TestNoSuchProcess() { var startup = new ProcessConfig { ProcessName = "MockWs3270NoSuch.exe" }; var session = new ProcessSession(startup); var startResult = session.Start(); Assert.AreEqual(false, startResult.Success); }
public ProcessSession StartNewSession(string userId, long appId) { ProcessSession session = new ProcessSession() { State = SessionState.NotStarted, CreatorId = userId, App = dbContext.AppDefinitions.Find(appId), }; dbContext.ProcessSessions.Add(session); dbContext.SaveChanges(); return(session); }
public async Task ClientSendOutput(ClientSendOutputArguments args) { await HubOperation(nameof(ClientSendCommand), args, async() => { ProcessSession session = sessionManager.GetSession(args.SessionId); var user = Context.User; if (session.CanSendCommands(user.GetUserId())) { await Clients.GroupExcept(session.GroupName, Context.ConnectionId).SendAsync("AddMessage", args.Output); } }); }
public bool TryCreateActivity(ProcessSession processSession, out UserActivity userActivity) { if (!_gameMatcher.TryMatch(processSession.FilePath, out var matchedGame)) { userActivity = null; Log.Debug("Failed to match {FilePath}", processSession.FilePath); return(false); } userActivity = _userActivityFactory.Create(processSession, matchedGame); Log.Debug("Created user activity for game {GameId}.", matchedGame.GameId); SystemTrayForm.ShowBalloonInfo($"Played {matchedGame.Name} for {(processSession.EndTime - processSession.StartTime).HumanReadable()}."); return(true); }
public async Task ClientSendCommand(ExecuteProcessCommandArguments args) { await HubOperation(nameof(ClientSendCommand), args, async() => { ProcessSession session = sessionManager.GetSession(args.SessionId); var user = Context.User; if (session.CanSendCommands(user.GetUserId())) { await Clients.GroupExcept(session.GroupName, Context.ConnectionId).SendAsync("AddMessage", args.Command); var workerContext = GetWorkerContext(session.WorkerConnection); await workerContext.ExecuteProcessCommand(args); } }); }
/// <summary> /// Initializes a new instance of the <see cref="AddressItem" /> class. /// </summary> /// <param name="baseAddress">The base address. This will be added as an offset from the resolved base identifier.</param> /// <param name="dataType">The data type of the value at this address.</param> /// <param name="description">The description of this address.</param> /// <param name="moduleName">The identifier for the base address of this object.</param> /// <param name="pointerOffsets">The pointer offsets of this address item.</param> /// <param name="isValueHex">A value indicating whether the value at this address should be displayed as hex.</param> /// <param name="value">The value at this address. If none provided, it will be figured out later. Used here to allow immediate view updates upon creation.</param> public PointerItem( ProcessSession processSession, UInt64 baseAddress, Type dataType, String description = "New Address", String moduleName = null, IEnumerable <Int32> pointerOffsets = null, Boolean isValueHex = false, Object value = null) : base(processSession, dataType, description, isValueHex, value) { // Bypass setters to avoid running setter code this.moduleOffset = baseAddress; this.moduleName = moduleName; this.pointerOffsets = pointerOffsets; }
/// <summary> /// Main method. /// </summary> /// <param name="args">Command line arguments.</param> public static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage: TrivialConsoleApp <hostname>"); Environment.Exit(1); } var session = new ProcessSession(); var startResult = session.Start(); if (!startResult.Success) { Console.WriteLine("Start failed: {0}", startResult.FailReason); session.Close(); Environment.Exit(1); } var ioResult = session.Connect(args[0]); if (!ioResult.Success) { Console.WriteLine("Connect failed: {0}", ioResult.Result[0]); session.Close(); Environment.Exit(1); } ioResult = session.Wait(WaitMode.InputField); if (!ioResult.Success) { Console.WriteLine("Wait failed: {0}", ioResult.Result[0]); session.Close(); Environment.Exit(1); } ioResult = session.Ascii(); if (!ioResult.Success) { Console.WriteLine("Ascii failed: {0}", ioResult.Result[0]); session.Close(); Environment.Exit(1); } Console.Write(string.Join("\n", ioResult.Result)); session.Close(); }
public async Task WorkerSendOutput(WorkerSendOutputArguments args) { await HubOperation(nameof(WorkerSendOutput), args, async() => { ProcessSession session = sessionManager.GetSession(args.SessionId); if (session.CanSendOutput(Context.ConnectionId)) { if (args.ConnectionId == null) { await Clients.Group(session.GroupName).SendAsync("AddMessage", args.Text); } else { await Clients.Client(args.ConnectionId).SendAsync("AddMessage", args.Text); } } }); }
/// <summary> /// Initializes a new instance of the <see cref="AddressItem" /> class. /// </summary> /// <param name="processSession">The process session used to resolve addresses and values.</param> /// <param name="dataType">The data type of the value at this address.</param> /// <param name="description">The description of this address.</param> /// <param name="isValueHex">A value indicating whether the value at this address should be displayed as hex.</param> /// <param name="value">The value at this address. If none provided, it will be figured out later. Used here to allow immediate view updates upon creation.</param> public AddressItem( ProcessSession processSession, DataTypeBase dataType, String description = "New Address", Boolean isValueHex = false, Object value = null) : base(description) { // Bypass setters to avoid running setter code this.processSession = processSession; this.dataType = dataType; this.isValueHex = isValueHex; if (!this.isValueHex && SyntaxChecker.CanParseValue(dataType, value?.ToString())) { this.addressValue = value; } else if (this.isValueHex && SyntaxChecker.CanParseHex(dataType, value?.ToString())) { this.addressValue = value; } }
public async Task ClientJoinSession(long sessionId) { await HubOperation(nameof(ClientJoinSession), sessionId, async() => { ProcessSession session = sessionManager.GetSession(sessionId); var user = userManager.GetUserById(Context.User.GetUserId()); await Groups.AddToGroupAsync(Context.ConnectionId, session.GroupName); _ = Clients.Group(session.GroupName).SendAsync("AddSystemMessage", $"Użytkownik {user.DisplayName} dołączył do sesji."); if (session.State == SessionState.NotStarted) { _ = Clients.Group(session.GroupName).SendAsync("AddSystemMessage", "Rozpoczynanie procesu zdalnego."); WorkerConnection worker = workerManager.GetAvaliableWorker(session.App.Name); StartProcessArguments args = new StartProcessArguments() { UserName = user.Email, SessionId = session.Id, ApplicationName = session.App.Name, UserId = user.Id, }; dynamic workerSignalR = GetWorkerContext(worker); await workerSignalR.StartProcess(args); session.State = SessionState.Active; session.WorkerConnection = worker; session.WorkerConnectionId = worker.Id; sessionManager.Update(session); } else { await Clients.Client(session.WorkerConnection.ConnectionId).SendAsync("GetProcessOutput", new GetProcessOutputArguments() { SessionId = sessionId, ConnectionId = Context.ConnectionId, }); } }); }
public void TestExpandHostName() { // Start out with an X3270if session with no options, hence no default connect flags. var emulator = new ProcessSession(); // Trivial version, does nothing. var s = emulator.ExpandHostName("host", null, null, ConnectFlags.None); Assert.AreEqual("host", s); // Make the host quotable. s = emulator.ExpandHostName("a:b::27", null, null, ConnectFlags.None); Assert.AreEqual("[a:b::27]", s); // Add a port. s = emulator.ExpandHostName("host", "port", null, ConnectFlags.None); Assert.AreEqual("host:port", s); // Add some LUs. s = emulator.ExpandHostName("host", null, new string[] { "lu1", "lu2" }, ConnectFlags.None); Assert.AreEqual("\"lu1,lu2@host\"", s); // Add some options. s = emulator.ExpandHostName("host", null, null, ConnectFlags.Secure); Assert.AreEqual("L:host", s); // Combine options, LUs and a port. // This is a little bit tricky to test, because the connect flags can appear in any order. // Otherwise, the order of the elements is fixed. s = emulator.ExpandHostName("1::2", "port", new string[] { "lu1", "lu2" }, ConnectFlags.Secure | ConnectFlags.NonTN3270E); Assert.IsTrue(s.StartsWith("\"")); Assert.IsTrue(s.EndsWith("\"")); s = s.Substring(1, s.Length - 2); const string LogicalUnitHostPort = "lu1,lu2@[1::2]:port"; Assert.IsTrue(s.EndsWith(LogicalUnitHostPort)); var flags = s.Substring(0, s.Length - LogicalUnitHostPort.Length); Assert.AreEqual(4, flags.Length); Assert.IsTrue(flags.Contains("L:")); Assert.IsTrue(flags.Contains("N:")); // Try all of the connect flags. s = emulator.ExpandHostName("host", null, null, ConnectFlags.All); const string LogicalUnitHostPort2 = "host"; Assert.IsTrue(s.EndsWith(LogicalUnitHostPort2)); flags = s.Substring(0, s.Length - LogicalUnitHostPort2.Length); Assert.AreEqual(12, flags.Length); Assert.IsTrue(flags.Contains("C:")); Assert.IsTrue(flags.Contains("L:")); Assert.IsTrue(flags.Contains("N:")); Assert.IsTrue(flags.Contains("P:")); Assert.IsTrue(flags.Contains("S:")); Assert.IsTrue(flags.Contains("B:")); // Try a session with non-default connect flags. var portEmulator = new PortSession(new PortConfig { AutoStart = false, DefaultConnectFlags = ConnectFlags.Secure }); s = portEmulator.ExpandHostName("host", null, null, ConnectFlags.None); Assert.AreEqual("L:host", s); // Make sure the specific connect flags override the defaults (and are not ORed in). s = portEmulator.ExpandHostName("host", null, null, ConnectFlags.NonTN3270E); Assert.AreEqual("N:host", s); // Check the exceptions thrown on bad hostname, port, and LU. Assert.Throws <ArgumentException>(() => portEmulator.ExpandHostName("host/wrong")); Assert.Throws <ArgumentException>(() => portEmulator.ExpandHostName("host@wrong")); Assert.Throws <ArgumentException>(() => portEmulator.ExpandHostName("host", "port/wrong")); Assert.Throws <ArgumentException>(() => portEmulator.ExpandHostName("host", "port:wrong")); Assert.Throws <ArgumentException>(() => portEmulator.ExpandHostName("host", "port.wrong")); Assert.Throws <ArgumentException>(() => portEmulator.ExpandHostName("host", "port@wrong")); Assert.Throws <ArgumentException>(() => portEmulator.ExpandHostName("host", lus: new string[] { "lu/wrong" })); Assert.Throws <ArgumentException>(() => portEmulator.ExpandHostName("host", lus: new string[] { "lu-okay", "lu:wrong" })); Assert.Throws <ArgumentException>(() => portEmulator.ExpandHostName("host", lus: new string[] { "lu@wrong" })); Assert.DoesNotThrow(() => portEmulator.ExpandHostName("123:456::1.2.3.4")); Assert.DoesNotThrow(() => portEmulator.ExpandHostName("host-okay")); Assert.DoesNotThrow(() => portEmulator.ExpandHostName("host_okay")); Assert.DoesNotThrow(() => portEmulator.ExpandHostName("host", "port-okay")); Assert.DoesNotThrow(() => portEmulator.ExpandHostName("host", "port_okay")); Assert.DoesNotThrow(() => portEmulator.ExpandHostName("host", lus: new string[] { "lu.okay" })); Assert.DoesNotThrow(() => portEmulator.ExpandHostName("host", lus: new string[] { "lu-okay" })); Assert.DoesNotThrow(() => portEmulator.ExpandHostName("host", lus: new string[] { "lu_okay" })); Assert.DoesNotThrow(() => portEmulator.ExpandHostName("года.ru")); Assert.DoesNotThrow(() => emulator.ExpandHostName("六.cn")); }
public InstructionItem(ProcessSession processSession) : this(processSession, 0, null, null, null) { }
/// <summary> /// Initializes a new instance of the <see cref="AddressItem" /> class. /// </summary> public AddressItem(ProcessSession processSession) : this(processSession, DataTypeBase.Int32, "New Address") { }
/// <summary> /// Initializes a new instance of the <see cref="AddressItem" /> class. /// </summary> public PointerItem(ProcessSession processSession) : this(processSession, 0, DataTypeBase.Int32, "New Address") { }
public void Update(ProcessSession session) { dbContext.Entry(session).State = EntityState.Modified; dbContext.SaveChanges(); }
public JavaItem(ProcessSession processSession) : base(processSession) { }
public DotNetItem(ProcessSession processSession, String name, Type type, String identifier) : base(processSession, type, name) { this.Identifier = identifier; }
public DotNetItem(ProcessSession processSession) : base(processSession) { }