Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ReaderString
- {
- private static ReaderString instance;
- private List<Sup> sup;
- private List<Dep> dep;
- private ReaderString()
- {}
- public static ReaderString getInstance()
- {
- if (instance == null)
- instance = new ReaderString();
- return instance;
- }
- /// <summary>
- /// Считывание и деление строки на размеры структуры файла .sup, возврат в виде коллекции данных .sup
- /// </summary>
- /// <param name="filepath">путь к файлу</param>
- /// <returns></returns>
- public void FileToByteArraySup(string filepath)
- {
- List<Sup> list = new List<Sup>();
- using (BinaryReader binaryReader = new BinaryReader(File.Open(filepath, FileMode.Open), Encoding.GetEncoding(866)))
- {
- while (binaryReader.PeekChar() > -1)
- {
- float factor = binaryReader.ReadSingle();
- short num = binaryReader.ReadInt16();
- short size = binaryReader.ReadInt16();
- char format = binaryReader.ReadChar();
- char[] units = binaryReader.ReadChars(11);
- char[] names = binaryReader.ReadChars(21);
- string unit = new string(units);
- string name = new string(names);
- list.Add(new Sup(factor, num, size, format, unit, name));
- }
- }
- this.sup = list;
- }
- //СМОТРИ НА ДЛИНУ ВСЕЙ ЗАПИСИ В БАЙТАХ И ОТ ЭТОГО ОТТАЛКИВАЙСЯ, ДЕЛАЙ ПРОВЕРКИ
- public void FileToByteArrayDep(string filepath)
- {
- List<Dep> list = new List<Dep>();
- using (BinaryReader binaryReader = new BinaryReader(File.Open(filepath, FileMode.Open), Encoding.GetEncoding(1251)))
- {
- while (binaryReader.PeekChar() > -1)
- {
- int NumRecord = binaryReader.ReadInt32();
- ushort UniqueWell = binaryReader.ReadUInt16();
- ushort RecordLength = binaryReader.ReadUInt16();
- byte KeyField = binaryReader.ReadByte();
- byte NumAllParams = binaryReader.ReadByte();
- byte NumRef = 0;
- byte NumPar = 0;
- uint Size = 0;
- for (int i = 0; i <= NumAllParams; i++)
- {
- NumRef = binaryReader.ReadByte();
- NumPar = binaryReader.ReadByte();
- Size = binaryReader.ReadUInt32();
- }
- list.Add(new Dep(NumRecord, UniqueWell, RecordLength, KeyField, NumAllParams, NumRef, NumPar, Size));
- }
- }
- this.dep = list;
- }
- public List<Sup> function GetSup()
- {
- return this.sup;
- }
- public List<Dep> function GetSup()
- {
- return this.dep;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement