コード例 #1
0
        /// <summary>
        /// The get json for rows.
        /// </summary>
        /// <param name="columns">
        /// The columns.
        /// </param>
        /// <param name="jsonValueWriter">
        /// The json value writer.
        /// </param>
        /// <param name="rows">
        /// The rows.
        /// </param>
        /// <param name="propertyName">
        /// The property name.
        /// </param>
        /// <returns>
        /// The <see cref="JObject[]"/>.
        /// </returns>
        private JObject[] GetJsonForRows(List <ColumnInfo> columns, IJsonValueWriter jsonValueWriter, List <object[]> rows, string propertyName)
        {
            // ReSharper disable once StyleCop.SA1305
            var jObjects = new List <JObject>();

            foreach (var row in rows)
            {
                // ReSharper disable once StyleCop.SA1305
                var jObject = new JObject();
                foreach (var col in columns)
                {
                    var value = row[col.index];

                    var shouldWriteColumn = value != null && value != DBNull.Value;

                    // only write if it is not the default
                    if (col.ElasticSearchType.Equals("keyword", StringComparison.OrdinalIgnoreCase) ||
                        col.ElasticSearchType.Equals("text", StringComparison.OrdinalIgnoreCase))
                    {
                        if (value == null ||
                            value == DBNull.Value ||
                            string.IsNullOrEmpty((string)value) ||
                            ((string)value).Equals("NULL", StringComparison.OrdinalIgnoreCase))
                        {
                            shouldWriteColumn = false;
                        }
                    }

                    if (shouldWriteColumn)
                    {
                        jObject.Add(col.Name, value != null ? JToken.FromObject(value) : null);

                        //jsonValueWriter.WriteValue(writer, col.ElasticSearchType, value);
                    }
                }

                jObjects.Add(jObject);
            }

            return(jObjects.ToArray());
        }
コード例 #2
0
        private JObject[] GetJsonForRowForMerge(List <ColumnInfo> columns, IJsonValueWriter jsonValueWriter, List <object[]> rows, string propertyName, string mypropertyType)
        {
            var jObjects = new List <JObject>();

            foreach (var row in rows)
            {
                var jObjectOuter = new JObject();

                var jObject = jObjectOuter;

                if (!string.IsNullOrEmpty(propertyName))
                {
                    var properties = propertyName.Split('.');


                    var jObject1 = jObjectOuter;
                    int level    = 1;

                    string currentFullPropertyName = null;

                    foreach (var property in properties)
                    {
                        currentFullPropertyName = currentFullPropertyName != null
                            ? currentFullPropertyName + '.' + property
                            : property;

                        jObject = new JObject();

                        var propertyType = QueueContext.PropertyTypes[currentFullPropertyName];

                        if (propertyType != null && propertyType.Equals("object", StringComparison.OrdinalIgnoreCase))
                        {
                            jObject1[property] = jObject;
                            jObject1           = jObject;
                        }
                        else //it is a nested list
                        {
                            // add a key column so we know what key this object corresponds to
                            var key      = "KeyLevel" + level++;
                            var keyValue =
                                row[columns.FirstOrDefault(c => c.Name.Equals(key, StringComparison.OrdinalIgnoreCase))
                                    .Verify($"{key} column not found")
                                    .index];

                            jObject.Add(key, GetJToken(keyValue));
                            var jArray = new JArray {
                                jObject
                            };
                            jObject1[property] = jArray;
                            jObject1           = jObject;
                        }
                    }
                }

                foreach (var col in columns)
                {
                    var value = row[col.index];

                    var shouldWriteColumn = value != null && value != DBNull.Value;

                    //only write if it is not the default
                    if (col.ElasticSearchType.Equals("keyword", StringComparison.OrdinalIgnoreCase) ||
                        col.ElasticSearchType.Equals("text", StringComparison.OrdinalIgnoreCase)
                        )
                    {
                        if (value == null ||
                            value == DBNull.Value ||
                            string.IsNullOrEmpty((string)value) ||
                            ((string)value).Equals("NULL", StringComparison.OrdinalIgnoreCase))
                        {
                            shouldWriteColumn = false;
                        }
                    }

                    if (shouldWriteColumn)
                    {
                        JToken tempToken;
                        if (!jObject.TryGetValue(col.Name, out tempToken))
                        {
                            jObject.Add(col.Name, GetJToken(value));
                        }

                        //jsonValueWriter.WriteValue(writer, col.ElasticSearchType, value);
                    }
                }
                jObjects.Add(jObjectOuter);
            }

            return(jObjects.ToArray());
        }