public void WriteToFile(string proteinFile, IIdentifiedResult mr) { if (this.proteinConverter == null) { this.proteinConverter = IdentifiedProteinPropertyConverterFactory.GetInstance().GetConverters( "Locus\tSequence Count\tSpectrum Count\tSequence Coverage\tLength\tMolWt\tpI\tValidation Status\tDescriptive Name", '\t', "Dtaselect"); this.peptideConverter = IdentifiedSpectrumPropertyConverterFactory.GetInstance().GetConverters( "Unique\tFileName\tScore\tDeltCN\tM+H+\tCalcM+H+\tTotalIntensity\tSpRank\tSpScore\tIonProportion\tRedundancy\tSequence", '\t', "Dtaselect"); } using (var sw = new StreamWriter(proteinFile)) { sw.WriteLine("DTASelect v1.9"); sw.WriteLine(); sw.WriteLine("true Use criteria"); sw.WriteLine(); sw.WriteLine(this.proteinConverter.Name); sw.WriteLine(this.peptideConverter.Name); foreach (IdentifiedProteinGroup mpg in mr) { for (int proteinIndex = 0; proteinIndex < mpg.Count; proteinIndex++) { IIdentifiedProtein mpro = mpg[proteinIndex]; sw.WriteLine(this.proteinConverter.GetProperty(mpro)); } mpg.GetSortedPeptides().ForEach(m => sw.WriteLine(this.peptideConverter.GetProperty(m))); } } }
/// <summary> /// If supported, convert the provided value into a <see cref="IPropertyToken"/>. /// </summary> /// <param name="converter">Converter for conversion of additional values.</param> /// <param name="value">The value to convert.</param> /// <param name="result">Value converted to <see cref="IPropertyToken"/> if conversion was successful.</param> /// <returns><c>true</c> if the value could be converted under this policy; <c>false</c> otherwise.</returns> public bool TryConvert(IPropertyConverter converter, object value, out IPropertyToken result) { result = null; if (converter == null) { throw new ArgumentNullException(nameof(converter)); } var enumerable = value as IEnumerable; if (enumerable == null) { return(false); } if (value.GetType().IsDictionary()) { return(false); } var elements = enumerable.Cast <object>(); if (_config.ItemLimit > 0) { elements = elements.Take(_config.ItemLimit); } result = new SequenceToken(elements.Select(converter.Convert)); return(true); }
public void TestNoredundant() { string header = " Reference PepCount UniquePepCount CoverPercent MW PI IdentifiedName"; IPropertyConverter <IIdentifiedProtein> converter = IdentifiedProteinPropertyConverterFactory.GetInstance().GetConverters(header, '\t'); Assert.AreEqual(header, converter.Name); string line = "\tIPI:IPI00784154.1|SWISS-PROT:P10809|TREMBL:B2R5M6;Q53QD5;Q53SE2;Q96RI4;Q9UCR6|ENSEMBL:ENSP00000340019;ENSP00000373620|REFSEQ:NP_002147;NP_955472|H-INV:HIT000031088 Tax_Id=9606 Gene_Symbol=HSPD1 60 kDa heat shock protein, mitochondrial 84 19 43.46% 61054.43 5.70 IPI:IPI00784154.1|SWISS-PROT:P10809|TREMBL:B2R5M6;Q53QD5;Q53SE2;Q96RI4;Q9UCR6|ENSEMBL:ENSP00000340019;ENSP00000373620|REFSEQ:NP_002147;NP_955472|H-INV:HIT000031088 Tax_Id=9606 Gene_Symbol=HSPD1 60 kDa heat shock protein, mitochondrial"; IIdentifiedProtein protein = new IdentifiedProtein(); converter.SetProperty(protein, line); Assert.AreEqual("IPI:IPI00784154.1|SWISS-PROT:P10809|TREMBL:B2R5M6;Q53QD5;Q53SE2;Q96RI4;Q9UCR6|ENSEMBL:ENSP00000340019;ENSP00000373620|REFSEQ:NP_002147;NP_955472|H-INV:HIT000031088", protein.Name); Assert.AreEqual("Tax_Id=9606 Gene_Symbol=HSPD1 60 kDa heat shock protein, mitochondrial", protein.Description); Assert.AreEqual(19, protein.UniquePeptideCount); Assert.AreEqual(43.46, protein.Coverage); Assert.AreEqual(61054.43, protein.MolecularWeight); Assert.AreEqual(5.7, protein.IsoelectricPoint); for (int i = 0; i < 84; i++) { protein.Peptides.Add(new IdentifiedPeptide(new IdentifiedSpectrum())); } Assert.AreEqual(line, converter.GetProperty(protein)); }
public void TestDtaselect() { string header = "Locus Sequence Count Spectrum Count Sequence Coverage Length MolWt pI Validation Status Descriptive Name"; IPropertyConverter <IIdentifiedProtein> converter = IdentifiedProteinPropertyConverterFactory.GetInstance().GetConverters(header, '\t'); Assert.AreEqual(header, converter.Name); string line = "YDR050C 495 495 81.10% 249 26795.41 5.74 U YDR050C TPI1 SGDID:S000002457, Chr IV from 556470-555724, reverse complement, Verified ORF, \"Triose phosphate isomerase, abundant glycolytic enzyme; mRNA half-life is regulated by iron availability; transcription is controlled by activators Reb1p, Gcr1p, and Rap1p through binding sites in the 5' non-coding region\""; IIdentifiedProtein protein = new IdentifiedProtein(); converter.SetProperty(protein, line); Assert.AreEqual("YDR050C", protein.Name); Assert.AreEqual("TPI1 SGDID:S000002457, Chr IV from 556470-555724, reverse complement, Verified ORF, \"Triose phosphate isomerase, abundant glycolytic enzyme; mRNA half-life is regulated by iron availability; transcription is controlled by activators Reb1p, Gcr1p, and Rap1p through binding sites in the 5' non-coding region\"", protein.Description); Assert.AreEqual(495, protein.UniquePeptideCount); Assert.AreEqual(81.1, protein.Coverage); Assert.AreEqual(26795.41, protein.MolecularWeight); Assert.AreEqual(5.74, protein.IsoelectricPoint); for (int i = 0; i < 495; i++) { protein.Peptides.Add(new IdentifiedPeptide(new IdentifiedSpectrum())); } Assert.AreEqual(line, converter.GetProperty(protein)); }
private XElement ToXml(object obj, PropertyInfo pInfo) { if (pInfo == null) { return(null); } object[] atts = pInfo.GetCustomAttributes(typeof(XmlPersistAttribute), false); if (atts == null || atts.Length == 0) { return(ValueTypePropertyToXml(obj, pInfo)); } XmlPersistAttribute xlmPersistAtt = atts[0] as XmlPersistAttribute; IPropertyConverter convter = null; try { convter = Activator.CreateInstance(xlmPersistAtt.PropertyConverter) as IPropertyConverter; object propertyValue = obj.GetType().InvokeMember(pInfo.Name, BindingFlags.GetProperty, null, obj, null); if (propertyValue != null) { return(convter.ToXml(pInfo.Name, propertyValue)); } return(null); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
public PropertyAliasConverter(IPropertyConverter <T> source, string aliasName) { this.source = source; this.aliasName = aliasName; InitializeAliasName(aliasName); }
/// <summary> /// Initializes a new instance of the <see cref="EntityProperty"/> class. /// </summary> /// <param name="propertyContext">The property info that object is associated with.</param> /// <param name="item">The data item.</param> /// <param name="converter">The converter. Optionally you can convert your source property to a different format depending on the UI and scenario.</param> public EntityProperty(object propertyContext, object item, IPropertyConverter converter) { this.PropertyContext = propertyContext; this.Errors = new ObservableCollection <object>(); this.DataItem = item; this.PropertyConverter = converter; }
private IEnumerable <PropertyToken> GetProperties(object value, IPropertyConverter converter) { foreach (var property in value.GetType().GetDerivedProperties()) { object propertyValue; try { propertyValue = property.GetValue(value); } catch (TargetParameterCountException) { // These properties will be ignored since they never produce values they're not // of concern to auditing and exceptions can be suppressed. _logger.Warning( $"The property accessor '{property.DeclaringType.FullName}.{property.Name}' is a non-default indexer"); continue; } catch (TargetInvocationException ex) { _logger.Error(ex, $"The property accessor '{property.DeclaringType.FullName}.{property.Name}' threw an {ex.InnerException.GetType().Name}"); propertyValue = $"The property accessor threw an exception: {ex.InnerException.GetType().Name}"; } yield return(new PropertyToken(property.Name, converter.Convert(propertyValue))); } }
/// <summary> /// If supported, convert the provided value into a <see cref="IPropertyToken"/>. /// </summary> /// <param name="converter">Converter for conversion of additional values.</param> /// <param name="value">The value to convert.</param> /// <param name="result">Value converted to <see cref="IPropertyToken"/> if conversion was successful.</param> /// <returns><c>true</c> if the value could be converted under this policy; <c>false</c> otherwise.</returns> public bool TryConvert(IPropertyConverter converter, object value, out IPropertyToken result) { result = null; if (converter == null) { throw new ArgumentNullException(nameof(converter)); } var bytes = value as byte[]; if (bytes == null) { return(false); } //Enforce limit on size of array if (_config.ByteArrayLimit > 0 && bytes.Length > _config.ByteArrayLimit) { string hexValue = string.Concat(bytes.Take(16).Select(b => b.ToString("X2"))); string description = $"0x: {hexValue}... ({bytes.Length} bytes)"; result = new ScalarToken(description); return(true); } result = new ScalarToken(bytes.ToArray()); return(true); }
private static DynamoDBEntry ToDynamoDBEntry(Type type, object value, IPropertyConverter converter, bool canReturnPrimitiveInsteadOfList) { if (value == null) { return(null); } if (converter != null) { return(converter.ToEntry(value)); } Primitive primitive; if (TryToPrimitive(type, value, out primitive)) { return(primitive); } DynamoDBEntry primitiveList; if (TryToPrimitiveList(type, value, canReturnPrimitiveInsteadOfList, out primitiveList)) { return(primitiveList); } throw new InvalidOperationException("Unable to convert value of type " + value.GetType().FullName + ", type is not primitive or primitive collection and does not define a converter"); }
public void TestDtaselect() { string header = "Unique FileName Score DeltCN M+H+ CalcM+H+ TotalIntensity SpRank SpScore IonProportion Redundancy Sequence"; IPropertyConverter <IIdentifiedSpectrum> converter = IdentifiedSpectrumPropertyConverterFactory.GetInstance().GetConverters(header, '\t'); Assert.AreEqual(header, converter.Name); }
/// <summary> /// Adds a type converter /// </summary> /// <param name="converter"></param> /// <typeparam name="TProperty"></typeparam> /// <returns></returns> public IConnectionStringUtility <T> AddTypeConverter <TProperty>(IPropertyConverter converter) where TProperty : struct { _converters.Add(converter); return(this); }
public void RegisterConverter(IPropertyConverter <T> item, params string[] aliasNames) { itemMap.Add(item); foreach (var name in aliasNames) { itemMap.Add(new PropertyAliasConverter <T>(item, name)); } }
public PropertyViewModel(IGenericProperty <TProperty> property, IEqualityComparer <TProperty> equalityComparer, IPropertyConverter <TProperty> converter) { _property = property; _equalityComparer = equalityComparer; _converter = converter; _objectProperty = _property.Value; Validate(); }
public ConditionPropertyDescriptor(string name, IPropertyConverter <T1, T2> converter) { this.converter = converter; field = AccessTools.Field(typeof(Condition), name); if (!typeof(T1).IsAssignableFrom(field.FieldType)) { throw new ArgumentException("Bad T1!"); } }
public bool IsMessagePropertyConverter <T>(out IPropertyConverter <TProperty, T> propertyConverter) { if (_converter is ITypeConverter <TProperty, T> converter) { propertyConverter = new ConvertPropertyConverter <TProperty, T>(converter); return(true); } propertyConverter = null; return(false); }
public bool TryGetConverter(out IPropertyConverter <TMessage, TMessage> converter) { if (Count > 0) { converter = new TransformPropertyConverter <TMessage>(Build()); return(true); } converter = default; return(false); }
/// <summary> /// If supported, convert the provided value into a <see cref="IPropertyToken"/>. /// </summary> /// <param name="converter">Converter for conversion of additional values.</param> /// <param name="value">The value to convert.</param> /// <param name="result">Value converted to <see cref="IPropertyToken"/> if conversion was successful.</param> /// <returns><c>true</c> if the value could be converted under this policy; <c>false</c> otherwise.</returns> public bool TryConvert(IPropertyConverter converter, object value, out IPropertyToken result) { result = null; if (converter == null) { throw new ArgumentNullException(nameof(converter)); } var enumerable = value as IEnumerable; if (enumerable == null) { return(false); } // Only dictionaries with 'scalar' keys are permitted, as // more complex keys may not serialize to unique values for // representation in targets. This check strengthens the expectation // that resulting dictionary is representable in JSON as well // as richer formats (e.g. XML, .NET type-aware...). // Only actual dictionaries are supported, as arbitrary types // can implement multiple IDictionary interfaces and thus introduce // multiple different interpretations. var type = value.GetType(); if (!type.IsDictionary()) { return(false); } var typeInfo = typeof(KeyValuePair <,>).MakeGenericType(type.GenericTypeArguments).GetTypeInfo(); var keyProperty = typeInfo.GetDeclaredProperty("Key"); var valueProperty = typeInfo.GetDeclaredProperty("Value"); var items = enumerable.Cast <object>(); if (_config.ItemLimit > 0) { items = items.Take(_config.ItemLimit); } var elements = items .Select(kvp => new KeyValuePair <ScalarToken, IPropertyToken>( (ScalarToken)converter.Convert(keyProperty.GetValue(kvp)), converter.Convert(valueProperty.GetValue(kvp)) ) ) .Where(kvp => kvp.Key.Value != null); result = new DictionaryToken(elements); return(true); }
private XElement ToXml(object obj, PropertyInfo pInfo) { if (pInfo == null) { return(null); } object[] atts = pInfo.GetCustomAttributes(typeof(GeoDo.Core.XmlPersistAttribute), true); if (atts == null || atts.Length == 0) { return(ValueTypePropertyToXml(obj, pInfo)); } GeoDo.Core.XmlPersistAttribute xmlPersistAtt = atts[0] as GeoDo.Core.XmlPersistAttribute; if (!xmlPersistAtt.IsNeedPersisted) { return(null); } IPropertyConverter convter = null; try { object propertyValue = obj.GetType().InvokeMember(pInfo.Name, BindingFlags.GetProperty, null, obj, null); if (propertyValue != null) { if (xmlPersistAtt.PropertyConverter != null) { convter = Activator.CreateInstance(xmlPersistAtt.PropertyConverter) as IPropertyConverter; } if (pInfo.PropertyType.IsArray) { XElement containerXml = new XElement(pInfo.Name); Array array = propertyValue as Array; GenerateCollectionItemXElement(pInfo, array as IList, convter, xmlPersistAtt, containerXml); return(containerXml); } else if (PropertyIsList(pInfo)) { XElement containerXml = new XElement(pInfo.Name); IList lst = propertyValue as IList; GenerateCollectionItemXElement(pInfo, lst, convter, xmlPersistAtt, containerXml); return(containerXml); } else { return(convter.ToXml(pInfo.Name, propertyValue)); } } return(null); } catch (Exception ex) { Console.WriteLine(ex.Message); return(null); } }
private void ReadComplexProperty(XElement pElement, object obj) { string proName = pElement.Name.LocalName; PropertyInfo pInfo = obj.GetType().GetProperty(proName); object[] atts = pInfo.GetCustomAttributes(typeof(XmlPersistAttribute), false); XmlPersistAttribute xmlPersisitAtt = atts[0] as XmlPersistAttribute; IPropertyConverter convter = Activator.CreateInstance(xmlPersisitAtt.PropertyConverter) as IPropertyConverter; object value = convter.FromXml(pElement); obj.GetType().InvokeMember(proName, BindingFlags.SetProperty, null, obj, new object[] { value }); }
public FieldConfiguration(string propertyName, Type type, bool isComplexType = false, ICollection <FieldConfiguration> fieldConfigurations = null, IPropertyConverter propertyConverter = null, AccessStrategy accessStrategy = AccessStrategy.Default) { Type = type; PropertyName = propertyName; IsComplexType = isComplexType; FieldConfigurations = fieldConfigurations ?? new List <FieldConfiguration>(); PropertyConverter = propertyConverter; AccessStrategy = accessStrategy; }
public IdentifiedProteinTextWriter(string proteinHeader, IEnumerable <IIdentifiedProtein> proteins) { this._proteins = proteins; this._annotationKeys = AnnotationUtils.GetAnnotationKeys(this._proteins); var sb = new StringBuilder(); sb.Append(proteinHeader); foreach (string key in this._annotationKeys) { sb.Append("\t" + key); } this.converter = IdentifiedProteinPropertyConverterFactory.GetInstance().GetConverters(sb.ToString(), '\t'); }
public void Apply(ITransformConfigurator <TInput> configurator) { if (_transformConfigurator.TryGetConverter(out var converter)) { var inputPropertyProvider = new InputPropertyProvider <TInput, TProperty>(_property); IPropertyConverter <TProperty, TProperty> arrayConverter = typeof(TProperty).IsArray ? new ArrayPropertyConverter <TElement, TElement>(converter) as IPropertyConverter <TProperty, TProperty> : new ListPropertyConverter <TElement, TElement>(converter) as IPropertyConverter <TProperty, TProperty>; var provider = new PropertyConverterPropertyProvider <TInput, TProperty, TProperty>(arrayConverter, inputPropertyProvider); configurator.Transform(_property, provider); } }
public PropertyConvertInputValuePropertyProvider(IPropertyConverter <TProperty, TInputProperty> converter, string inputPropertyName) { if (converter == null) { throw new ArgumentNullException(nameof(converter)); } if (inputPropertyName == null) { throw new ArgumentNullException(nameof(inputPropertyName)); } _converter = converter; _inputProperty = ReadPropertyCache <TInput> .GetProperty <TInputProperty>(inputPropertyName); }
internal object GetConvertBackValue(object value) { object result; IPropertyConverter propertyConverter = this.PropertyConverter; if (propertyConverter != null) { result = propertyConverter.ConvertBack(value); } else { result = value; } return(result); }
public PropertyConverterPropertyProvider(IPropertyConverter <TProperty, TInputProperty> converter, IPropertyProvider <TInput, TInputProperty> inputProvider) { if (converter == null) { throw new ArgumentNullException(nameof(converter)); } if (inputProvider == null) { throw new ArgumentNullException(nameof(inputProvider)); } _converter = converter; _inputProvider = inputProvider; }
/// <summary> /// If supported, convert the provided value into a <see cref="IPropertyToken"/>. /// </summary> /// <param name="converter">Converter for conversion of additional values.</param> /// <param name="value">The value to convert.</param> /// <param name="result">Value converted to <see cref="IPropertyToken"/> if conversion was successful.</param> /// <returns><c>true</c> if the value could be converted under this policy; <c>false</c> otherwise.</returns> public bool TryConvert(IPropertyConverter converter, object value, out IPropertyToken result) { result = null; if (converter == null) { throw new ArgumentNullException(nameof(converter)); } if (value == null) { return(false); } var type = value.GetType(); string typeName = type.IsCompilerGenerated() ? null : type.Name; result = new StructureToken(GetProperties(value, converter), typeName); return(true); }
private void GenerateCollectionItemXElement(PropertyInfo pInfo, IList items, IPropertyConverter convter, XmlPersistAttribute persistAtt, XElement containerXml) { foreach (object it in items) { XElement ele = null; if (convter != null) { ele = convter.ToXml(persistAtt.CollectionItemName, it); } else { ele = ToXml(it); } if (ele != null) { containerXml.Add(ele); } } }
public ConvertObjectPropertyInitializer(IPropertyConverter <TProperty, TInputProperty> converter, string messagePropertyName, string inputPropertyName = null) { if (converter == null) { throw new ArgumentNullException(nameof(converter)); } if (messagePropertyName == null) { throw new ArgumentNullException(nameof(messagePropertyName)); } _converter = converter; _inputProperty = ReadPropertyCache <TInput> .GetProperty <TInputProperty>(inputPropertyName ?? messagePropertyName); _messageProperty = WritePropertyCache <TMessage> .GetProperty <TProperty>(messagePropertyName); }
/// <summary> /// If supported, convert the provided value into a <see cref="IPropertyToken"/>. /// </summary> /// <param name="converter">Converter for conversion of additional values.</param> /// <param name="value">The value to convert.</param> /// <param name="result">Value converted to <see cref="IPropertyToken"/> if conversion was successful.</param> /// <returns><c>true</c> if the value could be converted under this policy; <c>false</c> otherwise.</returns> public bool TryConvert(IPropertyConverter converter, object value, out IPropertyToken result) { result = null; if (converter == null) { throw new ArgumentNullException(nameof(converter)); } var del = value as Delegate; if (del == null) { return(false); } result = new ScalarToken(del.GetMethodInfo().ToString()); return(true); }