public async Task <Guid?> ErstelleNummerInformationAsync() { Guid?guid = StandardRequirement.Instance.BonsaiTransferGuid; if (!guid.HasValue && StandardRequirement.Instance.ErstellteNummerDefinitionResponse != null) { long deuWoauftragsnummer = Common.Helpers.Random_Helper.GetLong(0, 10000); using (var httpClient = new HttpClient()) { ErstelleNummerInformationRequest erstelleNummerInformationRequest = LieferErstelleNummerInformation(deuWoauftragsnummer); StringContent content = new StringContent(JsonConvert.SerializeObject(erstelleNummerInformationRequest), Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await httpClient.PostAsync(BaseAPIURL + "ErstelleNummerInformation/", content)) { if (response.IsSuccessStatusCode) { string apiResponse = await response.Content.ReadAsStringAsync(); StandardRequirement.Instance.BonsaiTransferGuid = JsonConvert.DeserializeObject <Guid>(apiResponse); if (StandardRequirement.Instance.BonsaiTransferGuid.HasValue) { guid = StandardRequirement.Instance.BonsaiTransferGuid; StandardRequirement.Instance.DeuWoAuftragsnummer = deuWoauftragsnummer; } } } } } return(guid); }
public static ErstelleNummerInformationRequest LieferErstelleNummerInformation(long auftragsnummer) { ErstelleNummerInformationRequest erstelleNummerInformationRequest = new ErstelleNummerInformationRequest(); if (StandardRequirement.Instance.ErstellteNummerDefinitionResponse != null) { erstelleNummerInformationRequest.Nummer_definition_id = StandardRequirement.Instance.ErstellteNummerDefinitionResponse.Id; erstelleNummerInformationRequest.Quellen = new object[] { auftragsnummer }; } return(erstelleNummerInformationRequest); }
private static async Task <Guid?> ErstelleNummerInformationAsync(ErstelleNummerInformationRequest erstelleNummerInformationRequest) { Guid?guid = null; using (var httpClient = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(erstelleNummerInformationRequest), Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await httpClient.PostAsync(BaseAPIURL + "ErstelleNummerInformation/", content)) { if (response.IsSuccessStatusCode) { string apiResponse = await response.Content.ReadAsStringAsync(); guid = JsonConvert.DeserializeObject <Guid>(apiResponse); } } } return(guid); }
public async Task <ActionResult <Guid?> > ErstelleNummerInformation(ErstelleNummerInformationRequest erstelleNummerInformationRequest) { Guid?guid = null; NummerDefinition foundNummerDefinition = this._context.Nummerdefinitionen.Include("NummerDefinitionQuellen").Where(e => (e.Id == erstelleNummerInformationRequest.Nummer_definition_id)).FirstOrDefault(); if (foundNummerDefinition == null) { throw new Exception(string.Format("für die nummer_definition_id = '{0}' existiert keine gültig Nummerdefinition.", erstelleNummerInformationRequest.Nummer_definition_id)); } else if (foundNummerDefinition.NummerDefinitionQuellen == null || foundNummerDefinition.NummerDefinitionQuellen.Count == 0) { throw new Exception("Für die Nummerdefinition sind keine Quellen definiert."); } else if (foundNummerDefinition.NummerDefinitionQuellen.Count != erstelleNummerInformationRequest.Quellen.Count()) { throw new Exception("Die Anzahl der definierten Quellen stimmt nicht mit der Anzahl der übergebenen Quellen überein."); } //else if (erstelleNummerInformation.Ziel == null) //{ // throw new Exception("Das Ziel ist null."); //} else { Data.Models.NummerInformation nummerInformation = new Data.Models.NummerInformation(); nummerInformation.NummerdefinitionenId = erstelleNummerInformationRequest.Nummer_definition_id; string jsonQuellen = NumberInformationJSONGenerator.GenerateJSON(foundNummerDefinition.NummerDefinitionQuellen, erstelleNummerInformationRequest.Quellen); nummerInformation.Quelle = jsonQuellen; nummerInformation.Ziel = erstelleNummerInformationRequest.Ziel != null?erstelleNummerInformationRequest.Ziel.ToString() : null; this._context.Nummerinformationen.Add(nummerInformation); await this._context.SaveChangesAsync(); guid = nummerInformation.Guid; } return(guid); }
private static ErstelleNummerInformationRequest CreateRandomErstelleNummerInformation(NummerDefinition nummerDefinition) { ErstelleNummerInformationRequest erstelleNummerInformationRequest = new ErstelleNummerInformationRequest(); if (nummerDefinition != null) { erstelleNummerInformationRequest.Nummer_definition_id = nummerDefinition.Id; int anzahlQuellen = nummerDefinition.NummerDefinitionQuellen.Count; object[] quellen = new object[anzahlQuellen]; int index = 0; foreach (var NummerDefinitionQuelle in nummerDefinition.NummerDefinitionQuellen) { object value = null; switch ((Datentypwerte)NummerDefinitionQuelle.DatentypenId) { case Datentypwerte.String: value = Guid.NewGuid().ToString(); break; case Datentypwerte.Integer: value = Random_Helper.GetLong(0L, 100000L); break; case Datentypwerte.Guid: value = Guid.NewGuid().ToString(); break; default: break; } quellen[index] = value; index++; } erstelleNummerInformationRequest.Quellen = quellen; } return(erstelleNummerInformationRequest); }
public async Task <NummerInformation> HoleNummerInformationAsync(NummerDefinition nummerDefinition, ErstelleNummerInformationRequest erstelleNummerInformationRequest) { NummerInformation nummerInformation = null; HoleNummerInformationRequest holeNummerInformationRequest = new HoleNummerInformationRequest(); holeNummerInformationRequest.Nummer_definition_id = nummerDefinition.Id; holeNummerInformationRequest.DurchQuellen = true; holeNummerInformationRequest.Quellen = erstelleNummerInformationRequest.Quellen; using (var httpClient = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(holeNummerInformationRequest), Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await httpClient.PostAsync(BaseAPIURL + "HoleNummerInformation/", content)) { if (response.IsSuccessStatusCode) { string apiResponse = await response.Content.ReadAsStringAsync(); nummerInformation = JsonConvert.DeserializeObject <NummerInformation>(apiResponse); } } } return(nummerInformation); }
public async Task <MassTestResult> RunAsync(long max) { MassTestResult massTestResult = new MassTestResult(); List <NummerDefinition> nummerDefinitionen = new List <NummerDefinition>(); List <ErstelleNummerInformationRequest> erstelleNummerInformationRequests = new List <ErstelleNummerInformationRequest>(); long countOfDefinitions = Random_Helper.GetLong(1L, max); massTestResult.CountOfDefinitions = countOfDefinitions; for (long i = 0; i < countOfDefinitions; i++) { NummerDefinition nummerDefinition = CreateRandomNummerDefinition(); ErstellteNummerDefinitionResponse ErstellteNummerDefinitionResponse = await ErstelleNummerDefinitionAsync(nummerDefinition); if (ErstellteNummerDefinitionResponse != null) { nummerDefinition.Guid = ErstellteNummerDefinitionResponse.Guid; nummerDefinition.Id = ErstellteNummerDefinitionResponse.Id; nummerDefinitionen.Add(nummerDefinition); } else { WriteRedTextToConsole("NummerDefinition konnte nicht erstellt werden."); } } long countOfInformations = Random_Helper.GetLong(1L, max); massTestResult.CountOfInformations = countOfInformations; foreach (var nummerDefinition in nummerDefinitionen) { for (int i = 0; i < countOfInformations; i++) { ErstelleNummerInformationRequest erstelleNummerInformationRequest = CreateRandomErstelleNummerInformation(nummerDefinition); Guid?guid = await ErstelleNummerInformationAsync(erstelleNummerInformationRequest); if (guid.HasValue) { erstelleNummerInformationRequests.Add(erstelleNummerInformationRequest); SetzeZielFürNummerInformationRequest setzeZielFürNummerInformationRequest = ErstelleSetzeZielFürNummerInformation(guid, nummerDefinition); bool success = await SetzeZielFürNummerInformationAsync(setzeZielFürNummerInformationRequest); if (success) { MassTestMeasure massTestMeasure = new MassTestMeasure(); massTestMeasure.CountOfInformations = await this._context.Nummerinformationen.CountAsync(); massTestMeasure.Start = DateTime.Now; NummerInformation nummerInformation = await HoleNummerInformationAsync(nummerDefinition, erstelleNummerInformationRequest); if (nummerInformation != null && nummerInformation.Ziel.ToString() == setzeZielFürNummerInformationRequest.Ziel.ToString()) { massTestMeasure.End = DateTime.Now; massTestMeasure.Milliseconds = (massTestMeasure.End - massTestMeasure.Start).TotalMilliseconds; massTestResult.MassTestMeasures.Add(massTestMeasure); } else { WriteRedTextToConsole("NummerInformation konnte nicht geholt werden."); } } } else { WriteRedTextToConsole("NummerInformation konnte nicht erstellt werden."); } } } massTestResult.CountOfErstelleNummerInformationen = erstelleNummerInformationRequests.Count; return(massTestResult); }