예제 #1
0
        /// <summary>
        /// Read return information in and store in a list. </summary>
        /// <param name="filename"> filename containing return flow information </param>
        /// <param name="smdataCompType"> the StateMod_DataSet component type, passed to the constructor of StateMod_ReturnFlow
        /// objects. </param>
        /// <exception cref="Exception"> if an error occurs </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static java.util.List<StateMod_ReturnFlow> readStateModFile(String filename, int smdataCompType) throws Exception
        public static IList <StateMod_ReturnFlow> readStateModFile(string filename, int smdataCompType)
        {
            string         routine = "StateMod_ReturnFlow.readStateModFile";
            string         iline   = null;
            IList <string> v;
            IList <StateMod_ReturnFlow> theReturns = new List <StateMod_ReturnFlow>();
            int linecount = 0;

            StateMod_ReturnFlow aReturn = null;
            StreamReader        @in     = null;

            Message.printStatus(2, routine, "Reading return file: " + filename);
            int size       = 0;
            int errorCount = 0;

            try
            {
                @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename));
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    ++linecount;
                    // check for comments
                    if (iline.StartsWith("#", StringComparison.Ordinal) || (iline.Trim().Length == 0))
                    {
                        // Special dynamic header comments written by software and blank lines - no need to keep
                        continue;
                    }
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "line: " + iline);
                    }
                    // Break the line using whitespace, while allowing for quoted strings...
                    v    = StringUtil.breakStringList(iline, " \t", StringUtil.DELIM_ALLOW_STRINGS | StringUtil.DELIM_SKIP_BLANKS);
                    size = 0;
                    if (v != null)
                    {
                        size = v.Count;
                    }
                    if (size < 4)
                    {
                        Message.printStatus(2, routine, "Ignoring line " + linecount + " not enough data values.  Have " + size + " expecting 4+");
                        ++errorCount;
                        continue;
                    }
                    // Uncomment if testing...
                    //Message.printStatus ( 2, routine, "" + v );

                    // Allocate new plan node and set the values
                    aReturn = new StateMod_ReturnFlow(smdataCompType);
                    aReturn.setID(v[0].Trim());
                    aReturn.setName(v[0].Trim());             // Same as ID
                    aReturn.setCrtnid(v[1].Trim());
                    aReturn.setCgoto(v[1].Trim());            // Redundant
                    aReturn.setPcttot(v[2].Trim());
                    aReturn.setIrtndl(v[3].Trim());
                    if (v.Count > 4)
                    {
                        aReturn.setComment(v[4].Trim());
                    }

                    // Set the return to not dirty because it was just initialized...

                    aReturn.setDirty(false);

                    // Add the return to the list of returns
                    theReturns.Add(aReturn);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, "Error reading line " + linecount + " \"" + iline + "\" uniquetempvar.");
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
            if (errorCount > 0)
            {
                throw new Exception("There were " + errorCount + " errors processing the data - refer to log file.");
            }
            return(theReturns);
        }