EaseFilter Demo Project
SecureAgentForm.cs
Go to the documentation of this file.
1 //
3 // (C) Copyright 2011 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.IO;
19 using System.Windows.Forms;
20 
22 
23 namespace SecureAgent
24 {
25  public partial class SecureAgentForm : Form
26  {
27  ShareFilesManagerForm shareFileManagerForm = new ShareFilesManagerForm();
28  AccountForm accountForm = new AccountForm();
29  SharedFileAccessLogForm sharedFileAccessLogForm = new SharedFileAccessLogForm();
30  AccessControlForm accessControlForm = null;
31 
32  string accountName = string.Empty;
33  string password = string.Empty;
34 
35  public SecureAgentForm()
36  {
38  InitializeComponent();
39 
40  GlobalConfig.filterType = FilterAPI.FilterType.FILE_SYSTEM_EASE_FILTER_ALL;
41 
42  EventManager.ShowNotificationDlgt showNotificationDlgt = new EventManager.ShowNotificationDlgt(ShowNotification);
43  EventManager.showNotificationDlgt = showNotificationDlgt;
44 
45  accessControlForm = new AccessControlForm();
46 
47  }
48 
49  private void SecureForm_Load(object sender, EventArgs e)
50  {
51  this.Hide();
52  this.notifyIcon.Visible = true;
53 
54  ShowNotification("SecureAgent started successfully,\r\nRight click the SecureAgent icon to open the menu context.", false);
55 
56  }
57 
58  private void SecureForm_FormClosing(object sender, FormClosingEventArgs e)
59  {
61  FilterAPI.StopFilter();
62  }
63 
64 
65 
66  private void toolStripMenuItem_Start_Click(object sender, EventArgs e)
67  {
68  try
69  {
70  if (null == toolStripMenuItem_Start.Tag || (bool)toolStripMenuItem_Start.Tag == false)
71  {
72  string secureFolder = string.Empty;
73 
74  if (GlobalConfig.FilterRules.Count > 0)
75  {
76  string includeFilterMask = GlobalConfig.FilterRules.First().Key;
77 
78  if (includeFilterMask.EndsWith("\\*"))
79  {
80  secureFolder = includeFilterMask.Remove(includeFilterMask.IndexOf("\\*"));
81  }
82  }
83 
84  ShareFileFolderInputForm secureFolderForm = new ShareFileFolderInputForm(secureFolder);
85 
86  if (secureFolderForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
87  {
88  secureFolder = secureFolderForm.dropFolder;
89  }
90 
91  if (!Directory.Exists(secureFolder))
92  {
93  ShowNotification("The folder " + secureFolder + " doesn't exist.", true);
94  return;
95  }
96 
97 
98  FilterRule filterRule = new FilterRule();
99 
100  filterRule.IncludeFileFilterMask = secureFolder + "\\*";
101  filterRule.AccessFlag |= (uint)FilterAPI.AccessFlag.FILE_ENCRYPTION_RULE | FilterAPI.ALLOW_MAX_RIGHT_ACCESS;
102  GlobalConfig.AddFilterRule(filterRule);
103 
104  FilterRule filterRule2 = new FilterRule();
105  filterRule2.IncludeFileFilterMask = secureFolder + "\\*" + DigitalRightControl.SECURE_SHARE_FILE_EXTENSION;
106  filterRule2.AccessFlag = FilterAPI.ALLOW_MAX_RIGHT_ACCESS;
107  filterRule2.EventType = (uint)FilterAPI.EVENTTYPE.CREATED | (uint)FilterAPI.EVENTTYPE.RENAMED;
108  GlobalConfig.AddFilterRule(filterRule2);
109 
111 
112  if (!accessControlForm.StartFilterService())
113  {
114  return;
115  }
116  else
117  {
118  toolStripMenuItem_Start.Tag = true;
119  toolStripMenuItem_Start.Text = "Stop secure agent";
120  }
121  }
122  else
123  {
124  FilterAPI.StopFilter();
125 
126  toolStripMenuItem_Start.Tag = false;
127  toolStripMenuItem_Start.Text = "Start secure agent";
128 
129  }
130  }
131  catch (Exception ex)
132  {
133  FilterAPI.StopFilter();
134  EventManager.WriteMessage(157, "start service", EventLevel.Error, "start service failed with error:" + ex.Message);
135  }
136  }
137 
138  private void toolStripMenuItem_ShareFileManager_Click(object sender, EventArgs e)
139  {
140 
142  {
143  accountForm.ShowDialog();
144  }
145 
146  if (!AccountForm.isGuest)
147  {
148  shareFileManagerForm.GetSharedFileList();
149  }
150 
151  shareFileManagerForm.StartPosition = FormStartPosition.CenterScreen;
152  shareFileManagerForm.ShowDialog();
153  }
154 
155  private void toolStripMenuItem_AccessLogViewer_Click(object sender, EventArgs e)
156  {
157  try
158  {
160  {
161  accountForm.ShowDialog();
162  }
163 
164  if (!sharedFileAccessLogForm.initialized)
165  {
166  string accessLogStr = string.Empty;
167 
168  if (AccountForm.isGuest)
169  {
170  ShowNotification("The guest user can't access the log file.", true);
171  return;
172  }
173 
174  string accountName = AccountForm.accountName;
175  string password = AccountForm.password;
176  string lastError = string.Empty;
177 
178  sharedFileAccessLogForm.initialized = true;
179 
180  //get the access log from the remote server.
181  bool retVal = true;
182 
183  if (retVal)
184  {
185  sharedFileAccessLogForm.accessLogStr = accessLogStr;
186  }
187  else
188  {
189  lastError = "Get access log failed,system return error:" + lastError;
190  EventManager.WriteMessage(180, "AccessViewer", EventLevel.Error, lastError);
191  ShowNotification(lastError, true);
192  return;
193  }
194  }
195  sharedFileAccessLogForm.StartPosition = FormStartPosition.CenterScreen;
196  sharedFileAccessLogForm.ShowDialog();
197  }
198  catch (Exception ex)
199  {
200  EventManager.WriteMessage(190, "AccessViewer", EventLevel.Error, "Get access log failed,system return error:" + ex.Message);
201  return;
202  }
203 
204  }
205 
206  private void toolStripMenuItem_Settings_Click(object sender, EventArgs e)
207  {
208  if (!accessControlForm.Visible)
209  {
210  accessControlForm.StartPosition = FormStartPosition.CenterScreen;
211  accessControlForm.ShowDialog();
212  }
213  }
214 
215  private void toolStripMenuItem_Help_Click(object sender, EventArgs e)
216  {
217  System.Diagnostics.Process.Start("http://www.easefilter.com/Forums_Files/AssureFiles_Secure_File_Sharing.htm");
218  }
219 
220  private void exitToolStripMenuItem_Exit_Click(object sender, EventArgs e)
221  {
222  GlobalConfig.Stop();
223  FilterAPI.StopFilter();
224 
225  Application.Exit();
226  }
227 
228  private void ShowNotification(string message, bool isErrorMessage)
229  {
231  {
232  return;
233  }
234 
235  if (this.InvokeRequired)
236  {
237  this.Invoke(new EventManager.ShowNotificationDlgt(ShowNotification), new Object[] { message, isErrorMessage });
238  }
239  else
240  {
241  popupNotifier1.ShowInternalImage(isErrorMessage, !isErrorMessage);
242  popupNotifier1.TitleText = "";
243  popupNotifier1.ContentText = message;
244  popupNotifier1.Popup();
245  }
246 
247  }
248 
249  private void eventLogViewerToolStripMenuItem_Click(object sender, EventArgs e)
250  {
252  }
253 
254 
255 
256  }
257 }
static bool AddFilterRule(FilterRule newRule)
System.Windows.Forms.NotifyIcon notifyIcon
static bool isAuthorized
Definition: AccountForm.cs:28
uint EventType
The register the file I/O events
static string accountName
Definition: AccountForm.cs:26
static string password
Definition: AccountForm.cs:27
static void CopyOSPlatformDependentFiles()
Definition: Utils.cs:92
static Dictionary< string, FilterRule > FilterRules
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