예제 #1
0
        /// <summary>
        /// Create configuration object, which implements given Structure.
        /// Structure properties are parsed from input stream.
        /// </summary>
        /// <param name="parser">Parser which is used for input/output.</param>
        /// <param name="readFromParser">Determine that values can be read from parser.</param>
        /// <typeparam name="Structure">Interface which describes structure of configuration file.</typeparam>
        /// <returns>Configuration object.</returns>
        private static Structure createConfig <Structure>(ConfigParser parser, bool readFromParser = true)
            where Structure : IConfiguration
        {
            var structureType = typeof(Structure);

            //throws exception for invalid structureType
            StructureValidation.ThrowOnInvalid(structureType);

            var structureInfo = StructureFactory.CreateStructureInfo(structureType);
            var optionValues  = readFromParser ? parser.GetOptionValues(structureInfo) : getDefaults(structureInfo);

            if (!readFromParser)
            {
                //parser has to now about structure
                parser.RegisterStructure(structureInfo);
            }


            var configRoot = ConfigFactory.CreateConfigRoot(structureInfo);

            configRoot.AssociateParser(parser);
            //fill config with option values
            foreach (var value in optionValues)
            {
                configRoot.SetOption(value);
                if (!readFromParser)
                {
                    //parser doesn't know about default values - notify it
                    var info = configRoot.GetOptionInfo(value.Name);
                    parser.SetOption(info, value);
                }
            }

            return((Structure)(object)configRoot);
        }
예제 #2
0
        public Holder validateFileStructure(StreamReader csvReader, enteredData enteredData) //VALIDA ESTRUCTURA A TRAVÉS DE LA CLASE StructureValidation
        {
            Holder hold            = new Holder();
            var    selectedStation = db.stations.Where(a => a.idStation.Equals(enteredData.idStation)).FirstOrDefault();

            if (enteredData.idDataType == 1)                //LOS DATOS A VALIDAR SON OBSERVACIONES
            {
                if (selectedStation.idMeasurementType == 1) //VALIDAR ESTRUCTURA DATOS METEOROLOGICOS
                {
                    hold = new StructureValidation().checkMeteorologicalStructure(csvReader, enteredData, selectedStation);
                }
                else if (selectedStation.idMeasurementType == 2) //VALIDAR ESTRUCTURA DATOS GLACIOLOGICOS
                {
                    hold = new StructureValidation().checkGlaciologicalStructure(csvReader);
                }
                else //VALIDAR ESTRUCTURA DATOS HIDROLOGICOS
                {
                    hold = new StructureValidation().checkHydrologicalStructure(csvReader);
                }
            }
            else //DATOS A VALIDAR SON SIMULACIONES
            {
                hold.status  = true;
                hold.message = "NO";
            }
            return(hold);
        }