Exemplo n.º 1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            Dictionary <string, object> output = parser.ReadLine(inputString);

            if (output != null)
            {
                WriteObject(TypeConversion.DictToPSObject(output));
            }
        }
Exemplo n.º 2
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (!parallel)
            {
                string line;
                if (psEncoding == FileSystemCmdletProviderEncoding.Default)
                {
                    reader = new StreamReader(stream, true);
                }
                else
                {
                    reader = new StreamReader(stream, CmdletEncoding.Convert(psEncoding));
                }

                while ((line = reader.ReadLine()) != null)
                {
                    Dictionary <string, object> output = parser.ReadLine(line);
                    if (output != null)
                    {
                        WriteObject(TypeConversion.DictToPSObject(output));
                    }
                }
            }
            else
            {
                ConcurrentQueue <PSObject> outputQueue = new ConcurrentQueue <PSObject>();
                Task processingTask = Task.Factory.StartNew(() =>
                                                            System.Threading.Tasks.Parallel.ForEach(ParseIDX.splitIDX(stream, CmdletEncoding.Convert(psEncoding)), (byte[] docBytes) => {
                    string doc = CmdletEncoding.Convert(psEncoding).GetString(docBytes);
                    Dictionary <string, object> parsed = ParseIDX.ParseBlock(doc);
                    outputQueue.Enqueue(TypeConversion.DictToPSObject(parsed));
                })
                                                            );
                while (!processingTask.IsCompleted || !outputQueue.IsEmpty)
                {
                    if (outputQueue.TryDequeue(out PSObject output))
                    {
                        WriteObject(output);
                    }
                    else
                    {
                        System.Threading.Thread.Yield();
                    }
                }
            }
        }