public void CreateConfigFile() { var config = new FileConfig(); config.DeCorrespondentUsername = "******"; config.DeCorrespondentPassword = Encryptor.EncryptAES("password"); config.EvoPdfLicenseKey = "lickey"; config.MaxAantalArticles = 20; config.KindleEmail = "t"; config.SmtpUsername = "******"; config.SmtpPassword = Encryptor.EncryptAES(@"password"); config.Save("d:\\config.xml"); }
private static ProgramArguments HandleArguments(string[] args, FileConfig config) { if (args.Length == 0) return new ProgramArguments(true); if (args.Length > 0 && args[0] == "/config") { typeof (FileConfig).GetProperties() .Where(p => p.GetCustomAttributes(typeof (FileConfig.ConfigurableViaCommandLine), true).Any()) .Select(p => new { Property = p, Attribute = p.GetCustomAttributes(typeof (FileConfig.ConfigurableViaCommandLine), true).OfType<FileConfig.ConfigurableViaCommandLine>().First(), Value = p.GetGetMethod().Invoke(config, new object[0]) as string }) .Select(x => new { x.Property, x.Attribute, x.Value, IsEncrypted = x.Attribute.IsPassword }) .ToList() .ForEach(x => { Console.WriteLine("{0}:\n [enter]='{1}'", x.Attribute.Description, x.Attribute.Display(x.Value)); var newValue = Console.ReadLine(); if (!string.IsNullOrEmpty(newValue)) x.Property.GetSetMethod().Invoke(config, new object[] { x.IsEncrypted ? Encryptor.EncryptAES(newValue) : newValue }); }); config.Save(null); Console.WriteLine("Configuratie opgeslagen."); return new ProgramArguments(false); } else if (args.Length > 0 && args[0].StartsWith("/id=")) { var result = new ProgramArguments(true); result.ArticleId = int.Parse(args[0].Split('=')[1]); return result; } else if (args.Length > 0 && args[0].StartsWith("/i")) { var result = new ProgramArguments(true); result.RunInteractiveMode = true; return result; } else { Console.WriteLine("/config : Pas de configuratie aan (config.xml)"); Console.WriteLine("/id={articleId} : Run voor 1 specifiek artikel (id)"); Console.WriteLine("/i : Interactieve modus: vraag welke artikelen te versturen"); return new ProgramArguments(false); } }