Update of /cvsroot/csmail/csmail/src/CSMail.Utils
In directory usw-pr-cvs1:/tmp/cvs-serv28949
Modified Files:
ChangeLog Properties.cs
Added Files:
Utils.cs
Log Message:
2002-08-29
* Properties.cs : GetDefaultProperties - Implemented
: CopyFrom - Implemented
: MergeWith - Implemented
: ConvertIfPossible - Implemented
* Utils.cs : Added new utility class.
--- NEW FILE ---
/**
* Namespace: CSMail.Utils
* Class: Utils
*
* Author: Gaurav Vaish
* Maintainer: mastergaurav AT users DOT sf DOT net
*
* (C) Gaurav Vaish (2002)
*/
using System;
using CSMail;
namespace CSMail.Utils
{
public class Utils
{
[MailTODO]
public static SeparatePath(string path)
{
throw new NotImplementedException();
}
}
}
Index: ChangeLog
===================================================================
RCS file: /cvsroot/csmail/csmail/src/CSMail.Utils/ChangeLog,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ChangeLog 29 Aug 2002 07:03:04 -0000 1.3
+++ ChangeLog 29 Aug 2002 10:02:02 -0000 1.4
@@ -1,9 +1,18 @@
-2002-08-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net>
+2002-08-29 Gaurav Vaish <mastergaurav AT users DOT sf DOT net>
+
+ * Properties.cs : GetDefaultProperties - Implemented
+ : CopyFrom - Implemented
+ : MergeWith - Implemented
+ : ConvertIfPossible - Implemented
+ * Utils.cs : Added new utility class.
+
+2002-08-29 Gaurav Vaish <mastergaurav AT users DOT sf DOT net>
* Properties.cs : Indexer - Implemented
: LoadFrom(string) - Implemented
: LoadFrom(TextReader) - Implemented
+ : GetKeyValue(...) - Marked internal
2002-08-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net>
Index: Properties.cs
===================================================================
RCS file: /cvsroot/csmail/csmail/src/CSMail.Utils/Properties.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Properties.cs 29 Aug 2002 07:03:04 -0000 1.3
+++ Properties.cs 29 Aug 2002 10:02:02 -0000 1.4
@@ -42,11 +42,48 @@
}
}
+ public static Properties GetDefaultProperties()
+ {
+ Properties retVal = new Properties();
+
+ foreach(object current in Environment.GetEnvironmentVariables().Keys)
+ {
+ if(current is string)
+ {
+ string cenv = (string) current;
+ string penv = ConvertIfPossible(cenv);
+ retVal[penv] = Environment.GetEnvironmentVariable(cenv);
+ }
+ }
+
+ return retVal;
+ }
+
+ private static string ConvertIfPossible(string env)
+ {
+ string retVal = env.ToUpper();
+ switch(retVal)
+ {
+ case "CSMAIL_HOME" : retVal = "CSMail.home";
+ break;
+ case "CSMAIL_PATH" : retVal = "CSMail.path";
+ break;
+ case "HOME" : retVal = "user.home";
+ break;
+ case "PATH" : retVal = "path";
+ break;
+ default : retVal = env;
+ break;
+ }
+
+ return retVal;
+ }
+
public static Properties LoadFrom(string filename)
{
return LoadFrom(new StreamReader(filename));
}
-
+
public static Properties LoadFrom(TextReader reader)
{
string currentLine;
@@ -68,8 +105,25 @@
}
return retVal;
}
-
- private static void GetKeyValue(string line, out string key,
+
+ public void CopyFrom(Properties from)
+ {
+ foreach(string key in from.Keys)
+ {
+ this[key] = from[key];
+ }
+ }
+
+ public void MergeWith(Properties with)
+ {
+ foreach(string key in with.Keys)
+ {
+ if(!this.ContainsKey(key))
+ this[key] = with[key];
+ }
+ }
+
+ internal static void GetKeyValue(string line, out string key,
out string value)
{
int colon = line.IndexOfAny(Separators);
@@ -84,4 +138,4 @@
}
}
}
-}
\ No newline at end of file
+}
|