protected ProfileBase(string name, double startValue, double endValue, ValueUnit unit) { this.Name = name; this.StartValue = startValue; this.EndValue = endValue; this.Unit = unit; }
public ValueUnit BizAction(ValueUnitDto inputData) { if (string.IsNullOrWhiteSpace(inputData.Name)) { AddError("Value Unit Name is Required."); return(null); } if (inputData.ParentId.HasValue) { if (!_dbAccess.HaveValidParent(inputData.ParentId.Value)) { AddError("Value unit parnet is not valid."); return(null); } } var desStatus = ValueUnit.CreateValueUnit(inputData.Name, inputData.MathType, inputData.MathNum, inputData.ParentId); CombineErrors(desStatus); if (!HasErrors) { _dbAccess.Add(desStatus.Result); } return(HasErrors ? null : desStatus.Result); }
//private void fill_Combo() //{ // for (int i = 0; i <= 75; i++) // { // comboBox1.Items.Add(Global.PNo[i] + " " + Global.PSName[i]); // comboBox2.Items.Add(Global.PNo[i] + " " + Global.PSName[i]); // comboBox3.Items.Add(Global.PNo[i] + " " + Global.PSName[i]); // comboBox4.Items.Add(Global.PNo[i] + " " + Global.PSName[i]); // comboBox5.Items.Add(Global.PNo[i] + " " + Global.PSName[i]); // } // comboBox1.SelectedIndex = 0; // comboBox2.SelectedIndex = 1; // comboBox3.SelectedIndex = 7; // comboBox4.SelectedIndex = 10; // comboBox5.SelectedIndex = 13; //} private void ConfigureGraph() { rangeX.Type = (int)MathIntervalType.RightClosedBoundary; rangeX.Min = 0; rangeX.Max = 30;//rangeX.Max is fixed to 10 seconds. TimeUnit timeunit = TimeUnit.Second; m_simGraph.SetXCoordinate(rangeX, label_XCoordinateMin, label_XCoordinateMax, timeunit); rangeY.Max = 10; // Convert.ToDouble(numericUpDown8.Value); rangeY.Min = 10; //Convert.ToDouble(numericUpDown7.Value); ValueUnit unit = (ValueUnit)(-1); // Don't show unit in the label. //if (radioButton7.Checked == true) //{ // rangeY.Max = 3; // rangeY.Min = 0; //} //else if (radioButton8.Checked == true) //{ // rangeY.Max = 10; // rangeY.Min = 0; //} m_simGraph.SetYCoordinate(rangeY, label_YCoordinateMax, label_YCoordinateMin, label_YCoordinateMiddle, unit); m_simGraph.clear(); }
/// <summary> /// Loads the initial processing data for a given association request. /// </summary> /// <param name="value">Value.</param> /// <param name="unit">Unit.</param> public void Load(double value, ValueUnit unit) { _value = value; _valueUnit = unit; var url = string.Format("http://www.wolframalpha.com/input/?i={0}", UnitConverter.Explain(value, unit).Replace(" ", "+")); var html = ReadResponse(() => { var request = CreateRequest(url); request.Method = "GET"; request.Referer = url; return(request); }); var rawPods = GetRawPods(html); var pods = GetPods(rawPods); _workerHost = GetWorkerHost(html); _pods = new Dictionary <string, PodInfo>(); foreach (var pod in pods) { if (!_pods.ContainsKey(pod.Category)) { _pods.Add(pod.Category, pod); } } }
public EventedProfile( string name, double startValue, double endValue, ValueUnit unit) : this(name, startValue, endValue, unit, new List <IEvent>()) { }
public void TryParse_NegativeDecimal() { var input = "-1.3"; var result = ValueUnit.TryParse(input, out var valueUnit); Assert.IsTrue(result); Assert.AreEqual(-1.3, valueUnit.GetResult()); }
public void TryParse_NegativeInteger() { var input = "-5"; var result = ValueUnit.TryParse(input, out var valueUnit); Assert.IsTrue(result); Assert.AreEqual(-5, valueUnit.GetResult()); }
public EventedProfile( string name, double startValue, double endValue, ValueUnit unit, List <IEvent> events) : base(name, startValue, endValue, unit) { this.Events = events; }
/// <summary> /// Reads the JSON representation of the object. /// </summary> /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param> /// <param name="objectType">Type of the object.</param> /// <param name="existingValue">The existing value of object being read.</param> /// <param name="serializer">The calling serializer.</param> /// <returns> /// The object value. /// </returns> /// <exception cref="UnitsNetException">Unable to parse value and unit from JSON.</exception> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { ValueUnit vu = serializer.Deserialize <ValueUnit>(reader); // A null System.Nullable value was deserialized so just return null. if (vu == null) { return(null); } // "MassUnit.Kilogram" => "MassUnit" and "Kilogram" string unitEnumTypeName = vu.Unit.Split('.')[0]; string unitEnumValue = vu.Unit.Split('.')[1]; // "MassUnit" => "Mass" string unitTypeName = unitEnumTypeName.Substring(0, unitEnumTypeName.Length - "Unit".Length); // "UnitsNet.Units.MassUnit,UnitsNet" string unitEnumTypeAssemblyQualifiedName = "UnitsNet.Units." + unitEnumTypeName + ",UnitsNet"; // "UnitsNet.Mass,UnitsNet" string unitTypeAssemblyQualifiedName = "UnitsNet." + unitTypeName + ",UnitsNet"; // -- see http://stackoverflow.com/a/6465096/1256096 for details Type reflectedUnitEnumType = Type.GetType(unitEnumTypeAssemblyQualifiedName); if (reflectedUnitEnumType == null) { var ex = new UnitsNetException("Unable to find enum type."); ex.Data["type"] = unitEnumTypeAssemblyQualifiedName; throw ex; } Type reflectedUnitType = Type.GetType(unitTypeAssemblyQualifiedName); if (reflectedUnitType == null) { var ex = new UnitsNetException("Unable to find unit type."); ex.Data["type"] = unitTypeAssemblyQualifiedName; throw ex; } object unit = Enum.Parse(reflectedUnitEnumType, unitEnumValue); // Mass.From() method, assume no overloads exist MethodInfo fromMethod = reflectedUnitType.GetMethod("From"); // Ex: Mass.From(55, MassUnit.Gram) // TODO: there is a possible loss of precision if base value requires higher precision than double can represent. // Example: Serializing Information.FromExabytes(100) then deserializing to Information // will likely return a very different result. Not sure how we can handle this? return(fromMethod.Invoke(null, BindingFlags.Static, null, new[] { vu.Value, unit }, CultureInfo.InvariantCulture)); }
/// <summary> /// Returns a user-friendly explanation of a given value. /// </summary> /// <param name="value">Value.</param> /// <param name="unit">Value unit.</param> /// <returns>User-friendly explanation.</returns> public static string Explain(double value, ValueUnit unit) { string unitString = System.Enum.GetName(typeof(ValueUnit), unit).ToLowerInvariant(); if (value.ToString().EndsWith("1")) { unitString = unitString.Substring(0, unitString.Length - 1); } return(string.Format("{0} {1}", value.ToString(), unitString)); }
public SampledProfile( string name, double startValue, double endValue, ValueUnit unit, List <List <double> > samples, List <double> weights) : base(name, startValue, endValue, unit) { Samples = samples; Weights = weights; }
public SampledProfile( string name, double startValue, double endValue, ValueUnit unit) : this( name, startValue, endValue, unit, new List <List <double> >(), new List <double>()) { }
/// <summary> /// Convert a <see cref="ValueUnit"/> to an <see cref="IQuantity"/> /// </summary> /// <param name="valueUnit">The value unit to convert</param> /// <exception cref="UnitsNetException">Thrown when an invalid Unit has been provided</exception> /// <returns>An IQuantity</returns> protected IQuantity ConvertValueUnit(ValueUnit valueUnit) { if (string.IsNullOrWhiteSpace(valueUnit?.Unit)) { return(null); } var unit = GetUnit(valueUnit.Unit); return(valueUnit switch { ExtendedValueUnit { ValueType : "decimal" } extendedValueUnit => Quantity.From(decimal.Parse(extendedValueUnit.ValueString), unit), _ => Quantity.From(valueUnit.Value, unit) });
private void ConfigureGraph1() { rangeX.Type = (int)MathIntervalType.RightClosedBoundary; rangeX.Min = 0; rangeX.Max = 30;//rangeX.Max is fixed to 10 seconds. TimeUnit timeunit = TimeUnit.Second; m_simGraph.SetXCoordinate(rangeX, label_XCoordinateMin, label_XCoordinateMax, timeunit); rangeY.Max = 10; rangeY.Min = 0; ValueUnit unit = (ValueUnit)(-1); m_simGraph.SetYCoordinate(rangeY, label_YCoordinateMax, label_YCoordinateMin, label_YCoordinateMiddle, unit); m_simGraph.clear(); }
public void TestValueFailed() { var sequence = new Sequence().AddIgnoreSymbol(' '); UnitError error = null; ValueUnit value = null; //----------------------------------------------------------------- sequence .Add(new ValueUnit().Action(x => value = x)) .Error(x => error = x); //----------------------------------------------------------------- var result = sequence.DecodeLine("value value "); Assert.IsFalse(result); Assert.IsTrue(error != null); Assert.IsTrue(error.PositionInLine == 6); }
public void TestValueAndNextUnit5Success() { var sequence = new Sequence().AddIgnoreSymbol(' '); UnitError error = null; ValueUnit value = null; //----------------------------------------------------------------- sequence .Add(new ValueUnit().Action(x => value = x), new SymbolUnit(';')) .Error(x => error = x); //----------------------------------------------------------------- var result = sequence.DecodeLine(" value value ; "); Assert.IsTrue(result); Assert.IsTrue(error == null); Assert.IsTrue(value.StartPosition == 7); Assert.IsTrue(string.Equals(value.Value, "value value", StringComparison.OrdinalIgnoreCase)); }
void Entry_TextChanged(object sender, TextChangedEventArgs e) { ValueUnit response = null; var value = GetValue (); if (value.HasValue) { if (_picker == null) { response = new ValueUnit { Value = value.Value }; } else { var selectedUnitOptionValue = _picker.Value; if (selectedUnitOptionValue != null) { response = new ValueUnit { Value = value.Value, Unit = selectedUnitOptionValue.Value }; } } } _question.Response = response; }
protected override void ImplWrite ( TextWriter tw, IValueUnit source, IRepositorySerializationContext context ) { if ( context.SerializeMetadata && context.Metadata != null ) if ( source == null ) source = context.Metadata as IValueUnit; else { IValueUnit wrapperVu = new ValueUnit (); wrapperVu.Add ( "$Metadata", context.Metadata ); wrapperVu.Add ( "$Data", source ); source = wrapperVu; } base.ImplWrite ( tw, source, context ); } // End of ImplWrite (...)
public void TestValueAndNoIgnoreSymbols1Success() { var sequence = new Sequence().AddIgnoreSymbol(' '); UnitError error = null; ValueUnit value = null; //----------------------------------------------------------------- sequence .Add(new ValueUnit().Action(x => value = x).ClearIgnoreSymbols(true)) .Error(x => error = x); //----------------------------------------------------------------- var result = sequence.DecodeLine(" "); Assert.IsTrue(result); Assert.IsTrue(error == null); Assert.IsTrue(value.Available); Assert.IsTrue(value.StartPosition == 0); Assert.IsTrue(string.Equals(value.Value, " ", StringComparison.OrdinalIgnoreCase)); }
public async Task CreateOrMergeItemAsync(ShoppingListItem item) { ShoppingListItem itemOnList = await GetItemByNameAsync(item.OwnerId, item.Name); // check if items could be merged if (itemOnList != null && (ValueUnit.TryParse(itemOnList.Quantity, out ValueUnit onlistValue) && ValueUnit.TryParse(item.Quantity, out ValueUnit coreDataValue))) { // merge items ValueUnit newValueUnit = ValueUnit.Add(onlistValue, coreDataValue); itemOnList.Quantity = newValueUnit.ToString(); } else { // create new item _context.ShoppingListItems.Add(item); } await _context.SaveChangesAsync(); }
private void ConfigureGraph() { m_simpleGraph.XCordTimeDiv = 1000; string[] X_rangeLabels = new string[2]; Helpers.GetXCordRangeLabels(X_rangeLabels, 10, 0, TimeUnit.Second); label_XCoordinateMax.Text = X_rangeLabels[0]; label_XCoordinateMin.Text = X_rangeLabels[1]; ValueUnit unit = (ValueUnit)(-1); // Don't show unit in the label. string[] Y_CordLables = new string[3]; Helpers.GetYCordRangeLabels(Y_CordLables, 10, -10, unit); label_YCoordinateMax.Text = Y_CordLables[0]; label_YCoordinateMin.Text = Y_CordLables[1]; label_YCoordinateMiddle.Text = Y_CordLables[2]; m_simpleGraph.YCordRangeMax = 10; m_simpleGraph.YCordRangeMin = -10; m_simpleGraph.Clear(); }
public IEnumerable <AssociationResult> ReceiveAssociations(double value, ValueUnit unit) { WolframAlphaClient client = null; IEnumerable <AssociationResult> ret = null; if (!IsValidRequest()) { throw new HttpResponseException(HttpStatusCode.BadRequest); } client = new WolframAlphaClient() { Silent = true }; client.Load(value, unit); ret = client.GetComparisonData(); return(ret); }
/// <summary> /// Convert a <see cref="ValueUnit"/> to an <see cref="IQuantity"/> /// </summary> /// <param name="valueUnit">The value unit to convert</param> /// <exception cref="UnitsNetException">Thrown when an invalid Unit has been provided</exception> /// <returns>An IQuantity</returns> protected IQuantity ConvertValueUnit(ValueUnit valueUnit) { if (valueUnit == null || string.IsNullOrWhiteSpace(valueUnit.Unit)) { return(null); } var unitParts = valueUnit.Unit.Split('.'); if (unitParts.Length != 2) { var ex = new UnitsNetException($"\"{valueUnit.Unit}\" is not a valid unit."); ex.Data["type"] = valueUnit.Unit; throw ex; } // "MassUnit.Kilogram" => "MassUnit" and "Kilogram" var unitEnumTypeName = unitParts[0]; var unitEnumValue = unitParts[1]; // "UnitsNet.Units.MassUnit,UnitsNet" var unitEnumTypeAssemblyQualifiedName = "UnitsNet.Units." + unitEnumTypeName + ",UnitsNet"; // -- see http://stackoverflow.com/a/6465096/1256096 for details var unitEnumType = Type.GetType(unitEnumTypeAssemblyQualifiedName); if (unitEnumType == null) { var ex = new UnitsNetException("Unable to find enum type."); ex.Data["type"] = unitEnumTypeAssemblyQualifiedName; throw ex; } var value = valueUnit.Value; var unitValue = (Enum)Enum.Parse(unitEnumType, unitEnumValue); // Ex: MassUnit.Kilogram return(Quantity.From(value, unitValue)); }
private void ConfigureGraph() { m_simpleGraph.XCordTimeDiv = 1000; string[] X_rangeLabels = new string[2]; Helpers.GetXCordRangeLabels(X_rangeLabels, trackBar1.Value, 0, TimeUnit.Second); label_XCoordinateMax.Text = X_rangeLabels[0]; label_XCoordinateMin.Text = X_rangeLabels[1]; ValueUnit unit = (ValueUnit)(1); // Don't show unit in the label. string[] Y_CordLables = new string[3]; Helpers.GetYCordRangeLabels(Y_CordLables, trackBar2.Value, -trackBar2.Value, unit); label_YCoordinateMax.Text = Y_CordLables[0]; label_YCoordinateMin.Text = Y_CordLables[1]; label_YCoordinateMiddle.Text = Y_CordLables[2]; m_simpleGraph.AmplificationFactor = 1; m_simpleGraph.XcordChangeRate = (float)(10.0 / trackBar1.Value); m_simpleGraph.YCordRangeMax = trackBar2.Value; m_simpleGraph.YCordRangeMin = -trackBar2.Value; m_simpleGraph.Clear(); }
private static IQuantity ParseValueUnit(ValueUnit vu) { // "MassUnit.Kilogram" => "MassUnit" and "Kilogram" string unitEnumTypeName = vu.Unit.Split('.')[0]; string unitEnumValue = vu.Unit.Split('.')[1]; // "UnitsNet.Units.MassUnit,UnitsNet" string unitEnumTypeAssemblyQualifiedName = "UnitsNet.Units." + unitEnumTypeName + ",UnitsNet"; // -- see http://stackoverflow.com/a/6465096/1256096 for details Type unitEnumType = Type.GetType(unitEnumTypeAssemblyQualifiedName); if (unitEnumType == null) { var ex = new UnitsNetException("Unable to find enum type."); ex.Data["type"] = unitEnumTypeAssemblyQualifiedName; throw ex; } double value = vu.Value; Enum unitValue = (Enum)Enum.Parse(unitEnumType, unitEnumValue); // Ex: MassUnit.Kilogram return(Quantity.From(value, unitValue)); }
void Slider_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "Value") { ValueUnit response = null; if (_picker == null) { response = new ValueUnit { Value = _labelledSlider.Slider.Value }; } else { var selectedUnitOptionValue = _picker.Value; if (selectedUnitOptionValue != null) { response = new ValueUnit { Value = _labelledSlider.Slider.Value, Unit = selectedUnitOptionValue.Value }; } } _question.Response = response; } }
void SetLimit(string targetUnitCode, ValueUnit limit, Action<double> applyAction) { if (limit == null) { return; } double converted; if (!SurveyExecutionContext.Default.TryConvertUnit (limit.Value, limit.Unit, targetUnitCode, out converted)) { return; } applyAction (converted); }
public Value() { Number = float.NaN; Unit = ValueUnit.Undefined; }
public static void GetYCordRangeLabels(string[] ranges, Double rangeMax, Double rangeMin, ValueUnit unit) { string[] sUnit = { "kV", "V", "mV", "uV", "KA", "A", "mA", "uA", "C", "" }; int index = (int)unit; if (-1 == index)//No unit { index = sUnit.Length - 1; } ranges[0] = rangeMax.ToString() + sUnit[index]; ranges[1] = rangeMin.ToString() + sUnit[index]; ranges[2] = (rangeMax == -rangeMin) ? "0" : ""; }
public Value(Value value) { Number = value.Number; Unit = value.Unit; }
public Value(float value, ValueUnit unit) { Number = value; Unit = unit; }
public void SetYCoordinate(MathInterval rangeY, Label label_YCoordinateMax, Label label_YCoordinateMin, Label label_YCoordinateMiddle, ValueUnit unit) { m_YcoordinateMax = rangeY.Max; m_YcoordinateMin = rangeY.Min; string sUnit = ""; switch (unit) { case ValueUnit.Kilovolt: sUnit = "kV"; break; case ValueUnit.Volt: sUnit = "V"; break; case ValueUnit.Millivolt: sUnit = "mV"; m_YcoordinateMax = rangeY.Max / 1000; m_YcoordinateMin = rangeY.Min / 1000; break; case ValueUnit.Milliampere: sUnit = "mA"; break; case ValueUnit.Ampere: sUnit = "A"; break; case ValueUnit.Kiloampere: sUnit = "KA"; break; case ValueUnit.CelsiusUnit: sUnit = "C"; break; default: break; } label_YCoordinateMax.Text = rangeY.Max.ToString() + sUnit; label_YCoordinateMin.Text = rangeY.Min.ToString() + sUnit; if (rangeY.Max == -rangeY.Min) { label_YCoordinateMiddle.Text = " 0"; } else { label_YCoordinateMiddle.Text = ""; } }
private IQuantity Test_ConvertValueUnit(ValueUnit valueUnit) => ConvertValueUnit(valueUnit);