//take screenshots every 3 seconds if user is active in the last minute
        public void takeScreenShots()
        {
            StringBuilder outputStringBuilder = new StringBuilder();

            while (!isStopped)
            {
                try
                {
                    String currentTime = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
                    String filename    = "screenshot_" + currentTime + ".png";

                    //one minute of inactivity
                    if (UserInteractionManager.GetLastInputTime() < 60)
                    {
                        Console.WriteLine("Taking screenshot...");
                        takeScreenshot(outputFolderPath + "/" + filename);
                    }
                }
                catch (Exception e)
                {
                    logger.Error("Error in ActivityTracker: ", e);
                }

                try
                {
                    Thread.Sleep(3000);
                }
                catch (Exception e)
                {
                    logger.Error("Error in ActivityTracker: ", e);
                }
            }
        }
Exemplo n.º 2
0
        public void stopServices()
        {
            ActivityTracker.stop();
            ScreenshotManager.stop();
            UserInteractionManager.stop();
            URLFetcher.stop();

            isStarted = false;
        }
Exemplo n.º 3
0
        public void getData()
        {
            ConcurrentStack <DataCollectionStructure> activityTrackerData =
                ActivityTracker.getDataAndResetCollector();
            ConcurrentStack <DataCollectionStructure> userInteractionData =
                UserInteractionManager.getDataAndResetCollector();
            ConcurrentStack <DataCollectionStructure> urlFetcherService =
                URLFetcher.getDataAndResetCollector();

            IEnumerator <DataCollectionStructure> activityTrackerDataIterator = activityTrackerData.GetEnumerator();
            IEnumerator <DataCollectionStructure> userInteractionDataIterator = userInteractionData.GetEnumerator();
            IEnumerator <DataCollectionStructure> urlFetcherServiceIterator   = urlFetcherService.GetEnumerator();

            String data = "Activity Tracker: \r\n";

            while (activityTrackerDataIterator.MoveNext())
            {
                data += activityTrackerDataIterator.Current.ToString();
            }

            data += "\r\nUserInteraction:\r\n";
            while (userInteractionDataIterator.MoveNext())
            {
                data += userInteractionDataIterator.Current.ToString();
            }

            data += "\r\nURL fetcher:\r\n";
            while (urlFetcherServiceIterator.MoveNext())
            {
                data += urlFetcherServiceIterator.Current.ToString();
            }

            ScreenshotManager.takeScreenshot(localCacheFolder + "/photo.jpg");

            writeDataToFile(localCacheFolder + "/fisier.txt", data);
        }
Exemplo n.º 4
0
        static void RunPCInteractionListener()
        {
            String        lastActivity        = "";
            String        currentActivity     = "";
            StringBuilder outputStringBuilder = new StringBuilder();
            //String lastMinuteFilename = "chunk#4_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm");
            String lastMinuteFilename = "pcinteractionlog_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm");

            while (!isStopped)
            {
                try
                {
                    //added for testing!!
                    String output = "";

                    if (UserInteractionManager.GetLastInputTime() < 60)
                    {
                        output = "[**Activity**]";
                    }
                    else
                    {
                        output = "[**Inactivity**]";
                    }

                    String last = "";
                    if (synchronizedCollectedResults.Count > 0)
                    {
                        DataCollectionStructure dataCollectionStructure = null;
                        synchronizedCollectedResults.TryPeek(out dataCollectionStructure);

                        if (dataCollectionStructure != null)
                        {
                            last = dataCollectionStructure.data;
                        }
                    }

                    if (last.Equals(output))
                    {
                        DataCollectionStructure dataCollectionStructure = null;
                        synchronizedCollectedResults.TryPop(out dataCollectionStructure);

                        if (dataCollectionStructure != null)
                        {
                            dataCollectionStructure.counter++;
                            synchronizedCollectedResults.Push(dataCollectionStructure);
                        }
                    }
                    else
                    {
                        synchronizedCollectedResults.Push(new DataCollectionStructure(output, 1));
                    }
                    //added for testing!!



                    String currentTime = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
                    String currentTimeMinutePrecision = currentTime.Substring(0, currentTime.LastIndexOf("_"));
                    //String filename = "chunk#4_" + currentTimeMinutePrecision;
                    String filename = "pcinteractionlog_" + currentTimeMinutePrecision;

                    if (filename.Equals(lastMinuteFilename))
                    {
                        //one minute of inactivity
                        if (UserInteractionManager.GetLastInputTime() < 60)
                        {
                            currentActivity = "[**Activity**]";
                            Console.WriteLine("[**Activity**]");
                            if (!lastActivity.Equals(currentActivity))
                            {
                                String line = "[**Output**]";
                                line += "[" + currentTime + "]";
                                line += "\n";

                                line += currentActivity;

                                line += "\n";

                                outputStringBuilder.Append(line);
                                lastActivity = currentActivity;

                                logger.Info(line);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Inactivity...");
                            currentActivity = "[**Inactivity**]";

                            if (!lastActivity.Equals(currentActivity))
                            {
                                String line = "[**Output**]";
                                line += "[" + currentTime + "]";
                                line += "\n";
                                line += "[**Inactivity**]";
                                line += "\n";

                                outputStringBuilder.Append(line);
                                lastActivity = currentActivity;

                                logger.Info(line);
                            }
                        }
                    }
                    else
                    {
                        String outputLine      = "";
                        String toStringBuilder = outputStringBuilder.ToString();

                        if (toStringBuilder.Length > 0)
                        {
                            //including computer information firstly
                            String companyInfo = "company:" + companyName + "\n";
                            companyInfo += "office:" + officeName + "\n";
                            companyInfo += "computer:" + computerName + "\n";

                            outputLine = companyInfo + toStringBuilder;

                            //encrypt current line before writing it to file
                            //String chunkedData = XorEncrypt.Encrypt(outputLine);

                            //write this output from current minute to file
                            writeDataToFile(outputFolderPath + "/" + lastMinuteFilename, outputLine);
                            //writeDataToFile(outputFolderPath + "/" + lastMinuteFilename, chunkedData);

                            //reset variables to process next minute
                            //lastMinuteFilename = filename;

                            outputStringBuilder.Clear();
                        }

                        //reset variables to process next minute
                        lastMinuteFilename = filename;
                    }
                }
                catch (Exception e)
                {
                    logger.Error("Error in ActivityTracker: ", e);
                }


                try
                {
                    Thread.Sleep(3000);
                }
                catch (Exception e)
                {
                    logger.Error("Error in ActivityTracker: ", e);
                }
            }
        }