Пример #1
0
        private void UpdateValue(ParameterDataSet dataset, string name, string value, string comments, string lastmodified)
        {
            if (RemapDictionary.ContainsKey(name))
            {
                var codename = RemapDictionary[name];
                if (codename != "XXXX")
                {
                    var param = new InputParameter()
                    {
                        Id         = Guid.NewGuid(),
                        NameInFile = name,
                        Value      = value,
                        NameInCode = codename
                    };

                    dataset.AddParameter(param);
                }
                else
                {
                    AddErrorOutput($"Parameter {name} is defined as XXXX in remap dictionary");
                }
            }
            else
            {
                AddErrorOutput($"Parameter {name} not in remap dictionary");
            }
        }
Пример #2
0
 private ParameterDataSet ExtractParameterDataSet(string filename)
 {
     try
     {
         var         name = Path.GetFileNameWithoutExtension(filename);
         XmlDocument Doc  = new XmlDocument();
         Doc.Load(filename);
         var dataset = new ParameterDataSet();
         dataset.SourceFileName = filename;
         dataset.DataType       = ExtractDataType(filename);
         ReadNodes(Doc.CreateNavigator(), dataset);
         return(dataset);
     }
     catch (Exception ex)
     {
         throw ErrorLogger.CreateException(ex);
     }
     //return null;
 }
Пример #3
0
 public ParameterDataSetPtr(ParameterDataSet dataset)
 {
     Overrides = new List <ParameterOverride>();
     DataSet   = dataset;
 }
Пример #4
0
        private void ReadNodes(XPathNavigator nav, ParameterDataSet dataset)
        {
            XPathNodeIterator nodes = nav.Select("*");

            while (nodes.MoveNext())
            {
                var current       = nodes.Current;
                var name          = current.Name;
                var isSequence    = (name == "PesticideDatesAndRates" || name == "FertilizerInputDateSequences" || name == "IrrigationDates" || name == "IrrigationRunoffSequence" || name == "AdditionalInflowSequence");
                var hasAttributes = current.HasAttributes;
                var hasChildren   = current.HasChildren;
                var arrayvalues   = GetArrayValues(current);
                var lastmodified  = GetAttribute(current, "LastModified");
                var description   = GetAttribute(current, "Description");
                var state         = GetAttribute(current, "state");
                var index         = GetAttribute(current, "index");
                var comments      = GetAttribute(current, "Comments");
                var count         = GetAttribute(current, "Count");
                var day           = GetAttribute(current, "Day");
                var month         = GetAttribute(current, "Month");
                var href          = GetAttribute(current, "href");
                var value         = GetElementValue(current);
                var innerxml      = current.InnerXml;

                //var nodetype=ExtractNodeType(name,hasAttributes,hasChildren,innerxml,arrayvalues,timeseries,href,lastmodified,description,state,index,comments,count,value);
                HLNodeType nodetype = HLNodeType.Root;
                if (isSequence)
                {
                    nodetype = HLNodeType.Sequence;
                }
                else if (IsValid(index))
                {
                    nodetype = HLNodeType.Enum;
                }
                else if (IsValid(day) && IsValid(month))
                {
                    nodetype = HLNodeType.DayMonth;
                }
                else if (IsValid(state) && (state.ToLower() == "true" || state.ToLower() == "false"))
                {
                    nodetype = HLNodeType.Switch;
                }
                else if (IsValid(arrayvalues))
                {
                    nodetype = HLNodeType.Vector;
                }
                else if (IsValid(count))
                {
                    nodetype = HLNodeType.TimeSeries;
                }
                else if (isNumber(value))
                {
                    nodetype = HLNodeType.Value;
                }
                else if (hasChildren && hasAttributes && (IsValid(href) || IsValid(description)))
                {
                    nodetype = HLNodeType.Header;
                }



                switch (nodetype)
                {
                case HLNodeType.Root: break;

                case HLNodeType.Header: dataset.Description = description; dataset.Comments = comments; dataset.Name = name; break;

                case HLNodeType.Vector: UpdateValue(dataset, name, arrayvalues, comments, lastmodified); break;

                case HLNodeType.Value: UpdateValue(dataset, name, value, comments, lastmodified); break;

                case HLNodeType.Switch: UpdateValue(dataset, name, state, comments, lastmodified); break;

                case HLNodeType.Enum: UpdateValue(dataset, name, index, comments, lastmodified); break;

                case HLNodeType.DayMonth: UpdateValue(dataset, name, $"{day},{month}", comments, lastmodified); break;

                case HLNodeType.TimeSeries: UpdateValue(dataset, name, GetTimeSeriesValue(current), comments, lastmodified); break;

                case HLNodeType.Sequence: UpdateValue(dataset, name, innerxml, comments, lastmodified); break;
                }



                ReadNodes(current, dataset);
            }
        }