public override void ParseUserQuery (string input) { if (input.Length > 1 && (input[input.Length - 1] == 'b' || input[input.Length - 1] == 'B')) { input = input.Substring (0, input.Length - 1); } double double_value; IsEmpty = !Double.TryParse (input, out double_value); if (IsEmpty && input.Length > 1) { IsEmpty = !Double.TryParse (input.Substring (0, input.Length - 1), out double_value); } if (!IsEmpty) { switch (input[input.Length - 1]) { case 'k': case 'K': factor = FileSizeFactor.KB; break; case 'm': case 'M': factor = FileSizeFactor.MB; break; case 'g': case 'G': factor = FileSizeFactor.GB; break; case 't': case 'T': factor = FileSizeFactor.TB; break; case 'p': case 'P': factor = FileSizeFactor.PB; break; default : factor = FileSizeFactor.None; break; } value = (long)((double)factor * double_value); } }
public override void ParseXml(XmlElement node) { base.ParseUserQuery(node.InnerText); if (node.HasAttribute("factor")) { this.factor = (FileSizeFactor)Enum.Parse(typeof(FileSizeFactor), node.GetAttribute("factor")); } else { DetermineFactor(); } }
protected void DetermineFactor() { if (!IsEmpty && value != 0) { foreach (FileSizeFactor factor in Enum.GetValues(typeof(FileSizeFactor))) { if (value >= (double)factor) { this.factor = factor; } } } }
public override void ParseUserQuery(string input) { if (input.Length > 1 && (input[input.Length - 1] == 'b' || input[input.Length - 1] == 'B')) { input = input.Substring(0, input.Length - 1); } double double_value; IsEmpty = !Double.TryParse(input, out double_value); if (IsEmpty && input.Length > 1) { IsEmpty = !Double.TryParse(input.Substring(0, input.Length - 1), out double_value); } if (!IsEmpty) { switch (input[input.Length - 1]) { case 'k': case 'K': factor = FileSizeFactor.KB; break; case 'm': case 'M': factor = FileSizeFactor.MB; break; case 'g': case 'G': factor = FileSizeFactor.GB; break; case 't': case 'T': factor = FileSizeFactor.TB; break; case 'p': case 'P': factor = FileSizeFactor.PB; break; default: factor = FileSizeFactor.None; break; } value = (long)((double)factor * double_value); } }
public void SetValue(double value, FileSizeFactor factor) { this.value = (long)(value * (double)factor); this.factor = factor; IsEmpty = false; }
protected void DetermineFactor() { if (!IsEmpty && value != 0) { foreach (FileSizeFactor factor in Enum.GetValues (typeof(FileSizeFactor))) { if (value >= (double)factor) { this.factor = factor; } } } }
public override void ParseXml(XmlElement node) { base.ParseUserQuery (node.InnerText); if (node.HasAttribute ("factor")) { this.factor = (FileSizeFactor) Enum.Parse (typeof(FileSizeFactor), node.GetAttribute ("factor")); } else { DetermineFactor (); } }