public RemotePipeLogger(RemoteControlProtocol p, string path, params string[] logPipeNames) { _logPipeNames = new List<string> (logPipeNames); _path = path; p.PipeData += HandlerPipeData; foreach (string pipeName in logPipeNames) p.RemoteRequestPipe (pipeName); }
public void SendCommand(RemoteControlProtocol r) { RemoteProcessInfo[] processes = null; ManualResetEvent evt = new ManualResetEvent (false); r.RemoteProcessInfo += delegate(RemoteProcessInfo[] lProcesses) { processes = lProcesses; evt.Set (); }; SimpleFormatter f = new SimpleFormatter (); f.OnGetParameter += delegate(string parameterName) { KeyValuePair<string, string>? keyP = StringHelper.SplitToKeyValue (parameterName, "|"); if (keyP == null) throw new ArgumentException ("Invalid variable speciication"); switch (keyP.Value.Key) { case "remote-pid": if (processes == null) { r.RemoteProcesses (); evt.WaitOne (); } RemoteProcessInfo procInfo = FindProcess (processes, keyP.Value.Value); if (procInfo == null) throw new ArgumentException (string.Format ("Could not find process '{0}'", keyP.Value.Value)); return procInfo.Pid.ToString (); default: throw new NotSupportedException ("The specified variable is not supported"); } }; string newCmd = f.Format (_cmd.Path); List<string> newArgs = new List<string> (); foreach (string arg in _cmd.Args) newArgs.Add (f.Format (arg)); List<string> newEnv = new List<string> (); foreach (String env in _cmd.EnvP) newEnv.Add (f.Format (env)); r.SendCommand (new RemoteExecCommand (_cmd.Name, newCmd, newArgs, newEnv)); }
/// <summary> /// Initializes the remote control and extracts the commands to execute /// from the configuration file /// </summary> private void InitRemote() { if (_remoteControlProtocol != null) { _remoteControlProtocol.Dispose (); _remoteControlProtocol = null; } XmlElement remoteControlNode = (XmlElement)_doc.DocumentElement.SelectSingleNode ("RemoteControl"); //remote control is not mandatory, but strongly recommended. //Without remote control there is no way to capture remote memory allocations //and therefore a lot information to analyze gets lost if (remoteControlNode != null) { _remoteControlProtocol = new RemoteControlProtocol (); _remoteControlProtocol.SetConnection (RemoteControlConnectionBuilder.Connect ( _formatter.Format (XmlHelper.ReadString (remoteControlNode, "Host")), int.Parse (_formatter.Format (XmlHelper.ReadString (remoteControlNode, "Port"))))); _remoteControlProtocol.ExecStatus += Handle_remoteControlProtocolExecStatus; foreach (XmlElement execNode in remoteControlNode.SelectNodes ("Exec")) { ExecutionTriggerEnum execTrigger = (ExecutionTriggerEnum)Enum.Parse (typeof(ExecutionTriggerEnum), execNode.GetAttribute ("trigger"), true); string cmd = XmlFactoryHelpers.GenerateFilename (_configDir, XmlHelper.ReadString (execNode, "Cmd"), _formatter); if(cmd == null) throw new ArgumentException("Exec node without cmd"); List<string> arguments = new List<string>(XmlHelper.ReadStringArray(execNode, "Arg")); List<string> environment = new List<string>(XmlHelper.ReadStringArray(execNode, "Env")); for(int i = 0; i<arguments.Count; i++) arguments[i] = _formatter.Format(arguments[i]); for(int i = 0; i<environment.Count; i++) environment[i] = _formatter.Format(environment[i]); if(_triggeredExecutions.ContainsKey(execTrigger) == false) _triggeredExecutions[execTrigger] = new List<RemoteExecCommand>(); _triggeredExecutions[execTrigger].Add( new RemoteExecCommand(cmd, cmd, arguments, environment)); } RemoteExec(ExecutionTriggerEnum.Immediate); } }