Dispose() публичный Метод

public Dispose ( ) : void
Результат void
Пример #1
0
        public void CsvDisposeReader()
        {
            var sr = new StreamReader(@"CsvReader\Simple.csv");
            var fr = new CsvFileReader(sr);

            fr.Dispose();
            fr.Dispose();
        }
Пример #2
0
        private static void LoadConversionDataIntoString(int year, bool yeartype)// yeartype true= nep, false = eng
        {
            int prevyear = year - 1,
                nextyear = year + 1;

            _conversionData.AppendLine("NepaliDate,EnglishDate,DaysInNepaliMonth");
            string filepath, prevYearFilepath, nextYearFilepath;

            if (yeartype)
            {
                prevYearFilepath = FileBox.GetBsDateFile(prevyear);
                filepath         = FileBox.GetBsDateFile(year);
                nextYearFilepath = FileBox.GetBsDateFile(nextyear);
            }
            else
            {
                prevYearFilepath = FileBox.GetAdDateFile(prevyear);
                filepath         = FileBox.GetAdDateFile(year);
                nextYearFilepath = FileBox.GetAdDateFile(nextyear);
            }

            List <string> columnNames = new List <string>()
            {
                "NepaliDate",
                "EnglishDate",
                "DaysInMonth"
            };


            //load the both previous year and next year data
            CsvFileReader            prevfile   = new CsvFileReader(prevYearFilepath);
            Dictionary <int, string> resultprev = prevfile.ReadFile(columnNames);

            prevfile.Dispose();
            foreach (KeyValuePair <int, string> pair in resultprev)
            {
                _conversionData.AppendLine(pair.Value);
            }


            CsvFileReader            file   = new CsvFileReader(filepath);
            Dictionary <int, string> result = file.ReadFile(columnNames);

            file.Dispose();
            foreach (KeyValuePair <int, string> pair in result)
            {
                _conversionData.AppendLine(pair.Value);
            }


            CsvFileReader            nextfile   = new CsvFileReader(nextYearFilepath);
            Dictionary <int, string> resultnext = nextfile.ReadFile(columnNames);

            nextfile.Dispose();
            foreach (KeyValuePair <int, string> pair in resultnext)
            {
                _conversionData.AppendLine(pair.Value);
            }
        }
Пример #3
0
        public void CsvOpenAndClose()
        {
            var sr = new StreamReader(@"CsvReader\Simple.csv");
            var fr = new CsvFileReader(sr);

            Assert.AreEqual(sr.EndOfStream, false);
            fr.Dispose();
        }
Пример #4
0
        public void CsvReadAllRows()
        {
            var sr = new StreamReader(@"CsvReader\Simple.csv");
            var fr = new CsvFileReader(sr);

            while (fr.ReadRow())
            {
            }
            fr.Dispose();
        }
Пример #5
0
        public void CsvMoveFile()
        {
            var sr     = new StreamReader(@"CsvReader\Move.csv");
            var fr     = new CsvFileReader(sr);
            var values = new List <string>();

            fr.Dispose();

            File.Move(@"CsvReader\Move.csv", @"CsvReader\MoveTemp.csv");
            File.Move(@"CsvReader\MoveTemp.csv", @"CsvReader\Move.csv");
        }
Пример #6
0
        public void CsvFieldCount()
        {
            var sr = new StreamReader(@"CsvReader\Simple.csv");
            var fr = new CsvFileReader(sr);

            fr.ReadRow();
            var values = fr.Values();

            Assert.AreEqual(3, values.Count);
            fr.Dispose();
        }
Пример #7
0
        public void CsvEmbeddedQuote()
        {
            var sr = new StreamReader(@"CsvReader\Simple.csv");
            var fr = new CsvFileReader(sr);

            fr.ReadRow();
            fr.ReadRow();
            fr.ReadRow();
            var values = fr.Values();

            Assert.AreEqual("Embedded \" Quote", values[1]);
            fr.Dispose();
        }
Пример #8
0
        public void CsvEmbeddedComma()
        {
            var sr = new StreamReader(@"CsvReader\Simple.csv");
            var fr = new CsvFileReader(sr);

            fr.ReadRow();
            fr.ReadRow();
            fr.ReadRow();
            var values = fr.Values();

            Assert.AreEqual(values[2], "Q;A");
            fr.Dispose();
        }
Пример #9
0
        public void CsvCommaSeperated()
        {
            var sr = new StreamReader(@"CsvReader\Comma.csv");
            var fr = new CsvFileReader(sr, fieldDelimiter: ',');

            fr.ReadRow();
            fr.ReadRow();
            var values = fr.Values();

            CollectionAssert.AreEqual(new List <string> {
                "Row1A", "Row1B", "Row1C"
            }, values);
            fr.Dispose();
        }
Пример #10
0
    public List <PlayerObject> ReturnObjects()
    {
        //Row to read values from Other files(dataset, new high score in 000001.csv)
        CsvRow readerRow;
        //Reader Object for New High Score (or old if run early)
        CsvFileReader reader = new CsvFileReader("HighScoreFile.csv");
        //Array of Player Objects to fill with readerRow's values read
        List <PlayerObject> pastPlayers = new List <PlayerObject> ();

        //Loop through the reader till the end
        while (!reader.EndOfStream)
        {
            //if (reader.BaseStream.ReadByte() == -1)
            //	break;
            //Build a new player Object to fill
            PlayerObject obj = new PlayerObject();
            //Instatiate the CsvRow
            readerRow = new CsvRow();
            //Build a string array to hold the CsvRow values
            string[] list = new string[2];
            //Read the rows and Copy the data to the array
            reader.ReadRow(readerRow);
            readerRow.CopyTo(list);
            //Check for "Player" as the first column and skip it
            if (list [0].ToString().Contains("Player"))
            {
                readerRow.Clear();
                readerRow = new CsvRow();
                list      = new string[2];
                reader.ReadRow(readerRow);
                readerRow.CopyTo(list);
            }
            //Set player names by formatting the string, and parsing to a float

            obj.setPlayerName(string.Format("{0}", list[0].ToString()));
            obj.setPoints(float.Parse(list [1]));
            //Add the player Object to the array
            pastPlayers.Add(obj);
            readerRow.Clear();
        }        //End of while loop
        reader.Dispose();
        reader.Close();

        return(pastPlayers);
    }
Пример #11
0
        public void CsvGetValue()
        {
            var sr = new StreamReader(@"CsvReader\Simple.csv");
            var fr = new CsvFileReader(sr);

            bool ok1 = fr.ReadRow();

            Assert.IsTrue(ok1, "rij 1");
            var values1 = fr.Values();

            Assert.IsNotNull(values1);
            CollectionAssert.AreEqual(new List <string> {
                "Header1", "Header2", "Header3"
            }, values1);

            bool ok2 = fr.ReadRow();

            Assert.IsTrue(ok2, "rij 2");
            var values2 = fr.Values();

            Assert.IsNotNull(values2);
            CollectionAssert.AreEqual(new List <string> {
                "Row1A", "Row1B", "Row1C"
            }, values2);

            bool ok3 = fr.ReadRow();

            Assert.IsTrue(ok3, "rij 3");
            var values3 = fr.Values();

            Assert.IsNotNull(values3);
            CollectionAssert.AreEqual(new List <string> {
                "Quotes", "Embedded \" Quote", "Q;A"
            }, values3);

            bool ok4 = fr.ReadRow();

            Assert.IsFalse(ok4, "er is geen rij 4");
            Assert.IsNull(fr.Values());

            fr.Dispose();
        }
Пример #12
0
        private void ReadWords()
        {
            using (CsvFileReader reader = new CsvFileReader(dic + ".csv"))
            {
                CsvRow row = new CsvRow();

                while (reader.ReadRow(row))
                {
                    foreach (string s in row)
                    {
                        hunspell.Add(s);
                    }
                }

                reader.Dispose();
            }
        }
Пример #13
0
        public void F_SaveLog()
        {
            //Read FILE LOG_Source
            v_FileInput = new DirectoryInfo(ConfigurationManager.AppSettings["PathInput"].ToString()).GetFiles().OrderByDescending(f => f.LastWriteTime).First();
            if (v_FileInput.Extension != ".csv")
            {
                return;
            }
            DataTable v_DT_Result = new DataTable();

            v_DT_Result.Columns.Add("Times", typeof(string));
            v_DT_Result.Columns.Add("Model", typeof(string));
            v_DT_Result.Columns.Add("Status", typeof(string));
            List <string> columns  = new List <string>();
            CsvFileReader v_Reader = WriteDatatableToFileCSV.ReadFile(v_FileInput.FullName);

            while (v_Reader.ReadRow(columns))
            {
                if (columns[0].Trim().Length > 0 && columns[1].Trim().Length > 0)
                {
                    DataRow v_Dr = v_DT_Result.NewRow();
                    v_Dr[0] = columns[1].Trim();
                    v_Dr[1] = columns[5].Trim();
                    v_Dr[2] = columns[3].Trim();
                    v_DT_Result.Rows.Add(v_Dr);
                }
            }
            v_Reader.Dispose();
            v_DT_Result.Rows.RemoveAt(0);
            v_DT_Result.Rows.RemoveAt(0);
            //Get PASS OR FAIL
            string v_Status  = "F";
            string v_Model   = string.Empty;
            string v_Serial  = string.Empty;
            string v_Station = string.Empty;

            //GET Model
            v_Model = v_DT_Result.Rows[v_DT_Result.Rows.Count - 1][1].ToString().Trim().Split('_')[1];

            //GET Serial
            v_Serial = v_DT_Result.Rows[v_DT_Result.Rows.Count - 1][1].ToString().Trim().Split('_')[0];

            //Get Status
            try
            {
                if (v_DT_Result.Rows[v_DT_Result.Rows.Count - 1][2].ToString().Trim() == "OK")
                {
                    v_Status = "P";
                }
                else
                {
                    v_Status = "F";
                }
            }
            catch { v_Status = "F"; }

            //Get Station
            try
            {
                //v_Station = Cbx_Station.SelectedValue.ToString();
            }
            catch { }


            Tbx_BarCode.Text      = v_Serial + "_" + v_Model;
            Tbx_BarCode.ForeColor = Color.Green;
            string v_TimeCurrent = DateTime.Now.ToString("yyMMddHHmmss");
            string v_FileContent = v_Model + "|" + v_Serial + "_" + v_Model + "|" + v_TimeCurrent + "|" + v_Status + "|" + v_Station;

            //Delete OLD File log
            try
            {
                bool          v_StatusOld = false;
                List <string> v_ListPaths = Directory.GetFiles(ConfigurationManager.AppSettings["PathOutput"].ToString(), "*.txt", SearchOption.AllDirectories).ToList();
                string        v_PathPASS  = "";
                string        v_PathNG    = "";
                try
                {
                    v_PathPASS = v_ListPaths.Where(p => File.ReadAllLines(p).Any(line => line.IndexOf(v_Serial + "_" + v_Model) >= 0 && line.IndexOf("|P|") >= 0 && line.IndexOf(v_Station) >= 0)).First();
                }
                catch { }
                try
                {
                    v_PathNG = v_ListPaths.Where(p => File.ReadAllLines(p).Any(line => line.IndexOf(v_Serial + "_" + v_Model) >= 0 && line.IndexOf("|F|") >= 0 && line.IndexOf(v_Station) >= 0)).First();
                }
                catch { }
                if (v_PathPASS.Trim().Length > 0)
                {
                    ControlFile.F_DeleteFile(v_PathPASS);
                    v_Total = v_Total - 1;
                    if (v_Status == "P")
                    {
                        v_Pass = v_Pass - 1;
                    }
                    else if (v_Status == "F")
                    {
                        v_Pass = v_Pass - 1;
                        v_NG   = v_NG;
                    }
                    if (v_Total < 0)
                    {
                        v_Total = 0;
                    }
                    if (v_Pass < 0)
                    {
                        v_Pass = 0;
                    }
                    if (v_NG < 0)
                    {
                        v_NG = 0;
                    }
                }
                else if (v_PathNG.Trim().Length > 0)
                {
                    ControlFile.F_DeleteFile(v_PathNG);
                    v_Total = v_Total - 1;
                    if (v_Status == "P")
                    {
                        v_Pass = v_Pass;
                        v_NG   = v_NG - 1;
                    }
                    else if (v_Status == "F")
                    {
                        v_NG = v_NG - 1;
                    }
                    if (v_Total < 0)
                    {
                        v_Total = 0;
                    }
                    if (v_Pass < 0)
                    {
                        v_Pass = 0;
                    }
                    if (v_NG < 0)
                    {
                        v_NG = 0;
                    }
                }
            }
            catch { }
            //Create NEW File log
            ControlFile.F_CreateAndWriteFile(ConfigurationManager.AppSettings["PathOutput"].ToString() + "\\" + v_TimeCurrent + "_" + v_Model.Replace(" ", "").Substring(0, 9) + ".txt", v_FileContent);

            if (v_Status == "P")
            {
                Panel_Result.BackColor = System.Drawing.Color.Blue;
                Lbl_Result.BackColor   = System.Drawing.Color.Blue;
                Lbl_Result.Text        = "PASS";
            }
            else if (v_Status == "F")
            {
                Panel_Result.BackColor = System.Drawing.Color.Red;
                Lbl_Result.BackColor   = System.Drawing.Color.Red;
                Lbl_Result.Text        = "FAIL";
            }

            //Count PCS
            F_CountModelsChecked(v_Status);
            F_LoadTotalPCS();
        }
Пример #14
0
    public void FillHighScores()
    {
        //Row to read values from Other files(dataset, new high score in 000001.csv)
        CsvRow readerRow;
        //Row to insert values into CsvFileWriter below for HighScoreFile good copy
        CsvRow row = new CsvRow();
        //Reader Object for New High Score (or old if run early)
        CsvFileReader reader = new CsvFileReader("HighScoreFile.csv");
        //Array of Player Objects to fill with readerRow's values read
        List <PlayerObject> pastPlayers = new List <PlayerObject> ();

        //Loop through the reader till the end
        while (!reader.EndOfStream)
        {
            //if (reader.BaseStream.ReadByte() == -1)
            //	break;
            //Build a new player Object to fill
            PlayerObject obj = new PlayerObject();
            //Instatiate the CsvRow
            readerRow = new CsvRow();
            //Build a string array to hold the CsvRow values
            string[] list = new string[2];
            //Read the rows and Copy the data to the array
            reader.ReadRow(readerRow);
            readerRow.CopyTo(list);
            //Check for "Player" as the first column and skip it
            if (list [0].ToString().Contains("Player"))
            {
                continue;
            }

            //Set player names by formatting the string, and parsing to a float
            obj.setPlayerName(string.Format("{0}", list[0].ToString()));
            obj.setPoints(float.Parse(list [1]));
            //Add the player Object to the array
            pastPlayers.Add(obj);
            readerRow.Clear();
        }        //End of while loop

        reader.Dispose();
        reader.Close();

        //Reader to loop through Dataset for run just taken. Keeps the values safe.
        reader = new CsvFileReader("000001.csv");

        while (!reader.EndOfStream)
        {
            PlayerObject obj = new PlayerObject();
            readerRow = new CsvRow();
            string[] list = new string[2];
            //Read the rows and Copy the data to the array
            reader.ReadRow(readerRow);
            readerRow.CopyTo(list);
            //Set player names by formatting the string, and parsing to a float
            obj.setPlayerName(string.Format("{0}", list [0].ToString()));
            obj.setPoints(float.Parse(list [1]));
            //Add the player Object to the array
            pastPlayers.Add(obj);
            readerRow.Clear();
        }

        reader.Dispose();
        reader.Close();
        //Reader to loop through Dataset given for assignment, which pulls the values
        //of the name of the commodity in the list, and the value of the commodity.
        //It has taken a shortened version, at the behest of Professor Stanley Pieda
        //when asked if I needed to keep the 100K+ file or revise it slightly.

        /*reader = new CsvFileReader ("000000.csv");
         *
         * while(!reader.EndOfStream){
         *
         *      PlayerObject obj = new PlayerObject();
         *      readerRow = new CsvRow();
         *      string[] list = new string[6];
         *
         *      reader.ReadRow (readerRow);
         *      readerRow.CopyTo(list);
         *      obj.setPlayerName(string.Format("{0}", list [2].ToString ()));
         *      obj.setPoints (float.Parse(list[5]));
         *
         *      pastPlayers.Add(obj);
         *      readerRow.Clear ();
         * }
         *
         * reader.Dispose ();
         * reader.Close ();
         */
        //CsvFileWriter Object to write the high score objects to the csv file
        CsvFileWriter writer = new CsvFileWriter("HighScoreFile.csv");

        //Adding the headers for Player and Score in the table
        row.Add(string.Format("Player"));
        row.Add(string.Format("Score"));
        //Writing it to the file, and clearing the row which was written
        writer.WriteRow(row);
        row.Clear();

        pastPlayers.Sort((x, y) => y.points.CompareTo(x.points));
        //Looping through the number of playerObjects in the List. Printing each one
        //To it's own row and clearing that row after it's written.
        for (int i = 0; i < pastPlayers.Count; i++)
        {
            row.Add(string.Format("{0}", pastPlayers[i].getPlayerName()));
            row.Add(string.Format("{0}", pastPlayers[i].getPoints()));
            writer.WriteRow(row);
            row.Clear();
        }
        //Clean up the writers
        writer.Dispose();
        writer.Close();

        //pastPlayers.Sort (0,pastPlayers.Count,pastPlayers [0].points);
    }