Exemple #1
0
        /// <summary>
        /// Read data from SWAT output file using TextFieldParser
        /// </summary>
        /// <remarks>
        /// 1. Need to know the number and width of columns
        /// 2. Doesn't support select partial data
        /// </remarks>
        static void TestExtractFromText_TextFieldParser(string filePah)
        {
            Console.WriteLine("TextFieldParser");
            DateTime before = DateTime.Now;

            using (Microsoft.VisualBasic.FileIO.TextFieldParser reader =
                       new Microsoft.VisualBasic.FileIO.TextFieldParser(filePah))
            {
                reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.FixedWidth;
                reader.SetFieldWidths(6, 4, 10, 4,
                                      10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
                                      10, 10, 10, 10, 10, 10, 10, 10, 10, 11,
                                      10, 10, 10, 6);
                string[] currentRow = null;
                int      i          = 0;
                //ignore the first 9 lines
                while (!reader.EndOfData && i < 9)
                {
                    reader.ReadLine();
                    i++;
                }
                while (!reader.EndOfData)
                {
                    currentRow = reader.ReadFields();
                }
            }
            DateTime after = DateTime.Now;

            Console.WriteLine(string.Format("******\nTime Used: {0} seconds\n******", after.Subtract(before).TotalSeconds));
        }
        private List <structDWG> ReadCSV(string filePathName, bool hasHeaders)
        {
            List <structDWG> dwgList = new List <structDWG>();

            using (Microsoft.VisualBasic.FileIO.TextFieldParser MyReader = new Microsoft.VisualBasic.FileIO.TextFieldParser(filePathName)) {
                MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
                MyReader.Delimiters    = new string[] { "," };
                string[] currentRow = null;

                //if CSV file has headers then discard first line
                if (hasHeaders == true)
                {
                    MyReader.ReadLine().Skip(1);
                }

                while (!MyReader.EndOfData)
                {
                    try {
                        currentRow = MyReader.ReadFields();

                        //create temp sheet
                        structDWG curFile = new structDWG();
                        curFile.fileName = currentRow[0];
                        curFile.linkView = currentRow[1];

                        //add sheet to list
                        dwgList.Add(curFile);
                    } catch (Microsoft.VisualBasic.FileIO.MalformedLineException ex) {
                        Debug.Print("Line " + ex.Message + " is invalid.  Skipping");
                    }
                }

                return(dwgList);
            }
        }
        /// <summary>
        /// Import2s the specified CSV RDR.
        /// </summary>
        /// <param name="csvRdr">The CSV RDR.</param>
        public void Import2(Microsoft.VisualBasic.FileIO.TextFieldParser csvRdr)
        {
            //CurrentStatesBeingManaged = new List<State>(HospitalRegion.Default.SelectedStates);
            var startTime = DateTime.Now;

            Importing(this, EventArgs.Empty);
            CountInserted  = 0;
            NumberOfErrors = 0;
            AssertErrorFile();

            csvRdr.ReadLine();
            while (!csvRdr.EndOfData)
            {
                int n = 1;

                IList <ImportError> errors = new List <ImportError>();

                Events.GetEvent <PleaseStandByMessageUpdateEvent>()
                .Publish("Importing line " + n.ToString());
                try
                {
                    ExtractAndSave2(csvRdr, errors);

                    ImportErrors.AddRange(errors);
                }
                finally
                {
                    n++;
                }
            }

            FinalProcessing();

            Events.GetEvent <PleaseStandByMessageUpdateEvent>().Publish("Finalizing import...");

            // what is the purpose of this delay???
            const int MAX_DELAY_SECONDS = 3;

            var elapsed   = DateTime.Now - startTime;
            var seconds   = elapsed.TotalSeconds;
            var remaining = MAX_DELAY_SECONDS - seconds;

            if (remaining > 0)
            {
                Thread.Sleep(TimeSpan.FromSeconds(remaining));
            }

            Imported(this, EventArgs.Empty);
            Events.GetEvent <PleaseStandByMessageUpdateEvent>().Publish("Import Complete");
            Events.GetEvent <SimpleImportCompletedEvent>().Publish(this);
        }
Exemple #4
0
 public override void ParseFileByteArray(byte[] fileData)
 {
     using (var stream = new System.IO.MemoryStream(fileData))
     {
         using (var reader = new StreamReader(stream))
         {
             using (var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(reader))
             {
                 while (!parser.EndOfData)
                 {
                     var      line   = parser.ReadLine();
                     string[] values = line.Split(';');
                     UpdateDataBpm(values);
                 }
             }
         }
     }
 }
Exemple #5
0
        public static double[,] LoadCsv(string path, string delimiter = ",", string commentToken = "#", bool quotes = false, bool header = false)
        {
            using (var csvParser = new Microsoft.VisualBasic.FileIO.TextFieldParser(path))
            {
                csvParser.CommentTokens = new string[] { commentToken };
                csvParser.SetDelimiters(new string[] { delimiter });
                csvParser.HasFieldsEnclosedInQuotes = quotes;

                if (header)
                {
                    csvParser.ReadLine();
                }

                var data = new List <double[]>();

                while (!csvParser.EndOfData)
                {
                    // Read current line fields, pointer moves to the next line.
                    string[] fields = csvParser.ReadFields();
                    data.Add(new double[fields.Length]);

                    for (int i = 0; i < fields.Length; i++)
                    {
                        data[data.Count - 1][i] = Convert.ToDouble(fields[i]);
                    }
                }

                double[,] newData = new double[data.Count, data[0].Length];

                for (int i = 0; i < newData.GetLength(0); i++)
                {
                    for (int j = 0; j < newData.GetLength(1); j++)
                    {
                        newData[i, j] = data[i][j];
                    }
                }

                return(newData);
            }
        }
        public static List <JRM.mSheetMaker.structSheet> ReadCSV(string filePathName, bool hasHeaders)
        {
            List <JRM.mSheetMaker.structSheet> sheetList = new List <JRM.mSheetMaker.structSheet>();

            using (Microsoft.VisualBasic.FileIO.TextFieldParser MyReader = new Microsoft.VisualBasic.FileIO.TextFieldParser(filePathName)) {
                MyReader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited;
                MyReader.Delimiters    = new string[] { "," };
                string[] currentRow = null;

                //if CSV file has headers then discard first line
                if (hasHeaders == true)
                {
                    MyReader.ReadLine().Skip(1);
                }

                while (!MyReader.EndOfData)
                {
                    try {
                        currentRow = MyReader.ReadFields();

                        //create temp sheet

                        JRM.mSheetMaker.structSheet curSheet = new JRM.mSheetMaker.structSheet();
                        curSheet.sheetNum  = currentRow[0];
                        curSheet.sheetName = currentRow[1];
                        curSheet.viewName  = currentRow[2];

                        //add sheet to list
                        sheetList.Add(curSheet);
                    } catch (Microsoft.VisualBasic.FileIO.MalformedLineException ex) {
                        Debug.Print("Line " + ex.Message + " is invalid.  Skipping");
                    }
                }

                return(sheetList.ToList());
            }
        }
Exemple #7
0
 /// <summary>
 /// Read the file and save it in a list. Nothing clever here.
 /// </summary>
 /// <param name="filepath"></param>
 private void ParseFile(string filepath)
 {
     using (StreamReader reader = new StreamReader(filepath))
     {
         using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(reader))
         {
             parser.SetDelimiters(",");
             parser.ReadLine();
             while (!parser.EndOfData)
             {
                 var      line     = parser.ReadFields();
                 LineType type     = (LineType)Enum.Parse(typeof(LineType), line[0], true);
                 string   name     = line[1];
                 string   rootname = line[11];
                 double   incl     = Convert.ToDouble(line[4]);
                 double   excl     = Convert.ToDouble(line[5]);
                 Line     l        = new Line(name, incl, excl, type, rootname);
                 if (l.Type == LineType.Callee)
                 {
                     callees.Add(l);
                 }
                 else if (l.Type == LineType.Caller)
                 {
                     callers.Add(l);
                 }
                 else if (l.Type == LineType.Root)
                 {
                     roots.Add(l);
                 }
                 else
                 {
                     Debug.Assert(false, "Invalid Line Type");
                 }
             }
         }
     }
 }
Exemple #8
0
 /// <summary>
 /// Read data from SWAT output file using TextFieldParser
 /// </summary>
 /// <remarks>
 /// 1. Need to know the number and width of columns
 /// 2. Doesn't support select partial data
 /// </remarks>
 static void TestExtractFromText_TextFieldParser(string filePah)
 {
     Console.WriteLine("TextFieldParser");
     DateTime before = DateTime.Now;
     using (Microsoft.VisualBasic.FileIO.TextFieldParser reader =
         new Microsoft.VisualBasic.FileIO.TextFieldParser(filePah))
     {
         reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.FixedWidth;
         reader.SetFieldWidths(6,4,10,4,
             10,10,10,10,10,10,10,10,10,10,
             10,10,10,10,10,10,10,10,10,11,
             10,10,10,6);
         string[] currentRow = null;
         int i = 0;
         //ignore the first 9 lines
         while (!reader.EndOfData && i<9)
         {
             reader.ReadLine();
             i++;
         }
         while(!reader.EndOfData)
            {
                currentRow = reader.ReadFields();
            }
     }
     DateTime after = DateTime.Now;
     Console.WriteLine(string.Format("******\nTime Used: {0} seconds\n******", after.Subtract(before).TotalSeconds));
 }
Exemple #9
0
        private bool InitializeData()
        {
            try
            {
                using (System.IO.StreamReader sr = new System.IO.StreamReader(
                    Application.StartupPath + "/shared/quirk/quirk_library.json"))
                {
                    quirk_data = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonQuirkData>(sr.ReadToEnd());
                    quirks = quirk_data.quirks.ToList();
                    sr.Close();
                }

                using (System.IO.FileStream fs = System.IO.File.OpenRead(
                    Application.StartupPath + "/curios/curio_type_library.csv"))
                using (Microsoft.VisualBasic.FileIO.TextFieldParser parser =
                    new Microsoft.VisualBasic.FileIO.TextFieldParser(fs))
                {
                    List<string> curiotypes = new List<string>();
                    int i = 0;

                    parser.Delimiters = new[] { "," };
                    while (!parser.EndOfData)
                    {
                        if (parser.ReadFields()[1] != "")
                        {
                            for (i = 0; i < 7; i++)
                            {
                                if (!parser.EndOfData)
                                {
                                    parser.ReadLine();
                                }
                                else break;
                            }

                            curiotypes.Add(parser.ReadFields()[2]);
                        }
                    }

                    cbx_curiotags.Items.Add("(none)");
                    cbx_curiotags.Items.AddRange(
                        curiotypes.Select(a => a).Distinct().OrderBy(b => b).ToArray());

                    parser.Close();
                }

                using (System.IO.StreamReader sr = new System.IO.StreamReader(
                    Application.StartupPath + "/shared/buffs/buff_library.json"))
                {
                    buff_data = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonBuffData>(sr.ReadToEnd());

                    lbx_buffroster.Items.AddRange(
                        buff_data.buffs.Select(
                            a => a.id)
                            .Distinct()
                            .OrderBy(b => b)
                            .ToArray());

                    sr.Close();
                }

                descriptions = XDocument.Load(
                    Application.StartupPath + "/localization/quirks.string_table.xml");

                dialogue = XDocument.Load(
                    Application.StartupPath + "/localization/dialogue.string_table.xml");

                return true;
            }
            catch //(Exception ex)
            {
                MessageBox.Show("Move this application to your game's installation folder\nor varify your game cache.", "Error");

                //System.Diagnostics.Debug.WriteLine(ex);
            }

            return false;
        }