87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
|
|
namespace APICLI
|
|
{
|
|
internal class Program
|
|
{
|
|
static string logfile = "";
|
|
static string errorlog = "";
|
|
static string oklog = "";
|
|
static string loglevel = "";
|
|
static void WriteLog (string message, string filename, int erroor)
|
|
{
|
|
switch (loglevel.ToUpper())
|
|
{
|
|
case "ALL":
|
|
}
|
|
message=DateTime.Now.ToString("yyyyMMdd_HHmms") + "_" + message;
|
|
System.IO.File.WriteAllText(filename,message);
|
|
Console.WriteLine (message);
|
|
}
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
DirectoryInfo d = new DirectoryInfo(args[0].ToString());
|
|
string ApiUrl = Properties.Settings.Default.resturi + args[0].ToString();
|
|
|
|
logfile = args[1].ToString();
|
|
errorlog = args[2].ToString();
|
|
oklog = args[3].ToString();
|
|
loglevel = args[4].ToString();
|
|
|
|
FileInfo[] files = d.GetFiles("*.json");
|
|
foreach (FileInfo file in files)
|
|
{
|
|
WriteLog("Processing file: " + file.FullName, logfile, 0);
|
|
try
|
|
{
|
|
using (var client = new HttpClient())
|
|
{
|
|
// 🔐 Bearer Token
|
|
string json = System.IO.File.ReadAllText(file.FullName.ToString());
|
|
client.DefaultRequestHeaders.Accept.Clear();
|
|
client.DefaultRequestHeaders.Accept.Add(
|
|
new MediaTypeWithQualityHeaderValue("application/json"));
|
|
client.DefaultRequestHeaders.Authorization =
|
|
new AuthenticationHeaderValue("Bearer", Properties.Settings.Default.token);
|
|
|
|
var content = new StringContent(
|
|
json,
|
|
Encoding.UTF8,
|
|
"application/json");
|
|
|
|
var response = client.PostAsync(ApiUrl, content).Result;
|
|
|
|
var responseText = response.Content.ReadAsStringAsync().Result;
|
|
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
// optional: Logging
|
|
Console.WriteLine($"Error: {response.StatusCode} - {responseText}");
|
|
}
|
|
|
|
var jsonResult = JObject.Parse(responseText);
|
|
Console.WriteLine(responseText);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Logging
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|