예제 #1
0
        public void AssertUri(EtpUri uri, bool IsValid, EtpVersion EtpVersion, bool IsRootUri = false, bool IsDataspaceUri = false, bool IsFamilyVersionUri = false, bool IsObjectUri = false, bool IsQueryUri = false, bool IsFolderUri = false, bool IsBaseUri = false, bool IsCanonicalUri = false, bool IsAlternateUri = false, bool IsHierarchicalUri = false, bool IsTemplateUri = false, bool IsObjectTemplateUri = false, bool IsFolderTemplateUri = false, bool HasEmptyObjectId = false, bool HasQuery = false, bool HasHash = false)
        {
            Assert.AreEqual(IsValid, uri.IsValid, $"IsValid: {uri}");
            if (!uri.IsValid)
            {
                return;
            }

            Assert.AreEqual(EtpVersion, uri.EtpVersion, $"EtpVersion: {uri}");
            if (uri.EtpVersion == EtpVersion.v11)
            {
                Assert.IsTrue(uri.IsEtp11, $"Etp11: {uri}");
            }
            else
            {
                Assert.IsTrue(uri.IsEtp12, $"Etp12: {uri}");
            }

            Assert.AreEqual(IsRootUri, uri.IsRootUri, $"IsRootUri: {uri}");
            Assert.AreEqual(IsDataspaceUri, uri.IsDataspaceUri, $"IsDataspaceUri: {uri}");
            Assert.AreEqual(IsFamilyVersionUri, uri.IsFamilyVersionUri, $"IsFamilyVersionUri: {uri}");
            Assert.AreEqual(IsObjectUri, uri.IsObjectUri, $"IsObjectUri: {uri}");
            Assert.AreEqual(IsQueryUri, uri.IsQueryUri, $"IsQueryUri: {uri}");
            Assert.AreEqual(IsFolderUri, uri.IsFolderUri, $"IsFolderUri: {uri}");
            Assert.AreEqual(IsBaseUri, uri.IsBaseUri, $"IsBaseUri: {uri}");
            Assert.AreEqual(IsCanonicalUri, uri.IsCanonicalUri, $"IsCanonicalUri: {uri}");
            Assert.AreEqual(IsAlternateUri, uri.IsAlternateUri, $"IsAlternateUri: {uri}");
            Assert.AreEqual(IsHierarchicalUri, uri.IsHierarchicalUri, $"IsHierarchicalUri: {uri}");
            Assert.AreEqual(IsTemplateUri, uri.IsTemplateUri, $"IsTemplateUri: {uri}");
            Assert.AreEqual(IsObjectTemplateUri, uri.IsObjectTemplateUri, $"IsObjectTemplateUri: {uri}");
            Assert.AreEqual(IsFolderTemplateUri, uri.IsFolderTemplateUri, $"IsFolderTemplateUri: {uri}");
            Assert.AreEqual(HasEmptyObjectId, uri.HasEmptyObjectId, $"HasEmptyObjectId: {uri}");
            Assert.AreEqual(HasQuery, uri.HasQuery, $"HasQuery: {uri}");
            Assert.AreEqual(HasHash, uri.HasHash, $"HasHash: {uri}");
        }
예제 #2
0
        public MockObject GetObject(EtpVersion version, EtpUri uri)
        {
            CheckLocked();

            if (!((version == EtpVersion.v11 && uri.IsEtp11) || (version == EtpVersion.v12 && uri.IsEtp12)))
            {
                return(null);
            }

            var dataspace = GetDataspace(uri);

            if (dataspace == null)
            {
                return(null);
            }

            MockObject @object;

            if (!ObjectsByUri[version].TryGetValue(uri, out @object))
            {
                return(null);
            }

            return(@object);
        }
예제 #3
0
        public IEnumerable <MockObject> GetDeletedObjects(EtpVersion version, EtpUri uri, ISet <EtpDataObjectType> objectTypes = null, DateTime?deleteTimeFilter = null)
        {
            CheckLocked();

            if (!((version == EtpVersion.v11 && uri.IsEtp11) || (version == EtpVersion.v12 && uri.IsEtp12)))
            {
                yield break;
            }

            if (!uri.IsDataspaceUri)
            {
                yield break;
            }

            var dataspace = GetDataspace(uri);

            if (dataspace == null)
            {
                yield break;
            }

            foreach (var @object in dataspace.DeletedObjects.Values.FilterByType(objectTypes).FilterByStoreLastWrite(deleteTimeFilter))
            {
                yield return(@object);
            }
        }
예제 #4
0
        /// <summary>
        /// Creates an <see cref="EtpClient"/> instance configurated with the
        /// current connection and authorization parameters.
        /// </summary>
        /// <param name="webSocketType">The WebSocket type.</param>
        /// <param name="etpVersion">The ETP version.</param>
        /// <param name="url">The WebSocket URL.</param>
        /// <param name="authorization">The client's authorization details.</param>
        /// <param name="etpEncoding">The encoding to use.</param>
        /// <returns>A new <see cref="IEtpClient"/> instance.</returns>
        protected IEtpClient CreateClient(WebSocketType webSocketType, EtpVersion etpVersion, string url, Security.Authorization authorization = null, EtpEncoding etpEncoding = EtpEncoding.Binary)
        {
            var version = GetType().Assembly.GetName().Version.ToString();

            if (authorization == null)
            {
                authorization = Security.Authorization.Basic(TestSettings.Username, TestSettings.Password);
            }

            var endpointInfo = EtpFactory.CreateClientEndpointInfo(GetType().AssemblyQualifiedName, version, "ETP DevKit Integration Test");

            var client = EtpFactory.CreateClient(webSocketType, url, etpVersion, etpEncoding, endpointInfo, authorization: authorization);

            if (etpVersion == EtpVersion.v11)
            {
                client.Register(new v11.Protocol.ChannelStreaming.ChannelStreamingConsumerHandler());
                client.Register(new v11.Protocol.Discovery.DiscoveryCustomerHandler());
                client.Register(new v11.Protocol.Store.StoreCustomerHandler());
            }
            else
            {
                client.Register(new v12.Protocol.ChannelStreaming.ChannelStreamingConsumerHandler());
                client.Register(new v12.Protocol.Discovery.DiscoveryCustomerHandler());
                client.Register(new v12.Protocol.Store.StoreCustomerHandler());
            }

            return(client);
        }
예제 #5
0
        public override string Xml(EtpVersion version, string indentation = "", bool embedded = false) =>
        $@"{indentation}<ChannelSet{Namespaces(embedded)} schemaVersion=""2.0"" uuid=""{Uuid}""{DefaultNamespace(embedded)}>
{indentation}  <Citation xmlns=""http://www.energistics.org/energyml/data/commonv2"">
{indentation}    <Title>{Title}</Title>
{indentation}    <Originator>ETP DevKit</Originator>
{indentation}    <Creation>{Creation.ToUniversalTime():O}</Creation>
{indentation}    <Format>Energistics:ETP DevKit {typeof(IEtpSession).Assembly.GetName().Version}</Format>
{indentation}    <LastUpdate>{LastUpdate.ToUniversalTime():O}</LastUpdate>
{indentation}  </Citation>
{indentation}  <Index>
{indentation}    <IndexType>{(IsTime ? "date time" : "measured depth")}</IndexType>
{indentation}    <Uom>{(IsTime ? "s" : "m")}</Uom>
{indentation}    <Direction>increasing</Direction>
{indentation}    <Mnemonic>{(IsTime ? "Time" : "Depth")}</Mnemonic>
{indentation}  </Index>
{string.Concat(Channels.Select(c => c.Xml(version, indentation = "  ", embedded = true)))}
{indentation}  <TimeDepth>{(IsTime ? "time" : "depth")}</TimeDepth>
{indentation}  <StartIndex xsi:type=""{(IsTime ? "TimeIndexValue" : "DepthIndexValue")}"">
{indentation}    <{(IsTime ? "Time" : "Depth")}>{(IsTime ? TimeStartIndex?.ToString("O", CultureInfo.InvariantCulture) : DepthStartIndex?.ToString(CultureInfo.InvariantCulture))}</{(IsTime ? "Time" : "Depth")}>
{indentation}  </StartIndex>
{indentation}  <EndIndex xsi:type=""{(IsTime ? "TimeIndexValue" : "DepthIndexValue")}"">
{indentation}    <{(IsTime ? "Time" : "Depth")}>{(IsTime ? TimeEndIndex?.ToString("O", CultureInfo.InvariantCulture) : DepthEndIndex?.ToString(CultureInfo.InvariantCulture))}</{(IsTime ? "Time" : "Depth")}>
{indentation}  </EndIndex>
{indentation}  <LoggingCompanyName>ETP DevKit</LoggingCompanyName>
{indentation}  <Wellbore>
{indentation}    <ContentType xmlns=""http://www.energistics.org/energyml/data/commonv2"">{Wellbore.ContentType}</ContentType>
{indentation}    <Title xmlns=""http://www.energistics.org/energyml/data/commonv2"">{Wellbore.Title}</Title>
{indentation}    <Uuid xmlns=""http://www.energistics.org/energyml/data/commonv2"">{Wellbore.Uuid}</Uuid>
{indentation}    <Uri xmlns=""http://www.energistics.org/energyml/data/commonv2"">{Wellbore.Uri(version)}</Uri>
{indentation}  </Wellbore>
{indentation}</ChannelSet>";
예제 #6
0
        /// <summary>
        /// Checks if this message is the only or final message in response to a request.
        /// </summary>
        /// <param name="header">The message header.</param>
        /// <param name="version">The ETP version.</param>
        /// <returns><c>true</c> if this is an acknowledge message with NoData set,
        /// a protocol exception, or a different message type that is either the final
        /// part of a multi-part message or not part of a multi-part message;
        /// <c>false</c> otherwise.</returns>
        public static bool IsFinalResponse(this IMessageHeader header, EtpVersion version)
        {
            if (!header.HasCorrelationId())
            {
                return(false);
            }

            if (version == EtpVersion.v11)
            {
                if (header.IsAcknowledge() && header.IsNoData())
                {
                    return(true);
                }

                if (header.IsProtocolException())
                {
                    return(true);
                }

                return(!header.IsMultiPart() || header.IsFinalPart());
            }
            else
            {
                return(header.IsFinalPart());
            }
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EtpProtocolHandler"/> class.
 /// </summary>
 /// <param name="version">The ETP version.</param>
 /// <param name="protocol">The protocol.</param>
 /// <param name="role">The role.</param>
 /// <param name="requestedRole">The requested role.</param>
 protected EtpProtocolHandler(EtpVersion version, int protocol, string role, string requestedRole)
 {
     SupportedVersion = version;
     Protocol         = protocol;
     Role             = role;
     RequestedRole    = requestedRole;
 }
예제 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EtpServer"/> class.
 /// </summary>
 /// <param name="webSocket">The web socket.</param>
 /// <param name="etpVersion">The ETP version for the session.</param>
 /// <param name="encoding">The ETP encoding for the session.</param>
 /// <param name="info">The server's information.</param>
 /// <param name="parameters">The server's parameters.</param>
 /// <param name="headers">The WebSocket or HTTP headers.</param>
 public EtpServer(EtpServerWebSocket webSocket, EtpVersion etpVersion, EtpEncoding encoding, EtpEndpointInfo info, EtpEndpointParameters parameters = null, IDictionary <string, string> headers = null)
     : base(etpVersion, encoding, info, parameters, headers, false, webSocket.WebSocketSession.SessionID, false)
 {
     _webSocket = webSocket;
     _session   = _webSocket.WebSocketSession;
     _session.SocketSession.Closed += OnSocketSessionClosed;
 }
예제 #9
0
        public IEnumerable <MockObject> GetObjects(EtpVersion version, MockGraphContext context, bool?activeStatusFilter = null, DateTime?storeLastWriteFilter = null)
        {
            CheckLocked();

            var uri = context.Uri;

            if (!((version == EtpVersion.v11 && uri.IsEtp11) || (version == EtpVersion.v12 && uri.IsEtp12)))
            {
                yield break;
            }

            IEnumerable <MockObject> objects = null;

            var dataspace = GetDataspace(uri);

            if (dataspace == null)
            {
                if (uri.IsRootUri)
                {
                    objects = Dataspaces.SelectMany(d => d.Objects.Values);
                }
                else
                {
                    yield break;
                }
            }

            if (objects == null)
            {
                if (uri.IsBaseUri)
                {
                    if (uri.IsFamilyVersionUri)
                    {
                        objects = dataspace.Objects.Values.FilterByFamilyAndVersion(uri.DataObjectType);
                    }
                    else
                    {
                        objects = dataspace.Objects.Values;
                    }
                }
                else
                {
                    var @object = GetObject(version, uri);
                    if (@object == null)
                    {
                        yield break;
                    }

                    objects = @object.WalkGraph(context);
                }
            }

            var objectTypes = context.DataObjectTypes;

            foreach (var @object in objects.FilterByType(objectTypes).FilterByActiveStatus(activeStatusFilter).FilterByStoreLastWrite(storeLastWriteFilter))
            {
                yield return(@object);
            }
        }
예제 #10
0
        public IEnumerable <EtpUri> AlternateUris(EtpVersion version)
        {
            if (Parents.Count == 0 && Containers.Count == 0)
            {
                return(Enumerable.Empty <EtpUri>());
            }

            return(ConstructAlternateUris(this, version));
        }
예제 #11
0
        /// <summary>
        /// Initializes common resources.
        /// </summary>
        /// <param name="webSocketType">The WebSocket type.</param>
        /// <param name="etpVersion">The ETP version</param>
        protected void SetUp(WebSocketType webSocketType, EtpVersion etpVersion)
        {
            // Clean up any remaining resources
            _client?.Dispose();
            _server?.Dispose();

            // Create server and client instances
            _server = CreateServer(webSocketType);
            _client = CreateClient(webSocketType, etpVersion, _server.Uri.ToWebSocketUri().ToString());
        }
예제 #12
0
 /// <summary>
 /// Creates a deep copy of this instance for the specified ETP version.
 /// Any protocol handlers not supported by the specified version will be removed from the clone.
 /// </summary>
 /// <param name="version">The ETP version for the clone.</param>
 /// <returns>A deep copy of this instance.</returns>
 public EtpEndpointParameters CloneForVersion(EtpVersion version)
 {
     return(new EtpEndpointParameters(
                new EtpEndpointCapabilities(Capabilities),
                SupportedProtocols.Where(p => version == EtpVersion.Unknown || p.EtpVersion == EtpVersion.Unknown || p.EtpVersion == version).Select(p => p.Clone()).ToList(),
                new List <EtpSupportedDataObject>(SupportedDataObjects),
                new List <string>(SupportedCompression),
                new List <string>(SupportedFormats)
                ));
 }
예제 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpProtocolHandler"/> class.
        /// </summary>
        /// <param name="version">The ETP version.</param>
        /// <param name="protocol">The protocol.</param>
        /// <param name="role">The role.</param>
        /// <param name="requestedRole">The requested role.</param>
        protected EtpProtocolHandler(EtpVersion version, int protocol, string role, string requestedRole) : base(false)
        {
            SupportedVersion = version;
            Protocol         = protocol;
            Role             = role;
            RequestedRole    = requestedRole;

            RegisterMessageHandler <IProtocolException>(v11.Protocols.Core, v11.MessageTypes.Core.ProtocolException, HandleProtocolException);
            RegisterMessageHandler <IAcknowledge>(v11.Protocols.Core, v11.MessageTypes.Core.Acknowledge, HandleAcknowledge);
        }
예제 #14
0
        public override string Xml(EtpVersion version, string indentation = "", bool embedded = false) =>
        $@"{indentation}<Well{Namespaces(embedded)} schemaVersion=""2.0"" uuid=""{Uuid}""{DefaultNamespace(embedded)}>
{indentation}  <Citation xmlns=""http://www.energistics.org/energyml/data/commonv2"">
{indentation}    <Title>{Title}</Title>
{indentation}    <Originator>ETP DevKit</Originator>
{indentation}    <Creation>{Creation.ToUniversalTime():O}</Creation>
{indentation}    <Format>Energistics:ETP DevKit {typeof(IEtpSession).Assembly.GetName().Version}</Format>
{indentation}    <LastUpdate>{LastUpdate.ToUniversalTime():O}</LastUpdate>
{indentation}  </Citation>
{indentation}</Well>";
예제 #15
0
        /// <summary>
        /// Converts an <see cref="EtpVersion"/> instance to an <see cref="System.Version"/>.
        /// </summary>
        /// <param name="version">The <see cref="EtpVersion"/> to convert.</param>
        /// <returns>The converted version.</returns>
        public static System.Version ToSystemVersion(this EtpVersion version)
        {
            switch (version)
            {
            case EtpVersion.v11: return(new System.Version(1, 1, 0, 0));

            case EtpVersion.v12: return(new System.Version(1, 2, 0, 0));

            default: return(new System.Version());
            }
        }
예제 #16
0
        /// <summary>
        /// Gets a consistent, version-specific key for this data object type.
        /// </summary>
        /// <param name="dataObjectType">The data object type to get the key for.</param>
        /// <param name="version">The ETP version to get the key for.</param>
        /// <returns>The version-specific key.</returns>
        public static string ToVersionKey(this IDataObjectType dataObjectType, EtpVersion version)
        {
            switch (version)
            {
            case EtpVersion.v11: return(dataObjectType.ContentType.ToString());

            case EtpVersion.v12: return(dataObjectType.DataObjectType.ToString());

            default: return(null);
            }
        }
예제 #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpClient"/> class.
        /// </summary>
        /// <param name="uri">The ETP server URI.</param>
        /// <param name="etpVersion">The ETP version for the session.</param>
        /// <param name="encoding">The ETP encoding for the session.</param>
        /// <param name="info">The client's information.</param>
        /// <param name="parameters">The client's parameters.</param>
        /// <param name="authorization">The client's authorization details.</param>
        /// <param name="headers">The WebSocket headers.</param>
        public EtpClient(string uri, EtpVersion etpVersion, EtpEncoding encoding, EtpEndpointInfo info, EtpEndpointParameters parameters, Security.Authorization authorization = null, IDictionary <string, string> headers = null)
            : base(etpVersion, encoding, info, parameters, headers, true, null, false)
        {
            Headers.SetAuthorization(authorization);

            _socket = new W4N.WebSocket(uri,
                                        subProtocol: EtpFactory.GetSubProtocol(EtpVersion),
                                        cookies: null,
                                        customHeaderItems: Headers.ToList(),
                                        userAgent: info.ApplicationName);
        }
예제 #18
0
        private static void GetChannelData(IList <MockDataItem> dataItems, EtpVersion version, IList <ChannelDataQuery> queries, IComparable minIndex, IComparable maxIndex, int maxDataItems)
        {
            var dataIndexes  = GetStartingDataIndexes(queries, minIndex);
            var currentIndex = GetStartingIndex(queries, dataIndexes, maxIndex);

            if (currentIndex.CompareTo(maxIndex) == 0) // No new data.
            {
                return;
            }

            var         endIndexes = GetEndingDataIndexes(queries, maxIndex);
            IComparable nextIndex;

            do
            {
                nextIndex = maxIndex;
                var nullIndex = false;
                for (int i = 0; i < queries.Count; i++)
                {
                    if (dataIndexes[i] >= endIndexes[i])
                    {
                        continue;
                    }

                    var channel = queries[i].Channel;
                    var index   = channel.Index(dataIndexes[i]);
                    if (index.CompareTo(currentIndex) == 0)
                    {
                        queries[i].StartIndex            = index;
                        queries[i].IsStartIndexInclusive = false;
                        dataItems.Add(channel.DataItem(version, queries[i].ChannelId, dataIndexes[i]++, nullIndex));

                        nullIndex = true;
                        if (dataItems.Count == maxDataItems)
                        {
                            return;
                        }

                        if (dataIndexes[i] < endIndexes[i])
                        {
                            var idx = channel.Index(dataIndexes[i]);
                            if (idx.CompareTo(nextIndex) < 0)
                            {
                                nextIndex = idx;
                            }
                        }
                    }
                }

                currentIndex = nextIndex;
            }while (dataItems.Count < maxDataItems && nextIndex.CompareTo(maxIndex) != 0);
        }
예제 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpSession"/> class.
        /// </summary>
        /// <param name="etpVersion">The ETP version for the session.</param>
        /// <param name="application">The application name.</param>
        /// <param name="version">The application version.</param>
        /// <param name="headers">The WebSocket or HTTP headers.</param>
        /// <param name="isClient">Whether or not this is the client-side of the session.</param>
        protected EtpSession(EtpVersion etpVersion, string application, string version, IDictionary <string, string> headers, bool isClient)
        {
            IsClient = isClient;

            Headers            = headers ?? new Dictionary <string, string>();
            HandlersByType     = new Dictionary <Type, IProtocolHandler>();
            HandlersByProtocol = new Dictionary <int, IProtocolHandler>();
            ApplicationName    = application;
            ApplicationVersion = version;
            ValidateHeaders();

            Adapter = ResolveEtpAdapter(etpVersion);
            Adapter.RegisterCore(this);
        }
예제 #20
0
        /// <summary>
        /// Resets any modified test settings.
        /// </summary>
        public static void Reset()
        {
            ServerCapabilitiesUrl = Settings.Default.ServerCapabilitiesUrl;
            AuthTokenUrl          = Settings.Default.AuthTokenUrl;
            ServerUrl             = Settings.Default.ServerUrl;
            Username   = Settings.Default.Username;
            Password   = Settings.Default.Password;
            EtpVersion = Settings.Default.EtpVersion;
            DefaultTimeoutInMilliseconds = 5000;
            ProxyUsername = Settings.Default.ProxyUsername;
            ProxyPassword = Settings.Default.ProxyPassword;

            WebSocketType = EtpSettings.DefaultWebSocketType;
        }
예제 #21
0
        /// <summary>
        /// Initializes common resources.
        /// </summary>
        /// <param name="webSocketType">The WebSocket type.</param>
        /// <param name="etpVersion">The ETP version</param>
        protected void SetUpWithProxy(WebSocketType webSocketType, EtpVersion etpVersion)
        {
            // Clean up any remaining resources
            _client?.Dispose();
            _server?.Dispose();

            var proxiedServer = CreateServer(webSocketType);

            _server = new EtpSelfHostedProxyWebServer(GetAvailablePort(), proxiedServer);

            // Use hostname so .NET will connect through the proxy.
            var uri = new UriBuilder(proxiedServer.Uri.Scheme, "vcap.me", proxiedServer.Uri.Port, proxiedServer.Uri.AbsolutePath, proxiedServer.Uri.Query).Uri;

            _client = CreateClient(webSocketType, etpVersion, uri.ToWebSocketUri().ToString());
        }
예제 #22
0
        /// <summary>
        /// Converts an <see cref="EtpVersion"/> instance to an <see cref="IVersion"/>.
        /// </summary>
        /// <param name="version">The <see cref="EtpVersion"/> to convert.</param>
        /// <returns>The converted version.</returns>
        public static TVersion ToVersion <TVersion>(this EtpVersion version)
            where TVersion : IVersion, new()
        {
            switch (version)
            {
            case EtpVersion.v11: return(new TVersion {
                    Major = 1, Minor = 1, Revision = 0, Patch = 0,
                });

            case EtpVersion.v12: return(new TVersion {
                    Major = 1, Minor = 2, Revision = 0, Patch = 0,
                });

            default: return(new TVersion());
            }
        }
예제 #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpClient"/> class.
        /// </summary>
        /// <param name="uri">The ETP server URI.</param>
        /// <param name="etpVersion">The ETP version for the session.</param>
        /// <param name="encoding">The ETP encoding for the session.</param>
        /// <param name="info">The client's information.</param>
        /// <param name="parameters">The client's parameters.</param>
        /// <param name="authorization">The client's authorization details.</param>
        /// <param name="headers">The WebSocket headers.</param>
        public EtpClient(string uri, EtpVersion etpVersion, EtpEncoding encoding, EtpEndpointInfo info, EtpEndpointParameters parameters = null, Security.Authorization authorization = null, IDictionary <string, string> headers = null)
            : base(etpVersion, encoding, new ClientWebSocket(), info, parameters, headers, true, null)
        {
            Headers.SetAuthorization(authorization);

            ClientSocket.Options.AddSubProtocol(EtpFactory.GetSubProtocol(EtpVersion));

            foreach (var item in Headers)
            {
                ClientSocket.Options.SetRequestHeader(item.Key, item.Value);
            }

            Uri = new Uri(uri);

            // NOTE: User-Agent cannot be set on a .NET Framework ClientWebSocket:
            // https://github.com/dotnet/corefx/issues/26627
        }
예제 #24
0
        /// <summary>
        /// Creates a Base URI for the specified ETP version with the specified family, version and dataspace.
        /// </summary>
        /// <param name="etpVersion">The ETP version.</param>
        /// <param name="family">The family.</param>
        /// <param name="version">The version.</param>
        /// <param name="dataspace">The dataspace.</param>
        /// <returns>The ETP URI Base.</returns>
        private static string CreateBaseUri(EtpVersion etpVersion, string family, string version, string dataspace)
        {
            var sb          = new StringBuilder();
            var appendSlash = false;

            if (etpVersion == EtpVersion.v11)
            {
                sb.Append($"{RootUri11.Uri}");
            }
            else
            {
                sb.Append($"{RootUri12.Uri}");
            }

            if (!string.IsNullOrEmpty(dataspace))
            {
                if (etpVersion == EtpVersion.v11)
                {
                    sb.Append(dataspace);
                }
                else
                {
                    sb.Append($"dataspace({dataspace})");
                }

                appendSlash = true;
            }

            if (etpVersion == EtpVersion.v11 && !string.IsNullOrEmpty(family) && !string.IsNullOrEmpty(version))
            {
                if (appendSlash)
                {
                    sb.Append("/");
                }

                var shortVersion = EtpDataObjectType.TryGetFamilyShortVersionFromVersion(family, version);
                sb.Append($"{family}{shortVersion}");
            }

            return(sb.ToString());
        }
예제 #25
0
        public IEnumerable <MockFamily> GetFamilies(EtpVersion version, EtpUri uri)
        {
            CheckLocked();

            if (!((version == EtpVersion.v11 && uri.IsEtp11) || (version == EtpVersion.v12 && uri.IsEtp12)))
            {
                yield break;
            }

            var dataspace = GetDataspace(uri);

            if (dataspace == null)
            {
                yield break;
            }

            foreach (var family in dataspace.Families)
            {
                yield return(family);
            }
        }
예제 #26
0
        /// <summary>
        /// Creates an <see cref="IEtpServer"/> instance.
        /// </summary>
        /// <param name="webSocket">The websocket to create the server for.</param>
        /// <param name="etpVersion">The ETP version for the session.</param>
        /// <param name="encoding">The ETP encoding for the session.</param>
        /// <param name="headers">The websocket headers.</param>
        /// <returns>The created server.</returns>
        public IEtpServer CreateServer(IEtpServerWebSocket webSocket, EtpVersion etpVersion, EtpEncoding encoding, IDictionary <string, string> headers)
        {
            if (webSocket == null)
            {
                throw new ArgumentNullException(nameof(webSocket));
            }
            if (!IsEtpVersionSupported(etpVersion))
            {
                throw new ArgumentException($"Unsupported ETP version: {etpVersion.ToVersionString()}");
            }

            var server = CreateServerCore(webSocket, etpVersion, encoding, headers ?? new Dictionary <string, string>());

            Logger.Debug(Log("[{0}] Server created.", server.SessionKey));

            server.SessionClosed     += OnServerSessionClosed;
            Servers[server.SessionId] = server;

            ServerCreated?.Invoke(this, new EtpServerEventArgs(server));

            return(server);
        }
예제 #27
0
        public bool StartChannelSubscription(EtpVersion version, Guid sessionId, int maxDataItems, TimeSpan maxMessageRate, bool autoStart, MockGrowingObjectCallbacks callbacks)
        {
            CheckLocked();

            if (ChannelSubscriptionsBySessionId.ContainsKey(sessionId))
            {
                return(false);
            }

            ChannelSubscriptionsBySessionId[sessionId] = new ChannelSubscription
            {
                Version = version,
                Uuid    = sessionId,
                LastNotificationTime = StoreLastWrite,
                AutoStart            = autoStart,
                MaxDataItems         = maxDataItems,
                MaxMessageRate       = maxMessageRate,
                Callbacks            = callbacks,
            };

            return(true);
        }
예제 #28
0
 public MockDataItem DataItem(EtpVersion version, long channelId, int dataIndex, bool nullIndex)
 {
     if (IsTime)
     {
         return(new MockDataItem
         {
             ChannelId = channelId,
             LongIndex = nullIndex ? (long?)null : TimeIndex(dataIndex).ToEtpTimestamp(),
             Value = Value(dataIndex),
         });
     }
     else
     {
         return(new MockDataItem
         {
             ChannelId = channelId,
             LongIndex = version == EtpVersion.v11 ? (nullIndex ? (long?)null : DepthIndexToLong(DepthIndex(dataIndex))) : null,
             DoubleIndex = version == EtpVersion.v12 ? (nullIndex ? (double?)null : DepthIndex(dataIndex)) : null,
             Value = Value(dataIndex),
         });
     }
 }
예제 #29
0
        public bool SubscribeObjectNotifications(EtpVersion version, bool sendHistoricalChanges, DateTime historicalChangesStartTime, bool endIfRootDeleted, Guid sessionId, MockSubscriptionInfo subscriptionInfo, MockObjectCallbacks callbacks)
        {
            CheckLocked();

            if (ObjectSubscriptionsByRequestUuid.ContainsKey(subscriptionInfo.RequestUuid))
            {
                return(false);
            }

            MockObject root = null;
            var        uri  = subscriptionInfo.Context.Uri;

            if (uri.IsObjectUri)
            {
                root = GetObject(version, uri);
                if (root == null)
                {
                    return(false);
                }
            }

            ObjectSubscriptionsByRequestUuid[subscriptionInfo.RequestUuid] = new ObjectSubscription
            {
                SessionId             = sessionId,
                Version               = version,
                Uuid                  = subscriptionInfo.RequestUuid,
                LastNotificationTime  = sendHistoricalChanges ? historicalChangesStartTime : StoreLastWrite,
                SubscriptionInfo      = subscriptionInfo,
                Callbacks             = callbacks,
                Root                  = root,
                SendHistoricalChanges = sendHistoricalChanges,
                EndIfRootDeleted      = endIfRootDeleted,
            };

            return(true);
        }
예제 #30
0
        private static IList <MockDataItem> GetChannelData(EtpVersion version, IList <ChannelDataQuery> queries, int maxDataItems)
        {
            var timeQueries  = new List <ChannelDataQuery>();
            var depthQueries = new List <ChannelDataQuery>();

            for (int i = 0; i < queries.Count; i++)
            {
                if (queries[i].Channel.IsTime)
                {
                    timeQueries.Add(queries[i]);
                }
                else
                {
                    depthQueries.Add(queries[i]);
                }
            }

            var dataItems = new List <MockDataItem>();

            GetChannelData(dataItems, version, timeQueries, DateTime.MinValue, DateTime.MaxValue, maxDataItems);
            GetChannelData(dataItems, version, depthQueries, double.MinValue, double.MaxValue, maxDataItems);

            return(dataItems);
        }