/// <summary> /// Creates a new instance of the DbField class. /// </summary> /// <param name="name">The name to consider.</param> /// <param name="table">The data table to consider.</param> /// <param name="parameter">The parameter to consider.</param> public static DbField FieldAsParameter( string name, DbTable table, ScalarElement parameter) { return(Field(name, table).AsParameter(parameter)); }
/// <summary> /// Creates a new instance of the DbField class. /// </summary> /// <param name="expr">The expression to consider.</param> /// <param name="table">The data table to consider.</param> /// <param name="parameter">The parameter to consider.</param> public static DbField FieldAsParameter <T>( Expression <Func <T, object> > expr, DbTable table, ScalarElement parameter) where T : class { return(DbFluent.Field <T>(expr, table).AsParameter(parameter)); }
public void ElementAssignmentShouldreplaceExisting() { Section section = new Section(); section.AddElement("Foo = Bar"); section["Foo"] = new ScalarElement("Foo", "Baz"); Assert.Equal(1, section.ElementCount); Assert.Equal("Baz", (section["Foo"] as ScalarElement).Value); }
// Converts the value of the element to a hexadecimal representation. public static string ValueAsHex(this ScalarElement element) { byte[] value = element.GetValue(); string hex = BitConverter .ToString(value) .Replace("-", ""); return($"0x{hex}"); }
public void MultipleAssignmentsShouldResultInOneElement() { Section section = new Section(); section.AddElement("Foo = Bar = moo"); Assert.Equal(1, section.ElementCount); ScalarElement element = section["Foo"] as ScalarElement; Assert.NotNull(element); Assert.Equal("Foo", element.Name); Assert.Equal("Bar = moo", element.Value); }
public void SingleAssignment() { Section section = new Section(); section.AddElement("Foo = Bar"); Assert.Equal(1, section.ElementCount); ScalarElement element = section["Foo"] as ScalarElement; Assert.NotNull(element); Assert.Equal("Foo", element.Name); Assert.Equal("Bar", element.Value); }
// As parameter with parameter ----- /// <summary> /// Updates the specified field as parameter. /// </summary> /// <param name="field">The field to consider.</param> /// <param name="parameter">The parameter to consider.</param> public static DbField AsParameter( this DbField field, ScalarElement parameter) { if (field != null) { field.ValueType = DataValueTypes.None; field.Expression = parameter.AsExp(); } return(field); }
void WriteSection(Section section, Stream stream, ref StringBuilder sb, int indent) { String indentChars = "".PadLeft(4 * indent); foreach (IElement element in section) { ScalarElement scalar = element as ScalarElement; if (scalar != null) { sb.AppendFormat("{0}{1} = {2};\r\n", indentChars, element.Name, scalar.Value); } SectionElement se = element as SectionElement; if (se != null) { Section subSection = se.Value; sb.AppendFormat("\r\n{0}{1}\r\n{0}{{\r\n", indentChars, element.Name); WriteSection(subSection, stream, ref sb, indent + 1); sb.AppendFormat("{0}}}\r\n", indentChars); } } WriteStringBuilder(stream, ref sb); }
// Sets the value of the scalar element to the given value. public static void SetValue(this ScalarElement element, string value) { string trim = value.Trim(); Tag tag = Tag.GetTag(element.TagOfElement); // Determine whether the tag definition contains // a list of identifiers which can be used to // display the value in a more readable format IReadOnlyCollection <Identifier> identifiers = tag?.ValidIdentifiers ?? new List <Identifier>(); // Some identifier collections define a set of bitfields which can be // combined to represent a collection of states rather than a single value // and these are identified by the values being represented in hexadecimal List <Identifier> bitFields = identifiers.Where(id => id.Value.StartsWith("0x")).ToList(); if (bitFields.Count > 0) { HashSet <string> activeBitFields; uint bitSet = 0u; trim = value.Trim('{', '}'); activeBitFields = new HashSet <string>(trim.Split(',').Select(bitField => bitField.Trim()), StringComparer.OrdinalIgnoreCase); foreach (Identifier bitField in bitFields) { if (activeBitFields.Contains(bitField.Name)) { bitSet |= Convert.ToUInt32(bitField.Value, 16); } } trim = bitSet.ToString(); } else if (identifiers.Count > 0) { foreach (Identifier identifier in identifiers) { if (identifier.Name == value) { trim = identifier.Value; } } } if (element.TypeOfValue == PhysicalType.Guid) { element.SetGuid(Guid.Parse(trim)); } else if (element.TypeOfValue == PhysicalType.Complex8) { element.SetComplex8(ComplexNumber.Parse(trim)); } else if (element.TypeOfValue == PhysicalType.Complex16) { element.SetComplex16(ComplexNumber.Parse(trim)); } else { element.Set(trim); } }
// Converts the value of the element to a hexadecimal representation. public static string ValueAsHex(this ScalarElement element) { return("0x" + BitConverter.ToString(element.GetValue()).Replace("-", "")); }
// Converts the value of the element to a string representation. public static string ValueAsString(this ScalarElement element) { string identifierName; string valueString; object value; Tag tag; IReadOnlyCollection <Identifier> identifiers; List <Identifier> bitFields; uint bitSet; List <string> setBits; // Get the value of the element // parsed from the PQDIF file value = element.Get(); // Get the tag definition for the element being displayed tag = Tag.GetTag(element.TagOfElement); // Use the format string specified by the tag // or a default format string if not specified if (element.TypeOfValue == PhysicalType.Timestamp) { valueString = string.Format(tag?.FormatString ?? "{0:yyyy-MM-dd HH:mm:ss.fffffff}", value); } else { valueString = string.Format(tag?.FormatString ?? "{0}", value); } // Determine whether the tag definition contains // a list of identifiers which can be used to // display the value in a more readable format identifiers = tag?.ValidIdentifiers ?? new List <Identifier>(); // Some identifier collections define a set of bitfields which can be // combined to represent a collection of states rather than a single value // and these are identified by the values being represented in hexadecimal bitFields = identifiers.Where(id => id.Value.StartsWith("0x")).ToList(); if (bitFields.Count > 0) { // If the value is not convertible, // it cannot be converted to an // integer to check for bit states if (!(value is IConvertible)) { return(valueString); } // Convert the value to an integer which can // then be checked for the state of its bits bitSet = Convert.ToUInt32(value); // Get the names of the bitfields in the // collection of bitfields that are set setBits = bitFields .Select(id => new { Name = id.Name, Value = Convert.ToUInt32(id.Value, 16) }) .Where(id => bitSet == id.Value || (bitSet & id.Value) > 0u) .Select(id => id.Name) .ToList(); // If none of the bitfields are set, // show just the value by itself if (setBits.Count == 0) { return(valueString); } // If any of the bitfields are set, // display them as a comma-separated // list alongside the value identifierName = string.Join(", ", setBits); return($"{{ {identifierName} }} ({valueString})"); } // Determine if there are any identifiers whose value exactly // matches the string representation of the element's value identifierName = identifiers.SingleOrDefault(id => id.Value == valueString)?.Name; if ((object)identifierName != null) { return($"{identifierName} ({element.Get()})"); } // If the tag could not be recognized as // one that can be displayed in a more // readable form, display the value by itself return(valueString); }
/// <summary> /// Add the specified parameter to this instance. /// </summary> /// <param name="parameter">The parameter to consider.</param> /// <returns>Return this instance.</returns> public IDbQuery AddParameter(ScalarElement parameter) { ParameterSet?.Add(parameter as DataElement); return this; }
/// <summary> /// Creates a new instance of the DbField class. /// </summary> /// <param name="expr">The expression to consider.</param> /// <param name="parameter">The parameter to consider.</param> public static DbField FieldAsParameter <T>( Expression <Func <T, object> > expr, ScalarElement parameter) where T : class { return(FieldAsParameter <T>(expr, null, parameter)); }
/// <summary> /// Creates a new instance of the DbField class. /// </summary> /// <param name="name">The name to consider.</param> /// <param name="parameter">The parameter to consider.</param> public static DbField FieldAsParameter( string name, ScalarElement parameter) { return(DbFluent.FieldAsParameter(name, null, parameter)); }
static void ConvertProject(String input, String output) { XapFile xapFile = new XapFile(); String content = File.ReadAllText(input); xapFile.Open(content); xapFile.ContentVersion = "44"; xapFile.Release = "March 2008"; ElementCollection presets = xapFile.GetElements("Compression Preset"); if (presets.Count > 0) { /* * Change * Compression Preset * { * Name = Compression Preset; * Xbox Format Tag = 357; * Target Sample Rate = 48000; * Quality = 65; * Find Best Quality = 0; * High Freq Cut = 0; * Loop = 0; * PC Format Tag = 2; * Samples Per Block = 128; * } * to * Compression Preset * { * Name = Compression Preset; * Xbox Format Tag = 357; * Target Sample Rate = 48000; * XMA Quality = 65; * Find Best Quality = 0; * High Freq Cut = 0; * Loop = 0; * PC Format Tag = 353; * WMA Quality = 65; * } */ // Add WMA format to all compression presets that define XMA compression, // using the same quality setting for (int c = 0; c < presets.Count; c++) { SectionElement preset = presets[c] as SectionElement; ScalarElement xboxFormatTag = preset.Value["Xbox Format Tag"] as ScalarElement; int xboxFormatTagValue = 0; if (Int32.TryParse(xboxFormatTag.Value, out xboxFormatTagValue) == true && (CompressionFormat)xboxFormatTagValue == CompressionFormat.XMA) { preset.Value["PC Format Tag"].Value = String.Format("{0}", (int)CompressionFormat.WMA); ScalarElement xmaQuality = preset.Value["Quality"] as ScalarElement; preset.Value["Samples Per Block"] = null; preset.Value.Add(new ScalarElement("WMA Quality", xmaQuality.Value)); //REVIEW: Check Wave size: file too small to encode, must have at least 352256 bytes of data //REVIEW: Rename "Quality" element to "XMA Quality"? } } } using (FileStream outputStream = new FileStream(output, FileMode.Create)) { xapFile.Save(outputStream); } }