예제 #1
0
        private bool TryGetSession(object sender, out HubClientSession session)
        {
            var btn = sender as Button;

            session = btn?.CommandParameter as HubClientSession;
            return(session != null);
        }
예제 #2
0
        internal void Load(HubClientSession session)
        {
            _sess       = session;
            UnsavedText = _sess.JsonConfig ?? "";

            UpdateStates();
            UpdateTitle($"  {_sess}");
        }
예제 #3
0
        internal static void Show(HubClientSession session)
        {
            var win = new CfgEditorWindow1();
            var vm  = Components.Scope.Resolve <ConfigEditorVM>();

            win.DataContext = vm;
            vm.Load(session);
            win.Show();
        }
예제 #4
0
 private bool IsValidSession(HubCallerContext context, out HubClientSession session)
 {
     if (!context.TryGetSession(out session))
     {
         return(false);
     }
     session.HubName     = TargetHubName;
     session.HubClientIP = context.Request.Environment["server.RemoteIpAddress"].ToString();
     return(true);
 }
예제 #5
0
 public static bool TryGetSession(this HubCallerContext context, out HubClientSession session)
 {
     if (!context.Request.TryGetSession(out session))
     {
         return(false);
     }
     session.ConnectionId = context.ConnectionId;
     session.LastActivity = DateTime.Now;
     return(true);
 }
예제 #6
0
        private static void ConsolidateLogs(HubClientSession session, HubClientSession existing)
        {
            if (existing.Logs.Any() && !session.Logs.Any())
            {
                session.Logs.Add(existing.Logs);
            }

            if (existing.Errors.Any() && !session.Errors.Any())
            {
                session.Errors.Add(existing.Errors);
            }
        }
예제 #7
0
        private static string ComposeSessionJson(IHubClientSettings cfg)
        {
            var sess = new HubClientSession
            {
                UserAgent    = cfg.UserAgent,
                AgentVersion = CurrentExe.GetVersion(),
                ComputerName = Environment.MachineName,
                //JsonConfig   = JsonConvert.SerializeObject(cfg),
                JsonConfig = cfg.ReadSavedFile(),
            };

            return(JsonConvert.SerializeObject(sess));
        }
        private void Add(string userAgent)
        {
            var sess = new HubClientSession
            {
                HubName      = "MessageBroadcastHub1",
                UserAgent    = userAgent,
                AgentVersion = "1.0.17252.0043",
                ConnectionId = userAgent.SHA1ForUTF8().Substring(9),
                LastActivity = DateTime.Now,
                HubClientIP  = "123.456.789.1011",
                ComputerName = "FATS-SVR2",
                CurrentState = new CurrentClientState
                {
                    PublicIP = "221.123.456.789"
                }
            };

            sess.Logs.Add(new LogEntry("sample msg 1"));
            sess.Logs.Add(new LogEntry("sample msg 2"));

            List.Add(sess);
        }
예제 #9
0
        public static bool TryGetSession(this IRequest request, out HubClientSession session)
        {
            if (request.Environment.TryGetValue(ENV_KEY, out object sessionObj))
            {
                session = sessionObj as HubClientSession;
                return(session != null);
            }

            var timestamp = request.Headers[TIME_HEADER];
            var authHeadr = request.Headers[AUTH_HEADER];

            if (TryDecrypt(authHeadr, timestamp, out string json))
            {
                session = JsonConvert.DeserializeObject <HubClientSession>(json);
                request.Environment.Add(ENV_KEY, session);
                return(true);
            }
            else
            {
                session = null;
                return(false);
            }
        }
예제 #10
0
        public void AddOrUpdate(HubClientSession session)
        {
            var connId   = session.ConnectionId;
            var existing = List.FirstOrDefault(_ => _.ConnectionId == connId);

            if (existing == null)
            {
                ClientStateListeners.Notify.ClientConnected(session);
            }
            else
            {
                try
                {
                    AsUI(_ => ConsolidateLogs(session, existing));
                    Remove(connId);
                }
                catch (Exception ex)
                {
                    Alert.Show(ex, "AddOrUpdate existing client");
                }
                ClientStateListeners.Notify.ClientInteracted(session);
            }
            AsUI(_ => List.Add(session));
        }
예제 #11
0
        private void ShowScreenshotIfAny(HubClientSession session)
        {
            var cap = $"[{DateTime.Now.ToShortTimeString()}]  {session.UserAgent}";

            AsUI(_ => BitmapWindow1.Show(cap, session.CurrentState?.ScreenshotB64));
        }