Update vor Umbau Service
This commit is contained in:
@@ -934,6 +934,7 @@ namespace API_NetFramework.Controllers
|
||||
}
|
||||
onbasedoc.attributes.Add(new OnBaseDocUpload.attribute("O2O Dochandle", oba.DocumentHandle.ToString()));
|
||||
onbasedoc.attributes.Add(new OnBaseDocUpload.attribute("O2O Status", oba.Status.ToString()));
|
||||
onbasedoc.attributes.Add(new OnBaseDocUpload.attribute("O2O ExternalReference", oba.ReferenceId.ToString()));
|
||||
|
||||
ILResponse ilr = new ILResponse();
|
||||
string debugfilename = System.Configuration.ConfigurationManager.AppSettings["JSONDebugPath"];
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,6 +18,8 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Web.Http.Results;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Drawing;
|
||||
using Syncfusion.DocIO.DLS;
|
||||
|
||||
|
||||
namespace OnDocAPI_NetFramework.Controllers
|
||||
@@ -54,9 +56,19 @@ namespace OnDocAPI_NetFramework.Controllers
|
||||
}
|
||||
|
||||
if (json == null)
|
||||
return NotFound();
|
||||
{
|
||||
using (SqlConnection con = new SqlConnection(_connectionString))
|
||||
using (SqlCommand cmd = new SqlCommand(
|
||||
"SELECT JsonObjekt FROM _OnDoc_API_TestScripts WHERE id = @key", con))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@key", key);
|
||||
con.Open();
|
||||
json = cmd.ExecuteScalar()?.ToString();
|
||||
}
|
||||
if (json == null) return NotFound();
|
||||
}
|
||||
|
||||
return Ok(json);
|
||||
return Ok(json);
|
||||
}
|
||||
|
||||
// 🔹 JSON SPEICHERN
|
||||
@@ -69,13 +81,21 @@ namespace OnDocAPI_NetFramework.Controllers
|
||||
|
||||
using (SqlConnection con = new SqlConnection(_connectionString))
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
IF EXISTS (SELECT 1 FROM provdokuments WHERE provdokumentid = @key)
|
||||
UPDATE provdokuments SET JavaScriptObject = @json, geaendertam = GETDATE()
|
||||
WHERE provdokumentid = @key
|
||||
IF EXISTS (SELECT 1 FROM _OnDoc_API_TestScripts WHERE id = @key)
|
||||
UPDATE _OnDoc_API_TestScripts SET JsonObjekt =@json
|
||||
WHERE id = @key
|
||||
ELSE
|
||||
INSERT INTO provdokuments (provdokumentid,erstelltam,geaendertam, JavaScriptObject)
|
||||
VALUES (@key, getdate(),getdate(),@json)
|
||||
INSERT INTO _OnDoc_API_TestScripts (id,JsonObjekt)
|
||||
VALUES (@key, @json)
|
||||
", con))
|
||||
|
||||
//IF EXISTS (SELECT 1 FROM provdokuments WHERE provdokumentid = @key)
|
||||
// UPDATE provdokuments SET JavaScriptObject = @json, geaendertam = GETDATE()
|
||||
// WHERE provdokumentid = @key
|
||||
//ELSE
|
||||
// INSERT INTO provdokuments (provdokumentid,erstelltam,geaendertam, JavaScriptObject)
|
||||
// VALUES (@key, getdate(),getdate(),@json)
|
||||
//", con))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@key", dto.Key);
|
||||
cmd.Parameters.AddWithValue("@json", dto.Json);
|
||||
@@ -100,6 +120,8 @@ ELSE
|
||||
[System.Web.Http.Route("GeneratePDF")]
|
||||
public async Task<HttpResponseMessage> GeneratePdf(JsonRequestDto dto)
|
||||
{
|
||||
|
||||
|
||||
if (dto == null || string.IsNullOrWhiteSpace(dto.Json))
|
||||
return new HttpResponseMessage(HttpStatusCode.BadRequest);
|
||||
|
||||
@@ -109,8 +131,8 @@ ELSE
|
||||
{
|
||||
Content = new ByteArrayContent(pdfBytes)
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
response.Content.Headers.ContentType =
|
||||
new MediaTypeHeaderValue("application/pdf");
|
||||
|
||||
@@ -120,81 +142,208 @@ ELSE
|
||||
FileName = $"{dto.Key}.pdf"
|
||||
};
|
||||
response.Content.Headers.ContentLength = pdfBytes.Length;
|
||||
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
private async Task<byte[]> CallExternalPdfApi(string json)
|
||||
{
|
||||
|
||||
string ownHost = System.Configuration.ConfigurationManager.AppSettings["OwnHost"];
|
||||
string token = System.Configuration.ConfigurationManager.AppSettings["OwnToken"];
|
||||
string URL = ownHost + "API/DokumentGenerator";
|
||||
|
||||
try
|
||||
{
|
||||
APIErrorSimple apireturn = new APIErrorSimple();
|
||||
APIOK apiok = new APIOK();
|
||||
;
|
||||
string jsonstring = json;
|
||||
|
||||
WebRequest request;
|
||||
|
||||
var data = Encoding.UTF8.GetBytes(jsonstring);
|
||||
string OwnHost = System.Configuration.ConfigurationManager.AppSettings["OwnHost"].ToString();
|
||||
string uri = OwnHost + "/API/CreateCLM";
|
||||
uri = OwnHost + "/API/DokumentGenerator";
|
||||
request = WebRequest.Create(uri);
|
||||
request.ContentLength = data.Length;
|
||||
request.ContentType = "application/json";
|
||||
request.Method = "POST";
|
||||
request.Headers["Authorization"] = "Bearer " + "pZkuG6l6ORCEckqQimPK58PO1A9EnkMtL5oCgRX9WiWnD4xeH7ikGzhWnTBy/vk8J4Iiz8gCSx9uFHA4+DvITG0roO97sk82d/0BCjVlwLWINpXlJfGYEF3X96AdoCQvb3ruwv/tVqEHsSU5aNfyxBAe+EhLTHQ8t7ysgJZWh98=";
|
||||
using (Stream requestStream = request.GetRequestStream())
|
||||
var webRequest = System.Net.WebRequest.Create(URL);
|
||||
if (webRequest != null)
|
||||
{
|
||||
requestStream.Write(data, 0, data.Length);
|
||||
requestStream.Close();
|
||||
webRequest.Method = "POST";
|
||||
webRequest.Timeout = 20000;
|
||||
webRequest.ContentType = "application/json";
|
||||
webRequest.Headers["Authorization"] = "Bearer " + token;
|
||||
|
||||
using (Stream responseStream = request.GetResponse().GetResponseStream())
|
||||
using (System.IO.Stream s = webRequest.GetRequestStream())
|
||||
{
|
||||
using (var reader = new StreamReader(responseStream))
|
||||
{
|
||||
var response = reader.ReadToEnd();
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
apiok = JsonConvert.DeserializeObject<APIOK>(response);
|
||||
var jo = JObject.Parse(response.ToString());
|
||||
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(s))
|
||||
sw.Write(json);
|
||||
}
|
||||
|
||||
return Convert.FromBase64String(apiok.file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
apireturn = JsonConvert.DeserializeObject<APIErrorSimple>(response);
|
||||
}
|
||||
using (System.IO.Stream s = webRequest.GetResponse().GetResponseStream())
|
||||
{
|
||||
using (System.IO.StreamReader sr = new System.IO.StreamReader(s))
|
||||
{
|
||||
var jsonResponse = sr.ReadToEnd();
|
||||
System.Diagnostics.Debug.WriteLine(String.Format("Response: {0}", jsonResponse));
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch {
|
||||
byte[] pdf;
|
||||
return null;}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.ToString());
|
||||
}
|
||||
|
||||
|
||||
// var request = (HttpWebRequest)WebRequest.Create("https://api.example.com/generate-pdf");
|
||||
//request.Method = "POST";
|
||||
//request.ContentType = "application/json";
|
||||
|
||||
//byte[] payload = Encoding.UTF8.GetBytes(json);
|
||||
//request.ContentLength = payload.Length;
|
||||
|
||||
//using (var stream = request.GetRequestStream())
|
||||
// stream.Write(payload, 0, payload.Length);
|
||||
|
||||
//using (var response = (HttpWebResponse)request.GetResponse())
|
||||
//using (var rs = response.GetResponseStream())
|
||||
//using (var ms = new MemoryStream())
|
||||
//string URL = ownHost + "API/CreateCLM";
|
||||
//HttpWebRequest webRequest = HttpWebRequest.Create(URL) as HttpWebRequest;
|
||||
//webRequest.Method = WebRequestMethods.Http.Post;
|
||||
//webRequest.
|
||||
//webRequest.Headers["Authorization"] = "Bearer " + Token;
|
||||
//try
|
||||
//{
|
||||
// rs.CopyTo(ms);
|
||||
// return ms.ToArray();
|
||||
// using (HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse)
|
||||
// {
|
||||
// if (response.StatusCode == HttpStatusCode.OK)
|
||||
// {
|
||||
// StreamReader reader = new StreamReader(response.GetResponseStream());
|
||||
// string responseContent = reader.ReadToEnd();
|
||||
|
||||
// return responseContent;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Logging.Logging.Error(URL + ": " + response.StatusCode.ToString() + " / " + response.StatusDescription, "Client - GetImage", "");
|
||||
// return "";
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// return "";
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
string uri = ownHost + "/API/CreateCLM";
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization =
|
||||
new AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
client.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response = client.PostAsync(uri, content).Result;
|
||||
|
||||
|
||||
string responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
try
|
||||
{
|
||||
// Erfolgsfall
|
||||
var apiok = JsonConvert.DeserializeObject<APIOK>(responseContent);
|
||||
|
||||
if (!string.IsNullOrEmpty(apiok?.file))
|
||||
{
|
||||
return Convert.FromBase64String(apiok.file);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fehlerfall
|
||||
var apireturn = JsonConvert.DeserializeObject<APIErrorSimple>(responseContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.APIDocLog.Error("API-Call fehlgeschlagen", ex.Message,"","");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
//try
|
||||
//{
|
||||
|
||||
// APIErrorSimple apireturn = new APIErrorSimple();
|
||||
// APIOK apiok = new APIOK();
|
||||
// ;
|
||||
// string jsonstring = json;
|
||||
|
||||
// WebRequest request;
|
||||
|
||||
// var data = Encoding.UTF8.GetBytes(jsonstring);
|
||||
// string OwnHost = System.Configuration.ConfigurationManager.AppSettings["OwnHost"].ToString();
|
||||
// string uri = OwnHost + "/API/CreateCLM";
|
||||
// uri = OwnHost + "/API/DokumentGenerator";
|
||||
// Logging.APIDocLog.Info("URI", "IIS", "123", uri);
|
||||
// request = WebRequest.Create(uri);
|
||||
// request.ContentLength = data.Length;
|
||||
// request.ContentType = "application/json";
|
||||
// request.Method = "POST";
|
||||
// request.Headers["Authorization"] = "Bearer " + System.Configuration.ConfigurationManager.AppSettings["OwnToken"].ToString();
|
||||
|
||||
// try
|
||||
// {
|
||||
|
||||
// using (Stream requestStream = request.GetRequestStream())
|
||||
// {
|
||||
|
||||
// requestStream.Write(data, 0, data.Length);
|
||||
// requestStream.Close();
|
||||
|
||||
// using (Stream responseStream = request.GetResponse().GetResponseStream())
|
||||
// {
|
||||
// using (var reader = new StreamReader(responseStream))
|
||||
// {
|
||||
// var response = reader.ReadToEnd();
|
||||
// try
|
||||
// {
|
||||
|
||||
// apiok = JsonConvert.DeserializeObject<APIOK>(response);
|
||||
// var jo = JObject.Parse(response.ToString());
|
||||
|
||||
// return Convert.FromBase64String(apiok.file);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
|
||||
// apireturn = JsonConvert.DeserializeObject<APIErrorSimple>(response);
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
|
||||
// return null;
|
||||
// }
|
||||
//}
|
||||
//catch {
|
||||
// byte[] pdf;
|
||||
// return null;}
|
||||
|
||||
|
||||
//// var request = (HttpWebRequest)WebRequest.Create("https://api.example.com/generate-pdf");
|
||||
////request.Method = "POST";
|
||||
////request.ContentType = "application/json";
|
||||
|
||||
////byte[] payload = Encoding.UTF8.GetBytes(json);
|
||||
////request.ContentLength = payload.Length;
|
||||
|
||||
////using (var stream = request.GetRequestStream())
|
||||
//// stream.Write(payload, 0, payload.Length);
|
||||
|
||||
////using (var response = (HttpWebResponse)request.GetResponse())
|
||||
////using (var rs = response.GetResponseStream())
|
||||
////using (var ms = new MemoryStream())
|
||||
////{
|
||||
//// rs.CopyTo(ms);
|
||||
//// return ms.ToArray();
|
||||
////}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user