コード例 #1
0
        /// <summary>
        /// Handler open file dialog, creates stream and it's reader
        /// </summary>
        private void openFileDialog1_FileOk_1(object sender, CancelEventArgs e)
        {
            stream_container = new Streams_Container();

            stream_container.stream_reader = Stream_controler.Create_Reader(openFileDialog1.FileName);
            stream_container.base_stream   = Stream_controler.Get_Base_Stream(stream_container.stream_reader);

            stream_container.input_file_path = openFileDialog1.FileName;

            stream_exists = true;
        }
コード例 #2
0
/*
 *      /// <summary>
 *      /// Iterates through whole file and counts number of lines in it (Resets stream to origin)
 *      /// </summary>
 *     public static int Get_line_lenght(Streams_Container s_container)
 *     {
 *          int lenght = 0;
 *
 *          s_container = Move_Stream(s_container, (int)MoveMode.Start);
 *
 *          while(s_container.stream_reader.ReadLine()!=null)
 *          {
 *              lenght++;
 *          }
 *
 *          return lenght;
 *     }
 */

        public static void Generate_log(Streams_Container sc, string filename)
        {
            StreamWriter sw = sc.stream_writer;

            string line;

            long length = new System.IO.FileInfo((sc.input_file_path)).Length;

            sw.WriteLine("Big Data reader log");
            sw.WriteLine("Filename: " + filename);
            sw.WriteLine();
            sw.WriteLine(length);
            sw.WriteLine();
            sw.WriteLine("First 20 lines: ");
            sw.WriteLine();
            Stream_controler.Move_Stream(sc, (int)MoveMode.Start);
            for (int i = 0; i < 20; i++)
            {
                sw.WriteLine(sc.stream_reader.ReadLine());
            }
            sw.WriteLine();
            sw.WriteLine("Last 20 lines: ");
            sw.WriteLine();
            Stream_controler.Move_Stream(sc, (int)MoveMode.End);
            for (int i = 0; i < 20; i++)
            {
                line = sc.stream_reader.ReadLine();
                if (line == null)
                {
                    break;
                }
                sw.WriteLine(line);
            }
            sw.WriteLine();
            sw.WriteLine("End of log");

            sw.Flush();
            sw.Close();
        }
コード例 #3
0
        public static Streams_Container Move_Stream(Streams_Container s_container, int OperationType, int amount = 0)
        {
            switch (OperationType)
            {
            case (int)(MoveMode.Start):
                s_container.base_stream.Seek(0, SeekOrigin.Begin);
                s_container.stream_reader.DiscardBufferedData();
                break;

            case (int)(MoveMode.End):
                long lenght = 0;
                lenght = s_container.base_stream.Length;
                s_container.base_stream.Seek(lenght - 100, SeekOrigin.Begin);
                s_container.stream_reader.DiscardBufferedData();
                break;

            case (int)(MoveMode.Amount):
                s_container.base_stream.Seek(amount, SeekOrigin.Current);
                s_container.stream_reader.DiscardBufferedData();
                break;
            }

            return(s_container);
        }