Пример #1
0
        public NetStatItemViewModel Upsert(NetStatItemViewModel netStat)
        {
            using (var db = new LiteDatabase(DB.Path))
            {
                var col    = db.GetCollection <NetStatItemViewModel>(DB.CollConnections);
                var result = col.Query().Where(x => x.RemoteIp.Equals(netStat.RemoteIp)).FirstOrDefault();

                db.BeginTrans();

                if (result is null)
                {
                    col.Upsert(netStat);
                }
                else
                {
                    result = netStat;
                    col.Upsert(result);
                }

                col.EnsureIndex(x => x.RemoteIp);
                db.Commit();
            }

            return(netStat);
        }
Пример #2
0
        private void pushPipeLine(ProcessIPInfo proc)
        {
            //remote IP is already logged
            //publish update
            if (netStatDict.ContainsKey(proc.RemoteIp))
            {
                var er = netStatDict[proc.RemoteIp];
                er.ProcessInfo = proc;

                if (er.IpInfo is null)
                {
                    // er.IpInfo = ips.GetIPInfo(proc).Result;
                }

                ea.GetEvent <ConnectionUpdateEvent>().Publish(er);
            }

            //new remote IP
            //get IP info and update current view of connections
            else
            {
                ips.GetIPInfo(proc.RemoteIp, (error, ipInfo) =>
                {
                    if (error == null)
                    {
                        var netstat = new NetStatItemViewModel(proc)
                        {
                            IpInfo = ipInfo, Host = GetHostByAddress(proc.RemoteIp)
                        };

                        netStatDict.Add(proc.RemoteIp, netstat);
                        ea.GetEvent <ConnectionUpdateEvent>().Publish(netstat);
                    }
                });
            }
        }