public bool AppendRecord(FishData fishData) { string file = GetFile(fishData.TimeStamp); string toAppend = CSVEncode(fishData.WindowTitle) + "," + CSVEncode(fishData.ProcessName) + "," + CSVEncode((fishData.TimeStamp - new DateTime(1970, 1, 1)).TotalSeconds.ToString()) + Environment.NewLine; File.AppendAllText(file, toAppend); return(true); }
static void Main(string[] args) { FishDataSource fishDataSource = new FishDataSource(); for (; ;) { FishData fishData = fishDataSource.RetrieveFishData(); Console.WriteLine(fishData); Thread.Sleep(1000); } }
static void Main(string[] args) { FishDataSource fishDataSource = new FishDataSource(); for (; ;) { FishData fishData = fishDataSource.RetrieveFishData(); if (fishData != null) { FishTimeDataStorage.Instance.AppendRecord(fishData); } Thread.Sleep(1000); } }
public FishData RetrieveFishData() { FishData result = new FishData(); IntPtr foreWin = GetForegroundWindow(); if (foreWin == IntPtr.Zero) { return(null); } UInt32 procId = 0; GetWindowThreadProcessId(foreWin, out procId); if (procId == 0) { return(null); } using (Process proc = Process.GetProcessById((int)procId)) { result.ProcessName = Path.GetFileNameWithoutExtension(proc.ProcessName); } char[] buf = new char[512]; int len = GetWindowText(foreWin, buf, 512); result.TimeStamp = DateTime.Now; if (len > 0) { result.WindowTitle = new string(buf, 0, len); } else { result.WindowTitle = ""; } return(result); }