118 lines
5.1 KiB
C#
118 lines
5.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
using dezentrale.model;
|
|
|
|
namespace dezentrale
|
|
{
|
|
public class Program
|
|
{
|
|
public static uint VersionNumber { get; private set; } = 0x19051500;
|
|
public static string VersionString { get; private set; } = $"{VersionNumber:x}";
|
|
|
|
public static string AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
public static string DmDirectory = Path.Combine(AppData, "dezentrale-members");
|
|
|
|
public static string ConfigFile = Path.Combine(DmDirectory, "configuration.xml");
|
|
public static string MemberFile = Path.Combine(DmDirectory, "members.xml");
|
|
|
|
public static Configuration config = new Configuration();
|
|
public static MemberList members = new MemberList();
|
|
public enum eMode
|
|
{
|
|
CommandLine = 0,
|
|
Gui = 1,
|
|
Cronjob = 2,
|
|
}
|
|
|
|
public static eMode ProgramMode = eMode.CommandLine;
|
|
|
|
static int Main(string[] args)
|
|
{
|
|
bool printHelp = false;
|
|
Console.WriteLine($"dezentrale-members, Version {VersionString}");
|
|
|
|
try { Directory.CreateDirectory(DmDirectory); }
|
|
catch (Exception ex) { Console.WriteLine($"Error while creating data directory:\n{ex.Message}"); return 1; }
|
|
|
|
try
|
|
{
|
|
try { config = (Configuration)XmlData.LoadFromFile(ConfigFile); }
|
|
catch (FileNotFoundException) { XmlData.SaveToFile(ConfigFile, config); Console.WriteLine("Created new configuration file."); }
|
|
|
|
try { members = (MemberList)XmlData.LoadFromFile(MemberFile); }
|
|
catch (FileNotFoundException) { XmlData.SaveToFile(MemberFile, members); Console.WriteLine("Created new member file."); }
|
|
} catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error while accessing program data:");
|
|
Console.WriteLine(ex.Message);
|
|
return 1;
|
|
}
|
|
|
|
List<string> clArgs = new List<string>();
|
|
foreach(string argIt in args)
|
|
{
|
|
string argn;
|
|
string argv;
|
|
if (argIt.Contains("="))
|
|
{
|
|
argn = argIt.Substring(0, argIt.IndexOf('='));
|
|
argv = argIt.Substring(argIt.IndexOf('=') + 1);
|
|
} else
|
|
{
|
|
argn = argIt;
|
|
argv = "";
|
|
}
|
|
if (argn.StartsWith("-")) argn = argn.Substring(1);
|
|
if (argn.StartsWith("/") || argn.StartsWith("-")) argn = argn.Substring(1);
|
|
switch(argn.ToLower())
|
|
{
|
|
case "help": printHelp = true; break;
|
|
case "mode":
|
|
switch(argv.ToLower())
|
|
{
|
|
case "cl": ProgramMode = eMode.CommandLine; Console.WriteLine($"Setting Mode to {ProgramMode}"); break;
|
|
case "gui": ProgramMode = eMode.Gui; Console.WriteLine($"Setting Mode to {ProgramMode}"); break;
|
|
case "cronjob":
|
|
case "auto": ProgramMode = eMode.Cronjob; Console.WriteLine($"Setting Mode to {ProgramMode}"); break;
|
|
default:
|
|
Console.WriteLine("Invalid mode.");
|
|
printHelp = true;
|
|
break;
|
|
}
|
|
break;
|
|
default:
|
|
Console.WriteLine($"Invalid command({argn})");
|
|
printHelp = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (printHelp)
|
|
{
|
|
Console.WriteLine("command line arguments:");
|
|
Console.WriteLine("--help Display this help message");
|
|
Console.WriteLine("--mode=<mode> Starts the program in given mode. Supported modes are:");
|
|
Console.WriteLine(" cl (default) Manual/interactive use from command line.");
|
|
Console.WriteLine(" gui Start in GUI mode (not implemented yet)");
|
|
Console.WriteLine(" auto, cronjob Check and perform pending required membership actions");
|
|
Console.WriteLine();
|
|
return 1;
|
|
}
|
|
|
|
|
|
|
|
Member m = new Member();
|
|
|
|
FormMail result = FormMail.GenerateNewMemberWelcome().ReplaceReflect(m);
|
|
Console.WriteLine($" To: {result.To}");
|
|
Console.WriteLine($" Subject: {result.Subject}");
|
|
Console.WriteLine($" Body: {result.Body}");
|
|
|
|
//result.Send();
|
|
return 0;
|
|
}
|
|
}
|
|
}
|