using System; using System.Configuration; using Newtonsoft.Json.Linq; using System.Net.Http; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Binder; using Microsoft.Extensions.Configuration.EnvironmentVariables; using Microsoft.Extensions.Configuration.FileExtensions; using Microsoft.Extensions.Configuration.Json; using Microsoft.Extensions.Configuration.UserSecrets; using System.IO; namespace OMSECFaPiaoSMS { class Program { static void Main(string[] args) { try { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); IConfigurationRoot configuration = builder.Build(); B2BDB.ConnectionString = configuration.GetConnectionString("ss_xx"); var settings = configuration.GetSection("AppSettings"); string key = settings.GetValue<string>("key"); string account = settings.GetValue<string>("account"); string sdate = ""; string whse = args[0]; if (args.Length > 1) { DateTime tempdate; if (DateTime.TryParse(args[1], out tempdate)) { sdate = String.Format("{0:yyyy-MM-dd}", tempdate); } else throw new Exception("日期格式错误!"); } else { sdate = String.Format("{0:yyyy-MM-dd}", System.DateTime.Now.AddDays(-3)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }
appsetting.json 文件
{ "ConnectionStrings": { "ss_xx": "Data Source=aaaaa;Initial Catalog=aaa;Persist Security Info=True;User ID=aa;Password=aaa;Connect Timeout=30" }, "AppSettings": { "account": "aaaa", "key": "aaaaa" }, "Logging": { "LogLevel": { "Default": "Warning" } } }