public void SearchInstruments(SearchRequest searchRequest, OnSearchResponse searchCallback, OnFailure onFailure) { try { SearchResponseHandler handler = new SearchResponseHandler(); Response response = _httpInvoker.GetInSession(_baseUri, searchRequest, _xmlParser, handler, _sessionId); if (response.IsOk) { if (handler.IsOk) { searchCallback(handler.Instruments, handler.HasMoreResults); } else { onFailure(new FailureResponse(false, handler.Message, "", null)); } } else { onFailure(new FailureResponse(true, "HttpStatus: " + response.Status + ", for: " + _baseUri + searchRequest.Uri)); } } catch (Exception e) { onFailure(new FailureResponse(e, "URI: " + _baseUri + searchRequest.Uri)); } }
public void SearchInstruments(SearchRequest searchRequest, OnSearchResponse searchCallback, OnFailure onFailure) { try { SearchResponseHandler searchResponseHandler = new SearchResponseHandler(); Response inSession = this._httpInvoker.GetInSession(this._baseUri, (IRequest)searchRequest, this._xmlParser, (Handler)searchResponseHandler, this._sessionId); if (inSession.IsOk) { if (searchResponseHandler.IsOk) { searchCallback(searchResponseHandler.Instruments, searchResponseHandler.HasMoreResults); } else { onFailure(new FailureResponse(false, searchResponseHandler.Message, "", (Exception)null)); } } else { onFailure(new FailureResponse(true, "HttpStatus: " + (object)inSession.Status + ", for: " + this._baseUri + searchRequest.Uri)); } } catch (Exception ex) { onFailure(new FailureResponse(ex, "URI: " + this._baseUri + searchRequest.Uri)); } }
/// <summary> /// Called when [search]. /// </summary> /// <param name="Target_Directory">The target directory.</param> /// <param name="Search_Pattern">The search pattern.</param> /// <param name="Include_Sub_Directory">The include sub directory.</param> /// <param name="Filter_Query">The filter query.</param> /// <returns>OnSearchResponse object.if successful return a list of file match with Filter_Query and Search_Pattern(if no error and no file find return empty list) else return error</returns> public OnSearchResponse OnSearch(string Target_Directory, string Search_Pattern, int Include_Sub_Directory, string Filter_Query = "1=1") { OnSearchResponse ROnSearchResponse = new OnSearchResponse(); ROnSearchResponse.Target_Directory = Target_Directory; ROnSearchResponse.Search_Pattern = Search_Pattern; try { DirectoryInfo dir = new DirectoryInfo(Target_Directory); IEnumerable <System.IO.FileInfo> fileList = dir.GetFiles(Search_Pattern, (SearchOption)Include_Sub_Directory); var query = fileList.Where(Filter_Query); foreach (FileInfo file in query) { ROnSearchResponse.Paths.Add(file.FullName); } } catch (Exception ex) { ROnSearchResponse.Errors.AddErrorToErrorList(MethodBase.GetCurrentMethod().ToString(), ex.Message); } return(ROnSearchResponse); }
private void ProcessReceivingMessages(UdpClient _udpClient) { Debug.WriteLine("Höre jetzt auf: " + (_udpClient.Client.LocalEndPoint as IPEndPoint).Port); Task.Run(async() => { int rofl = 0; try { while (!StopProcessing) { rofl++; var result = await _udpClient.ReceiveAsync(); var knxResponse = _receiveParserDispatcher.Build(result.Buffer); //if(!(knxResponse is SearchResponse)) // Debug.WriteLine("Telegram angekommen: " + knxResponse?.ToString()); switch (knxResponse) { case ConnectStateResponse connectStateResponse: Debug.WriteLine("Connection State Response: " + connectStateResponse.Status.ToString()); switch (connectStateResponse.Status) { case 0x00: IsConnected = true; ConnectionChanged?.Invoke(IsConnected); break; default: Debug.WriteLine("Connection State: Fehler: " + connectStateResponse.Status.ToString()); LastError = ConnectionErrors.NotConnectedToBus; IsConnected = false; ConnectionChanged?.Invoke(IsConnected); break; } break; case ConnectResponse connectResponse: _flagCRRecieved = true; switch (connectResponse.Status) { case 0x00: _sequenceCounter = 0; _communicationChannel = connectResponse.CommunicationChannel; IsConnected = true; ConnectionChanged?.Invoke(IsConnected); PhysicalAddress = connectResponse.ConnectionResponseDataBlock.KnxAddress; Debug.WriteLine("Connected: Eigene Adresse: " + PhysicalAddress.ToString()); break; default: Debug.WriteLine("Connected: Fehler: " + connectResponse.Status.ToString()); LastError = ConnectionErrors.Undefined; IsConnected = false; ConnectionChanged?.Invoke(IsConnected); break; } break; case Builders.TunnelResponse tunnelResponse: if (tunnelResponse.IsRequest && tunnelResponse.DestinationAddress != PhysicalAddress) { Debug.WriteLine("Telegram erhalten das nicht mit der Adresse selbst zu tun hat!"); Debug.WriteLine("Typ: " + tunnelResponse.APCI); Debug.WriteLine("Eigene Adresse: " + PhysicalAddress.ToString()); break; } _sendMessages.Add(new Responses.TunnelResponse(0x06, 0x10, 0x0A, 0x04, _communicationChannel, tunnelResponse.SequenceCounter, 0x00).GetBytes()); //Debug.WriteLine("Telegram APCI: " + tunnelResponse.APCI.ToString()); if (tunnelResponse.APCI.ToString().EndsWith("Response")) { List <byte> data = new List <byte>() { 0x11, 0x00 }; TunnelRequest builder = new TunnelRequest(); builder.Build(UnicastAddress.FromString("0.0.0"), tunnelResponse.SourceAddress, ApciTypes.Ack, tunnelResponse.SequenceNumber); data.AddRange(builder.GetBytes()); _ = Send(data.ToArray(), _sequenceCounter); _sequenceCounter++; //Debug.WriteLine("Got Response " + tunnelResponse.SequenceCounter + " . " + tunnelResponse.SequenceNumber); } else if (tunnelResponse.APCI == ApciTypes.Ack) { OnTunnelAck?.Invoke(new MsgAckRes() { ChannelId = tunnelResponse.CommunicationChannel, SequenceCounter = tunnelResponse.SequenceCounter, SequenceNumber = tunnelResponse.SequenceNumber, SourceAddress = tunnelResponse.SourceAddress, DestinationAddress = tunnelResponse.DestinationAddress }); break; } List <string> temp = new List <string>(); var q = from t in Assembly.GetExecutingAssembly().GetTypes() where t.IsClass && t.IsNested == false && (t.Namespace == "Kaenx.Konnect.Messages.Response" || t.Namespace == "Kaenx.Konnect.Messages.Request") select t; IMessage message = null; foreach (Type t in q.ToList()) { IMessage resp = (IMessage)Activator.CreateInstance(t); if (resp.ApciType == tunnelResponse.APCI) { message = resp; break; } } if (message == null) { //throw new Exception("Kein MessageParser für den APCI " + tunnelResponse.APCI); message = new MsgDefaultRes() { ApciType = tunnelResponse.APCI }; Debug.WriteLine("Kein MessageParser für den APCI " + tunnelResponse.APCI); } message.Raw = tunnelResponse.Data; message.ChannelId = tunnelResponse.CommunicationChannel; message.SequenceCounter = tunnelResponse.SequenceCounter; message.SequenceNumber = tunnelResponse.SequenceNumber; message.SourceAddress = tunnelResponse.SourceAddress; message.DestinationAddress = tunnelResponse.DestinationAddress; switch (CurrentType) { case ProtocolTypes.cEmi: message.ParseDataCemi(); break; case ProtocolTypes.Emi1: message.ParseDataEmi1(); break; case ProtocolTypes.Emi2: message.ParseDataEmi2(); break; default: throw new NotImplementedException("Unbekanntes Protokoll - TunnelResponse KnxIpTunneling"); } if (tunnelResponse.APCI.ToString().EndsWith("Response")) { OnTunnelResponse?.Invoke(message as IMessageResponse); } else { OnTunnelRequest?.Invoke(message as IMessageRequest); } break; case SearchResponse searchResponse: MsgSearchRes msg = new MsgSearchRes(searchResponse.responseBytes); switch (CurrentType) { case ProtocolTypes.cEmi: msg.ParseDataCemi(); break; case ProtocolTypes.Emi1: msg.ParseDataEmi1(); break; case ProtocolTypes.Emi2: msg.ParseDataEmi2(); break; default: throw new NotImplementedException("Unbekanntes Protokoll - SearchResponse KnxIpTunneling"); } OnSearchResponse?.Invoke(msg); break; case TunnelAckResponse tunnelAck: //Do nothing break; case DisconnectResponse disconnectResponse: IsConnected = false; _communicationChannel = 0; ConnectionChanged?.Invoke(IsConnected); break; } } Debug.WriteLine("Stopped Processing Messages " + _udpClient.Client.LocalEndPoint.ToString()); _udpClient.Close(); _udpClient.Dispose(); } catch { } }); }