Пример #1
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();
                    }
                }
            }
        }
Пример #2
0
        protected override void BeginProcessing()
        {
            base.BeginProcessing();

            parser = new ParseIDX();

            try {
                Stream inStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 128 * 1024, FileOptions.SequentialScan);
                if (System.IO.Path.GetExtension(Path) == ".gz")
                {
                    stream = new GZipStream(inStream, CompressionMode.Decompress);
                }
                else
                {
                    stream = inStream;
                }
            } catch (Exception e) {
                WriteError(new ErrorRecord(e, "Could not open stream", ErrorCategory.OpenError, Path));
                return;
            }
        }
Пример #3
0
 protected override void BeginProcessing()
 {
     base.BeginProcessing();
     parser = new ParseIDX();
 }