public IActionResult Post([FromBody] string discovery) { _logger.LogInformation("CPAPI: Post"); // Deserialize the discovery filter DiscoveryEntity entity = new DiscoveryEntity(); if (discovery != null && discovery.Length > 0) { _logger.LogDebug("Deserializing Discovery of length: " + discovery.Length); entity = JsonConvert.DeserializeObject <DiscoveryEntity>(discovery); } // Clean the table and row keys entity.PartitionKey = Utils.CleanTableKey(entity.PartitionKey); entity.RowKey = Utils.CleanTableKey(DateTime.UtcNow.ToString(Utils.ISODateFormat)); bool isAddedOK = AddDiscovery(entity); if (isAddedOK) { // Return the added system entity ObjectResult result = new ObjectResult(entity); return(result); } else { return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError)); } }
private bool AddDiscovery(DiscoveryEntity discoveryEntity) { bool isAddedOk = false; CloudTable table = Utils.GetCloudTable("stlpdiscover", _logger); //log.Info("Creating record entity"); // Create the TableOperation that inserts or merges the entry. //log.Verbose("Creating table operation"); TableOperation insertReplaceOperation = TableOperation.InsertOrReplace(discoveryEntity); // Execute the insert operation. //log.Verbose("Executing table operation"); try { Task tResult = table.ExecuteAsync(insertReplaceOperation); tResult.Wait(); //log.Verbose("Add keyphrase (" + keyPhrase + ") result: " + tResult.HttpStatusCode.ToString()); } catch (StorageException ex) { var requestInformation = ex.RequestInformation; Console.WriteLine("http status msg: " + requestInformation.HttpStatusMessage); // get more details about the exception var information = requestInformation.ExtendedErrorInformation; // if you have aditional information, you can use it for your logs if (information != null) { var errorCode = information.ErrorCode; var errMessage = string.Format("({0}) {1}", errorCode, information.ErrorMessage); // var errDetails = information //.AdditionalDetails //.Aggregate("", (s, pair) => //{ // return s + string.Format("{0}={1},", pair.Key, pair.Value); //}); _logger.LogInformation(errMessage); } } catch (Exception aex) { _logger.LogInformation("ERR exception: " + aex.Message); } isAddedOk = true; return(isAddedOk); }