Exemplo n.º 1
0
        public HttpHeaderValues Write(AssetPath path)
        {
            var files = _writer.Write(path);
            var etag  = _eTagGenerator.Create(files);

            _cache.LinkFilesToResource(path.ResourceHash, files);

            return(HttpHeaderValues.ForETag(etag));
        }
Exemplo n.º 2
0
        public void Write(AssetPath path)
        {
            //_output.AppendHeader(HttpResponseHeader.ETag, "random");

            if (!_writer.Write(path, files => processAssetFiles(path, files)))
            {
                _output.Write("Cannot find asset " + path.ToFullName());
                _output.WriteResponseCode(HttpStatusCode.NotFound);
            }
        }
Exemplo n.º 3
0
        public void DoTransform(string content)
        {
            content = content.Trim();
            if (string.IsNullOrEmpty(content))
            {
                return;
            }

            var result = _transformService.Transform(content);

            _contentWriter.Write(result);
            _transformCount++;
        }
        public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context)
        {
            HttpResponse response = context.HttpContext.Response;

            IContentWriter writer = _writers[response.ContentType];

            (bool success, byte[] data) = await writer.Write(context.Object);

            if (success && data != null)
            {
                await response.Body.WriteAsync(data, 0, data.Length);
            }
        }
Exemplo n.º 5
0
 protected override void ProcessRecord()
 {
     foreach (string path in Path)
     {
         using (IContentWriter writer = InvokeProvider.Content.GetWriter(path).Single())
         {
             IList items = writer.Write(Value);
             // Need to close writer before disposing it otherwise Microsoft's
             // FileSystemProvider throws an exception.
             writer.Close();
         }
     }
 }
Exemplo n.º 6
0
        public void Write(AssetPath path)
        {
            var files = _writer.Write(path);

            if (files.Any())
            {
                processAssetFiles(path, files);
            }
            else
            {
                _output.WriteResponseCode(HttpStatusCode.NotFound);
                _output.Write("Cannot find asset " + path.ToFullName());
            }
        }
        public async Task TestRoundTrip()
        {
            (bool didWrite, byte[] writeData) = await _writer.Write(ExampleProto.Input);

            Assert.IsTrue(didWrite);
            Assert.IsTrue(writeData != null && writeData.Length != 0);

            using MemoryStream ms = new MemoryStream(writeData);

            (bool didRead, IMessage readMessage) = await _reader.Read(typeof(ExampleProto), ms);

            Assert.IsTrue(didRead);
            Assert.IsNotNull(readMessage);
            Assert.AreEqual(ExampleProto.Input, readMessage);
        }
        public void TestGetContentWriter()
        {
            FileSystemProvider fileSystemProvider = new FileSystemProvider();
            ProviderInfo       providerInfoToSet  = GetProvider();

            fileSystemProvider.SetProviderInformation(providerInfoToSet);
            fileSystemProvider.Context = new CmdletProviderContext(GetExecutionContext());

            IContentWriter contentWriter = fileSystemProvider.GetContentWriter(testPath);

            contentWriter.Write(new List <string>()
            {
                "contentWriterTestContent"
            });
            contentWriter.Close();
            Assert.Equal(File.ReadAllText(testPath), testContent + @"contentWriterTestContent" + System.Environment.NewLine);
        }
Exemplo n.º 9
0
        public void Process(string inputFilePath, string outputFilePath)
        {
            using var inputDictionary = new BlockingDictionary <int, byte[]>(
                      _settings.InputBufferSize,
                      new SortedDictionary <int, byte[]>(new Dictionary <int, byte[]>(_settings.InputBufferSize)));
            using var outputDictionary = new BlockingDictionary <int, byte[]>(
                      _settings.OutputBufferSize,
                      new Dictionary <int, byte[]>(_settings.OutputBufferSize));
            var workerThreads = new List <Thread>();

            _logger.Write($"Start processing with parallelism level {_settings.ParallelismLevel}");

            using var binaryReader = _fileService.GetReader(inputFilePath);
            var readerThread = new Thread(() => _reader.Read(inputDictionary, binaryReader));

            workerThreads.AddRange(
                Enumerable.Range(0, _settings.ParallelismLevel)
                .Select(_ => new Thread(() => _processor.ProcessChunks(inputDictionary, outputDictionary))));

            using var binaryWriter = _fileService.GetWriter(outputFilePath);
            var writerThread = new Thread(() => _writer.Write(outputDictionary, binaryWriter));

            readerThread.Start();
            foreach (var thread in workerThreads)
            {
                thread.Start();
            }
            writerThread.Start();
            readerThread.Join();
            inputDictionary.Close();

            foreach (var thread in workerThreads)
            {
                thread.Join();
            }

            outputDictionary.Close();
            writerThread.Join();
        }
Exemplo n.º 10
0
 public void Write(string content)
 {
     Clipboard.SetText(content);
     _contentWriter.Write(content);
 }