コード例 #1
0
        private void ok_Click(object sender, EventArgs e)
        {
            stationSystemMap map        = new stationSystemMap();
            FileStream       fileStream = File.Open(edaFilename.Text, FileMode.Open);
            XmlSerializer    serializer = new XmlSerializer(typeof(GameData));

            // get star system data to match stations
            for (int ii = 0; ii < data.stations.Count; ii++)
            {
                string systemName = map.checkIfStationPresent(data.stations[ii].CompleteName);
                if (systemName.Length == 0)
                {
                    systemName = data.stations[ii].SystemName;
                }
                string stationName = data.stations[ii].Name;
                if (systemName.Length == 0)
                {
                    // Last Option, because name not found: Ask.
                    starSystemNames_Input names = new starSystemNames_Input(data.stations[ii].CompleteName);
                    if (names.ShowDialog(this) == DialogResult.OK)
                    {
                        systemName = names.starSystemName.Text;
                    }
                    data.stations[ii].SystemName = systemName;
                    map.addSystemStation(outputData.StarSystems[ii].Name, data.stations[ii].CompleteName);
                    names.Dispose();
                }
                // Ready to add/update the data.
                Routines.AddOrUpdateStation(data, ii, outputData);

                /*
                 * // if the system the station is in has alread been defind use that...
                 * if (systemName.Length > 0)
                 * {
                 *  outputData.StarSystems.Add(new StarSystem());
                 *  outputData.StarSystems[ii].Name = systemName;
                 *  outputData.StarSystems[ii].Stations.Add(new Station(data.stations[ii]));
                 * }
                 * // ...otherwise ask
                 * else
                 * {
                 *  // Extract Station/System Name if possible
                 *  if (data.stations[ii].Name.IndexOf("(") != -1 &&
                 *      data.stations[ii].Name.IndexOf(")") != -1 &&
                 *      data.stations[ii].Name.IndexOf("(") < data.stations[ii].Name.IndexOf(")"))
                 *  {
                 *      outputData.StarSystems.Add(new StarSystem());
                 *      // Extract System name
                 *      outputData.StarSystems[ii].Name = data.stations[ii].Name.Substring(0, data.stations[ii].Name.IndexOf('(')).Trim();
                 *      // Extract Station name
                 *      data.stations[ii].Name = data.stations[ii].Name.Substring(
                 *              data.stations[ii].Name.IndexOf('('),
                 *              data.stations[ii].Name.IndexOf(')') - data.stations[ii].Name.IndexOf('(')
                 *          ).Trim();
                 *      outputData.StarSystems[ii].Stations.Add(new Station(data.stations[ii]));
                 *      map.addSystemStation(outputData.StarSystems[ii].Name, data.stations[ii].Name);
                 *  }
                 *  else
                 *  {
                 *      // Last Option, because name not found: Ask.
                 *      starSystemNames_Input names = new starSystemNames_Input(data.stations[ii].Name);
                 *      if (names.ShowDialog(this) == DialogResult.OK)
                 *      {
                 *          outputData.StarSystems.Add(new StarSystem());
                 *          outputData.StarSystems[ii].Name = names.starSystemName.Text;
                 *          outputData.StarSystems[ii].Stations.Add(new Station(data.stations[ii]));
                 *      }
                 *      // ...then add the system to the list
                 *      map.addSystemStation(outputData.StarSystems[ii].Name, data.stations[ii].Name);
                 *      names.Dispose();
                 *  }
                 * }
                 */
            }

            // write game data to xml file
            serializer.Serialize(fileStream, outputData);

            // write station data to dat file
            map.writeMapFile();

            // close file
            fileStream.Close();

            // close dialogue
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
コード例 #2
0
ファイル: csvData.cs プロジェクト: Rhys314/csv2edassistant
        /// <summary>
        /// Reads a row of data from a CSV file
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public bool ReadRow(CsvRow row)
        {
            row.LineText = ReadLine();
            if (String.IsNullOrEmpty(row.LineText))
            {
                return(false);
            }
            if (row.LineText.IndexOf("{\"message\":{\"buyPrice\":") != -1)
            // Firehose dump file
            {
                List <string> splitRow = Routines.SplitCSV(row.LineText, ',');

                /* Sample Result:
                 *  0 {"message":{"buyPrice":0.0
                 *  1 categoryName:"metals"
                 *  2 demand:2519
                 *  3 demandLevel:2
                 *  4 itemName:"gold"
                 *  5 sellPrice:9898.0
                 *  6 stationName:"Tilian (Maunder's Hope)"
                 *  7 stationStock:0
                 *  8 stationStockLevel:0
                 *  9 timestamp:"2014-09-12T20:47:58.999000+00:00"}
                 * 10 sender:"YJZ4oHnx89PNiFHb0UBKDgAdP3bo/p34XS0wbQUJ1VQ="
                 * 11 signature:"TIM5qsL4Yh7pfV7b8u4xm5ryB0b3NYTZj8y+oLxrAM49cOrDPICPi18oIuN+tkWDE4T50gqPkGiXvQCa35yiCw=="
                 * 12 type:"marketquote"
                 * 13 version:"0.1"}
                 */
                for (int i = 0; i < splitRow.Count - 1; i++)
                {
                    splitRow[i] = superTrim(splitRow[i], i == 0);
                }
                // Old CSV MarketDump format:

                /*
                 * 0 buyPrice
                 * 1 sellPrice
                 * 2 demand
                 * 3 demandLevel
                 * 4 stationStock
                 * 5 stationStockLevel
                 * 6 categoryName
                 * 7 itemName
                 * 8 stationName
                 * 9 timestamp
                 */
                while (row.Count < 10)
                {
                    row.Add(" ");
                }
                row[0] = splitRow[0];
                row[1] = splitRow[5];
                row[2] = splitRow[2];
                row[3] = splitRow[3];
                row[4] = splitRow[7];
                row[5] = splitRow[8];
                row[6] = splitRow[1];
                row[7] = splitRow[4];
                row[8] = splitRow[6];
                row[9] = splitRow[9];
            }
            else
            // Classic CSV
            {
                int pos  = 0;
                int rows = 0;

                while (pos < row.LineText.Length)
                {
                    string value;

                    // Special handling for quoted field
                    if (row.LineText[pos] == '"')
                    {
                        // Skip initial quote
                        pos++;

                        // Parse quoted value
                        int start = pos;
                        while (pos < row.LineText.Length)
                        {
                            // Test for quote character
                            if (row.LineText[pos] == '"')
                            {
                                // Found one
                                pos++;
                                // If two quotes together, keep one
                                // Otherwise, indicates end of value
                                if (pos >= row.LineText.Length || row.LineText[pos] != '"')
                                {
                                    pos--;
                                    break;
                                }
                            }
                            pos++;
                        }
                        value = row.LineText.Substring(start, pos - start);
                        value = value.Replace("\"\"", "\"");
                    }
                    else
                    {
                        // Parse unquoted value
                        int start = pos;
                        while (pos < row.LineText.Length && row.LineText[pos] != ',')
                        {
                            pos++;
                        }
                        value = row.LineText.Substring(start, pos - start);
                    }
                    // Add field to list
                    if (rows < row.Count)
                    {
                        row[rows] = value;
                    }
                    else
                    {
                        row.Add(value);
                    }
                    rows++;
                    // Eat up to and including next comma
                    while (pos < row.LineText.Length && row.LineText[pos] != ',')
                    {
                        pos++;
                    }
                    if (pos < row.LineText.Length)
                    {
                        pos++;
                    }
                }
                // Delete any unused items
                while (row.Count > rows)
                {
                    row.RemoveAt(rows);
                }
            }
            // Return true if any columns read
            return(row.Count > 0);
        }