/// <summary>Adds new Network Attribute Evaluators</summary> private void AddEvaluators(NetworkAttributeInfo nai, IEvaluatedNetworkAttribute netAttr) { foreach (EvaluatorInfo eval in nai.Evaluators) { INetworkEvaluator evaluator = null; if (eval.EvaluatorType == eEvaluatorType.Constant) { evaluator = new NetworkConstantEvaluatorClass(); if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTBoolean) ((INetworkConstantEvaluator)evaluator).ConstantValue = eval.Expression.Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase); else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTDouble) ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToDouble(eval.Expression); else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTFloat) ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToSingle(eval.Expression); else if (netAttr.DataType == esriNetworkAttributeDataType.esriNADTInteger) ((INetworkConstantEvaluator)evaluator).ConstantValue = Convert.ToInt32(eval.Expression); } else if (eval.EvaluatorType == eEvaluatorType.Script) { evaluator = new NetworkScriptEvaluatorClass(); #if ARCGIS_10_0 // Handle Python script language added in ArcGIS 10.1 if (eval.ScriptLanguage != "VBScript") throw new ApplicationException(RESMGR.GetString("GPTools_OSMGPCreateNetworkDataset_invalidScriptLanguage")); INetworkScriptEvaluator scriptEvaluator = (INetworkScriptEvaluator)evaluator; scriptEvaluator.SetExpression(eval.Expression, eval.Prelogic); #else INetworkScriptEvaluator2 scriptEvaluator = (INetworkScriptEvaluator2)evaluator; scriptEvaluator.SetLanguage(eval.ScriptLanguage); scriptEvaluator.SetExpression(eval.Expression, eval.Prelogic); #endif } else if (eval.EvaluatorType == eEvaluatorType.Field) { evaluator = new NetworkFieldEvaluatorClass(); #if ARCGIS_10_0 // Handle Python script language added in ArcGIS 10.1 if (eval.ScriptLanguage != "VBScript") throw new ApplicationException(RESMGR.GetString("GPTools_OSMGPCreateNetworkDataset_invalidScriptLanguage")); INetworkFieldEvaluator fieldEvaluator = (INetworkFieldEvaluator)evaluator; fieldEvaluator.SetExpression(eval.Expression, eval.Prelogic); #else INetworkFieldEvaluator2 fieldEvaluator = (INetworkFieldEvaluator2)evaluator; fieldEvaluator.SetLanguage(eval.ScriptLanguage); fieldEvaluator.SetExpression(eval.Expression, eval.Prelogic); #endif } INetworkSource source = EnumerateNetworkSources() .FirstOrDefault(ns => ns.Name.Equals(GetFullClassName(eval.Source), StringComparison.CurrentCultureIgnoreCase)); if (source != null) { esriNetworkEdgeDirection direction = eval.Direction; if (!(source is IEdgeFeatureSource)) direction = esriNetworkEdgeDirection.esriNEDNone; netAttr.set_Evaluator(source, direction, evaluator); } } }
/// <summary>Creates new network attribute parameters</summary> private static void AddNetworkParameters(NetworkAttributeInfo nai, IEvaluatedNetworkAttribute netAttr) { // Create parameters if ((nai.Parameters != null) && (nai.Parameters.Count > 0)) { IArray naParams = new ArrayClass(); foreach (ParameterInfo paramInfo in nai.Parameters) { INetworkAttributeParameter nap = new NetworkAttributeParameterClass(); nap.Name = paramInfo.Name; if (paramInfo.DefaultValue is double) nap.VarType = (int)VarEnum.VT_R8; else if (paramInfo.DefaultValue is bool) nap.VarType = (int)VarEnum.VT_BOOL; else if (paramInfo.DefaultValue is string) nap.VarType = (int)VarEnum.VT_BSTR; nap.DefaultValue = paramInfo.DefaultValue; naParams.Add(nap); } ((INetworkAttribute3)netAttr).Parameters = naParams; } }