///<summary> /// Creates a contig parser that parses Contigs using the given encoding /// and alphabet, by creating an XsvSparseReader that uses the given separator /// and sequenceIdPrefix characters. ///</summary> ///<param name="encoding">Encoding to use for the consensus and assembled sequences that are parsed.</param> ///<param name="alphabet">Alphabet to use for the consensus and assembled sequences that are parsed.</param> ///<param name="separator_">Character used to separate sequence item position and symbol in the Xsv file</param> ///<param name="sequenceIdPrefix_">Character used at the beginning of the sequence start line.</param> public XsvContigParser(IEncoding encoding, IAlphabet alphabet, char separator_, char sequenceIdPrefix_) : base(encoding, alphabet) { separator = separator_; sequenceIdPrefix = sequenceIdPrefix_; }
/// <summary> /// Add a new content encoding handler /// </summary> /// <param name="encodingId">The Accept-Encoding header value</param> /// <param name="encoding">The encoding engine to decode the content</param> /// <returns>The client itself, to allow call chains</returns> public IRestClient AddEncoding(string encodingId, IEncoding encoding) { _encodingHandlers[encodingId] = encoding; _acceptEncodings.Add(encodingId); UpdateAcceptsEncodingHeader(); return(this); }
public EncodingThatDetectsTypeFromTheHeader(IHeaderReader headerReader, IEncoding permutativeEncoding, IEncoding cyclicEncoding, IEncoding noEncoding) { this.headerReader = headerReader; this.permutativeEncoding = permutativeEncoding; this.cyclicEncoding = cyclicEncoding; this.noEncoding = noEncoding; }
/// <summary> /// Creates new instance of <see cref="JsonFileConfigurationLoader"/>. /// </summary> /// <param name="file">Enables file system access.</param> /// <param name="tokenConverter">Json token converter.</param> /// <param name="filePaths">Json file paths. The first file is considered the main file, the others act as overrides.</param> /// <param name="encoding">Encoding to be used for reading json file.</param> /// <param name="jsonSerializerSettingsProvider">Provides <see cref="JsonSerializerSettings"/> for deserialization of file content to <see cref="JToken"/>.</param> /// <param name="jsonConfigurationProviderFactory">A factory for creation of <see cref="IConfigurationProvider{TRawDataIn,TRawDataOut}"/>.</param> public JsonFileConfigurationLoader(IFile file, IJsonTokenConverter tokenConverter, string[] filePaths, IEncoding encoding = null, Func <JsonSerializerSettings> jsonSerializerSettingsProvider = null, Func <JToken[], IJsonTokenConverter, IConfigurationProvider <JToken, JToken> > jsonConfigurationProviderFactory = null) { if (file == null) { throw new ArgumentNullException(nameof(file)); } if (filePaths == null) { throw new ArgumentNullException(nameof(filePaths)); } if (tokenConverter == null) { throw new ArgumentNullException(nameof(tokenConverter)); } if (filePaths.Any(path => String.IsNullOrWhiteSpace(path))) { throw new ArgumentException("At least one of the configuration file path is empty.", nameof(filePaths)); } _file = file; _filePaths = filePaths; _tokenConverter = tokenConverter; _jsonSerializerSettingsProvider = jsonSerializerSettingsProvider; _encoding = encoding ?? new UTF8Encoding(false, true).ToInterface(); _jsonConfigurationProviderFactory = jsonConfigurationProviderFactory ?? ((tokens, converter) => new JsonFileConfigurationProvider(tokens, converter)); }
private void PruneMultiObjectiveOperators(IEncoding encoding) { if (encoding.Operators.Any(x => x is IMultiObjectiveOperator && !(x is ISingleObjectiveOperator))) { encoding.Operators = encoding.Operators.Where(x => !(x is IMultiObjectiveOperator) || x is ISingleObjectiveOperator).ToList(); } }
public async Task Invoke(IDictionary <string, object> environment) { IEncoding compression = SelectCompression(environment); if (compression == null) { await _next(environment); return; } ICompressedStorage storage = GetStorage(environment); if (storage == null) { await _next(environment); return; } var context = new StaticCompressionContext(environment, _options, compression, storage); context.Attach(); try { await _next(environment); await context.Complete(); } catch (Exception) { context.Detach(); throw; } }
private IEncoding SelectCompression(IDictionary <string, object> environment) { var request = new OwinRequest(environment); var bestAccept = new Accept { Encoding = "identity", Quality = 0 }; IEncoding bestEncoding = null; IList <string> acceptEncoding = request.Headers.GetValues("accept-encoding"); if (acceptEncoding != null) { foreach (var segment in acceptEncoding) { Accept accept = Parse(segment); if (accept.Quality == 0 || accept.Quality < bestAccept.Quality) { continue; } IEncoding compression = _options.EncodingProvider.GetCompression(accept.Encoding); if (compression == null) { continue; } bestAccept = accept; bestEncoding = compression; if (accept.Quality == 1000) { break; } } } return(bestEncoding); }
public override bool RemoveEncoding(IEncoding encoding) { var success = base.RemoveEncoding(encoding); encoding.SolutionCreatorChanged -= Encoding_SolutionCreatorChanged; return(success); }
/// <summary> /// Looks up the default encoding map for a known encoding to the /// default alphabet for that encoding. Several alphabets may exist /// for any one particular encoding. If you want to select a particular /// alphabet, consider using the GetMapToAlphabet() method. /// </summary> public static EncodingMap GetDefaultMap(IEncoding encoding) { if (encoding == Encodings.IupacNA) { return(IupacNAToDna); } else if (encoding == Encodings.Ncbi4NA) { return(Ncbi4NAToDna); } else if (encoding == Encodings.Ncbi2NA) { return(Ncbi2NAToDna); } else if (encoding == Encodings.NcbiStdAA) { return(NcbiStdAAToProtein); } else if (encoding == Encodings.NcbiEAA) { return(NcbiEAAToProtein); } Trace.Report(Resource.ParameterContainsNullValue); throw new ArgumentNullException(Resource.ParameterNameEncoding); }
public override void AddEncoding(IEncoding encoding) { base.AddEncoding(encoding); var parameter = GetParameter(encoding); parameter.Value = encoding.SolutionCreator; encoding.SolutionCreatorChanged += Encoding_SolutionCreatorChanged; }
public void SetEncodingFilter(EncodingType encodingType, IEncoding encoding) { if (encodingType != null && encoding != null && !"*".Equals(encodingType.Name, StringComparison.Ordinal)) { this.OutputStream = encoding.Encode(encodingType, this.OutputStream); this.Headers["Content-Encoding"] = encodingType.Name; } }
/// <summary> /// Creates a sequence encoder by defining the encoding to use. /// </summary> public SequenceEncoder(IEncoding encoding) { if (encoding == null) { throw new ArgumentException("The encoding paramater can not be null"); } this.encoding = encoding; }
protected IConstrainedValueParameter <T> GetParameter(IEncoding encoding) { if (!Parameters.ContainsKey(encoding.Name)) { throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name)); } return((IConstrainedValueParameter <T>)Parameters[encoding.Name]); }
public virtual bool RemoveEncoding(IEncoding encoding) { if (!encodings.Remove(encoding)) { throw new ArgumentException(string.Format("Encoding {0} was not added to the MultiEncoding.", encoding.Name)); } encoding.OperatorsChanged -= Encoding_OperatorsChanged; return(Parameters.Remove(encoding.Name)); }
/// <summary> /// Constructor for deserialization. /// </summary> /// <param name="info">Serialization Info.</param> /// <param name="context">Streaming context.</param> protected SequenceEncoder(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } encoding = Encodings.All.Single(E => E.Name.Equals(info.GetString("SequenceEncoder:EncodingName"))); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <param name="other">An object to compare with this object.</param> /// <returns>True if the current object is equal to the other parameter, otherwise false.</returns> public virtual bool Equals(IEncoding other) { if ((object)other != null) { return this.GetType().Equals(other.GetType()); } return false; }
public static byte[] Encode <T>(this IEncoding <T> encoding, T value) { using (MemoryStream stream = new MemoryStream()) { using (IBitWriter suitableBitWriter = stream.CreateSuitableBitWriter()) encoding.Encode(value, suitableBitWriter); return(stream.ToArray()); } }
public StaticCompressionContext(IDictionary <string, object> environment, StaticCompressionOptions options, IEncoding encoding, ICompressedStorage storage) { _environment = environment; _options = options; _encoding = encoding; _encodingSuffix = "^" + _encoding.Name; _encodingSuffixQuote = "^" + _encoding.Name + "\""; _storage = storage; _request = new OwinRequest(environment); _response = new OwinResponse(environment); }
public StaticCompressionContext(IDictionary<string, object> environment, StaticCompressionOptions options, IEncoding encoding, ICompressedStorage storage) { _environment = environment; _options = options; _encoding = encoding; _encodingSuffix = "^" + _encoding.Name; _encodingSuffixQuote = "^" + _encoding.Name + "\""; _storage = storage; _request = new OwinRequest(environment); _response = new OwinResponse(environment); }
/// <summary> /// Initializes a new instance of the <see cref="GrammarImpl"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <param name="ambiguityDegree">The ambiguity degree.</param> /// <param name="lookAhead">The look-ahead.</param> /// <param name="encoding">The encoding.</param> /// <param name="definition">The definition.</param> public GrammarImpl(string name, GrammarType type, int? ambiguityDegree, int? lookAhead, IEncoding encoding, IGrammarDefinition definition) : base(name, type, ambiguityDegree, lookAhead, encoding) { #region Contract Contract.Requires<ArgumentNullException>(name != null); Contract.Requires<InvalidEnumArgumentException>(Enum.IsDefined(typeof(GrammarType), type)); Contract.Requires<ArgumentNullException>(encoding != null); #endregion this.definition = definition; }
public static string ToHexString <T>(T obj, IEncoding <T> encoding) { using (OrientedBitStream inMemoryBitStream = CreateSuitableInMemoryBitStream()) { IBitWriter suitableBitWriter = inMemoryBitStream.CreateSuitableBitWriter(); encoding.Encode(obj, suitableBitWriter); inMemoryBitStream.Position = 0L; byte[] numArray = new byte[inMemoryBitStream.Length / 8L]; inMemoryBitStream.Read(numArray, 0, numArray.Length); return(numArray.ToHexString()); } }
private void CreateListViewItem(IEncoding enc) { encodingsListView.SmallImageList.Images.Add(enc.ItemImage); var item = new ListViewItem() { ImageIndex = encodingsListView.SmallImageList.Images.Count - 1, Text = enc.Name }; item.SubItems.Add(new ListViewItem.ListViewSubItem() { Text = enc.GetType().Name }); encodingsListView.Items.Add(item); }
public bool Remove(IEncoding encoding) { var success = encodings.Remove(encoding); Parameters.RemoveRange(encoding.Parameters); foreach (var @operator in Operators.OfType <IMultiEncodingOperator>()) { @operator.RemoveEncoding(encoding); } OnEncodingsChanged(); return(success); }
public SingleEncodingIndividual(IEncoding encoding, IScope scope) : base(encoding, scope) { if (encoding is MultiEncoding) { throw new ArgumentException("A MultiEncoding must not be used for the creation of a SingleEncodingIndividual"); } if (!scope.Variables.ContainsKey(encoding.Name)) { throw new ArgumentException("The provided scope does not contain an individual."); } }
/// <summary> /// Creates new ByteArray instance from the specified encoding which can store /// specified size of encoded values. /// ByteArray compacts and stores the byte values depending on the specified encoding. /// /// For example: Ncbi2NAEncoding contains four values, In this case two bits are sufficient /// to store index of an encoded value thus four encoded values can be stored in to a byte. /// /// Note that data will be compressed when the total number of encoded values present in the /// specified IEncoding is less than or equal to 16, otherwise it stores specified encoded values /// in the byte array. /// </summary> /// <param name="encoding">Encoding to which the specified values are belongs to.</param> /// <param name="size">Required size of ByteArray.</param> public ByteArray(IEncoding encoding, int size) { if (size < 0) { throw new ArgumentException(Resource.ParameterMustNonNegative, Resource.ParameterNameSize); } Count = size; // initialize fields from specified encoding. SetEncoding(encoding); }
/// <summary> /// Creates new ByteArray instance from the specified encoding and list of byte values. /// ByteArray compacts and stores the byte values depending on the specified encoding. /// /// For example: Ncbi2NAEncoding contains four values, In this case two bits are sufficient /// to store index of an encoded value thus four encoded values can be stored in to a byte. /// /// Note that data will be compressed when the total number of encoded values present in the /// specified IEncoding is less than or equal to 16, otherwise it stores specified encoded values /// in the byte array. /// </summary> /// <param name="encoding">Encoding to which the specified values are belongs to.</param> /// <param name="values">Encoded values.</param> public ByteArray(IEncoding encoding, IList <byte> values) { Count = (values == null ? 0 : values.Count); // initialize fields from specified encoding. SetEncoding(encoding); for (int i = 0; i < Count; i++) { SetByteValue(i, values[i]); } }
/// <summary> /// Looks amongst all the known encoding maps for one that provides a mapping /// from the encoding passed in as a parameter to the alphabet passed in as a /// parameter. /// </summary> /// <returns>The known encoding map, or null if one is not available</returns> public static EncodingMap GetMapToAlphabet(IEncoding encoding, IAlphabet alphabet) { foreach (EncodingMap map in encMaps) { if (map.Alphabet == alphabet && map.Encoding == encoding) { return(map); } } return(null); }
public void SetEncodingFilter(EncodingType encodingType, IEncoding encoding) { if (encodingType != null && encoding != null) { string contentEncoding = encoding.ContentEncoding(encodingType); if (!"*".Equals(contentEncoding, StringComparison.Ordinal)) { this.Headers["Content-Encoding"] = contentEncoding; this.httpResponse.Filter = encoding.Encode(encodingType, this.httpResponse.Filter); } } }
public virtual void AddEncoding(IEncoding encoding) { if (Parameters.ContainsKey(encoding.Name)) { throw new ArgumentException(string.Format("Encoding {0} was already added.", encoding.Name)); } encodings.Add(encoding); encoding.OperatorsChanged += Encoding_OperatorsChanged; var param = new ConstrainedValueParameter <T>(encoding.Name, new ItemSet <T>(encoding.Operators.OfType <T>())); param.Value = param.ValidValues.First(); Parameters.Add(param); }
private void PruneMultiObjectiveOperators(IEncoding encoding) { if (encoding.Operators.Any(x => x is IMultiObjectiveOperator && !(x is ISingleObjectiveOperator))) { encoding.Operators = encoding.Operators.Where(x => !(x is IMultiObjectiveOperator) || x is ISingleObjectiveOperator).ToList(); } foreach (var multiOp in Encoding.Operators.OfType <IMultiOperator>()) { foreach (var moOp in multiOp.Operators.Where(x => x is IMultiObjectiveOperator).ToList()) { multiOp.RemoveOperator(moOp); } } }
/// <summary> /// Validate parser using specified encoding /// </summary> /// <param name="nodeName">xml node name</param> /// <param name="encoding">encoding instance</param> void ValidateSAMParserWithEncoding(string nodeName, IEncoding encoding) { // Gets the expected sequence from the Xml string filePath = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.FilePathNode); string expectedSequenceFile = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); // Create parser using encoding ISequenceAlignmentParser parser = new SAMParser(encoding); try { IList <ISequenceAlignment> alignments = parser.Parse(filePath); // Get expected sequences using (FastaParser parserObj = new FastaParser()) { IList <ISequence> expectedSequences = parserObj.Parse(expectedSequenceFile); // Validate parsed output with expected output int count = 0; for (int index = 0; index < alignments.Count; index++) { for (int ialigned = 0; ialigned < alignments[index].AlignedSequences.Count; ialigned++) { for (int iseq = 0; iseq < alignments[index].AlignedSequences[ialigned].Sequences.Count; iseq++) { Assert.AreEqual(expectedSequences[count].ToString(), alignments[index].AlignedSequences[ialigned].Sequences[iseq].ToString()); count++; } } } } } finally { (parser as SAMParser).Dispose(); } }
// Does a direct symbol comparison to create the dictionary used in the mapping // This is a useful starting point for any map. The dictionary can then be customized // by adding or removing entries. internal static EncodingMap CreateBasicMap(IAlphabet alphabet, IEncoding encoding, EncodingMapDirection direction) { EncodingMap result = new EncodingMap(alphabet, encoding, direction); if (direction == EncodingMapDirection.AlphabetToEncoding) { result.map = GetMap( alphabet, item => encoding.LookupBySymbol(item.Symbol)); } else if (direction == EncodingMapDirection.EncodingToAlphabet) { result.map = GetMap( encoding, item => alphabet.LookupBySymbol(item.Symbol)); } return(result); }
public MultiEncoding Add(IEncoding encoding) { if (encoding is MultiEncoding) { throw new InvalidOperationException("Nesting of MultiEncodings is not supported."); } if (Encodings.Any(e => e.Name == encoding.Name)) { throw new ArgumentException("Encoding name must be unique", "encoding.Name"); } encodings.Add(encoding); Parameters.AddRange(encoding.Parameters); foreach (var @operator in Operators.OfType <IMultiEncodingOperator>()) { @operator.AddEncoding(encoding); } OnEncodingsChanged(); return(this); }
/// <summary> /// gets the input filter string for a given codec type (based on the encoder that is capable of encoding /// the desired codec) /// </summary> /// <param name="codec">the desired codec</param> /// <returns>the input filter string for the desired codec</returns> public string GetSupportedInput(TCodec codec) { IEncoding <TCodec, TType, TEncoderType> enc = null; foreach (IEncoding <TCodec, TType, TEncoderType> encoder in this.registeredEncoders) { if (encoder.GetSupportedCodecs().Contains(codec)) { enc = encoder; break; } } if (enc == null) { return(""); } else { return(enc.GetInputTypeFilter()); } }
/// <summary> /// Sets required fields from the specified encoding. /// </summary> /// <param name="encoding">IEncoding instance.</param> private void SetEncoding(IEncoding encoding) { if (encoding == null) { throw new ArgumentNullException(Resource.ParameterNameEncoding); } _valuesPerByte = 1; // Get number of bits required to store index of encoded values. _bitsRequired = GetBitsRequired(encoding.Count - 1); // If bits required is 1,2,4 then only compress the data. if ((8 % _bitsRequired) == 0 && _bitsRequired != 8) { _valuesPerByte = 8 / _bitsRequired; } else { _bitsRequired = 8; } // Calculate number of bytes required to store specified values. int totalBytesRequired = Count; if (_valuesPerByte > 1) { // Get all encoded values to a list so that the index can be maintained. _encodedValues = new byte[encoding.Count]; int index = 0; foreach (ISequenceItem seqItem in encoding) { _encodedValues[index++] = seqItem.Value; } totalBytesRequired = (Count / _valuesPerByte) + (Count % _valuesPerByte == 0 ? 0 : 1); } _compressedBytes = new byte[totalBytesRequired]; }
/// <summary> /// Initializes a new instance of the <see cref="Grammar"/> class. /// </summary> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <param name="ambiguityDegree">The ambiguity degree.</param> /// <param name="lookAhead">The look-ahead.</param> /// <param name="encoding">The encoding.</param> protected Grammar(string name, GrammarType type, int? ambiguityDegree, int? lookAhead, IEncoding encoding) { #region Contract Contract.Requires<ArgumentNullException>(name != null); Contract.Requires<InvalidEnumArgumentException>(Enum.IsDefined(typeof(GrammarType), type)); Contract.Requires<ArgumentNullException>(encoding != null); #endregion this.Name = name; this.Type = type; this.AmbiguityDegree = ambiguityDegree; this.LookAhead = lookAhead; this.Encoding = encoding; }
private ComponentBuilder(IEncoding config, int index) : base(config, index) { _subcomponents = new BuilderElementCache<SubcomponentBuilder>(CreateSubcomponentBuilder); }
private SegmentBuilder(IEncoding config, int index) : base(config, index) { _fields = new BuilderElementCache<FieldBuilder>(CreateFieldBuilder); }
protected CompiledProblemDefinition(IEncoding encoding) : base() { Encoding = encoding; }
/// <summary>Initialize the message builder base class.</summary> /// <param name="config">Configuration to use.</param> /// <param name="index">Index for new builder.</param> protected DescendantBuilder(IEncoding config, int index) : base(config, index) { Ancestor = null; }
private SubcomponentBuilder(IEncoding config, int index) : base(config, index) { }
private RepetitionBuilder(IEncoding config, int index) : base(config, index) { _components = new BuilderElementCache<ComponentBuilder>(CreateComponentBuilder); }
/// <summary>Initialize the message builder base class.</summary> internal Builder() { Encoding = new BuilderEncodingConfiguration(this); }
/// <summary>Initialize the message builder base class.</summary> /// <param name="config">Message's encoding configuration.</param> /// <param name="index">Index in the parent.</param> internal Builder(IEncoding config, int index) { Encoding = config; Index = index; }