using IStation.Epanet.Util; namespace IStation.Epanet.Enums { public static class EnumsTxt { public static bool TryParse(string text, out Varwords result) { if (text.Match(Keywords.wr_DEMAND)) result = Varwords.DEMAND; else if (text.Match(Keywords.wr_HEAD)) result = Varwords.HEAD; else if (text.Match(Keywords.wr_GRADE)) result = Varwords.GRADE; else if (text.Match(Keywords.wr_LEVEL)) result = Varwords.LEVEL; else if (text.Match(Keywords.wr_PRESSURE)) result = Varwords.PRESSURE; else if (text.Match(Keywords.wr_FLOW)) result = Varwords.FLOW; else if (text.Match(Keywords.wr_STATUS)) result = Varwords.STATUS; else if (text.Match(Keywords.wr_SETTING)) result = Varwords.SETTING; else if (text.Match(Keywords.wr_POWER)) result = Varwords.POWER; else if (text.Match(Keywords.wr_TIME)) result = Varwords.CLOCKTIME; else if (text.Match(Keywords.wr_CLOCKTIME)) result = Varwords.CLOCKTIME; else if (text.Match(Keywords.wr_FILLTIME)) result = Varwords.FILLTIME; else if (text.Match(Keywords.wr_DRAINTIME)) result = Varwords.DRAINTIME; else { result = (Varwords)(-1); return false; } return true; } public static bool TryParse(string text, out Values result) { if (text.Match(Keywords.wr_ACTIVE)) result = Values.IS_ACTIVE; else if (text.Match(Keywords.wr_CLOSED)) result = Values.IS_CLOSED; // else if (text.Match("XXXX")) result = Rule.Values.IS_NUMBER; else if (text.Match(Keywords.wr_OPEN)) result = Values.IS_OPEN; else { result = (Values)(-1); return false; } return true; } public static bool TryParse(this string text, out Rulewords result) { int index = text.FindMatch( text, Keywords.wr_AND, Keywords.wr_ELSE, string.Empty, Keywords.wr_IF, Keywords.wr_OR, Keywords.wr_PRIORITY, Keywords.wr_RULE, Keywords.wr_THEN); return (int)(result = (Rulewords)index) != -1; } public static bool TryParse(this string text, out Operators result) { text = text.Trim(); if (text.Equals(Keywords.wr_ABOVE, StringComparison.OrdinalIgnoreCase)) result = Operators.ABOVE; else if (text.Equals(Keywords.wr_BELOW, StringComparison.OrdinalIgnoreCase)) result = Operators.BELOW; else if (text == "=") result = Operators.EQ; else if (text == ">=") result = Operators.GE; else if (text == ">") result = Operators.GT; else if (text.Equals(Keywords.wr_IS, StringComparison.OrdinalIgnoreCase)) result = Operators.IS; else if (text == "<=") result = Operators.LE; else if (text == "<") result = Operators.LT; else if (text == "<>") result = Operators.NE; else if (text.Equals(Keywords.wr_NOT, StringComparison.OrdinalIgnoreCase)) result = Operators.NOT; else { result = (Operators)(-1); return false; } return true; } public static bool TryParse(this string text, out Objects result) { if (text.Match(Keywords.wr_JUNC)) result = Objects.JUNC; else if (text.Match(Keywords.w_RESERV)) result = Objects.RESERV; else if (text.Match(Keywords.w_TANK)) result = Objects.TANK; else if (text.Match(Keywords.w_PIPE)) result = Objects.PIPE; else if (text.Match(Keywords.w_PUMP)) result = Objects.PUMP; else if (text.Match(Keywords.w_VALVE)) result = Objects.VALVE; else if (text.Match(Keywords.w_NODE)) result = Objects.NODE; else if (text.Match(Keywords.w_LINK)) result = Objects.LINK; else if (text.Match(Keywords.w_SYSTEM)) result = Objects.SYSTEM; else { result = (Objects)(-1); return false; } return true; } public static bool TryParse(this string text, out MixType result) { if (text.Match(Keywords.w_MIXED)) result = MixType.Mix1; else if (text.Match(Keywords.w_2COMP)) result = MixType.Mix2; else if (text.Match(Keywords.w_FIFO)) result = MixType.Fifo; else if (text.Match(Keywords.w_LIFO)) result = MixType.Lifo; else { result = (MixType)(-1); return false; } return true; } public static string ParseStr(this MixType value) { switch (value) { case MixType.Fifo: return Keywords.w_FIFO; case MixType.Lifo: return Keywords.w_LIFO; case MixType.Mix1: return Keywords.w_MIXED; case MixType.Mix2: return Keywords.w_2COMP; default: return null; } } public static bool TryParse(this string text, out FieldType result) { if (text.Match(Keywords.t_ELEV)) result = FieldType.ELEV; else if (text.Match(Keywords.t_DEMAND)) result = FieldType.DEMAND; else if (text.Match(Keywords.t_HEAD)) result = FieldType.HEAD; else if (text.Match(Keywords.t_PRESSURE)) result = FieldType.PRESSURE; else if (text.Match(Keywords.t_QUALITY)) result = FieldType.QUALITY; else if (text.Match(Keywords.t_LENGTH)) result = FieldType.LENGTH; else if (text.Match(Keywords.t_DIAM)) result = FieldType.DIAM; else if (text.Match(Keywords.t_FLOW)) result = FieldType.FLOW; else if (text.Match(Keywords.t_VELOCITY)) result = FieldType.VELOCITY; else if (text.Match(Keywords.t_HEADLOSS)) result = FieldType.HEADLOSS; else if (text.Match(Keywords.t_LINKQUAL)) result = FieldType.LINKQUAL; else if (text.Match(Keywords.t_STATUS)) result = FieldType.STATUS; else if (text.Match(Keywords.t_SETTING)) result = FieldType.SETTING; else if (text.Match(Keywords.t_REACTRATE)) result = FieldType.REACTRATE; else if (text.Match(Keywords.t_FRICTION)) result = FieldType.FRICTION; else { result = (FieldType)(-1); return false; } return true; } public static bool TryParse(this string text, out SourceType result) { if (text.Match(Keywords.w_CONCEN)) result = SourceType.Concen; else if (text.Match(Keywords.w_FLOWPACED)) result = SourceType.FlowPaced; else if (text.Match(Keywords.w_MASS)) result = SourceType.Mass; else if (text.Match(Keywords.w_SETPOINT)) result = SourceType.SetPoint; else { result = (SourceType)(-1); return false; } return true; } public static string ReportStr(this StatusType value) { switch (value) { case StatusType.XHEAD: return Keywords.t_XHEAD; case StatusType.TEMPCLOSED: return Keywords.t_TEMPCLOSED; case StatusType.CLOSED: return Keywords.t_CLOSED; case StatusType.OPEN: return Keywords.t_OPEN; case StatusType.ACTIVE: return Keywords.t_ACTIVE; case StatusType.XFLOW: return Keywords.t_XFLOW; case StatusType.XFCV: return Keywords.t_XFCV; case StatusType.XPRESSURE: return Keywords.t_XPRESSURE; case StatusType.FILLING: return Keywords.t_FILLING; case StatusType.EMPTYING: return Keywords.t_EMPTYING; default: return null; } } public static string ParseStr(this ControlType value) { switch (value) { case ControlType.HiLevel: return Keywords.w_ABOVE; case ControlType.LowLevel: return Keywords.w_BELOW; case ControlType.TimeOfDay: return Keywords.w_CLOCKTIME; case ControlType.Timer: return Keywords.w_TIME; default: return null; } } public static string ParseStr(this FieldType value) { switch (value) { case FieldType.ELEV: return Keywords.t_ELEV; case FieldType.DEMAND: return Keywords.t_DEMAND; case FieldType.HEAD: return Keywords.t_HEAD; case FieldType.PRESSURE: return Keywords.t_PRESSURE; case FieldType.QUALITY: return Keywords.t_QUALITY; case FieldType.LENGTH: return Keywords.t_LENGTH; case FieldType.DIAM: return Keywords.t_DIAM; case FieldType.FLOW: return Keywords.t_FLOW; case FieldType.VELOCITY: return Keywords.t_VELOCITY; case FieldType.HEADLOSS: return Keywords.t_HEADLOSS; case FieldType.LINKQUAL: return Keywords.t_LINKQUAL; case FieldType.STATUS: return Keywords.t_STATUS; case FieldType.SETTING: return Keywords.t_SETTING; case FieldType.REACTRATE: return Keywords.t_REACTRATE; case FieldType.FRICTION: return Keywords.t_FRICTION; default: return null; } } public static bool TryParse(this string text, out FlowUnitsType result) { if (text.Match(Keywords.w_CFS)) result = FlowUnitsType.Cfs; else if (text.Match(Keywords.w_GPM)) result = FlowUnitsType.Gpm; else if (text.Match(Keywords.w_MGD)) result = FlowUnitsType.Mgd; else if (text.Match(Keywords.w_IMGD)) result = FlowUnitsType.Imgd; else if (text.Match(Keywords.w_AFD)) result = FlowUnitsType.Afd; else if (text.Match(Keywords.w_LPS)) result = FlowUnitsType.Lps; else if (text.Match(Keywords.w_LPM)) result = FlowUnitsType.Lpm; else if (text.Match(Keywords.w_MLD)) result = FlowUnitsType.Mld; else if (text.Match(Keywords.w_CMH)) result = FlowUnitsType.Cmh; else if (text.Match(Keywords.w_CMD)) result = FlowUnitsType.Cmd; else { result = (FlowUnitsType)(-1); return false; } return true; } public static string ParseStr(this FlowUnitsType value) { switch (value) { case FlowUnitsType.Afd: return Keywords.w_AFD; case FlowUnitsType.Cfs: return Keywords.w_CFS; case FlowUnitsType.Cmd: return Keywords.w_CMD; case FlowUnitsType.Cmh: return Keywords.w_CMH; case FlowUnitsType.Gpm: return Keywords.w_GPM; case FlowUnitsType.Imgd: return Keywords.w_IMGD; case FlowUnitsType.Lpm: return Keywords.w_LPM; case FlowUnitsType.Lps: return Keywords.w_LPS; case FlowUnitsType.Mgd: return Keywords.w_MGD; case FlowUnitsType.Mld: return Keywords.w_MLD; default: return null; } } /// Parse string id. public static string ParseStr(this HeadLossFormulaType value) { switch (value) { case HeadLossFormulaType.CM: return Keywords.w_CM; case HeadLossFormulaType.DW: return Keywords.w_DW; case HeadLossFormulaType.HW: return Keywords.w_HW; default: return null; } } public static bool TryParse(this string text, out QualType result) { if (text.Match(Keywords.w_NONE)) result = QualType.None; else if (text.Match(Keywords.w_CHEM)) result = QualType.Chem; else if (text.Match(Keywords.w_AGE)) result = QualType.Age; else if (text.Match(Keywords.w_TRACE)) result = QualType.Trace; else { result = (QualType)(-1); return false; } return true; } public static bool TryParse(this string text, out StatusLevel result) { if (text.Match(Keywords.w_NO)) result = StatusLevel.None; else if (text.Match(Keywords.w_FULL)) result = StatusLevel.FULL; else if (text.Match(Keywords.w_YES)) result = StatusLevel.Normal; else { result = (StatusLevel)(-1); return false; } return true; } public static string ParseStr(this StatusLevel value) { switch (value) { case StatusLevel.None: return Keywords.w_NO; case StatusLevel.FULL: return Keywords.w_FULL; case StatusLevel.Normal: return Keywords.w_YES; default: return null; } } public static string ParseStr(this TstatType value) { switch (value) { case TstatType.Average: return Keywords.w_AVG; case TstatType.Maximum: return Keywords.w_MAX; case TstatType.Minimum: return Keywords.w_MIN; case TstatType.Range: return Keywords.w_RANGE; case TstatType.None: return Keywords.w_NONE; default: return null; } } public static bool TryParse(this string text, out TstatType result) { if (text.Match(Keywords.w_NONE)) result = TstatType.None; else if (text.Match(Keywords.w_NO)) result = TstatType.None; else if (text.Match(Keywords.w_AVG)) result = TstatType.Average; else if (text.Match(Keywords.w_MIN)) result = TstatType.Minimum; else if (text.Match(Keywords.w_MAX)) result = TstatType.Maximum; else if (text.Match(Keywords.w_RANGE)) result = TstatType.Range; else { result = (TstatType)(-1); return false; } return true; } public static bool TryParse(this string text, out RangeType result) { if (text.Match(Keywords.w_BELOW)) result = RangeType.LOW; else if (text.Match(Keywords.w_ABOVE)) result = RangeType.HI; else if (text.Match(Keywords.w_PRECISION)) result = RangeType.PREC; else { result = (RangeType)(-1); return false; } return true; } public static string ParseStr(this SectType value) { if (value < SectType.TITLE || value > SectType.END) { // throw new System.ArgumentOutOfRangeException("value"); return null; } return "[" + value + "]"; } public static string ParseStr(this PressUnitsType value) { switch (value) { case PressUnitsType.KPA: return Keywords.w_KPA; case PressUnitsType.METERS: return Keywords.w_METERS; case PressUnitsType.PSI: return Keywords.w_PSI; default: return null; } } public static bool TryParse(this string text, out PressUnitsType result) { if (text.Match(Keywords.w_PSI)) result = PressUnitsType.PSI; else if (text.Match(Keywords.w_KPA)) result = PressUnitsType.KPA; else if (text.Match(Keywords.w_METERS)) result = PressUnitsType.METERS; else { result = (PressUnitsType)(-1); return false; } return true; } public static bool TryParse(this string text, out HeadLossFormulaType result) { if (text.Match(Keywords.w_HW)) result = HeadLossFormulaType.HW; else if (text.Match(Keywords.w_DW)) result = HeadLossFormulaType.DW; else if (text.Match(Keywords.w_CM)) result = HeadLossFormulaType.CM; else { result = (HeadLossFormulaType)(-1); return false; } return true; } public static bool TryParse(this string text, out HydType result) { if (text.Match(Keywords.w_USE)) result = HydType.USE; else if (text.Match(Keywords.w_SAVE)) result = HydType.SAVE; else { result = (HydType)(-1); return false; } return true; } public static bool TryParse(this string text, out ValveType result) { if (text.Match(Keywords.w_PRV)) result = ValveType.PRV; else if (text.Match(Keywords.w_PSV)) result = ValveType.PSV; else if (text.Match(Keywords.w_FCV)) result = ValveType.FCV; else if (text.Match(Keywords.w_TCV)) result = ValveType.TCV; else if (text.Match(Keywords.w_PBV)) result = ValveType.PBV; else if (text.Match(Keywords.w_GPV)) result = ValveType.GPV; else { result = (ValveType)(-1); return false; } return true; } } }