public void Insert(string jsonObject) { bool isValidJson = JsonValidator.IsValidJson(jsonObject); if (isValidJson) { try { BsonDocument document = MongoDB.Bson.Serialization.BsonSerializer.Deserialize <BsonDocument>(jsonObject); var insert = Con.Get(); insert.InsertOne(document); } catch (BsonException ex) { //Handle Exception } catch (Exception ex) { //Handle Exception } } else { //Handle Exception } }
public string CheckUserDataExist(LabQueryModel queryModel) { var isvalidate = new JsonValidator(); var querybyattribute = new QueryByAttribute("lab_orderscan") { ColumnSet = new ColumnSet("lab_json_checker", "lab_json_maker", "lab_orderscanid") }; try { querybyattribute.AddAttributeValue("lab_orderscanid", queryModel.OrderId); var labscanGuid = Guid.Parse(queryModel.OrderId); var orderCollection = Service.Retrieve("lab_orderscan", labscanGuid, new ColumnSet(true)); var statuscode = orderCollection.GetEntityReferenceValue <OptionSetValue>("statuscode").Value; return(queryModel.UserRole == Maker && (int)Open == statuscode && orderCollection.Contains("lab_json_maker") ? (isvalidate.IsValidJson(orderCollection["lab_json_maker"].ToString()) ? orderCollection["lab_json_maker"].ToString() : "") : (queryModel.UserRole != null && (queryModel.UserRole == Checker && (int)PendingforApproval == statuscode && !orderCollection.Contains("lab_json_checker") && orderCollection.Contains("lab_json_maker")) ? (isvalidate.IsValidJson(orderCollection["lab_json_maker"].ToString()) ? orderCollection["lab_json_maker"].ToString() : "") : (queryModel.UserRole == Checker && (int)PendingforApproval == statuscode && orderCollection.Contains("lab_json_checker") ? (isvalidate.IsValidJson(orderCollection["lab_json_checker"].ToString()) ? orderCollection[$"lab_json_checker"].ToString() : "") : ""))); } catch (Exception) { return(""); } }
public void IsValidJsonTestJObjectSuccess() { JObject json = new JObject { ["key"] = "value", ["anotherKey"] = "anotherValue" }; JObject nestedJson = new JObject { ["key"] = "value", ["anotherKey"] = "anotherValue" }; json["nested"] = nestedJson; Assert.IsTrue(JsonValidator.IsValidJson(json.ToString())); }
public void IsValidJsonTestJArraySuccess() { JArray jsonArray = new JArray(); JObject arrayEntry1 = new JObject { ["key1"] = "value1" }; JObject arrayEntry2 = new JObject { ["key2"] = "value2" }; jsonArray.Add(arrayEntry1); jsonArray.Add(arrayEntry2); // Add itself cause why not jsonArray.Add(jsonArray); Assert.IsTrue(JsonValidator.IsValidJson(jsonArray.ToString())); }
//scoped call public override async Task ProcessInScopeAsync(IServiceProvider serviceProvider) { try { var configId = _settings.ConfigId; var clientId = _settings.ClientId; _logger.LogInformation("Pulling configuration settings from database."); var date = DateTime.Today; var guid = Guid.NewGuid(); var configData = await _dataController.ReadConfiguration(configId.StringToGuid()); string jsonConfig = String.Empty; if (configData != null) { jsonConfig = configData.Configuration; } if (JsonValidator.IsValidJson(jsonConfig, out _TaskConfig)) { var serviceTimeInms = (_TaskConfig.Service.PollingFrequency.Minutes * 60) * 1000; ITaskObjFactory taskObjFactory = serviceProvider.GetService <ITaskObjFactory>(); foreach (var task in _TaskConfig.Tasks) { var toDo = taskObjFactory.GetTask(TaskType.DicType[task.Type.ToUpper()], serviceProvider); _logger.LogInformation($"{toDo.GetType().ToString().ToUpper()} task process starting."); await toDo.StartTask(task, configId, clientId, null); } //await Task.Delay(serviceTimeInms, stoppingToken); await Task.Delay(serviceTimeInms); } } catch (Exception e) { _logger.LogError(e, e.Message); throw; } }
public void IsValidJsonTestFailure() { string notJson = "This is not a json string."; Assert.IsFalse(JsonValidator.IsValidJson(notJson)); }
public void ShouldNotPass_IfJsonStringIsNull() { Assert.IsFalse(JsonValidator.IsValidJson(null)); }
public void ShouldNotPass_IfJsonArrayStringEndsWithNoTag() { string _jsonNotValid = _jsonArr.Substring(_jsonArr.Length - 1); Assert.IsFalse(JsonValidator.IsValidJson(_jsonNotValid)); }
public void ShouldNotPass_IfJsonArrayStringEndsWith2Tags() { string _jsonNotValid = _jsonArr + "{"; Assert.IsFalse(JsonValidator.IsValidJson(_jsonNotValid)); }
public void ShouldNotPass_IfJsonArrayStringBeginsWith2Tags() { string _jsonNotValid = "{" + _jsonArr; Assert.IsFalse(JsonValidator.IsValidJson(_jsonNotValid)); }
public void ShouldNotPass_IfJsonArrayStringHasNoBeginningTag() { string _jsonNotValid = _jsonArr.Remove(0, 1); Assert.IsFalse(JsonValidator.IsValidJson(_jsonNotValid)); }
public void ShouldPass_IfValidJsonArray() { Assert.IsTrue(JsonValidator.IsValidJson(_jsonArr)); }
public void ShouldNotPass_IfJsonStringIsWhitespace() { Assert.IsFalse(JsonValidator.IsValidJson(" ")); }