Пример #1
0
        private void OnServerSessionConnected(object sender, IEtpSession session)
        {
            var server = session as IEtpServer;

            if (server == null)
            {
                return;
            }

            server.Output = LogClientOutput;
            _server       = server;

            var message = $"[{server.SessionId}] ETP client connected.";

            LogClientOutput(message, true);
            _log.Debug(message);

            EtpExtender = server.CreateEtpExtender(Model.RequestedProtocols);

            EtpExtender.Register(LogObjectDetails,
                                 onOpenSession: OnOpenSession,
                                 onCloseSession: OnCloseSession,
                                 onGetResourcesResponse: OnGetResourcesResponse,
                                 onObject: OnObject,
                                 onObjectPart: OnObjectPart,
                                 onOpenChannel: OnOpenChannel);
        }
Пример #2
0
        public void RequestSession(IEtpSession session, string applicationName, string applicationVersion, string requestedCompression)
        {
            var requestedProtocols = session.GetSupportedProtocols();

            session.Handler <ICoreClient>()
            .RequestSession(applicationName, applicationVersion, requestedProtocols, requestedCompression);
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Etp12Extender"/> class.
 /// </summary>
 /// <param name="session">The ETP session.</param>
 /// <param name="protocolItems">The protocol items.</param>
 public Etp12Extender(IEtpSession session, IList <EtpProtocolItem> protocolItems)
 {
     Session                = session;
     ProtocolItems          = protocolItems;
     Protocols              = new Etp12Protocols();
     _channelSubscribeInfos = new List <ChannelSubscribeInfo>();
     _subscriptionInfos     = new List <SubscriptionInfo>();
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Etp11Extender"/> class.
 /// </summary>
 /// <param name="session">The ETP session.</param>
 /// <param name="protocolItems">The protocol items.</param>
 public Etp11Extender(IEtpSession session, IList <EtpProtocolItem> protocolItems)
 {
     Session                = session;
     ProtocolItems          = protocolItems;
     Protocols              = new Etp11Protocols();
     _channelStreamingInfos = new List <ChannelStreamingInfo>();
     _notificationRequests  = new List <NotificationRequestRecord>();
 }
Пример #5
0
        /// <summary>
        /// Registers the channel data load producer.
        /// </summary>
        /// <param name="etpSession">The ETP session.</param>
        /// <param name="container">The composition container.</param>
        /// <param name="contractName">The contract name.</param>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public static IDataLoadProducer RegisterChannelDataLoadProducer(this IEtpSession etpSession, IContainer container, string contractName = null, Action <IDataLoadProducer> callback = null)
        {
            var handler  = container.Resolve <Energistics.Etp.v12.Protocol.ChannelDataLoad.IChannelDataLoadProducer>(contractName);
            var producer = handler as IDataLoadProducer;

            callback?.Invoke(producer);
            etpSession.Register(() => handler);

            return(producer);
        }
Пример #6
0
 public void RegisterCore(IEtpSession session)
 {
     if (session.IsClient)
     {
         session.Register <ICoreClient, CoreClientHandler>();
     }
     else
     {
         session.Register <ICoreServer, CoreServerHandler>();
     }
 }
Пример #7
0
        /// <summary>
        /// Determines if the protocol handler has been registered with the current ETP session.
        /// </summary>
        /// <typeparam name="T">The handler type.</typeparam>
        /// <param name="session">The ETP session.</param>
        /// <returns><c>true</c> if the protocol handler has been registered, otherwise <c>false</c>.</returns>
        public static bool IsRegistered <T>(this IEtpSession session) where T : IProtocolHandler
        {
            if ((session?.CanHandle <T>()).GetValueOrDefault())
            {
                return(true);
            }
            var crlf = Environment.NewLine;

            session?.Output?.Invoke($"{crlf}// WARNING: Protocol handler not registered: {typeof(T).Name}{crlf}//");
            return(false);
        }
Пример #8
0
        /// <summary>
        /// Gets the ETP session associated with the specified WebSocket session.
        /// </summary>
        /// <param name="session">The WebSocket session.</param>
        /// <returns>The <see cref="IEtpSession"/> associated with the WebSocket session.</returns>
        private IEtpSession GetEtpSession(WebSocketSession session)
        {
            IEtpSession etpSession = null;
            object      item;

            lock (_sync)
            {
                if (session.Items.TryGetValue(EtpSessionKey, out item))
                {
                    etpSession = item as IEtpSession;
                }
            }

            return(etpSession);
        }
Пример #9
0
 /// <summary>
 /// Resolves the discovery store handler.
 /// </summary>
 /// <param name="etpSession">The ETP session.</param>
 /// <param name="container">The composition container.</param>
 /// <param name="contractName">The contract name.</param>
 /// <param name="callback">The callback.</param>
 /// <returns>An <see cref="IProtocolHandler"/> instance.</returns>
 public static IProtocolHandler RegisterDiscoveryStore(this IEtpSession etpSession, IContainer container, string contractName = null, Action <IProtocolHandler> callback = null)
 {
     if (etpSession.SupportedVersion == EtpVersion.v11)
     {
         var handler = container.Resolve <Energistics.Etp.v11.Protocol.Discovery.IDiscoveryStore>(contractName);
         callback?.Invoke(handler);
         etpSession.Register(() => handler);
         return(handler);
     }
     else
     {
         var handler = container.Resolve <Energistics.Etp.v12.Protocol.Discovery.IDiscoveryStore>(contractName);
         callback?.Invoke(handler);
         etpSession.Register(() => handler);
         return(handler);
     }
 }
Пример #10
0
        /// <summary>
        /// Creates the server capabilities object for the ETP session.
        /// </summary>
        /// <param name="etpSession">The ETP session.</param>
        /// <param name="supportedObjects">The supported objects.</param>
        /// <param name="supportedEncodings">The supported encodings.</param>
        /// <returns>A new server capabilities instance.</returns>
        public static object CreateServerCapabilities(this IEtpSession etpSession, IList <string> supportedObjects, IList <string> supportedEncodings)
        {
            if (etpSession.Adapter is Energistics.Etp.v11.Etp11Adapter)
            {
                return(new Energistics.Etp.v11.Datatypes.ServerCapabilities
                {
                    ApplicationName = etpSession.ApplicationName,
                    ApplicationVersion = etpSession.ApplicationVersion,
                    SupportedProtocols = etpSession.GetSupportedProtocols()
                                         .Cast <Energistics.Etp.v11.Datatypes.SupportedProtocol>()
                                         .ToList(),
                    SupportedObjects = supportedObjects,
                    SupportedEncodings = string.Join(";", supportedEncodings),
                    ContactInformation = new Energistics.Etp.v11.Datatypes.Contact
                    {
                        OrganizationName = WitsmlSettings.DefaultVendorName,
                        ContactName = WitsmlSettings.DefaultContactName,
                        ContactEmail = WitsmlSettings.DefaultContactEmail,
                        ContactPhone = WitsmlSettings.DefaultContactPhone
                    }
                });
            }

            return(new Energistics.Etp.v12.Datatypes.ServerCapabilities
            {
                ApplicationName = etpSession.ApplicationName,
                ApplicationVersion = etpSession.ApplicationVersion,
                SupportedProtocols = etpSession.GetSupportedProtocols()
                                     .Cast <Energistics.Etp.v12.Datatypes.SupportedProtocol>()
                                     .ToList(),
                SupportedObjects = supportedObjects,
                SupportedEncodings = string.Join(";", supportedEncodings),
                SupportedCompression = new[] { OptionsIn.CompressionMethod.Gzip.Value },
                ContactInformation = new Energistics.Etp.v12.Datatypes.Contact
                {
                    OrganizationName = WitsmlSettings.DefaultVendorName,
                    ContactName = WitsmlSettings.DefaultContactName,
                    ContactEmail = WitsmlSettings.DefaultContactEmail,
                    ContactPhone = WitsmlSettings.DefaultContactPhone
                }
            });
        }
Пример #11
0
        /// <summary>
        /// Registers the store customer.
        /// </summary>
        /// <param name="etpSession">The ETP session.</param>
        /// <param name="container">The container.</param>
        /// <param name="contractName">Name of the contract.</param>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public static IEtpStoreCustomer RegisterStoreCustomer(this IEtpSession etpSession, IContainer container, string contractName = null, Action <IEtpStoreCustomer> callback = null)
        {
            if (etpSession.SupportedVersion == EtpVersion.v11)
            {
                var handler  = container.Resolve <Energistics.Etp.v11.Protocol.Store.IStoreCustomer>(contractName);
                var customer = handler as IEtpStoreCustomer;

                callback?.Invoke(customer);
                etpSession.Register(() => handler);
                return(customer);
            }
            else
            {
                var handler  = container.Resolve <Energistics.Etp.v12.Protocol.Store.IStoreCustomer>(contractName);
                var customer = handler as IEtpStoreCustomer;

                callback?.Invoke(customer);
                etpSession.Register(() => handler);
                return(customer);
            }
        }
Пример #12
0
        private async void OnServerSessionClosed(object sender, IEtpSession session)
        {
            var server = session as IEtpServer;

            if (server == null)
            {
                return;
            }

            var message = $"[{server.SessionId}] ETP client disconnected.";

            LogClientOutput(message, true);
            _log.Debug(message);

            await OnCloseSession();

            if (server == _server)
            {
                _server = null;
            }
        }
Пример #13
0
        /// <summary>
        /// Resolves the channel streaming producer handler.
        /// </summary>
        /// <param name="etpSession">The ETP session.</param>
        /// <param name="container">The composition container.</param>
        /// <param name="contractName">The contract name.</param>
        /// <param name="callback">The callback.</param>
        /// <returns>An <see cref="IStreamingProducer"/> instance.</returns>
        public static IStreamingProducer RegisterChannelStreamingProducer(this IEtpSession etpSession, IContainer container, string contractName = null, Action <IStreamingProducer> callback = null)
        {
            if (etpSession.SupportedVersion == EtpVersion.v11)
            {
                var handler  = container.Resolve <Energistics.Etp.v11.Protocol.ChannelStreaming.IChannelStreamingProducer>(contractName);
                var producer = handler as IStreamingProducer;

                callback?.Invoke(producer);
                etpSession.Register(() => handler);

                return(producer);
            }
            else
            {
                var handler  = container.Resolve <Energistics.Etp.v12.Protocol.ChannelStreaming.IChannelStreamingProducer>(contractName);
                var producer = handler as IStreamingProducer;

                callback?.Invoke(producer);
                etpSession.Register(() => handler);

                return(producer);
            }
        }
Пример #14
0
 public void InitializeSession(IEtpSession session)
 {
     Session = session;
     InitializeSessionCore();
 }
Пример #15
0
 /// <summary>
 /// Sends a ProtocolException message with the specified exception details.
 /// </summary>
 /// <param name="exception">The ETP exception.</param>
 /// <param name="session">The session to send the exception on.</param>
 /// <param name="isFinalPart">Whether or not the protocol exception is the final part in a multi-part message.</param>
 /// <param name="extension">The message header extension to send with the message.</param>
 /// <returns>The sent message on success; <c>null</c> otherwise.</returns>
 public static EtpMessage <IProtocolException> Send(this EtpException exception, IEtpSession session, bool isMultiPart = false, bool isFinalPart = false, IMessageHeaderExtension extension = null)
 {
     return(session.ProtocolException(exception, isFinalPart: isFinalPart, extension: extension));
 }
Пример #16
0
 /// <summary>
 /// Raise the <see cref="SessionClosed"/> event.
 /// </summary>
 /// <param name="session">The closed session.</param>
 protected void InvokeSessionClosed(IEtpSession session)
 {
     SessionClosed?.Invoke(this, session);
 }
Пример #17
0
 /// <summary>
 /// Creates a new ETP extender for the specified ETP session.
 /// </summary>
 /// <param name="session">The ETP session.</param>
 /// <param name="protocolItems">The protocol items.</param>
 /// <returns>A new <see cref="IEtpExtender"/> instance.</returns>
 public static IEtpExtender CreateEtpExtender(this IEtpSession session, IList <EtpProtocolItem> protocolItems)
 {
     return(session.SupportedVersion == EtpVersion.v11
         ? new Etp11Extender(session, protocolItems)
         : new Etp12Extender(session, protocolItems) as IEtpExtender);
 }