private void RegisterProtocolHandlers(EtpClient client) { if (Requesting(Protocols.ChannelStreaming, "producer")) { client.Register <IChannelStreamingConsumer, ChannelStreamingConsumerHandler>(); RegisterEventHandlers(client.Handler <IChannelStreamingConsumer>()); } if (Requesting(Protocols.ChannelStreaming, "consumer")) { client.Register <IChannelStreamingProducer, ChannelStreamingProducerHandler>(); RegisterEventHandlers(client.Handler <IChannelStreamingProducer>()); } if (Requesting(Protocols.ChannelDataFrame, "producer")) { client.Register <IChannelDataFrameConsumer, ChannelDataFrameConsumerHandler>(); RegisterEventHandlers(client.Handler <IChannelDataFrameConsumer>()); } if (Requesting(Protocols.ChannelDataFrame, "consumer")) { client.Register <IChannelDataFrameProducer, ChannelDataFrameProducerHandler>(); RegisterEventHandlers(client.Handler <IChannelDataFrameProducer>()); } if (Requesting(Protocols.Discovery, "store")) { client.Register <IDiscoveryCustomer, DiscoveryCustomerHandler>(); RegisterEventHandlers(client.Handler <IDiscoveryCustomer>(), x => x.OnGetResourcesResponse += OnGetResourcesResponse); } if (Requesting(Protocols.Store, "store")) { client.Register <IStoreCustomer, StoreCustomerHandler>(); RegisterEventHandlers(client.Handler <IStoreCustomer>(), x => x.OnObject += OnObject); } if (Requesting(Protocols.StoreNotification, "store")) { client.Register <IStoreNotificationCustomer, StoreNotificationCustomerHandler>(); RegisterEventHandlers(client.Handler <IStoreNotificationCustomer>()); } if (Requesting(Protocols.GrowingObject, "store")) { client.Register <IGrowingObjectCustomer, GrowingObjectCustomerHandler>(); RegisterEventHandlers(client.Handler <IGrowingObjectCustomer>(), x => x.OnObjectFragment += OnObjectFragment); } if (Requesting(Protocols.DataArray, "store")) { client.Register <IDataArrayCustomer, DataArrayCustomerHandler>(); RegisterEventHandlers(client.Handler <IDataArrayCustomer>()); } if (Requesting(Protocols.WitsmlSoap, "store")) { //client.Register<IWitsmlSoapCustomer, WitsmlSoapCustomerHandler>(); //RegisterEventHandlers(client.Handler<IWitsmlSoapCustomer>()); } }
private void Button_Click(object sender, RoutedEventArgs e) { Client = new EtpClient(ServerUrl, "MyPDS", "1.0.0.0"); Client.Register <IDiscoveryCustomer, DiscoveryCustomerHandler>(); RegisterEventHandlers(Client.Handler <IDiscoveryCustomer>(), x => x.OnGetResourcesResponse += OnGetResourcesResponse); Client.Output = LogClientOutput; Client.Open(); //System.Windows.MessageBox.Show(Client.IsOpen.ToString()); }
/// <summary> /// Gets the resources and asserts. /// </summary> /// <param name="uri">The URI.</param> /// <param name="errorCode">The error code.</param> /// <param name="exist">if set to <c>true</c> resources exist; otherwise, <c>false</c>.</param> /// <returns>A collection of resources.</returns> protected async Task <List <ProtocolEventArgs <GetResourcesResponse, string> > > GetResourcesAndAssert(EtpUri uri, EtpErrorCodes?errorCode = null, bool exist = true) { var handler = _client.Handler <IDiscoveryCustomer>(); // Register event handler for GetResourcesResponse var onGetResourcesResponse = HandleMultiPartAsync <GetResourcesResponse, string>( x => handler.OnGetResourcesResponse += x); // Register exception hanlder var onProtocolException = HandleAsync <ProtocolException>(x => handler.OnProtocolException += x); // Send GetResources message for specified URI var messageId = handler.GetResources(uri); List <ProtocolEventArgs <GetResourcesResponse, string> > args = null; var tokenSource = new CancellationTokenSource(); var taskList = new List <Task>() { WaitFor(onGetResourcesResponse, tokenSource.Token), WaitFor(onProtocolException, tokenSource.Token) }; // Start each event taskList.ForEach(task => task.Start()); // Wait for a task to finish await Task.WhenAny(taskList); // Cancel the rest of the task tokenSource.Cancel(); // Wait for the rest to be finished await Task.WhenAll(taskList); if (onGetResourcesResponse.Status == TaskStatus.RanToCompletion) { // Wait for GetResourcesResponse args = await onGetResourcesResponse; Assert.IsNotNull(args); Assert.AreEqual(exist, args.Any()); var folder = ResourceTypes.Folder.ToString(); // Check Resource URIs foreach (var arg in args) { VerifyCorrelationId(arg, messageId); Assert.IsNotNull(arg?.Message?.Resource?.Uri); var resourceUri = new EtpUri(arg.Message.Resource.Uri); if (uri == EtpUri.RootUri) { Assert.IsTrue(uri.IsBaseUri); } else if (!folder.EqualsIgnoreCase(arg.Message.Resource.ResourceType)) { Assert.AreEqual(uri.Family, resourceUri.Family); Assert.AreEqual(uri.Version, resourceUri.Version); } } } if (onProtocolException.Status == TaskStatus.RanToCompletion) { var exceptionArgs = onProtocolException.Result; // Assert exception details Assert.IsNotNull(errorCode); Assert.IsNotNull(exceptionArgs?.Message); Assert.AreEqual((int)errorCode, exceptionArgs.Message.ErrorCode); } return(args); }