private IRecordPolicy CreateRecordPolicy() { IRecordPolicy policy = null; try { if (!string.IsNullOrEmpty(Global.Config.RecordPolicy)) { string path = System.IO.Path.Combine(Application.StartupPath, "Policy.dll"); if (System.IO.File.Exists(path)) { var assembly = System.Reflection.Assembly.LoadFrom(path); if (assembly != null) { policy = assembly.CreateInstance(Global.Config.RecordPolicy) as IRecordPolicy; } } else { var assembly = System.Reflection.Assembly.GetEntryAssembly(); if (assembly != null) { policy = assembly.CreateInstance(Global.Config.RecordPolicy) as IRecordPolicy; } } } } catch (Exception ex) { TraceLogger.Instance.WriteException(ex); } if (policy == null) { policy = new GenericPolicy(); } return(policy); }
public RawInputApp() { // load config try { TraceLogger.Instance.WriteLineInfo("Configuration is loading..."); string fpath = System.IO.Path.Combine(Application.StartupPath, "record.config"); Global.Config.LoadConfiguration(fpath); TraceLogger.Instance.WriteLineInfo("Configuration has loaded."); } catch (Exception ex) { TraceLogger.Instance.WriteException(ex); } // init app TraceLogger.Instance.WriteLineInfo("Application is initing..."); this.InitNotifyIcon(); Application.ApplicationExit += (o, ev) => { this.Dispose(false); }; Application.Idle += (o, ev) => { GC.Collect(); }; TraceLogger.Instance.WriteLineInfo("Application has inited."); // check license while (!IsLicenseValid()) { UpdateConfiguration(null); Thread.Sleep(10 * 1000); } // record policy TraceLogger.Instance.WriteLineInfo("RecordPolicy is creating: " + Global.Config.RecordPolicy); _policy = CreateRecordPolicy(); TraceLogger.Instance.WriteLineInfo("RecordPolicy has created."); // start hook TraceLogger.Instance.WriteLineInfo("RawInputWnd is creating..."); this.MainForm = this.CreateRawInputWnd(); TraceLogger.Instance.WriteLineInfo(string.Format("RawInputWnd has created: {0}", (this.MainForm == null) ? "null" : this.MainForm.Handle.ToString())); // start tasks TraceLogger.Instance.WriteLineInfo("Tasks is starting..."); _tasks = new Common.Task.PeriodTask(1000); _tasks.AddTask("Configuration", this.UpdateConfiguration, 60, 0); _tasks.AddTask("ShortSession", this.MakeShortSession, 10, 10); _tasks.Start(); TraceLogger.Instance.WriteLineInfo("Tasks has started."); // start worker TraceLogger.Instance.WriteLineInfo("BackgroundWorker is starting..."); _recordWorker = new BackgroundWorker(); _recordWorker.DoWork += (o, ev) => { this.RecordWorker(); }; _recordWorker.WorkerReportsProgress = true; _recordWorker.RunWorkerAsync(); TraceLogger.Instance.WriteLineInfo("BackgroundWorker has started."); }