コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: InstructionItem.cs プロジェクト: ilikemlik/Squalr
 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;
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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());
        }
コード例 #6
0
 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,
     });
 }
コード例 #7
0
        public void TestNoSuchProcess()
        {
            var startup = new ProcessConfig
            {
                ProcessName = "MockWs3270NoSuch.exe"
            };
            var session = new ProcessSession(startup);

            var startResult = session.Start();

            Assert.AreEqual(false, startResult.Success);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: AppsHub.cs プロジェクト: punio7/WebCrawler
        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);
                }
            });
        }
コード例 #10
0
        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);
        }
コード例 #11
0
ファイル: AppsHub.cs プロジェクト: punio7/WebCrawler
        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);
                }
            });
        }
コード例 #12
0
ファイル: PointerItem.cs プロジェクト: ilikemlik/Squalr
 /// <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;
 }
コード例 #13
0
        /// <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();
        }
コード例 #14
0
ファイル: AppsHub.cs プロジェクト: punio7/WebCrawler
        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);
                    }
                }
            });
        }
コード例 #15
0
ファイル: AddressItem.cs プロジェクト: ilikemlik/Squalr
        /// <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;
            }
        }
コード例 #16
0
ファイル: AppsHub.cs プロジェクト: punio7/WebCrawler
        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,
                    });
                }
            });
        }
コード例 #17
0
        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"));
        }
コード例 #18
0
ファイル: InstructionItem.cs プロジェクト: ilikemlik/Squalr
 public InstructionItem(ProcessSession processSession) : this(processSession, 0, null, null, null)
 {
 }
コード例 #19
0
ファイル: AddressItem.cs プロジェクト: ilikemlik/Squalr
 /// <summary>
 /// Initializes a new instance of the <see cref="AddressItem" /> class.
 /// </summary>
 public AddressItem(ProcessSession processSession) : this(processSession, DataTypeBase.Int32, "New Address")
 {
 }
コード例 #20
0
ファイル: PointerItem.cs プロジェクト: ilikemlik/Squalr
 /// <summary>
 /// Initializes a new instance of the <see cref="AddressItem" /> class.
 /// </summary>
 public PointerItem(ProcessSession processSession) : this(processSession, 0, DataTypeBase.Int32, "New Address")
 {
 }
コード例 #21
0
 public void Update(ProcessSession session)
 {
     dbContext.Entry(session).State = EntityState.Modified;
     dbContext.SaveChanges();
 }
コード例 #22
0
ファイル: JavaItem.cs プロジェクト: ilikemlik/Squalr
 public JavaItem(ProcessSession processSession) : base(processSession)
 {
 }
コード例 #23
0
 public DotNetItem(ProcessSession processSession, String name, Type type, String identifier) : base(processSession, type, name)
 {
     this.Identifier = identifier;
 }
コード例 #24
0
 public DotNetItem(ProcessSession processSession) : base(processSession)
 {
 }