Beispiel #1
0
        static void Main(string[] args)
        {
            var t = BinaryConnector.StaticLoad <List <AppSession> >(@"C:\Users\mhdb9\Desktop\API\Data\mhdb96\2021-01-16-data-file_02-36.hdf");
            var y = t.GroupBy(a => a.App.ExcutableName);

            //var hash = File.ReadAllText(@"C:\Users\mhdb9\Desktop\hash.txt");
            //byte[] data = System.Text.Encoding.ASCII.GetBytes(Console.ReadLine());
            //data = new System.Security.Cryptography.SHA256Managed().ComputeHash(data);
            //String hash = System.Text.Encoding.ASCII.GetString(data);
            //File.WriteAllText(@"C:\Users\mhdb9\Desktop\hash.txt", hash, Encoding.ASCII);
            //GlobalConfig.InitializeConnections();
            //var t = GlobalConfig.Connection.Sessions_GetByUserIdAndDate(12, new DateTime(2020, 9, 1), new DateTime(2020, 10, 1));
            //var t = BinaryConnector.StaticLoad<KeystrokeData[]>(@"C:\Users\mhdb9\Desktop\02-11-2020\data-file_16.kdf");
            //WrongDataFixer.CreateDatabaseRecordsFromCorrectFiles(@"C:\Users\mhdb9\Desktop\nurgul", 17);
            //CreateDatabaseRecordsFromFiles();
            //var user = new UserModel {Id = 12 };
            //GlobalConfig.Connection.GetHoldTimesStatistics(user);
            //Dictionary<int,int> counts = new Dictionary<int, int>();
            //foreach (var key in (KeysList[])Enum.GetValues(typeof(KeysList)))
            //{
            //    counts.Add((int)key, 0);
            //}
            //foreach (var session in user.Sessions)
            //{
            //    foreach (var key in session.SessionKeys)
            //    {
            //        counts[key.KeyId]++;
            //    }
            //}
            //var mylist = counts.ToList();
            //var t = mylist.OrderByDescending(x => x.Value);
            //CreateDataset();
            Console.WriteLine("finished");
            Console.ReadLine();
        }
Beispiel #2
0
 public void OnLogin(User user)
 {
     _user = user;
     BinaryConnector.StaticSave(_user, GlobalConfig.UserDataFile);
     WindowVisibility = Visibility.Visible;
     ActivateItem(new MainControlViewModel(_eventAggregator, _user));
 }
Beispiel #3
0
 public List <AppSession> GetAllSessions()
 {
     if (isInitilized)
     {
         if (sessions == null)
         {
             try
             {
                 sessions = BinaryConnector.StaticLoad <List <AppSession> >(filePath);
                 return(sessions);
             }
             catch (Exception)
             {
                 sessions = new List <AppSession>();
                 return(sessions);
             }
         }
         else
         {
             return(sessions);
         }
     }
     else
     {
         throw new Exception("Data cache file path was not provided. Call AppManager.Initialize(string path) to pass the path");
     }
 }
Beispiel #4
0
        public void CreateLocalFile(List <AppSession> data)
        {
            BinaryConnector.StaticSave(data, GlobalConfig.DataFilePath);
            BinaryFile file = EncodeIntoBinaryFile(GlobalConfig.DataFilePath);

            AddFile(file);
        }
Beispiel #5
0
 private void CheckForUser()
 {
     try
     {
         User = BinaryConnector.StaticLoad <User>(GlobalConfig.UserDataFile);
     }
     catch
     {
         User = null;
     }
 }
Beispiel #6
0
 private LogsManager()
 {
     try
     {
         logs = BinaryConnector.StaticLoad <Queue <Log> >(GlobalConfig.LogCacheFilePath);
     }
     catch (Exception)
     {
         LogToTextFile(new ErrorLog
         {
             Severity = LogSeverity.Low,
             Type     = ErrorType.IOError,
             Text     = "No cahced log file was found."
         });
         logs = new Queue <Log>();
     }
 }
Beispiel #7
0
 private FilesManager()
 {
     try
     {
         files = BinaryConnector.StaticLoad <Queue <BinaryFile> >(GlobalConfig.DataCacheFilePath);
     }
     catch (Exception e)
     {
         files = new Queue <BinaryFile>();
         LogsManager.LogToTextFile(new ErrorLog
         {
             Severity = LogSeverity.Low,
             Type     = ErrorType.IOError,
             Text     = "No cahced data file was found. - " + e.Message
         });
     }
 }
Beispiel #8
0
        public async Task SyncLogs(User user)
        {
            var api = ApiHelper.GetApiHelper();

            while (logs.Count > 0)
            {
                bool isPosted;
                try
                {
                    // !!!!!!!!!!!!!! NOT SENDING DATA TO SERVER !!!!!!!!!!!!!!!
                    isPosted = await api.PostLog(logs.Peek(), user);

                    if (isPosted)
                    {
                        logs.Dequeue();
                    }
                }
                catch (Exception)
                {
                    LogToTextFile(new ErrorLog
                    {
                        Severity = LogSeverity.Medium,
                        Type     = ErrorType.ConnectionError,
                        Text     = "Failed to sync logs, no connection to the server."
                    });
                    BinaryConnector.StaticSave(logs, GlobalConfig.LogCacheFilePath);
                    break;
                }
            }
            if (logs.Count == 0)
            {
                if (File.Exists(GlobalConfig.LogCacheFilePath))
                {
                    File.Delete(GlobalConfig.LogCacheFilePath);
                    LogToTextFile(new Log
                    {
                        Severity = LogSeverity.Low,
                        Type     = LogType.FileDeleted,
                        Text     = "Log cache file deleted after syncing properly."
                    });
                }
            }
        }
Beispiel #9
0
        private void open_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt       = ".kdf";                       // Default file extension
            dlg.Filter           = "KDA Data File (.kdf)|*.kdf"; // Filter files by extension
            dlg.InitialDirectory = @"C:\Users\mhdb9\Desktop\API\Data\MHD-MSI-mhdb9";
            dlg.Title            = "Open KDA Data File";

            // Show open file dialog box
            var result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;
                var    d        = BinaryConnector.StaticLoad <KeystrokeData[]>(filename);
            }
        }
Beispiel #10
0
        public void UploadFile(BinaryFile file)
        {
            DataFileModel model = new DataFileModel();

            model.Date    = file.Date;
            model.User.Id = file.User.Id;
            model.Path    = FileManager.GetFileManager().SaveSessionsFile(file);
            GlobalConfig.Connection.File_Insert(model);
            var sessions = BinaryConnector.StaticLoad <List <AppSession> >(model.Path);

            foreach (var session in sessions)
            {
                if (session.MouseData != null && session.EndTime != DateTime.MinValue)
                {
                    AppModel appModel = new AppModel();
                    appModel.ProcessName = session.App.ProcessName;
                    GlobalConfig.Connection.App_Insert(appModel);
                    SessionModel sessionModel = new SessionModel();
                    sessionModel.AppId = appModel.Id;
                    sessionModel.BackspaceStrokesCount = session.KeyboardData.BackspaceStrokesCount;
                    sessionModel.StrokesCount          = session.KeyboardData.StrokesCount;
                    sessionModel.StrokeHoldTimes       = session.KeyboardData.StrokeHoldTimes;
                    sessionModel.UniqueKeysCount       = session.KeyboardData.UniqueKeysCount;
                    sessionModel.MouseClickCount       = (int)session.MouseData.MouseClickCount;
                    sessionModel.MouseClickTotalTime   = (int)session.MouseData.MouseClickTotalTime;
                    sessionModel.StartTime             = session.StartTime;
                    sessionModel.EndTime = session.EndTime;
                    sessionModel.UserId  = model.User.Id;
                    sessionModel.AppId   = appModel.Id;
                    GlobalConfig.Connection.Session_Insert(sessionModel);
                    if (session.App.Type == HRPMSharedLibrary.Enums.AppType.Browser)
                    {
                        DomainModel domainModel = new DomainModel();
                        domainModel.Domain = session.App.Content;
                        GlobalConfig.Connection.Domain_Insert(domainModel);
                        GlobalConfig.Connection.SessionDomain_Insert(sessionModel.Id, domainModel.Id);
                    }
                }
            }
        }
Beispiel #11
0
 private void SaveSessionsToDisk()
 {
     BinaryConnector.StaticSave(GetAllSessions(), filePath);
 }