コード例 #1
0
 private void RunNext(Guid guid, string jsonData)
 {
     _internalCollection.Add(new BlockItem {
         SessionId = guid, Data = jsonData
     });
     CurrentLogger.LogInformation("Hub incoming message - {0}.", guid);
 }
コード例 #2
0
        private Task Reconnected(string arg)
        {
            if (Connection == null)
            {
                CurrentLogger.LogInformation("Hub connection state is empty! Not initialised. Please check if the URL is correct.");
            }
            else
            {
                CurrentLogger.LogInformation("Hub connection state - Reconnected - {0}", Connection.State);
            }

            return(Task.CompletedTask);
        }
コード例 #3
0
        private async Task Closed(Exception arg)
        {
            if (Connection == null)
            {
                CurrentLogger.LogInformation("Hub connection state is empty! Not initialised. Please check if the URL is correct.");
            }
            else
            {
                CurrentLogger.LogInformation("Hub connection state - Closed - {0}", Connection.State);
            }

            await Task.Delay(5000);
        }
コード例 #4
0
        public async Task <bool> Connect(CancellationToken token)
        {
            if (Connection == null)
            {
                CurrentLogger.LogInformation("Hub connection is empty! Not initialised. Please check if the URL is correct.");
                return(false);
            }

            while (true)
            {
                System.Reflection.Assembly         assembly = System.Reflection.Assembly.GetExecutingAssembly();
                System.Diagnostics.FileVersionInfo fvi      = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
                DateTime buildDate = LinkerHelper.GetLinkerTimestampUtc(assembly);

                CurrentLogger.LogInformation(String.Format("{0} version {1}. Build date and time {2}.", fvi.ProductName, fvi.ProductVersion, DateTimeOffset.FromFileTime(buildDate.ToFileTime())));
                CurrentLogger.LogInformation("Hub connection state - Method(Connect) - {0}", Connection.State);
                if (Connection.State == HubConnectionState.Connected)
                {
                    lock (consumeLock)
                    {
                        while (!_internalCollection.IsCompleted)
                        {
                            BlockItem item = _internalCollection.Take();

                            Task.Run(() =>
                            {
                                try
                                {
                                    dynamic data = JsonConvert.DeserializeObject <dynamic>(item.Data);
                                    IPreingestCommand command = Creator.FactoryMethod(item.SessionId, data);

                                    if (command != null)
                                    {
                                        Settings settings = data.settings == null ? null : JsonConvert.DeserializeObject <Settings>(data.settings.ToString());

                                        using (HttpClient client = new HttpClient())
                                        {
                                            if (settings == null)
                                            {
                                                command.Execute(client, item.SessionId);
                                            }
                                            else
                                            {
                                                command.Execute(client, item.SessionId, settings);
                                            }
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    CurrentLogger.LogInformation("An exception occurred with SessionId {0}.", item.SessionId);
                                    CurrentLogger.LogError(e, e.Message);
                                }
                                finally { }
                            });
                        }
                    }
                    return(true);
                }

                try
                {
                    await Connection.StartAsync(token);

                    CurrentLogger.LogInformation("Hub connection state - Method(Connect) after StartAsync - {0}", Connection.State);
                    return(true);
                }
                catch when(token.IsCancellationRequested)
                {
                    return(false);
                }