EaseFilter Demo Project
ShareFilesManagerForm.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.Windows.Forms;
19 using System.IO;
20 
22 
23 namespace SecureAgent
24 {
25  public partial class ShareFilesManagerForm : Form
26  {
27  DRPolicy selectedDRPolicy = new DRPolicy();
28  public Dictionary<string, DRPolicy> sharedFileList = new Dictionary<string, DRPolicy>();
29 
31  {
32  InitializeComponent();
33  InitListView();
34  }
35 
36  public void InitListView()
37  {
38  listView_SharedFiles.Clear();
39  //create column header for ListView
40  listView_SharedFiles.Columns.Add("fileName", 350, System.Windows.Forms.HorizontalAlignment.Left);
41  listView_SharedFiles.Columns.Add("CreationTime", 300, System.Windows.Forms.HorizontalAlignment.Left);
42 
43  try
44  {
45  foreach (KeyValuePair<string, DRPolicy> entry in sharedFileList)
46  {
47  ListViewItem lvItem = new ListViewItem();
48  string[] listData = new string[listView_SharedFiles.Columns.Count];
49  listData[0] = entry.Value.FileName;
50 
51  long creationTimeN = long.Parse(entry.Key);
52  DateTime creationTime = DateTime.FromFileTime(creationTimeN).ToLocalTime();
53  listData[1] = String.Format("{0:F}", creationTime);
54 
55  lvItem = new ListViewItem(listData, 0);
56  lvItem.Tag = entry.Key;
57 
58  listView_SharedFiles.Items.Add(lvItem);
59 
60  }
61  }
62  catch
63  {
64  }
65  }
66 
67  private void button_CreateShareEncryptedFile_Click(object sender, EventArgs e)
68  {
69  ShareFileForm shareFileForm = new ShareFileForm();
70  shareFileForm.ShowDialog();
71 
72  if (shareFileForm.isNewFileAddedToServer)
73  {
74  sharedFileList.Add(shareFileForm.selectedDRPolicy.CreationTime.ToString(), shareFileForm.selectedDRPolicy);
75  InitListView();
76  }
77  }
78 
79  private void button_Delete_Click(object sender, EventArgs e)
80  {
81  button_Delete.Enabled = false;
82 
83  try
84  {
85  if (listView_SharedFiles.SelectedItems.Count != 1)
86  {
87  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
88  MessageBox.Show("Please select a file.", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Error);
89  return;
90  }
91 
92  string creationTimeStr = (string)listView_SharedFiles.SelectedItems[0].Tag;
93 
94  if (sharedFileList.ContainsKey(creationTimeStr))
95  {
96  DRPolicy drPolicy = sharedFileList[creationTimeStr];
97 
98  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
99  if (MessageBox.Show("Are you sure you want to delete the file " + drPolicy.FileName + " ?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes)
100  {
101  return;
102  }
103 
104  string fileName = drPolicy.FileName + "." + creationTimeStr;
105  string lastError = string.Empty;
106 
107  //delete the shared file meta data from remote server
108  //if (!DeleteShareFile(AccountForm.accountName, AccountForm.password, fileName, ref lastError))
109  {
110  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
111  MessageBox.Show("Delete shared file " + selectedDRPolicy.FileName + " failed with error:" + lastError, "DeleteSharedFile", MessageBoxButtons.OK, MessageBoxIcon.Error);
112  return;
113  }
114 
115  sharedFileList.Remove(creationTimeStr);
116  }
117 
118  InitListView();
119 
120  }
121  catch (Exception ex)
122  {
123  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
124  MessageBox.Show("Delete shared file " + selectedDRPolicy.FileName + " failed with error " + ex.Message, "DeleteSharedFile", MessageBoxButtons.OK, MessageBoxIcon.Error);
125  }
126  finally
127  {
128  button_Delete.Enabled = true;
129  }
130  }
131 
132 
133  private void button_EditSharedFile_Click(object sender, EventArgs e)
134  {
135  if (listView_SharedFiles.SelectedItems.Count != 1)
136  {
137  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
138  MessageBox.Show("Please select a file.", "Edit", MessageBoxButtons.OK, MessageBoxIcon.Error);
139  return;
140  }
141 
142  string creationTimeStr = (string)listView_SharedFiles.SelectedItems[0].Tag;
143 
144  if (sharedFileList.ContainsKey(creationTimeStr))
145  {
146  DRPolicy drPolicy = sharedFileList[creationTimeStr];
147 
148  if (drPolicy.ExpireTime == 0)
149  {
150  string fileName = drPolicy.FileName;
151  long creationTime = drPolicy.CreationTime;
152  string lastError = string.Empty;
153  string encryptedDRPolicy = string.Empty;
154 
155  //modify the shared file meta data in remote server.
156  bool retVal = false;//GetFileDRInfo(AccountForm.accountName, AccountForm.password, fileName, creationTime, ref encryptedDRPolicy, ref lastError);
157  if (!retVal)
158  {
159  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
160  MessageBox.Show("Get digital right information for file " + fileName + " failed with error:" + lastError, "GetFileDRInfo", MessageBoxButtons.OK, MessageBoxIcon.Error);
161  return;
162  }
163 
164  drPolicy = DigitalRightControl.DecryptStrToObject<DRPolicy>(encryptedDRPolicy);
165  drPolicy.CreationTime = creationTime;
166 
167  sharedFileList[creationTimeStr] = drPolicy;
168 
169  }
170 
171  ShareFileForm shareFileForm = new ShareFileForm(drPolicy);
172  shareFileForm.ShowDialog();
173 
174  }
175  }
176 
177  private void button_Refresh_Click(object sender, EventArgs e)
178  {
179 
180  button_Refresh.Enabled = false;
181 
182  try
183  {
184  if (AccountForm.accountName.Length == 0)
185  {
186  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
187  MessageBox.Show("There are no shared file list for guest user.", "RefreshFileList", MessageBoxButtons.OK, MessageBoxIcon.Error);
188 
189  return;
190  }
191 
192  if (GetSharedFileList())
193  {
194  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
195  MessageBox.Show("Shared file list was refreshed.", "RefreshFileList", MessageBoxButtons.OK, MessageBoxIcon.Information);
196  }
197  }
198  catch
199  {
200  }
201  finally
202  {
203  button_Refresh.Enabled = true;
204  }
205  }
206 
207  public bool GetSharedFileList()
208  {
209  string lastError = string.Empty;
210  string encryptFileList = string.Empty;
211  Dictionary<string, DRPolicy> shareList = new Dictionary<string, DRPolicy>();
212 
213  //get the shared file list from remote server.
214  bool retVal = false;//GetFileList(AccountForm.accountName, AccountForm.password, ref encryptFileList, ref lastError);
215  if (!retVal)
216  {
217  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
218  MessageBox.Show(lastError, "GetFileList", MessageBoxButtons.OK, MessageBoxIcon.Error);
219 
220  return false;
221  }
222  else
223  {
224  if (encryptFileList.Length > 0)
225  {
226 
227  List<string> decrypFileList = DigitalRightControl.DecryptStrToObject<List<string>>(encryptFileList);
228 
229  foreach (string name in decrypFileList)
230  {
231  if (name.Length > 0)
232  {
233  //the extension of the file is the creation time.
234  string creationTimeStr = Path.GetExtension(name).Substring(1);
235  string fileName = Path.GetFileNameWithoutExtension(name);
236 
237  DRPolicy drPolicy = new DRPolicy();
238  drPolicy.FileName = fileName;
239  drPolicy.CreationTime = long.Parse(creationTimeStr);
240  drPolicy.ExpireTime = 0;
241 
242  shareList.Add(creationTimeStr, drPolicy);
243 
244 
245  }
246  }
247  }
248 
249 
250  sharedFileList = shareList;
251  InitListView();
252  }
253 
254  return true;
255  }
256 
257  private void listView_SharedFiles_SelectedIndexChanged(object sender, EventArgs e)
258  {
259 
260 
261 
262  }
263  }
264 }
static string accountName
Definition: AccountForm.cs:26
long ExpireTime
The file will be expired after the expire time, and it can&#39;t be accessed.
string FileName
the file name which was applied with policy.
This is the DR info meta data which will be stored in server if revoke access control is enabled...
long CreationTime
The time of the encrypted file was created.
Dictionary< string, DRPolicy > sharedFileList

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