private void ServerOnCallReceived(RemoteHostInfo remoteHostInfo, EventCallArgs eventCallArgs) { var callInfo = eventCallArgs.CallInfo; if (callInfo.TargetDeviceCode != MyCode) { return; } CallType type = callInfo.CallType; switch (type) { case CallType.Call: Call recall = new Call(DateTime.Now, MyCode, CallType.Recall, callInfo.DeviceCode); Sender.OnCall(remoteHostInfo, new EventCallArgs(recall)); break; case CallType.Recall: break; case CallType.WakeUp: break; case CallType.Ready: break; case CallType.Sleep: break; default: throw new ArgumentOutOfRangeException(); } }
public void OnCall(RemoteHostInfo remoteHost, EventCallArgs args) { Logger.Debug($"Invoked OnCall for {remoteHost.Host} via {remoteHost.Protocol} file {args.CallInfo}"); string message = Serializing.GetString(args.CallInfo); OnSend(this, new EventDataArg <string>(remoteHost, message)); }
public void WaitRecallTest() { //1 AddressBook = new AddressBook(); TimeSpan timeOut = new TimeSpan(0, 0, 10); var serverMoq = new MassageParserMoq(); string code = RndString(); RemoteHostInfo hostInfo = RndRemoteHostInfo(); Call call = RndCall(CallType.Recall, code); EventCallArgs arg = new EventCallArgs(call); Server = serverMoq; string ip = null; //2 var task = Task.Run(() => WaitRecall(code, timeOut, out ip)); Task.Delay(new TimeSpan(0, 0, 3)).Wait(); serverMoq.CallReceivedInvoke(hostInfo, arg); task.Wait(); //3 Assert.AreEqual(task.Result, ConnectionResult.Successful); Assert.AreEqual(ip, hostInfo.Host); }
//TODO заменить протокол на энам protected override ConnectionResult WakeUp(string ip, string deviceCode) { var remoteInfo = new RemoteHostInfo(ip, UdpProtocol); var wakeUpMessage = new Call(DateTime.Now, MyCode, CallType.WakeUp, deviceCode); var arg = new EventCallArgs(wakeUpMessage); Sender.OnCall(remoteInfo, arg); return(WaitReady(deviceCode, _timeOut)); }
protected override ConnectionResult GetIp(string deviceCode, TimeSpan timeOut, out string ip) { var remoteInfo = new RemoteHostInfo(_multicastHost, UdpProtocol); var wakeUpMessage = new Call(DateTime.Now, MyCode, CallType.Call, deviceCode); var arg = new EventCallArgs(wakeUpMessage); Sender.OnCall(remoteInfo, arg); return(WaitRecall(deviceCode, _timeOut, out ip)); }
public void CallReceivedInvoke(RemoteHostInfo hostInfo, EventCallArgs args) => CallReceived?.Invoke(hostInfo, args);
public void OnCall(RemoteHostInfo remoteHost, EventCallArgs args) { }