Exemplo n.º 1
0
        public static int Main2(string[] args)
        {
            Timetube tt = Timetube.getInstance();

            tt.SaveDirectory = "c:\\temp\\newDir";
            tt.Interval      = 10;
            Console.WriteLine("*** Started " + TimeFormat.GetDate() + " " + TimeFormat.GetTime());

            // initialise icon cache
            tt.loadIconMap();
            tt.BeginCapture();

            // spin wheels
            Console.WriteLine("press <enter> to stop...");
            Console.ReadLine();

            // shut down timer & event watchers
            tt.EndCapture();
            return(0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Timer entry point. At each timer tick, capture the desktop image, process list
        /// and window list. If the last tick hasn't finished processing, then this method
        /// returns without performing any processing.
        /// </summary>
        ///
        /// <param name="sender">Not entirely sure. Probably the timer object, I guess</param>
        /// <param name="e">The timer event</param>
        private void OnTimer(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (working)
            {
                Console.WriteLine("(skipping)");
            }
            else
            {
                working = true;

                // Console.WriteLine("Working.");
                HiPerfTimer pt = new HiPerfTimer();     // create a new PerfTimer object
                pt.Start();                             // start the timer

                // capturing screen takes about 0.2 secs

                string ext;
                if (SaveFormat.Equals("JPEG"))
                {
                    ext = ".jpg";
                }
                else if (SaveFormat.Equals("GIF"))
                {
                    ext = ".gif";
                }
                else if (SaveFormat.Equals("PNG"))
                {
                    ext = ".png";
                }
                else if (SaveFormat.Equals("BMP"))
                {
                    ext = ".bmp";
                }
                else
                {
                    ext = ".unknown";
                }

                String dir         = SaveDirectory + "\\";
                String thisDate    = TimeFormat.GetDate();
                String thisTime    = TimeFormat.GetTime();
                String imgFilename = dir + thisDate + "\\desktop-" + thisTime + ext;
                String logFilename = dir + thisDate + "\\windowList.log";

                if (!Directory.Exists(dir + thisDate))
                {
                    // make the directory
                    Directory.CreateDirectory(dir + thisDate);
                }
                ScreenCapture sc = new ScreenCapture();
                sc.CaptureScreenToFile(imgFilename, /*System.Drawing.Imaging.ImageFormat.Jpeg*/
                                       SaveFormat, SaveQuality);

                StreamWriter sw = new StreamWriter(logFilename, true); // true = append
                sw.WriteLine("*** Begin snapshot " + thisTime);
                Hashtable  newProcessMap = getProcessMap();
                List <int> newHwndOrder  = new List <int>();
                Hashtable  newWindowList = getWindowMap(newHwndOrder);
                mergeProcessMap(sw, newProcessMap);
                mergeWindowMap(sw, newWindowList);
                mergeHwndOrder(sw, newHwndOrder);

                lock (eventList) {
                    // Console.WriteLine("numevents:" + eventList.Count);
                    if (eventList.Count > 0)
                    {
                        String       plogFilename = dir + thisDate + "\\processList.log";
                        StreamWriter sw2          = new StreamWriter(plogFilename, true); // true = append
                        foreach (String s in eventList)
                        {
                            sw2.WriteLine(s);
                        }
                        sw2.Close();
                        eventList.Clear();
                    }
                }

                pt.Stop();                              // stop the timer
                sw.WriteLine("*** Snapshot time " + pt.Duration);
                sw.Close();
                working = false;
            }
        }
Exemplo n.º 3
0
 public void Win32ProcDeleted(object sender, EventArrivedEventArgs e) {
     List<string> eventList = Timetube.getInstance().eventList;
     if (eventList != null) {
         foreach (PropertyData pd in e.NewEvent.Properties) {
             ManagementBaseObject mbo = null;
             if ((mbo = pd.Value as ManagementBaseObject) != null) {
                 lock (eventList) {
                     eventList.Add(String.Format("{0} Start process {1} exe='{2}' cl='{3}'", TimeFormat.GetTime(),
                         mbo.Properties["ProcessId"].Value,
                         mbo.Properties["ExecutablePath"].Value, mbo.Properties["CommandLine"].Value));
                 }
             }
         }
     }
     /*
     //lock (Timetube.eventList) {
     if (Timetube.eventList != null) {
         Timetube.eventList.Add(String.Format("{0} End process {1} exe='{2}' cl='{3}'",
             TimeFormat.GetTime(), e.NewEvent.Properties["ProcessId"]));
     }
     //}
     Console.WriteLine("evc={0}",Timetube.eventList.Count);
      */
 }
Exemplo n.º 4
0
        public void Win32ProcCreated(object sender, EventArrivedEventArgs e) {
            List<string> eventList = Timetube.getInstance().eventList;
            if (Timetube.getInstance().eventList != null) {
                foreach (PropertyData pd in e.NewEvent.Properties) {
                    ManagementBaseObject mbo = null;
                    if ((mbo = pd.Value as ManagementBaseObject) != null) {
                        lock (eventList) {
                            eventList.Add(String.Format("{0} Start process {1} exe='{2}' cl='{3}'", TimeFormat.GetTime(),
                                mbo.Properties["ProcessId"].Value,
                                mbo.Properties["ExecutablePath"].Value, mbo.Properties["CommandLine"].Value));
                        }
                    }
                }
            }

            /*
            foreach (PropertyData pd in e.NewEvent.Properties) {
                ManagementBaseObject mbo = null;
                if ((mbo = pd.Value as ManagementBaseObject) != null) {
                    Console.WriteLine("--------------Properties------------------");
                    foreach (PropertyData prop in mbo.Properties)
                        Console.WriteLine("{0} - {1}", prop.Name, prop.Value);
                }
            }
            */
        }