protected override CommandResult ProcessXmppMessage(string message) { LookInstruction infoResult; try { infoResult = LookInstruction.Parse(message); } catch (Exception e) { return(CreateError($"Can't parse {CmdName} instruction output: got exception \n{e}\n{message}")); } if (!string.IsNullOrEmpty(infoResult.Error)) { return(CreateError(infoResult.Error)); } TextOutput updateResult; try { updateResult = SyncNodeInfo(infoResult.Node); } catch (Exception e) { return(CreateError($"Command {CmdName} failed. Can't sync node {infoResult.Node.Name} to net: \n{e}\n{message}")); } CommandResult result = CreateOutput(new TextOutput(Verbosity, message), CommandState.Finished); result.Output.Add(updateResult); return(result); }
public void SendMessage(string message) { if (message.StartsWith("target")) { if (message.Split(' ').Length > 1) { _target = message.Split(' ')[1]; string netPath = $"Server//Data//{_target}.xml"; _network = Serializer.DeserializeNet(netPath); } EmulateResponse("ok"); //404 target system:2739100 not found } else if (message.StartsWith("status")) { EmulateResponse(StatusInstruction.Assemble($"{_user}@{_domain}", string.IsNullOrEmpty(_target)?"none":_target, _admSystem, _proxyLevel, _visibleAs)); } else if (message.StartsWith("info")) { string codeStr = message.Replace("info #", ""); long softCode; string incorrectProgMessage = @"-------------------- incorrect program #{0} END----------------"; if (!long.TryParse(codeStr, out softCode)) { EmulateResponse(string.Format(incorrectProgMessage, codeStr)); } else { Structure.Software libSoft; if (!_softwareLib.All.TryGetValue(softCode, out libSoft)) { EmulateResponse(string.Format(incorrectProgMessage, codeStr)); return; } //soft found EmulateResponse(InfoInstruction.Assemble(libSoft)); } } else if (message.StartsWith("look")) { //todo: check errors string nodeName = message.Replace("look ", ""); Node node; if (_network == null) { EmulateResponse("network not found"); } if (!_network.Nodes.TryGetValue(nodeName, out node)) { EmulateResponse($@"-------------------- {_network.Name} / {nodeName}: not available END----------------"); } else { string response = LookInstruction.AssembleAccessible(_network.Name, node); EmulateResponse(response); } } else if (message.StartsWith("#")) { EmulateResponse("Not implemented"); } else { EmulateResponse("command no found"); } }