コード例 #1
0
ファイル: VnaAdjListReader.cs プロジェクト: BgRva/Blob1
        internal void DoSecondPass(StreamReader reader, Microsoft.VisualBasic.FileIO.TextFieldParser parser, IBasicAdjList network)
        {
            // now, the network had been created based on the headers of each section, the list of
            // header fields has been populated for each section, nodes have been created.
            // so populate the node data, create the edges, and populate edge data

            // 1) read line
            // 2) if line is a '*' line
            //      read line and set state, skip next line
            //  3) read items based on state
            int index = 0;
            string line = null;
            string[] fields = null;
            try
            {
                while (!parser.EndOfData)
                {
                    if (parser.PeekChars(1) == "*")
                    {
                        line = parser.ReadLine();
                        State = ReadStarLine(line);
                        // skip the header line
                        parser.ReadLine();
                        // reset the index at each * section
                        index = 0;
                        continue;
                    }

                    // if here, then it is not a header line or star line
                    fields = Clean(parser.ReadFields());
                    switch (State)
                    {
                        case VnaFileSection.NodeData:
                            ReadNodeDataFields(fields, network, index++, NodeDataHeaders);
                            break;
                        case VnaFileSection.NodeProperties:
                            ReadNodePropertyFields(fields, network, index++, NodePropertyHeaders);
                            break;
                        case VnaFileSection.EdgeData:
                            ReadEdgeDataFields(fields, network, EdgeDataHeaders);
                            break;
                        case VnaFileSection.EdgeProperties:
                            ReadEdgePropertyFields(fields, network, index++, EdgePropertyHeaders);
                            break;
                        default:
                            throw new InvalidOperationException(string.Format("{0} is an invalid state", State));
                    }
                }
            }
            catch (FormatException ex)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("A format error occured while reading the line {0}.{1}", parser.LineNumber, Environment.NewLine);
                sb.Append(ex.Message);
                ErrorMessages.Add(sb.ToString());
            }
            catch(NullReferenceException ex)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("A null value occured while reading the line {0}.{1}", parser.LineNumber, Environment.NewLine);
                sb.Append(ex.Message);
                ErrorMessages.Add(sb.ToString());
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("An error occurred while reading the line {0}.{1}", parser.LineNumber, Environment.NewLine);
                sb.Append(ex.Message);
                ErrorMessages.Add(sb.ToString());
            }
        }
コード例 #2
0
ファイル: VnaAdjListReader.cs プロジェクト: BgRva/Blob1
        internal void DoFirstPass(TextReader reader, Microsoft.VisualBasic.FileIO.TextFieldParser parser, out int nodeCount, out int edgeCount)
        {
            string mssg = null;
            nodeCount = 0;
            edgeCount = 0;
            string line = null;
            string[] fields = null;
            try
            {
                while (!parser.EndOfData)
                {
                    if (parser.PeekChars(1) == "*")
                    {
                        line = parser.ReadLine();
                        State = ReadStarLine(line);
                        // next line is header
                        fields = Clean(parser.ReadFields());
                        if (ValidateHeaderFields(fields, State, out mssg))
                            ReadHeaders(fields, State);
                        else
                        {
                            ErrorMessages.Add(mssg);
                            break;
                        }
                        continue;
                    }

                    line = parser.ReadLine();
                    // if here, then it is not a header line or star line
                    switch (State)
                    {
                        case VnaFileSection.NodeData:
                            nodeCount++;
                            break;
                        case VnaFileSection.EdgeData:
                            edgeCount++;
                            break;
                    }
                }
            }
            catch (NullReferenceException ex)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("A null value occured while reading the line {0}.{1}", parser.LineNumber, Environment.NewLine);
                sb.Append(ex.Message);
                ErrorMessages.Add(sb.ToString());
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("An error occurred while reading the line {0}.{1}", parser.LineNumber, Environment.NewLine);
                sb.Append(ex.Message);
                ErrorMessages.Add(sb.ToString());
            }
        }