public DiscoverableServiceHandlingOperativeDefs.DiscoverableServiceDefinition FindService(string ServiceNameToFind) { try { BroadCasting.Data.BroadCastRepliesContainer replies = default(BroadCasting.Data.BroadCastRepliesContainer); replies = this._DataBroadcastClient.BroadCastDataAndWaitOneFirstReply(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME_QUERY_BROADCAST_ID_NAME_STRING, DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME, ServiceNameToFind, TIME_OUT_SECONDS); if (replies.Count > 0) { //evaluates if the reply contains the reply from the service searched if (replies.ContainsReplyIDName(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME_QUERY_REPLYIDNAME_STRING)) { BroadCasting.Data.BroadCastReply STXSErviceReply = default(BroadCasting.Data.BroadCastReply); STXSErviceReply = replies.Item(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME_QUERY_REPLYIDNAME_STRING); //evaluates for the service parameters table attached with the data name specified //by the constant SERVICE_PARAMETERS_TABLE if (STXSErviceReply.DataName == DiscoverableServiceHandlingOperativeDefs.SERVICE_PARAMETERS_TABLE) { CustomHashTable paramsTable = (CustomHashTable)STXSErviceReply.Value; DiscoverableServiceDefinitionParametersContainer serviceParams = new DiscoverableServiceDefinitionParametersContainer(paramsTable); DiscoverableServiceHandlingOperativeDefs.DiscoverableServiceDefinition serviceDEfiniton = new DiscoverableServiceHandlingOperativeDefs.DiscoverableServiceDefinition(); DiscoverableServiceParameter param = default(DiscoverableServiceParameter); //retrieves the service name from the parameters list //and removes it from the parameters list param = serviceParams.GetParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME); if (param == null) { throw (new DiscoverableServiceDefinitionHandlingException(ServiceNameToFind, DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME)); } serviceDEfiniton.ServiceName = param.Value; serviceParams.RemoveParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME); //retrieves the service id from the parameters table and removes it param = serviceParams.GetParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_ID); if (param == null) { throw (new DiscoverableServiceDefinitionHandlingException(ServiceNameToFind, DiscoverableServiceHandlingOperativeDefs.SERVICE_ID)); } serviceDEfiniton.ServiceIDString = param.Value; serviceParams.RemoveParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_ID); //retrieves the service operation mode param = serviceParams.GetParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_OPERATION_MODE); if (param == null) { throw (new DiscoverableServiceDefinitionHandlingException(ServiceNameToFind, DiscoverableServiceHandlingOperativeDefs.SERVICE_OPERATION_MODE)); } serviceDEfiniton.ServiceOperationMode = DiscoverableServiceHandlingOperativeDefs.GetServiceOperationModeFromString(param.Value); serviceParams.RemoveParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_OPERATION_MODE); serviceDEfiniton.ServiceParameters = serviceParams; return(serviceDEfiniton); } else { throw (new DiscoverableServiceDefinitionHandlingSearchFailureException(ServiceNameToFind)); } } else { throw (new DiscoverableServiceDefinitionHandlingSearchFailureException(ServiceNameToFind)); } } else { throw (new DiscoverableServiceDefinitionHandlingSearchFailureException(ServiceNameToFind)); } } catch (Services.BroadCasting.DataBroadCastWaitReplyException) { throw (new DiscoverableServiceDefinitionHandlingSearchFailureException(ServiceNameToFind)); } catch (Exception) { throw (new DiscoverableServiceDefinitionHandlingSearchFailureException(ServiceNameToFind)); } }
public Services.DiscoverableServiceHandling.Data.DiscoverableServiceDefinitionsContainer DiscoverServicesNumOfInstances(string ServiceNameToFind, int numberOfInstances) { Services.DiscoverableServiceHandling.Data.DiscoverableServiceDefinitionsContainer servicesFoundContainer = new Services.DiscoverableServiceHandling.Data.DiscoverableServiceDefinitionsContainer(); BroadCasting.Data.BroadCastRepliesContainer replies = default(BroadCasting.Data.BroadCastRepliesContainer); try { replies = this._DataBroadcastClient.BroadCastDataAndWaitSpecifiedNumberOfReplies(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME_QUERY_BROADCAST_ID_NAME_STRING, DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME, ServiceNameToFind, numberOfInstances); IEnumerator enumm = replies.GetEnumerator(); BroadCastReply reply = default(BroadCastReply); while (enumm.MoveNext()) { reply = (BroadCastReply)enumm.Current; //evaluates if the reply contains the reply from the service searched if (reply.ReplyIDName == DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME_QUERY_REPLYIDNAME_STRING) { BroadCasting.Data.BroadCastReply STXSErviceReply = default(BroadCasting.Data.BroadCastReply); STXSErviceReply = reply; //evaluates for the service parameters table attached with the data name specified //by the constant SERVICE_PARAMETERS_TABLE if (STXSErviceReply.DataName == DiscoverableServiceHandlingOperativeDefs.SERVICE_PARAMETERS_TABLE) { CustomHashTable paramsTable = (CustomHashTable)STXSErviceReply.Value; DiscoverableServiceDefinitionParametersContainer serviceParams = new DiscoverableServiceDefinitionParametersContainer(paramsTable); DiscoverableServiceHandlingOperativeDefs.DiscoverableServiceDefinition serviceDEfiniton = new DiscoverableServiceHandlingOperativeDefs.DiscoverableServiceDefinition(); DiscoverableServiceParameter param = default(DiscoverableServiceParameter); //retrieves the service name from the parameters list //and removes it from the parameters list param = serviceParams.GetParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME); if (param == null) { throw (new DiscoverableServiceDefinitionHandlingException(ServiceNameToFind, DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME)); } serviceDEfiniton.ServiceName = param.Value; serviceParams.RemoveParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_NAME); //retrieves the service id from the parameters table and removes it param = serviceParams.GetParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_ID); if (param == null) { throw (new DiscoverableServiceDefinitionHandlingException(ServiceNameToFind, DiscoverableServiceHandlingOperativeDefs.SERVICE_ID)); } serviceDEfiniton.ServiceIDString = param.Value; serviceParams.RemoveParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_ID); //retrieves the service operation mode param = serviceParams.GetParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_OPERATION_MODE); if (param == null) { throw (new DiscoverableServiceDefinitionHandlingException(ServiceNameToFind, DiscoverableServiceHandlingOperativeDefs.SERVICE_OPERATION_MODE)); } serviceDEfiniton.ServiceOperationMode = DiscoverableServiceHandlingOperativeDefs.GetServiceOperationModeFromString(param.Value); serviceParams.RemoveParameter(DiscoverableServiceHandlingOperativeDefs.SERVICE_OPERATION_MODE); serviceDEfiniton.ServiceParameters = serviceParams; servicesFoundContainer.AddDefinition(serviceDEfiniton); } } } return(servicesFoundContainer); } catch (Exception) { return(servicesFoundContainer); } }