Example #1
0
        /// <summary>
        /// Initializes the ETP client.
        /// </summary>
        public async Task InitEtpClient()
        {
            try
            {
                Runtime.Invoke(() => Runtime.Shell.StatusBarText = "Connecting...");

                _log.Debug($"Establishing ETP connection for {Model.Connection}");

                Client      = Model.Connection.CreateEtpClient(Model.ApplicationName, Model.ApplicationVersion);
                EtpExtender = Client.CreateEtpExtender(Model.RequestedProtocols);

                EtpExtender.Register(LogObjectDetails,
                                     onOpenSession: OnOpenSession,
                                     onGetResourcesResponse: OnGetResourcesResponse,
                                     onObject: OnObject,
                                     onObjectPart: OnObjectPart,
                                     onOpenChannel: OnOpenChannel);

                Client.SocketClosed += OnClientSocketClosed;
                Client.Output        = LogClientOutput;
                await Client.OpenAsync();
            }
            catch (Exception ex)
            {
                Runtime.Invoke(() => Runtime.Shell.StatusBarText = "Error");
                Runtime.ShowError("Error connecting to server.", ex);
            }
        }
Example #2
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);
        }
        /// <summary>
        /// Initializes the ETP client.
        /// </summary>
        private void InitEtpClient()
        {
            try
            {
                Runtime.Invoke(() => StatusBarText = "Connecting...");

                var applicationName    = GetType().Assembly.FullName;
                var applicationVersion = GetType().GetAssemblyVersion();

                Client = Connection.CreateEtpClient(applicationName, applicationVersion);
                BindableCollection <EtpProtocolItem> requestedProtocols = new BindableCollection <EtpProtocolItem>();
                requestedProtocols.Add(new EtpProtocolItem(Energistics.Etp.v11.Protocols.Discovery, "store", true));

                EtpExtender = Client.CreateEtpExtender(requestedProtocols);

                EtpExtender.Register(onOpenSession: OnOpenSession,
                                     onCloseSession: CloseEtpClient,
                                     onGetResourcesResponse: OnGetResourcesResponse);

                Client.SocketClosed += OnClientSocketClosed;
                Client.OpenAsync();
            }
            catch (Exception)
            {
                Runtime.Invoke(() => StatusBarText = "Error Connecting");
            }
        }
Example #4
0
        /// <summary>
        /// Gets the graph resources using the Discovery protocol.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="parent">The parent.</param>
        /// <returns>The message identifier.</returns>
        public Task <long> GetGraphResources(string uri, int?depth, GraphScopes?scope, ResourceViewModel parent = null)
        {
            var contentTypes = new string[0];
            var result       = EtpExtender.GetGraphResources(uri, scope ?? 0, false, depth ?? 0, contentTypes);

            return(Task.FromResult(result));
        }
Example #5
0
        /// <summary>
        /// Gets the tree resources using the Discovery protocol.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="parent">The parent.</param>
        /// <returns>The message identifier.</returns>
        public Task <long> GetTreeResources(string uri, int?depth, ResourceViewModel parent = null)
        {
            var contentTypes = new string[0];
            var result       = EtpExtender.GetTreeResources(uri, depth ?? 0, contentTypes);

            return(Task.FromResult(result));
        }
Example #6
0
        /// <summary>
        /// Gets the resources using the Discovery protocol.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="parent">The parent.</param>
        /// <returns>The message identifier.</returns>
        public Task <long> GetResources(string uri, ResourceViewModel parent = null)
        {
            var  contentTypes = new string[0];
            long messageId;

            if (Model == null)
            {
                messageId = EtpExtender.GetResources(uri);
            }
            else if (Model.DiscoveryFunction == Functions.FindResources)
            {
                messageId = EtpExtender.FindResources(uri);
            }
            else if (Model.DiscoveryFunction == Functions.GetTreeResources)
            {
                messageId = EtpExtender.GetTreeResources(uri, Model.DiscoveryDepth, contentTypes);
            }
            else if (Model.DiscoveryFunction == Functions.GetGraphResources)
            {
                messageId = EtpExtender.GetGraphResources(uri, Model.DiscoveryScope, Model.GroupByType, Model.DiscoveryDepth, contentTypes);
            }
            else
            {
                messageId = EtpExtender.GetResources(uri);
            }

            return(Task.FromResult(messageId));
        }
Example #7
0
        /// <summary>
        /// Called when the OpenChannel message is recieved.
        /// </summary>
        /// <param name="header">The header.</param>
        /// <param name="message">The message.</param>
        /// <param name="channels">The channels.</param>
        private void OnOpenChannel(IMessageHeader header, ISpecificRecord message, IList <IChannelMetadataRecord> channels)
        {
            var dataLoadSettings = Model.DataLoad;

            var lastIndex = dataLoadSettings.IsTimeIndex
                ? new DateTimeOffset(dataLoadSettings.LastTimeIndex).ToUnixTimeMicroseconds()
                : (object)dataLoadSettings.LastDepthIndex;

            foreach (var channel in channels)
            {
                EtpExtender.OpenChannelResponse(header, channel.ChannelUri, channel.ChannelId, lastIndex, dataLoadSettings.IsInfill, dataLoadSettings.IsDataChange);
            }
        }
Example #8
0
 /// <summary>
 /// Sends the DeleteObject message with the specified URI.
 /// </summary>
 /// <param name="uri">The URI.</param>
 public void SendDeleteObject(string uri)
 {
     EtpExtender.DeleteObject(uri);
 }
Example #9
0
 /// <summary>
 /// Sends the FindObjects message with the specified URI.
 /// </summary>
 /// <param name="uri">The URI.</param>
 public void SendFindObjects(string uri)
 {
     EtpExtender.FindObjects(uri);
 }
Example #10
0
 /// <summary>
 /// Sends the GetObject message with the specified URI.
 /// </summary>
 /// <param name="uri">The URI.</param>
 public void SendGetObject(string uri)
 {
     EtpExtender.GetObject(uri);
 }
Example #11
0
        /// <summary>
        /// Finds the resources using the DiscoveryQuery protocol.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="parent">The parent.</param>
        /// <returns>The message identifier.</returns>
        public Task <long> FindResources(string uri, ResourceViewModel parent = null)
        {
            var result = EtpExtender.FindResources(uri);

            return(Task.FromResult(result));
        }
 /// <summary>
 /// Disconnects to the ETP server.
 /// </summary>
 public void Disconnect()
 {
     EtpExtender?.CloseSession();
 }