Exemple #1
0
        private void DeleteOldImages()
        {
            List <string> protectedFiles;

            using (var ctx = new CompSpyContext())
            {
                protectedFiles = ctx.Abuses.Where(a => !a.Read).Select(abuse => abuse.ScreenPath).ToList();
            }
            var di = new DirectoryInfo(GetUploadsDirectory());

            foreach (FileInfo file in di.GetFiles())
            {
                if (!protectedFiles.Contains(file.Name.Substring(0, file.Name.Length - 4)) &&
                    DateTime.Compare(file.CreationTime, DateTime.Now.AddSeconds(-30)) < 0)
                {
                    file.Delete();
                }
            }
        }
Exemple #2
0
        public void Disconnect(string stationDiscr)
        {
            using (var ctx = new CompSpyContext())
            {
                var comp = ctx.Computers.Where(c => c.StationDiscriminant == stationDiscr).FirstOrDefault();
                if (comp != null)
                {
                    comp.ConnectionID     = null;
                    ctx.Entry(comp).State = EntityState.Modified;
                    ctx.SaveChanges();

                    Groups.Remove(Context.ConnectionId, comp.Classroom.Name);
                    var groupsToInform = new List <string> {
                        comp.Classroom.Name, Context.ConnectionId
                    };
                    suirvelanceHub.Clients.Groups(groupsToInform).ComputerDisconnected(stationDiscr);
                }
            }
        }
Exemple #3
0
        public void ReceiveData(string data)
        {
            var json = new JavaScriptSerializer().Deserialize <Message>(data);

            using (var ctx = new CompSpyContext())
            {
                var comp = ctx.Computers.Where(c => c.ConnectionID == Context.ConnectionId).FirstOrDefault();
                if (comp != null)
                {
                    var black = ctx.Blacklists.Where(b => b.ClassroomID == comp.ClassroomID);
                    json.listaProcesow = json.listaProcesow.Where(x => black.Any(y => y.ProcessName == x)).ToList();
                    var jsonSerialized = new JavaScriptSerializer().Serialize(json);

                    if (json.listaProcesow.Count != 0)
                    {
                        var abuse = new Models.Abuse()
                        {
                            AbuserID   = comp.ComputerID,
                            DetectedOn = DateTime.Now,
                            Read       = false,
                            ScreenPath = json.image
                        };
                        ctx.Abuses.Add(abuse);
                        ctx.SaveChanges();
                    }

                    if (json.hq)
                    {
                        suirvelanceHub.Clients.Group(Context.ConnectionId).ComputerDataReceived(jsonSerialized);
                    }
                    else
                    {
                        suirvelanceHub.Clients.Group(comp.Classroom.Name).ComputerDataReceived(jsonSerialized);
                    }
                }
            }
        }