Exemplo n.º 1
0
        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
            }
        }
Exemplo n.º 2
0
        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("");
            }
        }
Exemplo n.º 3
0
        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()));
        }
Exemplo n.º 4
0
        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()));
        }
Exemplo n.º 5
0
        //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;
            }
        }
Exemplo n.º 6
0
        public void IsValidJsonTestFailure()
        {
            string notJson = "This is not a json string.";

            Assert.IsFalse(JsonValidator.IsValidJson(notJson));
        }
Exemplo n.º 7
0
 public void ShouldNotPass_IfJsonStringIsNull()
 {
     Assert.IsFalse(JsonValidator.IsValidJson(null));
 }
Exemplo n.º 8
0
        public void ShouldNotPass_IfJsonArrayStringEndsWithNoTag()
        {
            string _jsonNotValid = _jsonArr.Substring(_jsonArr.Length - 1);

            Assert.IsFalse(JsonValidator.IsValidJson(_jsonNotValid));
        }
Exemplo n.º 9
0
        public void ShouldNotPass_IfJsonArrayStringEndsWith2Tags()
        {
            string _jsonNotValid = _jsonArr + "{";

            Assert.IsFalse(JsonValidator.IsValidJson(_jsonNotValid));
        }
Exemplo n.º 10
0
        public void ShouldNotPass_IfJsonArrayStringBeginsWith2Tags()
        {
            string _jsonNotValid = "{" + _jsonArr;

            Assert.IsFalse(JsonValidator.IsValidJson(_jsonNotValid));
        }
Exemplo n.º 11
0
        public void ShouldNotPass_IfJsonArrayStringHasNoBeginningTag()
        {
            string _jsonNotValid = _jsonArr.Remove(0, 1);

            Assert.IsFalse(JsonValidator.IsValidJson(_jsonNotValid));
        }
Exemplo n.º 12
0
 public void ShouldPass_IfValidJsonArray()
 {
     Assert.IsTrue(JsonValidator.IsValidJson(_jsonArr));
 }
Exemplo n.º 13
0
 public void ShouldNotPass_IfJsonStringIsWhitespace()
 {
     Assert.IsFalse(JsonValidator.IsValidJson(" "));
 }