Example #1
0
        // GET: Home
        public ActionResult Index()
        {
            try
            {
                var req = WebRequest.Create(Utilities.GetConfigLocation() + "/Account/Signin") as HttpWebRequest;
                req.Method      = "GET";
                req.Accept      = "application/json";
                req.ContentType = "application/json";
                req.Headers.Add("Accept-Language", "en-us");
                req.UserAgent = "StardustProxy/1.0";
                ConfigCacheHelper.SetCredentials(req);
                req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                var resp = req.GetResponse();
                using (var reader = new StreamReader(resp.GetResponseStream()))
                {
                    ViewBag.ConnectionStatus = reader.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                ex.Log();

                ViewBag.ConnectionStatus = "Not connected";
            }
            if (Startup.hubConnection != null)
            {
                ViewBag.NotificationStatus = Startup.hubConnection.State.ToString();
            }
            var assemblyDate = GetType().Assembly.Location.IsNullOrWhiteSpace()
                ? DateTime.Now
                : System.IO.File.GetLastWriteTime(GetType().Assembly.Location);

            ViewBag.Version = $"{assemblyDate.Year}.{assemblyDate.Month}.{assemblyDate.DayOfYear}";
            return(View());
        }
Example #2
0
 public ActionResult Health()
 {
     try
     {
         var req = WebRequest.Create(Utilities.GetConfigLocation() + "/Account/Signin") as HttpWebRequest;
         req.Method      = "GET";
         req.Accept      = "application/json";
         req.ContentType = "application/json";
         req.Headers.Add("Accept-Language", "en-us");
         req.UserAgent = "StardustProxy/1.0";
         ConfigCacheHelper.SetCredentials(req);
         req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
         var resp = req.GetResponse();
         using (var reader = new StreamReader(resp.GetResponseStream()))
         {
             var status = reader.ReadToEnd();
             Logging.DebugMessage("Connection status: {0}", status);
         }
     }
     catch (Exception ex)
     {
         ex.Log();
         return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Not connected to nexus"));
     }
     if (Startup.hubConnection != null)
     {
         if (Startup.hubConnection.State == ConnectionState.Connecting || Startup.hubConnection.State == ConnectionState.Connected)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.OK, "Healthy"));
         }
     }
     return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Notification service not connected to nexus"));
 }
Example #3
0
 private static void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (hubConnection.State == ConnectionState.Disconnected)
     {
         try
         {
             hubConnection.Stop();
         }
         catch (Exception ex)
         {
             ex.Log();
         }
         ConfigCacheHelper.SetCredentials(hubConnection);
         hubConnection.Start();
     }
     hub.Invoke("ping", Environment.MachineName);
 }
Example #4
0
 static void hubConnection_Error(Exception obj)
 {
     obj.Log("Signalr connection issue");
     if (obj is UnauthorizedAccessException || obj.InnerException is UnauthorizedAccessException)
     {
         Logging.DebugMessage("Token expiry... refreshing oauth token");
         try
         {
             hubConnection.Stop();
         }
         catch (Exception)
         {
             // ignored
         }
         hubConnection.Dispose();
         ConfigCacheHelper.SetCredentials(hubConnection);
         hubConnection.Start();
     }
 }
Example #5
0
 private static void RegisterForNotifications()
 {
     try
     {
         var userName = GetConfigServiceUser();
         var password = GetConfigServicePassword();
         GlobalHost.HubPipeline.RequireAuthentication();
         hubConnection = new HubConnection(GetConfigLocation());
         if (hubConnection.CookieContainer == null)
         {
             hubConnection.CookieContainer = new CookieContainer();
         }
         //hubConnection.Credentials = new NetworkCredential(userName, password, GetConfigServiceDomain());
         ConfigCacheHelper.SetCredentials(hubConnection);
         hub = hubConnection.CreateHubProxy("configSetHub");
         hub.On("changed",
                (string id, string name) =>
         {
             if (string.Equals(id, "user", StringComparison.OrdinalIgnoreCase))
             {
                 UpdateUser(name);
             }
             else
             {
                 UpdateEnvironmet(id, name);
             }
         });
         hubConnection.EnsureReconnecting();
         hubConnection.Reconnecting += hubConnection_Reconnecting;
         hubConnection.Closed       += hubConnection_Closed;
         hubConnection.Error        += hubConnection_Error;
         hubConnection.StateChanged += hubConnection_StateChanged;
         hubConnection.Start();
         CreatePingService();
     }
     catch (Exception ex)
     {
         ex.Log();
     }
 }