Beispiel #1
0
        private void ComposeQuality()
        {
            FieldsMap fmap = _net.FieldsMap;

            if (_net.Nodes.Count == 0)
            {
                return;
            }

            _writer.WriteStartElement(SectType.QUALITY.ToString().ToLower());

            foreach (Node node in _net.Nodes)
            {
                if (node.C0 == 0.0)
                {
                    continue;
                }

                _writer.WriteStartElement("node");
                _writer.WriteAttributeString("name", node.Name);
                _writer.WriteAttributeString("value", XmlConvert.ToString(fmap.RevertUnit(FieldType.QUALITY, node.C0)));
                _writer.WriteEndElement();
            }

            _writer.WriteEndElement();
        }
Beispiel #2
0
        /// <summary>Computes intercept and slope of head v. flow curve at current flow.</summary>
        /// <param name="fMap"></param>
        /// <param name="q">Flow value.</param>
        /// <param name="h0">Head at zero flow (y-intercept).</param>
        /// <param name="r">dHead/dFlow (slope).</param>
        public void GetCoeff(FieldsMap fMap, double q, out double h0, out double r)
        {
            q *= fMap.GetUnits(FieldType.FLOW);

            int npts = points.Count;

            var k2 = 0;

            while (k2 < npts && points[k2].X < q)
            {
                k2++;
            }

            if (k2 == 0)
            {
                k2++;
            }
            else if (k2 == npts)
            {
                k2--;
            }

            int k1 = k2 - 1;

            r  = (points[k2].Y - points[k1].Y) / (points[k2].X - points[k1].X);
            h0 = points[k1].Y - r * points[k1].X;

            h0 /= fMap.GetUnits(FieldType.HEAD);
            r  *= fMap.GetUnits(FieldType.FLOW) / fMap.GetUnits(FieldType.HEAD);
        }
Beispiel #3
0
        public double GetLinkHeadLoss(int id, Link link, FieldsMap fMap)
        {
            try {
                if (GetLinkFlow(id, link, null) == 0)
                {
                    return(0.0);
                }
                else
                {
                    double hh = _dh[id];
                    if (!(link is Pump))
                    {
                        hh = Math.Abs(hh);
                    }

                    if (link.Type <= LinkType.PIPE)
                    {
                        return(1000 * hh / link.Lenght);
                    }
                    else
                    {
                        return(fMap != null?fMap.RevertUnit(FieldType.HEADLOSS, hh) : hh);
                    }
                }
            }
            catch (ENException) {
                return(0);
            }
        }
 /// <summary>Computes new water levels in tanks after current time step.</summary>
 public static void StepWaterLevels(List <SimulationTank> tanks, FieldsMap fMap, long tstep)
 {
     foreach (SimulationTank tank  in  tanks)
     {
         tank.UpdateLevel(fMap, tstep);
     }
 }
Beispiel #5
0
        private void ComposeDemands(Network net)
        {
            FieldsMap fMap = net.FieldsMap;

            if (!net.Junctions.Any())
            {
                return;
            }

            buffer.WriteLine(SectType.DEMANDS.ParseStr());
            buffer.WriteLine(DEMANDS_SUBTITLE);

            double ucf = fMap.GetUnits(FieldType.DEMAND);

            foreach (Node node in net.Junctions)
            {
                foreach (Demand demand in node.Demands)
                {
                    buffer.Write("{0}\t{1}", node.Name, ucf * demand.Base);

                    if (demand.pattern != null)
                    {
                        buffer.Write("\t" + demand.pattern.Name);
                    }

                    buffer.WriteLine();
                }
            }

            buffer.WriteLine();
        }
Beispiel #6
0
        private void ComposeReservoirs(Network net)
        {
            FieldsMap fMap = net.FieldsMap;

            if (!net.Reservoirs.Any())
            {
                return;
            }

            buffer.WriteLine(SectType.RESERVOIRS.ParseStr());
            buffer.WriteLine(RESERVOIRS_SUBTITLE);

            foreach (Tank tank in net.Reservoirs)
            {
                buffer.Write(" {0}\t{1}", tank.Name, fMap.RevertUnit(FieldType.ELEV, tank.Elevation));


                if (tank.Pattern != null)
                {
                    buffer.Write("\t{0}", tank.Pattern.Name);
                }


                if (!string.IsNullOrEmpty(tank.Comment))
                {
                    buffer.Write("\t;" + tank.Comment);
                }

                buffer.WriteLine();
            }

            buffer.WriteLine();
        }
 /// <summary>Constructor</summary>
 /// <param name="reader"></param>
 /// <param name="linkCount">Number of links.</param>
 /// <param name="nodeCount">Number of nodes.</param>
 /// <param name="fld">Units report properties & conversion object.</param>
 internal Step(FieldsMap fld, BinaryReader reader, int linkCount, int nodeCount)
 {
     this.fld    = fld;
     this.reader = reader;
     linkQ       = new float[linkCount];
     nodeQ       = new float[nodeCount];
 }
Beispiel #8
0
        private static double GetNodeValue(NodeVariableType type, FieldsMap fmap, AwareStep step, Node node, int index)
        {
            switch (type)
            {
            case NodeVariableType.BASEDEMAND: {
                double dsum = node.Demands.Sum(demand => demand.Base);
                return(fmap.RevertUnit((FieldType)type, dsum));
            }

            case NodeVariableType.ELEVATION:
                return(fmap.RevertUnit((FieldType)type, node.Elevation));

            case NodeVariableType.DEMAND:
                return(step != null?step.GetNodeDemand(index, node, fmap) : 0);

            case NodeVariableType.HEAD:
                return(step != null?step.GetNodeHead(index, node, fmap) : 0);

            case NodeVariableType.INITQUALITY:
                return(fmap.RevertUnit((FieldType)type, node.C0));

            case NodeVariableType.PRESSURE:
                return(step != null?step.GetNodePressure(index, node, fmap) : 0);

            case NodeVariableType.QUALITY:
                return(step != null?step.GetNodeQuality(index) : 0);

            default:
                return(0.0);
            }
        }
Beispiel #9
0
        private void ComposeValves()
        {
            var valves = _net.Valves.ToArray();

            if (valves.Length == 0)
            {
                return;
            }

            FieldsMap fMap = _net.FieldsMap;

            _writer.WriteStartElement(SectType.VALVES.ToString().ToLower());

            foreach (Valve valve in valves)
            {
                double d  = valve.Diameter;
                double kc = double.IsNaN(valve.Kc) ? 0.0 : valve.Kc;

                switch (valve.Type)
                {
                case LinkType.FCV:
                    kc = fMap.RevertUnit(FieldType.FLOW, kc);
                    break;

                case LinkType.PRV:
                case LinkType.PSV:
                case LinkType.PBV:
                    kc = fMap.RevertUnit(FieldType.PRESSURE, kc);
                    break;
                }

                double km = valve.Km * Math.Pow(d, 4) / 0.02517;

                _writer.WriteStartElement("link");
                _writer.WriteAttributeString("name", valve.Name);
                _writer.WriteAttributeString("node1", valve.FirstNode.Name);
                _writer.WriteAttributeString("node2", valve.SecondNode.Name);
                _writer.WriteAttributeString("diameter", XmlConvert.ToString(fMap.RevertUnit(FieldType.DIAM, d)));
                _writer.WriteAttributeString("type", valve.Type.ParseStr());

                if (valve.Type == LinkType.GPV && valve.Curve != null)
                {
                    _writer.WriteAttributeString("setting", valve.Curve.Name);
                }
                else
                {
                    _writer.WriteAttributeString("setting", XmlConvert.ToString(kc));
                }

                _writer.WriteAttributeString("minorloss", XmlConvert.ToString(km));

                ComposeElement(valve);
                ComposeVertices(valve);

                _writer.WriteEndElement();
            }

            _writer.WriteEndElement();
        }
Beispiel #10
0
 public double GetNodeDemand(int id, Node node, FieldsMap fMap)
 {
     try {
         return(fMap != null?fMap.RevertUnit(FieldType.DEMAND, _d[id]) : _d[id]);
     }
     catch (ENException) {
         return(0);
     }
 }
Beispiel #11
0
 public double GetNodeHead(int id, Node node, FieldsMap fMap)
 {
     try {
         return(fMap != null?fMap.RevertUnit(FieldType.HEAD, _h[id]) : _h[id]);
     }
     catch (ENException) {
         return(0);
     }
 }
Beispiel #12
0
 public double GetLinkFlow(int id, Link link, FieldsMap fMap)
 {
     try {
         return(fMap != null?fMap.RevertUnit(FieldType.FLOW, _q[id]) : _q[id]);
     }
     catch (ENException) {
         return(0);
     }
 }
Beispiel #13
0
        private void ComposePipes()
        {
            var pipes = _net.Links.Where(x => x.Type == LinkType.PIPE || x.Type == LinkType.CV).ToArray();

            if (pipes.Length == 0)
            {
                return;
            }

            FieldsMap fMap = _net.FieldsMap;

            _writer.WriteStartElement(SectType.PIPES.ToString().ToLower());

            foreach (Link link in pipes)
            {
                double d  = link.Diameter;
                double kc = link.Kc;
                if (_net.FormFlag == FormType.DW)
                {
                    kc = fMap.RevertUnit(FieldType.ELEV, kc * 1000.0);
                }

                double km = link.Km * Math.Pow(d, 4.0) / 0.02517;

                _writer.WriteStartElement("link");
                _writer.WriteAttributeString("name", link.Name);
                _writer.WriteAttributeString("node1", link.FirstNode.Name);
                _writer.WriteAttributeString("node2", link.SecondNode.Name);
                _writer.WriteAttributeString("length", XmlConvert.ToString(fMap.RevertUnit(FieldType.LENGTH, link.Lenght)));
                _writer.WriteAttributeString("diameter", XmlConvert.ToString(fMap.RevertUnit(FieldType.DIAM, d)));
                _writer.WriteAttributeString("roughness", XmlConvert.ToString(kc));
                _writer.WriteAttributeString("minorloss", XmlConvert.ToString(km));

                if (link.Type == LinkType.CV)
                {
                    _writer.WriteAttributeString("status", LinkType.CV.ToString());
                }
                else if (link.Status == StatType.CLOSED)
                {
                    _writer.WriteAttributeString("status", StatType.CLOSED.ToString());
                }
                else if (link.Status == StatType.OPEN)
                {
                    _writer.WriteAttributeString("status", StatType.OPEN.ToString());
                }

                ComposeVertices(link);

                ComposeElement(link);

                _writer.WriteEndElement();
            }

            _writer.WriteEndElement();
        }
Beispiel #14
0
        public double GetNodePressure(int id, Node node, FieldsMap fMap)
        {
            try {
                double p = (GetNodeHead(id, node, null) - node.Elevation);

                return(fMap != null?fMap.RevertUnit(FieldType.PRESSURE, p) : p);
            }
            catch (ENException) {
                return(0);
            }
        }
        protected override void OnClone(DataEditor cloned)
        {
            base.OnClone(cloned);
            WebDataEditorLookupDB obj = (WebDataEditorLookupDB)cloned;

            obj.SqlString = SqlString;
            if (FieldsMap != null)
            {
                obj.FieldsMap = (StringMapList)FieldsMap.Clone();
            }
            obj.ConnectionID = ConnectionID;
        }
Beispiel #16
0
        /// <summary>
        /// Returns a string for 'Sort' parameter of Google Analytics query based on given lambda expression
        /// </summary>
        /// <typeparam name="T">Result object data type</typeparam>
        /// <typeparam name="Tprop">Target field data type</typeparam>
        /// <param name="expression">Lambda expression</param>
        /// <param name="fieldsMap">The mapped set of Context model fields and Google Analytics fields</param>
        /// <returns>String</returns>
        public string Parse <T, Tprop>(Expression <Func <T, Tprop> > expression, FieldsMap fieldsMap)
        {
            string           result           = null;
            MemberExpression memberExpression = expression.Body as MemberExpression;

            if (memberExpression != null)
            {
                string propertyName = memberExpression.Member.Name;
                result = fieldsMap.FindByResultObjectFieldName(propertyName).ContextModelMemberName;
            }
            return(result);
        }
Beispiel #17
0
        /// <summary>
        ///     Retrieves a collection of client validation rules (which are next sent to browsers).
        /// </summary>
        /// <returns>
        ///     A collection of client validation rules.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            var rule = new ModelClientValidationRule
            {
                ErrorMessage   = FormattedErrorMessage,
                ValidationType = ProvideUniqueValidationType("assertthat")
            };

            rule.ValidationParameters.Add("expression", Expression);
            rule.ValidationParameters.Add("fieldsmap", FieldsMap.ToJson());
            rule.ValidationParameters.Add("constsmap", ConstsMap.ToJson());
            yield return(rule);
        }
        /// <summary>
        ///     Generates client validation rule with the basic set of parameters.
        /// </summary>
        /// <param name="type">The validation type.</param>
        /// <returns>
        ///     Client validation rule with the basic set of parameters.
        /// </returns>
        /// <exception cref="System.ComponentModel.DataAnnotations.ValidationException"></exception>
        protected ModelClientValidationRule GetBasicRule(string type)
        {
            try
            {
                var rule = new ModelClientValidationRule
                {
                    ErrorMessage   = FormattedErrorMessage,
                    ValidationType = ProvideUniqueValidationType(type)
                };

                rule.ValidationParameters.Add("expression", Expression.ToJson());

                Debug.Assert(FieldsMap != null);
                if (FieldsMap.Any())
                {
                    rule.ValidationParameters.Add("fieldsmap", FieldsMap.ToJson());
                }
                Debug.Assert(ConstsMap != null);
                if (ConstsMap.Any())
                {
                    rule.ValidationParameters.Add("constsmap", ConstsMap.ToJson());
                }
                Debug.Assert(EnumsMap != null);
                if (EnumsMap.Any())
                {
                    rule.ValidationParameters.Add("enumsmap", EnumsMap.ToJson());
                }
                Debug.Assert(MethodsList != null);
                if (MethodsList.Any())
                {
                    rule.ValidationParameters.Add("methodslist", MethodsList.ToJson());
                }
                Debug.Assert(ParsersMap != null);
                if (ParsersMap.Any())
                {
                    rule.ValidationParameters.Add("parsersmap", ParsersMap.ToJson());
                }
                Debug.Assert(ErrFieldsMap != null);
                if (ErrFieldsMap.Any())
                {
                    rule.ValidationParameters.Add("errfieldsmap", ErrFieldsMap.ToJson());
                }

                return(rule);
            }
            catch (Exception e)
            {
                throw new ValidationException(
                          $"{GetType().Name}: collecting of client validation rules for {FieldName} field failed.", e);
            }
        }
        /// Simulation methods

        ///<summary>Finds water volume in tank corresponding to elevation 'h'</summary>
        public double FindVolume(FieldsMap fMap, double h)
        {
            Curve curve = Vcurve;

            if (curve == null)
            {
                return(Vmin + (h - Hmin) * Area);
            }
            else
            {
                return
                    (curve.Interpolate((h - Elevation) * fMap.GetUnits(FieldType.HEAD)
                                       / fMap.GetUnits(FieldType.VOLUME)));
            }
        }
        /// <summary>Finds water level in tank corresponding to current volume.</summary>
        private double FindGrade(FieldsMap fMap)
        {
            Curve curve = Vcurve;

            if (curve == null)
            {
                return(Hmin + (_volume - Vmin) / Area);
            }
            else
            {
                return(Elevation
                       + curve.Interpolate(_volume * fMap.GetUnits(FieldType.VOLUME))
                       / fMap.GetUnits(FieldType.HEAD));
            }
        }
Beispiel #21
0
        public float ENgetnodevalue(int index, int code)
        {
            double v;

            FieldsMap fMap = _net.FieldsMap;

            if (index <= 0 || index > _nodes.Count)
            {
                return(203);
            }

            Tank tank;

            switch (code)
            {
            case EN_INITVOLUME:
                v    = 0.0;
                tank = _nodes[index - 1] as Tank;
                if (tank != null)
                {
                    v = fMap.RevertUnit(FieldType.VOLUME, tank.V0);
                }
                break;

            case EN_MIXMODEL:
                v    = (double)Enums.MixType.MIX1;
                tank = _nodes[index - 1] as Tank;
                if (tank != null)
                {
                    v = (double)tank.MixModel;
                }
                break;


            case EN_MIXZONEVOL:
                v    = 0.0;
                tank = _nodes[index - 1] as Tank;
                if (tank != null)
                {
                    v = fMap.RevertUnit(FieldType.VOLUME, tank.V1Max);
                }
                break;

            default:
                throw new ENException(ErrorCode.Err251);
            }
            return((float)v);
        }
Beispiel #22
0
        /// <summary>
        ///     Attaches client validation rule to the context.
        /// </summary>
        /// <param name="context">The Client Model Validation Context.</param>
        /// <param name="type">The validation type.</param>
        /// <param name="defaultErrorMessage">The default Error Message.</param>
        /// <returns>
        ///     void
        /// </returns>
        /// <exception cref="System.ComponentModel.DataAnnotations.ValidationException"></exception>
        protected void AttachValidationRules(ClientModelValidationContext context, string type, string defaultErrorMessage)
        {
            var errorMessage         = !string.IsNullOrEmpty(FormattedErrorMessage) ? FormattedErrorMessage : defaultErrorMessage;
            var uniqueValidationType = ProvideUniqueValidationType(type);

            try
            {
                MergeAttribute(context.Attributes, "data-val", "true");
                MergeAttribute(context.Attributes, $"data-val-{uniqueValidationType}", errorMessage);
                MergeAttribute(context.Attributes, $"data-val-{uniqueValidationType}-expression", Expression.ToJson());
                Debug.Assert(FieldsMap != null);
                if (FieldsMap.Any())
                {
                    MergeAttribute(context.Attributes, $"data-val-{uniqueValidationType}-fieldsmap", FieldsMap.ToJson());
                }
                Debug.Assert(ConstsMap != null);
                if (ConstsMap.Any())
                {
                    MergeAttribute(context.Attributes, $"data-val-{uniqueValidationType}-constsmap", ConstsMap.ToJson());
                }
                Debug.Assert(EnumsMap != null);
                if (EnumsMap.Any())
                {
                    MergeAttribute(context.Attributes, $"data-val-{uniqueValidationType}-enumsmap", EnumsMap.ToJson());
                }
                Debug.Assert(MethodsList != null);
                if (MethodsList.Any())
                {
                    MergeAttribute(context.Attributes, $"data-val-{uniqueValidationType}-methodslist", MethodsList.ToJson());
                }
                Debug.Assert(ParsersMap != null);
                if (ParsersMap.Any())
                {
                    MergeAttribute(context.Attributes, $"data-val-{uniqueValidationType}-parsersmap", ParsersMap.ToJson());
                }
                Debug.Assert(ErrFieldsMap != null);
                if (ErrFieldsMap.Any())
                {
                    MergeAttribute(context.Attributes, $"data-val-{uniqueValidationType}-errfieldsmap", ErrFieldsMap.ToJson());
                }
            }
            catch (Exception e)
            {
                throw new ValidationException(
                          $"{GetType().Name}: collecting of client validation rules for {FieldName} field failed.", e);
            }
        }
Beispiel #23
0
        private void ComposeTanks(Network net)
        {
            FieldsMap fMap = net.FieldsMap;

            if (!net.Tanks.Any())
            {
                return;
            }

            buffer.WriteLine(SectType.TANKS.ParseStr());
            buffer.WriteLine(TANK_SUBTITLE);

            foreach (Tank tank in net.Tanks)
            {
                double vmin = tank.Vmin;
                if (Math.Round(vmin / tank.Area) == Math.Round(tank.Hmin - tank.Elevation))
                {
                    vmin = 0;
                }

                buffer.Write(
                    " {0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}",
                    tank.Name,
                    fMap.RevertUnit(FieldType.ELEV, tank.Elevation),
                    fMap.RevertUnit(FieldType.ELEV, tank.H0 - tank.Elevation),
                    fMap.RevertUnit(FieldType.ELEV, tank.Hmin - tank.Elevation),
                    fMap.RevertUnit(FieldType.ELEV, tank.Hmax - tank.Elevation),
                    fMap.RevertUnit(FieldType.ELEV, 2 * Math.Sqrt(tank.Area / Math.PI)),
                    fMap.RevertUnit(FieldType.VOLUME, vmin));

                if (tank.Vcurve != null)
                {
                    buffer.Write(" " + tank.Vcurve.Name);
                }

                if (!string.IsNullOrEmpty(tank.Comment))
                {
                    buffer.Write("\t;" + tank.Comment);
                }
                buffer.WriteLine();
            }

            buffer.WriteLine();
        }
Beispiel #24
0
        public float ENgetlinkvalue(int index, int code)
        {
            FieldsMap fMap = _net.FieldsMap;

            double v;

            if (index <= 0 || index > _links.Count)
            {
                throw new ENException(ErrorCode.Err204);
            }

            var link = _links[index - 1];

            switch (code)
            {
            case EN_DIAMETER:
                v = link is Pump
                    ? 0.0
                    : fMap.RevertUnit(FieldType.DIAM, link.Diameter);
                break;

            case EN_LENGTH:
                v = fMap.RevertUnit(FieldType.ELEV, link.Lenght);
                break;

            case EN_ROUGHNESS:
                if (link.Type <= LinkType.PIPE)
                {
                    v = _net.FormFlag == FormType.DW
                        ? fMap.RevertUnit(FieldType.ELEV, link.Kc * 1000.00)
                        : link.Kc;
                }
                else
                {
                    v = 0.0;
                }
                break;

            default:
                throw new ENException(ErrorCode.Err251);
            }
            return((float)v);
        }
        public override void AddValidation(ClientModelValidationContext context)
        {
            SetupValidator(context.ModelMetadata);

            var validationId          = GetUniqueValidationId(context);
            var formattedErrorMessage = GetErrorMessage(context);

            MergeAttribute(context.Attributes, "data-val", "true");
            MergeAttribute(context.Attributes, $"data-val-{validationId}", formattedErrorMessage);

            MergeExpressiveAttribute(context, validationId, "expression", Attribute.Expression);

            if (AllowEmpty.HasValue)
            {
                MergeExpressiveAttribute(context, validationId, "allowempty", AllowEmpty);
            }

            if (FieldsMap != null && FieldsMap.Any())
            {
                MergeExpressiveAttribute(context, validationId, "fieldsmap", FieldsMap);
            }
            if (ConstsMap != null && ConstsMap.Any())
            {
                MergeExpressiveAttribute(context, validationId, "constsmap", ConstsMap);
            }
            if (EnumsMap != null && EnumsMap.Any())
            {
                MergeExpressiveAttribute(context, validationId, "enumsmap", EnumsMap);
            }
            if (MethodsList != null && MethodsList.Any())
            {
                MergeExpressiveAttribute(context, validationId, "methodslist", MethodsList);
            }
            if (ParsersMap != null && ParsersMap.Any())
            {
                MergeExpressiveAttribute(context, validationId, "parsersmap", ParsersMap);
            }
            if (ErrFieldsMap != null && ErrFieldsMap.Any())
            {
                MergeExpressiveAttribute(context, validationId, "errfieldsmap", ErrFieldsMap);
            }
        }
Beispiel #26
0
        private void ComposeJunctions(Network net)
        {
            FieldsMap fMap = net.FieldsMap;

            if (!net.Junctions.Any())
            {
                return;
            }

            buffer.WriteLine(SectType.JUNCTIONS.ParseStr());
            buffer.WriteLine(JUNCS_SUBTITLE);

            foreach (Node node in net.Junctions)
            {
                buffer.Write(" {0}\t{1}", node.Name, fMap.RevertUnit(FieldType.ELEV, node.Elevation));

                //if(node.getDemand()!=null && node.getDemand().size()>0 && !node.getDemand()[0].getPattern().getId().equals(""))
                //    buffer.write("\t"+node.getDemand()[0].getPattern().getId());

                if (node.Demands.Count > 0)
                {
                    Demand demand = node.Demands[0];
                    buffer.Write("\t{0}", fMap.RevertUnit(FieldType.DEMAND, demand.Base));

                    if (!string.IsNullOrEmpty(demand.pattern.Name) &&
                        !net.DefPatId.Equals(demand.pattern.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        buffer.Write("\t" + demand.pattern.Name);
                    }
                }

                if (!string.IsNullOrEmpty(node.Comment))
                {
                    buffer.Write("\t;" + node.Comment);
                }

                buffer.WriteLine();
            }


            buffer.WriteLine();
        }
Beispiel #27
0
        /// <summary>
        /// Retrieves a collection of client validation rules (rules sent to browsers).
        /// </summary>
        /// <returns>
        /// A collection of client validation rules.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            var count = Storage.Get <int>(AnnotatedField) + 1;

            Assert.AttribsQuantityAllowed(count);

            Storage.Set(AnnotatedField, count);

            var suffix = count == 1 ? string.Empty : char.ConvertFromUtf32(95 + count);
            var rule   = new ModelClientValidationRule
            {
                ErrorMessage   = FormattedErrorMessage,
                ValidationType = string.Format("assertthat{0}", suffix)
            };

            rule.ValidationParameters.Add("expression", Expression);
            rule.ValidationParameters.Add("fieldsmap", FieldsMap.ToJson());
            rule.ValidationParameters.Add("constsmap", ConstsMap.ToJson());
            yield return(rule);
        }
Beispiel #28
0
        public double GetLinkVelocity(int id, Link link, FieldsMap fMap)
        {
            try {
                double v;
                double flow = GetLinkFlow(id, link, null);
                if (link is Pump)
                {
                    v = 0;
                }
                else
                {
                    v = (Math.Abs(flow) / (Math.PI * Math.Pow(link.Diameter, 2) / 4.0));
                }

                return(fMap != null?fMap.RevertUnit(FieldType.VELOCITY, v) : v);
            }
            catch (ENException) {
                return(0);
            }
        }
Beispiel #29
0
        private static double GetLinkValue(
            LinkVariableType type,
            FormType formType,
            FieldsMap fmap,
            AwareStep step,
            Link link,
            int index)
        {
            switch (type)
            {
            case LinkVariableType.LENGHT:
                return(fmap.RevertUnit((FieldType)type, link.Lenght));

            case LinkVariableType.DIAMETER:
                return(fmap.RevertUnit((FieldType)type, link.Diameter));

            case LinkVariableType.ROUGHNESS:
                return(link.Type == LinkType.PIPE && formType == FormType.DW
                    ? fmap.RevertUnit(FieldType.DIAM, link.Kc)
                    : link.Kc);

            case LinkVariableType.FLOW:
                return(step != null?Math.Abs(step.GetLinkFlow(index, link, fmap)) : 0);

            case LinkVariableType.VELOCITY:
                return(step != null?Math.Abs(step.GetLinkVelocity(index, link, fmap)) : 0);

            case LinkVariableType.UNITHEADLOSS:
                return(step != null?step.GetLinkHeadLoss(index, link, fmap) : 0);

            case LinkVariableType.FRICTIONFACTOR:
                return(step != null?step.GetLinkFriction(index, link, fmap) : 0);

            case LinkVariableType.QUALITY:
                return(step != null?fmap.RevertUnit((FieldType)type, step.GetLinkAvrQuality(index)) : 0);

            default:
                return(0.0);
            }
        }
Beispiel #30
0
        /// <summary>
        /// Convert fields according to the storage attribute. For newly created field assign default value to that field.
        /// </summary>
        /// <param name="sourceDataSourceDefinition"></param>
        /// <param name="destinationDataSourceDefinition"></param>
        /// <param name="sourceValues"></param>
        /// <param name="destinationValues"></param>
        private void ConvertFields(DataSourceDefinition sourceDataSourceDefinition, DataSourceDefinition destinationDataSourceDefinition,
                                   FieldValues sourceValues, FieldValues destinationValues)
        {
            FieldsMap  fieldsMap   = new FieldsMap(sourceDataSourceDefinition.Fields, destinationDataSourceDefinition.Fields);
            DBField    sourceField = null;
            FieldValue sourceValue = null;

            for (int destinationFieldIndex = 0; destinationFieldIndex < destinationDataSourceDefinition.Fields.Count; destinationFieldIndex++)
            {
                int sourceFieldIndex = fieldsMap.GetSourceFieldIndex(destinationFieldIndex);

                DBField    destinationField = destinationDataSourceDefinition.Fields[destinationFieldIndex];
                FieldValue destinationValue = destinationValues[destinationFieldIndex];

                // If source field exists and source and destination types are comapatible then convert field values.
                // Else assign default value to destination field.
                if (sourceFieldIndex != -1)
                {
                    sourceField = sourceDataSourceDefinition.Fields[sourceFieldIndex];
                    sourceValue = sourceValues[sourceFieldIndex];

                    if (StorageAttributeCheck.IsTypeCompatibile((StorageAttribute)sourceField.Attr, (StorageAttribute)destinationField.Attr))
                    {
                        ConvertFieldValue(sourceField, destinationField, sourceValue, destinationValue);
                    }
                    else
                    {
                        destinationValue.Value  = destinationField.DefaultValue;
                        destinationValue.IsNull = destinationField.DefaultNull;
                    }
                }
                else
                {
                    destinationValue.Value  = destinationField.DefaultValue;
                    destinationValue.IsNull = destinationField.DefaultNull;
                }
            }
        }