Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. public class ReaderString
  2. {
  3. private static ReaderString instance;
  4.  
  5. private List<Sup> sup;
  6. private List<Dep> dep;
  7.  
  8. private ReaderString()
  9. {}
  10.  
  11. public static ReaderString getInstance()
  12. {
  13. if (instance == null)
  14. instance = new ReaderString();
  15. return instance;
  16. }
  17.  
  18. /// <summary>
  19. /// Считывание и деление строки на размеры структуры файла .sup, возврат в виде коллекции данных .sup
  20. /// </summary>
  21. /// <param name="filepath">путь к файлу</param>
  22. /// <returns></returns>
  23. public void FileToByteArraySup(string filepath)
  24. {
  25. List<Sup> list = new List<Sup>();
  26. using (BinaryReader binaryReader = new BinaryReader(File.Open(filepath, FileMode.Open), Encoding.GetEncoding(866)))
  27. {
  28. while (binaryReader.PeekChar() > -1)
  29. {
  30. float factor = binaryReader.ReadSingle();
  31. short num = binaryReader.ReadInt16();
  32. short size = binaryReader.ReadInt16();
  33. char format = binaryReader.ReadChar();
  34. char[] units = binaryReader.ReadChars(11);
  35. char[] names = binaryReader.ReadChars(21);
  36.  
  37. string unit = new string(units);
  38. string name = new string(names);
  39. list.Add(new Sup(factor, num, size, format, unit, name));
  40. }
  41. }
  42. this.sup = list;
  43. }
  44.  
  45. //СМОТРИ НА ДЛИНУ ВСЕЙ ЗАПИСИ В БАЙТАХ И ОТ ЭТОГО ОТТАЛКИВАЙСЯ, ДЕЛАЙ ПРОВЕРКИ
  46.  
  47. public void FileToByteArrayDep(string filepath)
  48. {
  49. List<Dep> list = new List<Dep>();
  50. using (BinaryReader binaryReader = new BinaryReader(File.Open(filepath, FileMode.Open), Encoding.GetEncoding(1251)))
  51. {
  52. while (binaryReader.PeekChar() > -1)
  53. {
  54. int NumRecord = binaryReader.ReadInt32();
  55. ushort UniqueWell = binaryReader.ReadUInt16();
  56. ushort RecordLength = binaryReader.ReadUInt16();
  57. byte KeyField = binaryReader.ReadByte();
  58. byte NumAllParams = binaryReader.ReadByte();
  59. byte NumRef = 0;
  60. byte NumPar = 0;
  61. uint Size = 0;
  62. for (int i = 0; i <= NumAllParams; i++)
  63. {
  64. NumRef = binaryReader.ReadByte();
  65. NumPar = binaryReader.ReadByte();
  66. Size = binaryReader.ReadUInt32();
  67.  
  68. }
  69.  
  70. list.Add(new Dep(NumRecord, UniqueWell, RecordLength, KeyField, NumAllParams, NumRef, NumPar, Size));
  71. }
  72. }
  73. this.dep = list;
  74. }
  75.  
  76. public List<Sup> function GetSup()
  77. {
  78. return this.sup;
  79. }
  80.  
  81. public List<Dep> function GetSup()
  82. {
  83. return this.dep;
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement