protected override void ProcessRecord() { var readers = InvokeProvider.Content.GetReader(InternalPaths, ProviderRuntime); foreach (var curContentReader in readers) { contentReader = curContentReader; try { if (Tail > 0) { WriteLastItemsToPipeline(); } else { WriteItemsToPipeline(); } WritePendingItems(); } finally { contentReader.Close(); } } }
public void AddReader(IContentReader reader) { foreach (var contentType in reader.ContentTypes) { readers.Add(contentType, reader); } }
private static void FromContentReader(IContentReader reader, Stream stream, UTF8Encoding binaryEncoding) { for (IList item = reader.Read(32768); item != null && item.Count > 0; item = reader.Read(32768)) { WriteContent(item, stream, binaryEncoding); } }
public GameScreen(Tanks tanksGame, IMapReader mapReader, IContentReader contentReader) { _tanksGame = tanksGame; _mapReader = mapReader; _contentReader = contentReader; map = _mapReader.ReadMapForLevel(1); }
// TODO: #DynamicParameter support protected override void ProcessRecord() { var readers = InvokeProvider.Content.GetReader(InternalPaths, ProviderRuntime); foreach (var curContentReader in readers) { contentReader = curContentReader; try { if (Tail > 0) { WriteLastItemsToPipeline(); } else { WriteItemsToPipeline(); } WritePendingItems(); } finally { contentReader.Close(); } } }
public override async Task <InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context) { HttpRequest request = context.HttpContext.Request; IContentReader reader = _readers[request.ContentType]; (bool success, IMessage msg) = await reader.Read(context.ModelType, request.Body); return(success ? await InputFormatterResult.SuccessAsync(msg) : await InputFormatterResult.FailureAsync()); }
public HTTPSourceConnection( PeerCast peercast, Channel channel, Uri source_uri, IContentReader content_reader, bool use_content_bitrate) : base(peercast, channel, source_uri) { contentReader = content_reader; contentSink = new BufferedContentSink(new AsynchronousContentSink(new ChannelContentSink(channel, use_content_bitrate))); }
public HTTPSourceConnection( PeerCast peercast, Channel channel, Uri source_uri, IContentReader content_reader, bool use_content_bitrate) : base(peercast, channel, source_uri) { contentReader = content_reader; useContentBitrate = use_content_bitrate; }
public static void LoadContent(ContentDescription contentDescription) { if (contentDescription.Stream != null) { IContentReader contentReader = GetContentReader(contentDescription.TypeName); ContentStream stream = PrepareContentStream(contentDescription); contentDescription.Content = contentReader.Read(stream, contentDescription.Content); return; } throw new InvalidOperationException("Cannot load manually added content item. Item must have been disposed and accessed again."); }
public ContentWriter(ITableStorage tableStorage, ILinkReader linkReader, IContentReader contentReader, IDataUpdater dataUpdater) { _contentReader = contentReader; _linkReader = linkReader; _dataUpdater = dataUpdater; _linkTable = tableStorage.TableClient.GetTableReference(Constants.LINKS_TABLE); _linkTable.CreateIfNotExistsAsync(); _contentTable = tableStorage.TableClient.GetTableReference(Constants.CONTENT_TABLE); _contentTable.CreateIfNotExistsAsync(); }
/// <inheritdoc /> public bool AddContentReader(Type type, IContentReader reader) { lock (_registeredContentReaders) { if (_registeredContentReaders.ContainsKey(type)) { return(false); } _registeredContentReaders.Add(type, reader); } return(true); }
public SmartText(Configuration configuration) { Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _ = Configuration.ContentReader ?? throw new ArgumentNullException(nameof(Configuration.ContentReader)); _contentReader = Configuration.ContentReader; if (Configuration.AutoLoadFile) { LoadContent(); } }
/// <summary> /// Gets the content reader for the item at the specified path. /// </summary> /// <param name="providerInstance"> /// The provider instance to use. /// </param> /// <param name="path"> /// The path to the item if it was specified on the command line. /// </param> /// <param name="context"> /// The context which the core command is running. /// </param> /// <exception cref="NotSupportedException"> /// If the <paramref name="providerInstance"/> does not support this operation. /// </exception> /// <exception cref="PipelineStoppedException"> /// If the pipeline is being stopped while executing the command. /// </exception> /// <exception cref="ProviderInvocationException"> /// If the provider threw an exception. /// </exception> private IContentReader GetContentReaderPrivate( CmdletProvider providerInstance, string path, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( path != null, "Caller should validate path before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); IContentReader result = null; try { result = providerInstance.GetContentReader(path, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { throw NewProviderInvocationException( "GetContentReaderProviderException", SessionStateStrings.GetContentReaderProviderException, providerInstance.ProviderInfo, path, e); } return(result); }
public T ProcessContent(IContentReader reader) { T result; using (var stream = reader.OpenStream()) using (var streamReader = new StreamReader(stream, Encoding.UTF8)) { var serializer = new XmlSerializer(typeof(T)); result = (T)serializer.Deserialize(streamReader); } return(result); }
public void TestGetContentReader() { FileSystemProvider fileSystemProvider = new FileSystemProvider(); ProviderInfo providerInfoToSet = GetProvider(); fileSystemProvider.SetProviderInformation(providerInfoToSet); fileSystemProvider.Context = new CmdletProviderContext(GetExecutionContext()); IContentReader contentReader = fileSystemProvider.GetContentReader(testPath); Assert.Equal(contentReader.Read(1)[0], testContent); contentReader.Close(); }
internal ContentHolder(PathInfo pathInfo, IContentReader reader, IContentWriter writer) { if (pathInfo != null) { this._pathInfo = pathInfo; this._reader = reader; this._writer = writer; return; } else { throw PSTraceSource.NewArgumentNullException("pathInfo"); } }
internal ContentHolder( PathInfo pathInfo, IContentReader reader, IContentWriter writer) { if (pathInfo == null) { throw PSTraceSource.NewArgumentNullException("pathInfo"); } PathInfo = pathInfo; Reader = reader; Writer = writer; }
public void Valid_cmd_configuration_for_node() { string json = @"{""CsAddress"": ""192.168.0.1"",""CsPort"": 5050}"; IContentReader contentReader = A.Fake <IContentReader>(); A.CallTo(() => contentReader.Read("test")).Returns(json); IConfigurationProvider confProvider = new ConfigurationProvider(contentReader); var result = confProvider.LoadConfiguration <TestNodeConfiguration>("test"); result.CsAddress.ShouldBe("192.168.0.1"); result.CsPort.ShouldBe(5050); }
static public void ProcessNames(string sFilePath) { IKernel kernel = new StandardKernel(); kernel.Load(Assembly.GetExecutingAssembly()); IContentReader provider = kernel.Get <IContentReader>(); string sFilepath = sFilePath; DataConsumer consumer = new DataSortingConsumer(provider) { path = sFilepath }; consumer.Process(); }
public T ProcessContentForEnvironment(IContentReader reader, string environment) { var baseContent = reader.ReadContent(); var envContent = reader.ReadContent(environment); var stringReader = new StringReader(string.Join("", baseContent, envContent)); var parser = new MergingParser(new Parser(stringReader)); var deserializer = new DeserializerBuilder() .WithNamingConvention(new CamelCaseNamingConvention()) .Build(); return(deserializer.Deserialize <T>(parser)); }
public GzipProcessor( IFileService fileService, ILogger logger, IContentReader reader, IContentWriter writer, IChunkProcessor processor, Settings settings) { _fileService = fileService; _logger = logger; _reader = reader; _writer = writer; _processor = processor; _settings = settings; }
public void Valid_cmd_configuration_for_server_without_bakcup() { string json = @"{""ListeningPortNumber"": 5050,""CommunicationsTimeout"": 50}"; IContentReader contentReader = A.Fake <IContentReader>(); A.CallTo(() => contentReader.Read("test")).Returns(json); IConfigurationProvider confProvider = new ConfigurationProvider(contentReader); var result = confProvider.LoadConfiguration <TestServerConfiguration>("test"); result.ListeningPortNumber.ShouldBe(5050); result.IsBackup.ShouldBe(false); result.CommunicationsTimeout.ShouldBe(50); }
public T ProcessContent(IContentReader reader) { T result; using (var stream = reader.OpenStream()) using (var streamReader = new StreamReader(stream, Encoding.UTF8)) { var deserializer = new DeserializerBuilder() .WithNamingConvention(new CamelCaseNamingConvention()) .Build(); result = deserializer.Deserialize <T>(streamReader); } return(result); }
private bool SeekPositionForTail(IContentReader reader) { bool flag; FileSystemContentReaderWriter fileSystemContentReaderWriter = reader as FileSystemContentReaderWriter; try { fileSystemContentReaderWriter.SeekItemsBackward(this.Tail); flag = true; } catch (BackReaderEncodingNotSupportedException backReaderEncodingNotSupportedException) { fileSystemContentReaderWriter.Seek((long)0, SeekOrigin.Begin); flag = false; } return(flag); }
/// <summary> /// Seek position to the right place. /// </summary> /// <param name="reader"> /// reader should be able to be casted to FileSystemContentReader /// </param> /// <returns> /// true if the stream pointer is moved to the right place /// false if we cannot seek /// </returns> private bool SeekPositionForTail(IContentReader reader) { var fsReader = reader as FileSystemContentReaderWriter; Dbg.Diagnostics.Assert(fsReader != null, "Tail is only supported for FileSystemContentReaderWriter"); try { fsReader.SeekItemsBackward(Tail); return(true); } catch (BackReaderEncodingNotSupportedException) { // Move to the head fsReader.Seek(0, SeekOrigin.Begin); return(false); } }
public string ReadFile(FileTypes fileType, string path, bool isEncrypted = false, string role = null) { if (roleProvider != null && !roleProvider.HasAccess(path, role)) { throw new UnauthorizedAccessException(); } IContentReader reader = ContentReaderFactory.GetReader(fileType); string content = reader.ReadContent(path); if (isEncrypted && encryptionProvider != null) { content = encryptionProvider.Decrypt(content); } return(content); }
} // GetContentReader /// <summary> /// Gets the content reader for the specified item. /// </summary> /// <param name="paths"> /// The path(s) to the item(s) to get the content reader from. /// </param> /// <param name="context"> /// The context which the core command is running. /// </param> /// <returns> /// The content readers for all items that the path resolves to. /// </returns> /// <exception cref="ArgumentNullException"> /// If <paramref name="path"/> is null. /// </exception> /// <exception cref="ProviderNotFoundException"> /// If the <paramref name="path"/> refers to a provider that could not be found. /// </exception> /// <exception cref="DriveNotFoundException"> /// If the <paramref name="path"/> refers to a drive that could not be found. /// </exception> /// <exception cref="NotSupportedException"> /// If the provider that the <paramref name="path"/> refers to does /// not support this operation. /// </exception> /// <exception cref="ProviderInvocationException"> /// If the provider threw an exception. /// </exception> /// <exception cref="ItemNotFoundException"> /// If <paramref name="path"/> does not contain glob characters and /// could not be found. /// </exception> internal Collection <IContentReader> GetContentReader( string[] paths, CmdletProviderContext context) { if (paths == null) { throw PSTraceSource.NewArgumentNullException("paths"); } ProviderInfo provider = null; CmdletProvider providerInstance = null; Collection <IContentReader> results = new Collection <IContentReader>(); foreach (string path in paths) { if (path == null) { throw PSTraceSource.NewArgumentNullException("paths"); } Collection <string> providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( path, false, context, out provider, out providerInstance); foreach (string providerPath in providerPaths) { IContentReader reader = GetContentReaderPrivate(providerInstance, providerPath, context); if (reader != null) { results.Add(reader); } context.ThrowFirstErrorOrDoNothing(true); } } return(results); } // GetContentReader
private static void FromBinaryContentReader(IContentReader reader, Stream stream) { for (IList item = reader.Read(32768); item != null && item.Count > 0; item = reader.Read(32768)) { byte[] buffer; if (item is byte[]) { buffer = (byte[])item; } else if (item is IEnumerable <byte> ) { buffer = ((IEnumerable <byte>)item).ToArray(); } else { for (int i = 0; i < item.Count; i++) { if (item[i] is byte) { stream.WriteByte((byte)(item[i])); } else { UTF8Encoding binaryEncoding = new UTF8Encoding(false); if (i == 0) { WriteContent(item, stream, binaryEncoding); } else { WriteContent(item.Cast <object>().Skip(i).ToArray(), stream, binaryEncoding); } FromContentReader(reader, stream, binaryEncoding); return; } } continue; } if (buffer.Length > 0) { stream.Write(buffer, 0, buffer.Length); } } }
public static void ScanAssembliesForContentReaders() { foreach (Assembly item in TypeCache.LoadedAssemblies.Where((Assembly a) => !TypeCache.IsKnownSystemAssembly(a))) { if (!m_scannedAssemblies.Contains(item)) { foreach (TypeInfo definedType in item.DefinedTypes) { ContentReaderAttribute customAttribute = definedType.GetCustomAttribute <ContentReaderAttribute>(); if (customAttribute != null && !m_contentReadersByTypeName.ContainsKey(customAttribute.ContentTypeName)) { IContentReader value = (IContentReader)Activator.CreateInstance(definedType.AsType()); m_contentReadersByTypeName.Add(customAttribute.ContentTypeName, value); } } m_scannedAssemblies.Add(item); } } }
public static byte[] ReadContent(this IContentReader reader, long pos, int size) { var buffer = new byte[size]; var read = 0; int len; while ((len = reader.ReadContentInto(pos + read, buffer, read, size - read)) > 0) { read += len; if (read == size) { return(buffer); } } Array.Resize(ref buffer, read); return(buffer); }
public T ProcessContentForEnvironment(IContentReader reader, string environment) { JObject baseObject; JObject envObject; using (var stream = reader.OpenStream()) { baseObject = GetJObjectFromStream(stream); } using (var stream = reader.OpenStream(environment)) { envObject = GetJObjectFromStream(stream); } baseObject.Merge(envObject, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Union }); return(baseObject.ToObject <T>()); }
public void Valid_cmd_configuration_for_server_with_bakcup() { string json = @"{ ""ListeningPortNumber"": 5050, ""CommunicationsTimeout"": 50, ""IsBackup"": true, ""MasterServerListeningPortNumber"": 6060, ""MasterServerAddress"": ""192.456""}"; IContentReader contentReader = A.Fake <IContentReader>(); A.CallTo(() => contentReader.Read("test")).Returns(json); IConfigurationProvider confProvider = new ConfigurationProvider(contentReader); var result = confProvider.LoadConfiguration <TestServerConfiguration>("test"); result.ListeningPortNumber.ShouldBe(5050); result.IsBackup.ShouldBe(true); result.CommunicationsTimeout.ShouldBe(50); result.MasterServerAddress.ShouldBe("192.456"); result.MasterServerListeningPortNumber.ShouldBe(6060); }
void IContentManager.Register(IContentReader reader) { Contract.Requires<ArgumentNullException>(reader != null); }
public override ISourceStream Create(Channel channel, Uri source, IContentReader reader) { return new HTTPSourceStream(this.PeerCast, channel, source, reader); }
public HTTPSourceStream(PeerCast peercast, Channel channel, Uri source_uri, IContentReader reader) : base(peercast, channel, source_uri) { this.ContentReader = reader; }
//Dependency Injection interface for Ninject public DataSortingConsumer(IContentReader provider) { this.provider = provider; }
/// <summary> /// Seek position to the right place /// </summary> /// <param name="reader"> /// reader should be able to be casted to FileSystemContentReader /// </param> /// <returns> /// true if the stream pointer is moved to the right place /// false if we cannot seek /// </returns> private bool SeekPositionForTail(IContentReader reader) { var fsReader = reader as FileSystemContentReaderWriter; Dbg.Diagnostics.Assert(fsReader != null, "Tail is only supported for FileSystemContentReaderWriter"); try { fsReader.SeekItemsBackward(Tail); return true; } catch (BackReaderEncodingNotSupportedException) { // Move to the head fsReader.Seek(0, SeekOrigin.Begin); return false; } }
public ContentProvider(IContentReader contentReader, HtmlCleaner htmlCleaner) { _contentReader = contentReader; _htmlCleaner = htmlCleaner; }
public override ISourceStream Create(Channel channel, Uri source, IContentReader reader) { return new RTMPSourceStream(PeerCast, channel, source); }
public HTTPSourceConnection( PeerCast peercast, Channel channel, Uri source_uri, IContentReader content_reader) : base(peercast, channel, source_uri) { contentReader = content_reader; if (channel.ChannelInfo!=null && channel.ChannelInfo.Bitrate!=0) { useContentBitrate = false; } }
public virtual ISourceStream Create(Channel channel, Uri source, IContentReader reader) { throw new NotImplementedException(); }
public HTTPSourceStream(PeerCast peercast, Channel channel, Uri source_uri, IContentReader reader) : base(peercast, channel, source_uri) { this.ContentReader = reader; this.UseContentBitrate = channel.ChannelInfo==null || channel.ChannelInfo.Bitrate==0; }
internal ContentHolder( PathInfo pathInfo, IContentReader reader, IContentWriter writer) { if (pathInfo == null) { throw PSTraceSource.NewArgumentNullException("pathInfo"); } PathInfo = pathInfo; Reader = reader; Writer = writer; } // constructor
public HTTPPushSourceConnection(PeerCast peercast, Channel channel, Uri source_uri, IContentReader content_reader, bool use_content_bitrate) : base(peercast, channel, source_uri) { this.ContentReader = content_reader; this.contentSink = new BufferedContentSink(new ChannelContentSink(channel, use_content_bitrate)); }
private bool SeekPositionForTail(IContentReader reader) { bool flag; FileSystemContentReaderWriter fileSystemContentReaderWriter = reader as FileSystemContentReaderWriter; try { fileSystemContentReaderWriter.SeekItemsBackward(this.Tail); flag = true; } catch (BackReaderEncodingNotSupportedException backReaderEncodingNotSupportedException) { fileSystemContentReaderWriter.Seek((long)0, SeekOrigin.Begin); flag = false; } return flag; }