From: Michael Wagner Date: Sat, 4 Jun 2016 18:41:03 +0000 (+0200) Subject: monodev X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=fd98c53230d650456bb9f0114a93d17280460809;p=mcloud.git monodev --- diff --git a/mCloudAwk/IMCloudAwk.cs b/mCloudAwk/IMCloudAwk.cs new file mode 100644 index 0000000..5a00453 --- /dev/null +++ b/mCloudAwk/IMCloudAwk.cs @@ -0,0 +1,13 @@ +using System; + +namespace mCloudAwk +{ + public interface IMCloudAwk : IDisposable + { + TConnection[] GetConnections(); + void AddConnection(TConnection t); + void DeleteConnection(string name); + int TestConnection(string name); + } +} + diff --git a/mCloudAwk/MCloudMgr.cs b/mCloudAwk/MCloudMgr.cs new file mode 100644 index 0000000..e61dfbe --- /dev/null +++ b/mCloudAwk/MCloudMgr.cs @@ -0,0 +1,69 @@ +using System; + +using util; + +namespace mCloudAwk +{ + public class MCloudMgr : IMCloudAwk, IDisposable + { + public TConnection[] GetConnections() + { + var Connections = util.Config.GetList ("General", "Connections"); + if (Connections == null) + return new TConnection[0]; + TConnection[] TConns = new TConnection[Connections.Count]; + int i = 0; + foreach (var C in Connections) { + TConnection TC = new TConnection (); + TC.Name = C; + TC.User = util.Config.RequireConfig (TC.Name, "User"); + TC.Server = util.Config.RequireConfig (TC.Name, "Server"); + TC.Password = util.Config.RequireConfig (TC.Name, "Password"); + TConns [i] = TC; + i++; + } + return TConns; + } + + public void AddConnection(TConnection C) { + var Connections = util.Config.GetList ("General", "Connections"); + if (Connections == null) { + Connections = new System.Collections.Generic.SortedSet { C.Name }; + } else { + Connections.Add (C.Name); + } + Config.Set ("General", "Connections", Connections); + Config.Set (C.Name, "User", C.User); + Config.Set (C.Name, "Server", C.Server); + Config.Set (C.Name, "Password", C.Password); + } + + public void DeleteConnection(string name) { + var Connections = Config.GetList ("General", "Connections"); + Connections.Remove (name); + Config.Set("General", "Connections", Connections); + Config.Remove(name); + } + + // TestConnection results + public const int SSH_NO_PW = 0; // connection without password possible + public const int SSH_WITH_PW = 1; // connection only possible with password + public const int SSH_NOK = 10; // so ssh connection possible + public int TestConnection(string name){return 5;} + + public MCloudMgr(){ + int r = util.Config.Load (System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + +"/.mCloud.Config"); + if (r == util.Config.LOAD_OK || r == util.Config.LOAD_NO_INPUT_FILE) { + // everything fine + } else { + throw new ApplicationException ("Config load failed"); + } + } + + public void Dispose() { + util.Config.Write (); + } + } +} + diff --git a/mCloudAwk/TConnection.cs b/mCloudAwk/TConnection.cs new file mode 100644 index 0000000..8a51001 --- /dev/null +++ b/mCloudAwk/TConnection.cs @@ -0,0 +1,18 @@ +using System; + +namespace mCloudAwk +{ + public class TConnection + { + public string Name; + public string User; + public string Server; + public string Password; + + public TConnection () + { + + } + } +} +