示例#1
0
        public void XamlEmptyXName()
        {
            // [Python Tools] Adding attribute through XAML in IronPython application crashes VS.
            // http://pytools.codeplex.com/workitem/743
            using (var analyzer = CreateAnalyzer()) {
                string xamlPath  = TestData.GetPath(@"TestData\Xaml\EmptyXName.xaml");
                string pyPath    = TestData.GetPath(@"TestData\Xaml\EmptyXName.py");
                var    xamlEntry = (IXamlProjectEntry)((IDotNetPythonInterpreter)analyzer.Analyzer.Interpreter).AddXamlEntry(xamlPath, new Uri(xamlPath));
                var    pyEntry   = analyzer.AddModule("EmptyXName", File.ReadAllText(pyPath), pyPath);

                xamlEntry.ParseContent(new FileStreamReader(xamlPath), null);

                using (var stream = new FileStreamReader(pyPath)) {
                    var parser = Parser.CreateParser(stream, PythonLanguageVersion.V27, new ParserOptions()
                    {
                        BindReferences = true
                    });
                    using (var p = pyEntry.BeginParse()) {
                        p.Tree = parser.ParseFile();
                        p.Complete();
                    }
                }

                pyEntry.Analyze(CancellationToken.None);
            }
        }
示例#2
0
        private static readonly int[] bufferSizes = { 64, 128, 256, 512, };         // Buffer sizes in KiB

        // This method may cause an OutOfMemoryException if run on 32bit process.
        // To avoid the exception, uncheck "Prefer 32-bit" in the build settings.
        public static async Task ReadAsync(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return;
            }

            foreach (var bufferSize in bufferSizes)
            {
                Console.WriteLine($"Start {bufferSize}KiB");

                var sw = new Stopwatch();
                sw.Start();

                double oldValue = 0;

                var progress = new Progress <StreamProgress>(x => ShowPercentage(ref oldValue, x.Percentage));

                await FileStreamReader.ReadBytesAsync(filePath, bufferSize * 1024, progress, CancellationToken.None);

                sw.Stop();

                Console.WriteLine($"Complete {bufferSize}KiB {sw.Elapsed.TotalSeconds:f3}sec");
            }
        }
        public void GetReaderSuccessTest()
        {
            //Arrange
            IFileStreamReader fileStreamReader = new FileStreamReader();
            string            filePath         = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestFiles\\DummyFile.txt");
            FileInfo          fileInfo         = new FileInfo(filePath);

            //Act
            var streamReader = fileStreamReader.GetReader(fileInfo);

            //Assert
            Assert.IsTrue(streamReader is StreamReader);
        }
示例#4
0
        public async void TestCustomFileStreamAdapter()
        {
            string path = Fixtures.IncrementingUint32_4;

            using (var file = FileStreamReader.ReadFile(path))
            {
                var pipe = file.Reader;

                int  counter = -1;
                long sum     = 0;

                var        readResults = new List <(bool Canceled, bool Completed)>();
                ReadResult result;
                do
                {
                    result = await pipe.ReadAsync();

                    readResults.Add((result.IsCanceled, result.IsCompleted));

                    this.output.WriteLine("Buffer length: " + result.Buffer.Length);

                    Check(result.Buffer);
                    pipe.AdvanceTo(result.Buffer.End);
                } while (!result.IsCompleted);

                Assert.Equal(1_048_575, counter);
                Assert.Equal(549_755_289_600L, sum);

                // check read results. All should be false except for the last completed
                Assert.True(readResults.SkipLast(1).All(x => x.Completed == false && x.Canceled == false));
                var last = readResults.Last();
                Assert.True(last.Completed == true && last.Canceled == false);


                void Check(ReadOnlySequence <byte> buffer)
                {
                    var reader = new SequenceReader <byte>(buffer);

                    while (!reader.End)
                    {
                        counter++;
                        Assert.True(reader.TryReadLittleEndian(out int value));
                        Assert.Equal(counter, value);
                        sum += value;
                    }

                    this.output.WriteLine($"{counter} values checked");
                }
            }
        }
示例#5
0
 public void StartVirtualHardwareAction()
 {
     if (!isBadFilename)
     {
         FileStreamReader myreader = new FileStreamReader(filename);
         logStreamOutput.DebugLog += "Port Number is " + portModel.PortNumber;
         portModel.IsEditable      = false;
         appserver = new NetworkAccess(portModel.PortNumber);
         appserver.NetworkStatus += listenNetworkStatus;
         appserver.ServerStatus  += listenServerStatus;
         Thread spawn = new Thread(new ThreadStart(appserver.StartServer));
         spawn.Start();
     }
     else
     {
         logStreamOutput.DebugLog = BadFileNameErrorMsg;
     }
 }
示例#6
0
        public async Task <ulong> PipelineAdapter()
        {
            ulong last = 0;

            using (var reader = FileStreamReader.ReadFile(File, BufferSize, FileOptions))
            {
                var        filePipeline = reader.Reader;
                ReadResult result       = default;
                while (!result.IsCompleted)
                {
                    result = await filePipeline.ReadAsync();

                    ParseLastNumber(result.Buffer, ref last);
                    filePipeline.AdvanceTo(result.Buffer.End);
                }

                return(last);
            }
        }
示例#7
0
        private Action ReadCompressedFileAction(string filePath)
        {
            return(() =>
            {
                using (var source = _io.FileOpenRead(filePath))
                {
                    int currentId = 0;

                    var reader = new FileStreamReader(source);
                    var readBytes = new MemoryStream();
                    var currByte = reader.GetNextByte();
                    if (currByte != 31)
                    {
                        throw new InvalidOperationException("not GZIP file!");
                    }
                    readBytes.WriteByte(currByte);
                    currByte = reader.GetNextByte();
                    if (currByte != 139)
                    {
                        throw new InvalidOperationException("not GZIP file!");
                    }
                    readBytes.WriteByte(currByte);

                    var gzipHeaderBytesRead = 0;
                    try
                    {
                        while (true)
                        {
                            currByte = reader.GetNextByte();
                            if (IsGzipHeaderCandidate(currByte, gzipHeaderBytesRead))
                            {
                                gzipHeaderBytesRead++;
                            }
                            else
                            {
                                if (gzipHeaderBytesRead > 0)
                                {
                                    WritePartGZipHeader(gzipHeaderBytesRead, readBytes);
                                    gzipHeaderBytesRead = 0;
                                }
                            }
                            if (IsCompleteGzipHeader(gzipHeaderBytesRead))
                            {
                                // full header read - push decompress task
                                _producerConsumer.Push(new ByteChunk
                                {
                                    Id = currentId++,
                                    Data = readBytes.ToArray()
                                });
                                readBytes = new MemoryStream();
                                WritePartGZipHeader(gzipHeaderBytesRead, readBytes);
                                gzipHeaderBytesRead = 0;
                            }
                            else
                            {
                                if (gzipHeaderBytesRead == 0)
                                {
                                    readBytes.WriteByte(currByte);
                                }
                            }
                        }
                    }
                    catch (FileEndException)
                    {
                        // just EoF - push the last decompress task
                        _producerConsumer.Push(new ByteChunk
                        {
                            Id = currentId++,
                            Data = readBytes.ToArray()
                        });
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    _producerConsumer.Stop();

                    _finishPc.Push(new ByteChunk {
                        Id = currentId
                    });
                }
            });
        }
示例#8
0
        public List <DataSetWebService> parseDateSet(String fileName)
        {
            dataSet = new List <DataSetWebService>();
            int count = 0;

            StreamReader FileStreamReader;

            FileStreamReader = File.OpenText(fileName);

            while (FileStreamReader.Peek() != -1)
            {
                String line = FileStreamReader.ReadLine();
                if (line.StartsWith("#"))
                {
                    continue;
                }

                string[] words = line.Split(',');

                if (words.Length > 10)
                {
                    count++;
                    DataSetWebService dsWebService = new DataSetWebService();

                    dsWebService.ResponseTime   = double.Parse(words[0]);
                    dsWebService.Availability   = double.Parse(words[1]);
                    dsWebService.Throughput     = double.Parse(words[2]);
                    dsWebService.Successability = double.Parse(words[3]);
                    dsWebService.Reliability    = double.Parse(words[4]);
                    dsWebService.Compliance     = double.Parse(words[5]);
                    dsWebService.BestPractices  = double.Parse(words[6]);
                    dsWebService.Latency        = double.Parse(words[7]);
                    dsWebService.Documentation  = double.Parse(words[8]);
                    dsWebService.ServiceName    = words[9];
                    dsWebService.WSDLAddress    = words[10];

                    if (dsWebService.ResponseTime > max[0])
                    {
                        max[0] = dsWebService.ResponseTime;
                    }
                    if (dsWebService.ResponseTime < min[0])
                    {
                        min[0] = dsWebService.ResponseTime;
                    }
                    if (dsWebService.Availability > max[1])
                    {
                        max[1] = dsWebService.Availability;
                    }
                    if (dsWebService.Availability < min[1])
                    {
                        min[1] = dsWebService.Availability;
                    }
                    if (dsWebService.Throughput > max[2])
                    {
                        max[2] = dsWebService.Throughput;
                    }
                    if (dsWebService.Throughput < min[2])
                    {
                        min[2] = dsWebService.Throughput;
                    }
                    if (dsWebService.Successability > max[3])
                    {
                        max[3] = dsWebService.Successability;
                    }
                    if (dsWebService.Successability < min[3])
                    {
                        min[3] = dsWebService.Successability;
                    }
                    if (dsWebService.Reliability > max[4])
                    {
                        max[4] = dsWebService.Reliability;
                    }
                    if (dsWebService.Reliability < min[4])
                    {
                        min[4] = dsWebService.Reliability;
                    }
                    if (dsWebService.Compliance > max[5])
                    {
                        max[5] = dsWebService.Compliance;
                    }
                    if (dsWebService.Compliance < min[5])
                    {
                        min[5] = dsWebService.Compliance;
                    }
                    if (dsWebService.BestPractices > max[6])
                    {
                        max[6] = dsWebService.BestPractices;
                    }
                    if (dsWebService.BestPractices < min[6])
                    {
                        min[6] = dsWebService.BestPractices;
                    }
                    if (dsWebService.Latency > max[7])
                    {
                        max[7] = dsWebService.Latency;
                    }
                    if (dsWebService.Latency < min[7])
                    {
                        min[7] = dsWebService.Latency;
                    }
                    if (dsWebService.Documentation > max[8])
                    {
                        max[8] = dsWebService.Documentation;
                    }
                    if (dsWebService.Documentation < min[8])
                    {
                        min[8] = dsWebService.Documentation;
                    }

                    dataSet.Add(dsWebService);
                }
            }

            Environment.outputLog.AppendText("Parsed " + count + " Web Services from file " + fileName + "\n");

            FileStreamReader.Close();
            return(getAllWebServicesWithQoS());
        }