Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
0
        private static void parseReceivedURL(string URL)
        {
            currentURL = URL;



            //added for testing!!
            String output = currentURL;

            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!!



            var timeDiff  = DateTime.UtcNow - new DateTime(1970, 1, 1);
            var totaltime = timeDiff.TotalMilliseconds;

            stopEventTime = (long)totaltime;

            elapsedTime += stopEventTime - startEventTime;


            if (elapsedTime >= EVENT_URL_TIMEOUT)
            {
                if (!previousURL.Equals(currentURL))
                {
                    writeURLToFile(currentURL);
                    previousURL = currentURL;
                }
            }

            //Console.WriteLine(elapsedTime);

            startEventTime = stopEventTime;
            elapsedTime    = 0;
        }