コード例 #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);
        }
コード例 #3
0
 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()); 
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        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;
        }
コード例 #6
0
 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());
     }
 }