[Pkg-mono-svn-commits] rev 317 - mono-nethostmanager/src
Pablo Fischer
pabl0-guest@quantz.debian.org
Sun, 22 Feb 2004 18:49:53 +0100
Author: pabl0-guest
Date: 2004-02-22 18:49:52 +0100 (Sun, 22 Feb 2004)
New Revision: 317
Modified:
mono-nethostmanager/src/Manager.cs
mono-nethostmanager/src/VirtualSchema.cs
Log:
Updated.. and already finished
Modified: mono-nethostmanager/src/Manager.cs
===================================================================
--- mono-nethostmanager/src/Manager.cs 2004-02-22 17:12:20 UTC (rev 316)
+++ mono-nethostmanager/src/Manager.cs 2004-02-22 17:49:52 UTC (rev 317)
@@ -55,7 +55,7 @@
///<summary>
///Open the file and load it inside @hosts
///</summary>
- private void LoadConfigInfo() {
+ private static void LoadConfigInfo() {
//Create that object
hosts = new VirtualHosts();
//So, lets load it
@@ -95,7 +95,7 @@
private static void WhatIsIt(string option) {
//We don't need this if we are just going to print or repair
- if(action == "repair" || action == "print") {
+ if(action == "print") {
//Get the file name, after the '=' char
//Does the option has a value?
try {
@@ -105,7 +105,7 @@
System.Environment.Exit(0);
}
//If the file does not exists and the action depends of the file
- if(!ExistsConfig() && action != "repair") {
+ if(!ExistsConfig()) {
Console.WriteLine("[FNE] The filename does not exists {0}", config_file);
System.Environment.Exit(0);
}
@@ -126,15 +126,19 @@
System.Environment.Exit(0);
}
//If the file does not exists and the action depends of the file
- if(!ExistsConfig()) {
- Console.WriteLine("[FNE] The filename does not exists {0}", config_file);
- System.Environment.Exit(0);
+ if(ExistsConfig()) {
+ if(!IsConfigValid() && action != "add") {
+ Console.WriteLine("[FNV] The file format is not valid {0}", config_file);
+ System.Environment.Exit(0);
+ }
}
- if(!IsConfigValid()) {
- Console.WriteLine("[FNV] The file format is not valid {0}", config_file);
- System.Environment.Exit(0);
- }
- break;
+ else {
+ if(action != "add") {
+ Console.WriteLine("[FNE] The filename does not exists {0}", config_file);
+ System.Environment.Exit(0);
+ }
+ }
+ break;
case "--path":
//Get the full path of the web files
//Does the option has a value?
@@ -165,6 +169,7 @@
break;
}
}
+ }
@@ -172,15 +177,19 @@
///The main
///</summary>
public static void Main(string[] args) {
- if(args.Length == 0 || args.Length < 4) {
+ try {
+ action = args[0];
+ }catch(System.IndexOutOfRangeException ex) {
+ Console.WriteLine("No values...");
+ }
+
+ if(args.Length == 0 || args.Length < 4 && action != "print") {
Console.WriteLine("VirtualHost Manager");
Console.WriteLine("Use: netvirtualhost action options \n");
Console.WriteLine("Actions:");
Console.WriteLine(" add Add a VirtualHost");
Console.WriteLine(" del Delete a VirtualHost");
- Console.WriteLine(" up Update the information of the host");
Console.WriteLine(" print Prints the file to screen in the xsp format (/alias:path)");
- Console.WriteLine(" repair Creates a new VirtualHost file");
Console.WriteLine("Options:");
Console.WriteLine(" --config-file=<file> The full path where the config file is");
Console.WriteLine(" --alias=<alias> The alias that you want for the host");
@@ -194,40 +203,41 @@
else {
action = args[0];
//Which action?
- if(action != "add" || action != "del" ||
- action != "up" || action != "repair" ||
- action != "print") {
- Console.WriteLine("[ANR] {0} Action not Recognized", action);
- System.Environment.Exit(0);
- }
for(int i=1; i<args.Length; i++) {
WhatIsIt(args[i]);
}
}
//Now, what we need to do?
+ int pos;
+
switch(action) {
case "add":
- hosts = new VirtualHosts();
- LoadConfigInfo();
- //We already have a host with this path/alias?
- if(hosts.GetHostPosition(host_alias, host_path) == -1) {
+ if(!ExistsConfig()) {
+ hosts = new VirtualHosts();
hosts.AddHost(new Host(host_path, host_alias));
Save();
}
else {
- Console.WriteLine("[VHE] The VirtualHost already exists");
- System.Environment.Exit(0);
+ LoadConfigInfo();
+ //We already have a host with this path/alias?
+ if(hosts.GetHostPosition(host_alias, host_path) == -1) {
+ hosts.AddHost(new Host(host_path, host_alias));
+ Save();
+ }
+ else {
+ Console.WriteLine("[VHE] The VirtualHost already exists");
+ System.Environment.Exit(0);
+ }
}
break;
case "del":
- hosts = new VirtualHosts();
LoadConfigInfo();
//We have this host?
//Save the value cause we will need it later..
- int position = hosts.GetHostPosition(host_alias, host_path);
- if(position != -1) {
- hosts.RemoveHost(position);
+ pos = hosts.GetHostPosition(host_alias, host_path);
+ if(pos != -1) {
+ hosts.RemoveHost(pos);
Save();
}
else {
@@ -235,12 +245,11 @@
System.Environment.Exit(0);
}
break;
- case "up":
-
-
-
-
-
+ case "print":
+ Console.WriteLine("aqui ando..");
+ LoadConfigInfo();
+ hosts.PrintHosts();
+ break;
}
}
}
Modified: mono-nethostmanager/src/VirtualSchema.cs
===================================================================
--- mono-nethostmanager/src/VirtualSchema.cs 2004-02-22 17:12:20 UTC (rev 316)
+++ mono-nethostmanager/src/VirtualSchema.cs 2004-02-22 17:49:52 UTC (rev 317)
@@ -35,8 +35,19 @@
((Host)hostArray[position]).alias = alias;
((Host)hostArray[position]).path = path;
}
+
+ public void PrintHosts() {
+ for(position=0; position<hostArray.Count; position++)
+ if(position == hostArray.Count-1) {
+ Console.WriteLine("{0}:{1}", ((Host)hostArray[position]).alias, ((Host)hostArray[position]).path);
+ }
+ else {
+ Console.WriteLine("{0}:{1},", ((Host)hostArray[position]).alias, ((Host)hostArray[position]).path);
+ }
+ }
}
+
public class Host {
[XmlElement("path")] public string path;
[XmlElement("alias")] public string alias;