private void referencedDirCall() { ShellCmd sc = new ShellCmd("dir"); sc.Output.ToConsole(); sc.Error.ToConsole(); }
private void CheckPermission(IXenConnection xenConnection) { ShellCmd cmd = _menuItemFeature.ShellCmd; RbacMethodList methodsToCheck = cmd.RequiredMethods.Count == 0 ? _menuItemFeature.GetMethodList(cmd.RequiredMethodList) : cmd.RequiredMethods; if (methodsToCheck == null || xenConnection.Session == null || xenConnection.Session.IsLocalSuperuser) { return; } log.DebugFormat("Checking Plugin can run against connection {0}", xenConnection.Name); List <Role> rolesAbleToCompleteAction; bool ableToCompleteAction = Role.CanPerform(methodsToCheck, xenConnection, out rolesAbleToCompleteAction); log.DebugFormat("Roles able to complete action: {0}", Role.FriendlyCSVRoleList(rolesAbleToCompleteAction)); log.DebugFormat("Subject {0} has roles: {1}", xenConnection.Session.UserLogName(), Role.FriendlyCSVRoleList(xenConnection.Session.Roles)); if (ableToCompleteAction) { log.Debug("Subject authorized to complete action"); return; } // Can't run on this connection, bail out string desc = string.Format(FriendlyErrorNames.RBAC_PERMISSION_DENIED_FRIENDLY_CONNECTION, xenConnection.Session.FriendlyRoleDescription(), Role.FriendlyCSVRoleList(rolesAbleToCompleteAction), xenConnection.Name); throw new Exception(desc); }
public bool AddCmd(ShellCmd cmd) { lock (ShellCmdLock) { try { ICmd newcmd; switch (Mw.ChipName) { default: newcmd = null; break; } if (!Cmd.Add(newcmd)) { return(false); } Cmd.Start(); return(true); } catch (Exception ex) { Log.error("添加命令失败!错误消息:" + ex.Message); return(false); } // TODO /*if (IsExclusiveMode) return false; * ShellCmdQueue.Enqueue(cmd); * return true;*/ } }
protected override void ReadThread(object state) { lock (ShellCmdLock) { if (ShellCmdQueue.Count > 0) { ShellCmd CurrentCmd = ShellCmdQueue.Peek(); if (CurrentCmd.TryAnalysisReslut()) { if (ShellCmdQueue.Count > 0) { ShellCmdQueue.Dequeue(); } if (IsExclusiveMode && ShellCmdQueue.Count == 0) { Log.info("========== 命令组 [" + CurrentCmd.GroupID + "] 执行完成 =========="); Log.info("开始时间: " + CurrentCmd.StartCmdTime.ToString("yyyy-MM-dd HH:mm:ss.fff")); Log.info("停止时间: " + CurrentCmd.ReadTime.ToString("yyyy-MM-dd HH:mm:ss.fff")); Log.info("执行时长: " + (((int)(CurrentCmd.ReadTime - CurrentCmd.StartCmdTime).TotalMilliseconds) * 0.001).ToString() + " 秒!"); IsExclusiveMode = false; } else if (IsExclusiveMode && ShellCmdQueue.Peek().GroupID == CurrentCmd.GroupID) { ShellCmdQueue.Peek().StartCmdTime = CurrentCmd.StartCmdTime; } else if (IsExclusiveMode) { Log.error("未知情景,退出命令独占状态!"); IsExclusiveMode = false; } } } } }
public async Task EchoTest() { var shell = new ShellCmd(); Assert.Equal("hi", (await shell.GetOutputAsync("echo hi")).Trim()); var expected = "^\"'"; var command = "echo" + CmdHelpers.GetEchoArguments(expected); Assert.Equal(expected, (await shell.GetOutputAsync(command)).Trim()); }
public bool AddCmd(ShellCmd cmd, string groupID) { lock (ShellCmdLock) { if (IsExclusiveMode && ShellCmdQueue.Count > 0 && ShellCmdQueue.Peek().GroupID == groupID) { cmd.GroupID = groupID; ShellCmdQueue.Enqueue(cmd); return(true); } else if (!IsExclusiveMode && ShellCmdQueue.Count == 0) { cmd.GroupID = groupID; cmd.IsStartCmd = true; ShellCmdQueue.Enqueue(cmd); IsExclusiveMode = true; return(true); } else { return(false); } } }
private void simpleDirCall() { var output = ShellCmd.Invoke("dir"); }
public void ShellCmd_Obj_Test() { ShellCmd sc = new ShellCmd("dir"); sc.Output.ToConsole(); }
public void ShellCmd_Invoke_Test() { ShellCmd.Invoke("dir").ToConsole(); }