EaseFilter Demo Project
ConfigSetting.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 
12 using System;
13 using System.Configuration;
14 using System.Collections;
15 using System.Collections.Generic;
16 
17 namespace EaseFilter.CommonObjects
18 {
19 
20  public class ConfigSetting
21  {
22  static private string configPath = string.Empty;
23  static private System.Configuration.Configuration config = null;
24  static private FilterRuleSection filterRuleSection = new FilterRuleSection();
25 
26  static ConfigSetting()
27  {
28  try
29  {
30  config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
31  configPath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
32 
33  filterRuleSection = (FilterRuleSection)config.Sections["FilterRuleSection"];
34 
35  if (filterRuleSection == null)
36  {
37  filterRuleSection = new FilterRuleSection();
38  config.Sections.Add("FilterRuleSection", filterRuleSection);
39 
40  }
41  }
42  catch
43  {
44  }
45  }
46 
47  public static void Save()
48  {
49  config.Save(ConfigurationSaveMode.Full);
50  }
51 
52  public static Dictionary<string, FilterRule> GetFilterRules()
53  {
54  Dictionary<string, FilterRule> filterRules = new Dictionary<string, FilterRule>();
55 
56  foreach (FilterRule filterRule in filterRuleSection.Instances)
57  {
58  filterRules.Add(filterRule.IncludeFileFilterMask, filterRule);
59  }
60 
61  return filterRules;
62  }
63 
64  public static void AddFilterRule(FilterRule filterRule)
65  {
66 
67  filterRuleSection.Instances.Add(filterRule);
68 
69  return ;
70  }
71 
72  public static void RemoveFilterRule(string includeFilterMask)
73  {
74  filterRuleSection.Instances.Remove(includeFilterMask);
75 
76  return;
77  }
78 
79  public static string GetFilePath()
80  {
81  return configPath;
82  }
83 
84  public static bool Get(string name, bool value)
85  {
86  try
87  {
88  return bool.Parse(config.AppSettings.Settings[name].Value);
89  }
90  catch
91  {
92  return value;
93  }
94  }
95 
96 
97  public static byte Get(string name, byte value)
98  {
99  try
100  {
101  return byte.Parse(config.AppSettings.Settings[name].Value);
102  }
103  catch
104  {
105  return value;
106  }
107  }
108 
109 
110  public static sbyte Get(string name, sbyte value)
111  {
112  try
113  {
114  return sbyte.Parse(config.AppSettings.Settings[name].Value);
115  }
116  catch
117  {
118  return value;
119  }
120  }
121 
122 
123  public static char Get(string name, char value)
124  {
125  try
126  {
127  return char.Parse(config.AppSettings.Settings[name].Value);
128  }
129  catch
130  {
131  return value;
132  }
133  }
134 
135 
136  public static decimal Get(string name, decimal value)
137  {
138  try
139  {
140  return decimal.Parse(config.AppSettings.Settings[name].Value);
141  }
142  catch
143  {
144  return value;
145  }
146  }
147 
148 
149  public static double Get(string name, double value)
150  {
151  try
152  {
153  return double.Parse(config.AppSettings.Settings[name].Value);
154  }
155  catch
156  {
157  return value;
158  }
159  }
160 
161  public static float Get(string name, float value)
162  {
163  try
164  {
165  return float.Parse(config.AppSettings.Settings[name].Value);
166  }
167  catch
168  {
169  return value;
170  }
171  }
172 
173 
174  public static int Get(string name, int value)
175  {
176  try
177  {
178  return int.Parse(config.AppSettings.Settings[name].Value);
179  }
180  catch
181  {
182  return value;
183  }
184  }
185 
186  public static uint Get(string name, uint value)
187  {
188  try
189  {
190  return uint.Parse(config.AppSettings.Settings[name].Value);
191  }
192  catch
193  {
194  return value;
195  }
196  }
197 
198 
199  public static long Get(string name, long value)
200  {
201  try
202  {
203  return long.Parse(config.AppSettings.Settings[name].Value);
204  }
205  catch
206  {
207  return value;
208  }
209  }
210 
211 
212  public static ulong Get(string name, ulong value)
213  {
214  try
215  {
216  return ulong.Parse(config.AppSettings.Settings[name].Value);
217  }
218  catch
219  {
220  return value;
221  }
222  }
223 
224 
225  public static short Get(string name, short value)
226  {
227  try
228  {
229  return short.Parse(config.AppSettings.Settings[name].Value);
230  }
231  catch
232  {
233  return value;
234  }
235  }
236 
237 
238  public static ushort Get(string name, ushort value)
239  {
240  try
241  {
242  return ushort.Parse(config.AppSettings.Settings[name].Value);
243  }
244  catch
245  {
246  return value;
247  }
248  }
249 
250  public static string Get(string name, string value)
251  {
252  string str = string.Empty;
253  try
254  {
255  str = config.AppSettings.Settings[name].Value;
256  }
257  catch
258  {
259  return value;
260  }
261 
262  if (str == null)
263  str = value;
264 
265  return str;
266  }
267 
268  public static void Set(string name, string value)
269  {
270  try
271  {
272  config.AppSettings.Settings.Remove(name);
273  config.AppSettings.Settings.Add(name, value);
274  config.Save(ConfigurationSaveMode.Modified);
275  ConfigurationManager.RefreshSection("appSettings");
276 
277  }
278  catch
279  {
280  }
281  }
282 
283  }
284 }
static byte Get(string name, byte value)
static string Get(string name, string value)
static double Get(string name, double value)
static void RemoveFilterRule(string includeFilterMask)
static sbyte Get(string name, sbyte value)
static ushort Get(string name, ushort value)
static void AddFilterRule(FilterRule filterRule)
static ulong Get(string name, ulong value)
static float Get(string name, float value)
static Dictionary< string, FilterRule > GetFilterRules()
static char Get(string name, char value)
static uint Get(string name, uint value)
static void Set(string name, string value)
static short Get(string name, short value)
static int Get(string name, int value)
static decimal Get(string name, decimal value)
static long Get(string name, long value)
static bool Get(string name, bool value)

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