示例#1
0
        private async Task WriteJson(IJsonOutput output, ProgressOutput progress,
                                     IList <IDictionary <string, object> > taken)
        {
            await output.WriteBatchAsync(taken).ConfigureAwait(false);

            var newVal         = Interlocked.Add(ref _totalWritten, taken.Count);
            var progressOutput = progress.Render(newVal, Count);

            PositionalConsole.WriteLineAt(0, 1,
                                          $"Written {newVal.ToString($"D{_countDigits}")} of {Count}...{progressOutput}");
            taken.Clear();
        }
示例#2
0
        private Task[] StartConsumers(IJsonOutput output)
        {
            var count = Environment.ProcessorCount * 2;
            var tasks = new Task[count];

            for (int i = 0; i < count; i++)
            {
                tasks[i] = Task.Factory.StartNew(ConsumeJson, output, TaskCreationOptions.LongRunning).Unwrap();
            }

            return(tasks);
        }
 public void Deconstruct(object value, IJsonOutput output)
 {
     if (value == null)            
         output.Null();
     else if (value is bool)
         output.Boolean((bool)value);
     else if (value is double)
         output.Number((double)value);
     else if (value is string)
         output.String((string)value);
     else if (!OutputObjectOrArray(value, output))
         output.String(value.ToString()); 
 }
        protected virtual bool OutputObjectOrArray(object value, IJsonOutput output)
        {
            if (value is IEnumerable <KeyValuePair <string, object> > )
            {
                output.BeginObject();

                foreach (var keyValuePair in (IEnumerable <KeyValuePair <string, object> >)value)
                {
                    if (keyValuePair.Value is Undefined)
                    {
                        continue;
                    }

                    output.NamedProperty(keyValuePair.Key);

                    Deconstruct(keyValuePair.Value, output);
                }

                output.EndObject();
                return(true);
            }

            if (value is IEnumerable)
            {
                output.BeginArray();

                foreach (var item in (IEnumerable)value)
                {
                    if (item is Undefined)
                    {
                        continue;
                    }

                    Deconstruct(item, output);
                }

                output.EndArray();
                return(true);
            }

            if (value.GetType() == typeof(object))
            {
                output.BeginObject();
                output.EndObject();
                return(true);
            }

            return(false);
        }
        protected virtual bool OutputObjectOrArray(object value, IJsonOutput output)
        {
            if (value is IEnumerable<KeyValuePair<string, object>>)
            {
                output.BeginObject();

                foreach (var keyValuePair in (IEnumerable<KeyValuePair<string, object>>)value)
                {
                    if (keyValuePair.Value is Undefined)
                        continue;

                    output.NamedProperty(keyValuePair.Key);

                    Deconstruct(keyValuePair.Value, output);
                }

                output.EndObject();
                return true;
            }

            if (value is IEnumerable)
            {
                output.BeginArray();

                foreach (var item in (IEnumerable)value)
                {
                    if (item is Undefined)
                        continue;

                    Deconstruct(item, output);
                }

                output.EndArray();
                return true;
            }

            if (value.GetType() == typeof(object))
            {
                output.BeginObject();
                output.EndObject();
                return true;
            }
            
            return false;
        }
 public void Deconstruct(object value, IJsonOutput output)
 {
     if (value == null)
     {
         output.Null();
     }
     else if (value is bool)
     {
         output.Boolean((bool)value);
     }
     else if (value is double)
     {
         output.Number((double)value);
     }
     else if (value is string)
     {
         output.String((string)value);
     }
     else if (!OutputObjectOrArray(value, output))
     {
         output.String(value.ToString());
     }
 }