EaseFilter Demo Project
MonitorForm.cs
Go to the documentation of this file.
1 //
3 // (C) Copyright 2012 EaseFilter Technologies Inc.
4 // All Rights Reserved
5 //
6 // This software is part of a licensed software product and may
7 // only be used or copied in accordance with the terms of that license.
8 //
10 
11 using System;
12 using System.Collections.Generic;
13 using System.ComponentModel;
14 using System.Data;
15 using System.Drawing;
16 using System.Linq;
17 using System.Text;
18 using System.Windows.Forms;
19 using System.Runtime.InteropServices;
20 
22 
23 namespace FileMonitor
24 {
25  public partial class MonitorForm : Form
26  {
27  //Purchase a license key with the link: http://www.easefilter.com/Order.htm
28  //Email us to request a trial key: info@FilterAPI.com //free email is not accepted.
29  string registerKey = "**************************************";
30 
31  FilterMessage filterMessage = null;
32 
33  public MonitorForm()
34  {
35 
36  GlobalConfig.filterType = FilterAPI.FilterType.FILE_SYSTEM_MONITOR;
37 
38  InitializeComponent();
39 
40  StartPosition = FormStartPosition.CenterScreen;
41 
42  filterMessage = new FilterMessage(listView_Info);
43 
44 
45  }
46 
47 
48  ~MonitorForm()
49  {
51  }
52 
53  private void MonitorForm_FormClosing(object sender, FormClosingEventArgs e)
54  {
56  }
57 
58  private void toolStripButton_StartFilter_Click(object sender, EventArgs e)
59  {
60  try
61  {
62  string lastError = string.Empty;
63 
64  bool ret = FilterAPI.StartFilter( (int)GlobalConfig.FilterConnectionThreads
65  , registerKey
66  , new FilterAPI.FilterDelegate(FilterCallback)
67  , new FilterAPI.DisconnectDelegate(DisconnectCallback)
68  , ref lastError);
69  if (!ret)
70  {
71  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
72  MessageBox.Show("Start filter failed." + lastError);
73  return;
74  }
75 
76  toolStripButton_StartFilter.Enabled = false;
77  toolStripButton_Stop.Enabled = true;
78 
79  if (GlobalConfig.FilterRules.Count == 0)
80  {
81  FilterRule filterRule = new FilterRule();
82  filterRule.IncludeFileFilterMask = "c:\\test\\*";
83  filterRule.ExcludeFileFilterMasks = "c:\\windows*";
84  filterRule.EventType = (uint)(FilterAPI.EVENTTYPE.WRITTEN | FilterAPI.EVENTTYPE.CREATED | FilterAPI.EVENTTYPE.DELETED | FilterAPI.EVENTTYPE.RENAMED);
85  filterRule.AccessFlag = (uint)FilterAPI.ALLOW_MAX_RIGHT_ACCESS;
86  GlobalConfig.FilterRules.Add(filterRule.IncludeFileFilterMask, filterRule);
87 
88  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
89  MessageBox.Show("You don't have any monitor folder setup, add c:\\test\\* as your default test folder, I/Os from c:\\test\\* will show up in the console.");
90  }
91 
93 
94  EventManager.WriteMessage(102, "StartFilter", EventLevel.Information, "Start filter service succeeded.");
95  }
96  catch (Exception ex)
97  {
98  EventManager.WriteMessage(104, "StartFilter", EventLevel.Error, "Start filter service failed with error " + ex.Message);
99  }
100 
101  }
102 
103  private void toolStripButton_Stop_Click(object sender, EventArgs e)
104  {
105  FilterAPI.StopFilter();
106 
107  toolStripButton_StartFilter.Enabled = true;
108  toolStripButton_Stop.Enabled = false;
109  }
110 
111  private void toolStripButton_ClearMessage_Click(object sender, EventArgs e)
112  {
113  filterMessage.InitListView();
114  }
115 
116  Boolean FilterCallback(IntPtr sendDataPtr, IntPtr replyDataPtr)
117  {
118  Boolean ret = true;
119 
120  try
121  {
122  FilterAPI.MessageSendData messageSend = new FilterAPI.MessageSendData();
123  messageSend = (FilterAPI.MessageSendData)Marshal.PtrToStructure(sendDataPtr, typeof(FilterAPI.MessageSendData));
124 
125  if (FilterAPI.MESSAGE_SEND_VERIFICATION_NUMBER != messageSend.VerificationNumber)
126  {
127  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
128  MessageBox.Show("Received message corrupted.Please check if the MessageSendData structure is correct.");
129 
130  EventManager.WriteMessage(139, "FilterCallback", EventLevel.Error, "Received message corrupted.Please check if the MessageSendData structure is correct.");
131 
132  return false;
133  }
134 
135  filterMessage.AddMessage(messageSend);
136 
137  string info = "FileMonitor process request " + FilterMessage.FormatIOName(messageSend) + ",pid:" + messageSend.ProcessId +
138  " ,filename:" + messageSend.FileName + ",return status:" + FilterMessage.FormatStatus(messageSend.Status);
139 
140  if (messageSend.Status == (uint)NtStatus.Status.Success)
141  {
142  ret = false;
143  EventManager.WriteMessage(98, "FilterCallback", EventLevel.Verbose, info);
144  }
145  else
146  {
147  ret = true;
148  EventManager.WriteMessage(98, "FilterCallback", EventLevel.Error, info);
149  }
150 
151  return ret;
152  }
153  catch (Exception ex)
154  {
155  EventManager.WriteMessage(134, "FilterCallback", EventLevel.Error, "filter callback exception." + ex.Message);
156  return false;
157  }
158 
159  }
160 
161  void DisconnectCallback()
162  {
163  EventManager.WriteMessage(165,"DisconnectCallback", EventLevel.Information,"Filter Disconnected." + FilterAPI.GetLastErrorMessage());
164  }
165 
166  private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
167  {
168  SettingsForm settingForm = new SettingsForm();
169  settingForm.StartPosition = FormStartPosition.CenterParent;
170  settingForm.ShowDialog();
171  }
172 
173 
174  private void reportAProblemToolStripMenuItem_Click(object sender, EventArgs e)
175  {
176  System.Diagnostics.Process.Start("http://www.easefilter.com/ReportIssue.htm");
177  }
178 
179  private void helpTopicsToolStripMenuItem_Click(object sender, EventArgs e)
180  {
181  System.Diagnostics.Process.Start("http://www.easefilter.com/Forums_Files/FileMonitor.htm");
182  }
183 
184  private void toolStripButton1_Click(object sender, EventArgs e)
185  {
187  }
188 
189  private void exitToolStripMenuItem_Click(object sender, EventArgs e)
190  {
191  Close();
192  }
193 
194  private void MonitorForm_FormClosed(object sender, FormClosedEventArgs e)
195  {
196  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
197  if (MessageBox.Show("Do you want to minimize to system tray?", "Close", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
198  {
199 
200  }
201  else
202  {
203  GlobalConfig.Stop();
204  Application.Exit();
205  }
206  }
207 
208  private void unInstallFilterDriverToolStripMenuItem_Click(object sender, EventArgs e)
209  {
210  FilterAPI.StopFilter();
211  FilterAPI.UnInstallDriver();
212  }
213 
214  private void toolStripButton_LoadMessage_Click(object sender, EventArgs e)
215  {
216  filterMessage.LoadMessageFromLogToConsole();
217  }
218 
219  }
220 }
uint EventType
The register the file I/O events
static string FormatIOName(FilterAPI.MessageSendData messageSend)
void AddMessage(FilterAPI.MessageSendData messageSend)
static Dictionary< string, FilterRule > FilterRules
Status
A NT status value.
Definition: NtStatus.cs:23
static FilterAPI.FilterType filterType
Definition: GlobalConfig.cs:79

Social Network


Services Overview

Architect, implement and test file system filter drivers for a wide range of functionality. We can offer several levels of assistance to meet your specific.

Contact Us

You are welcome to contact us for salse or partnership.

Sales: sales@easefilter.com
Support: support@easefilter.com
Info: info@easefilter.com