/// <summary> /// Open data/map file object with accessibility test before action /// </summary> /// <param name="DigestMode"></param> /// <param name="DataRead"></param> /// <param name="DataFile"></param> /// <param name="MapFile"></param> /// <returns></returns> public bool Open(bool DigestMode, bool DataRead, string DataFile, string MapFile) { MapDummy.Clear(); OpenError = ""; ParamDigestMode = DigestMode; ParamDataRead = DataRead; ParamDataFile = DataFile; ParamMapFile = MapFile; SegmentSizeL = 0; SegmentSize = 0; SegmentCount = 0; DigestFileSize = 0; DigestSegmentSize = 0; try { if (DataFile != null) { IsDummyFile = DataFile.StartsWith(DummyFileSign, StringComparison.InvariantCulture); if (IsDummyFile) { RandomSequence_ = RandomSequence.CreateRS(DataFile.Substring(1), MailSegment.RandomCacheStep); if (RandomSequence_ == null) { throw new Exception(RandomSequence.ErrorMsg); } DummyFileSize = RandomSequence.DummyFileSize; } else { FileStream Temp = DataOpen(); if (ParamDigestMode) { if (ParamDataRead) { if (Temp.Length < 32) { if (ParamDataRead) { Temp.Close(); OpenError = "Incorrect digest file"; return(false); } else { for (int i = 0; i < DigestSize; i++) { Temp.WriteByte((byte)'_'); } Temp.Seek(0, SeekOrigin.Begin); } } else { byte[] Buf1 = new byte[16]; byte[] Buf2 = new byte[16]; Temp.Seek(0, SeekOrigin.Begin); Temp.Read(Buf1, 0, 16); Temp.Read(Buf2, 0, 16); Temp.Seek(0, SeekOrigin.Begin); try { DigestFileSize = long.Parse(MailSegment.BinToStr(Buf1), NumberStyles.HexNumber); DigestSegmentSize = int.Parse(MailSegment.BinToStr(Buf2), NumberStyles.HexNumber); } catch { Temp.Close(); OpenError = "Incorrect digest file"; return(false); } } } } Temp.Close(); } } } catch (Exception e) { OpenError = e.Message; return(false); } try { if (MapFile != null) { FileStream Temp = MapOpen(); Temp.Close(); } } catch (Exception e) { OpenError = e.Message; return(false); } return(true); }
public static RandomSequence CreateRS(string Params, int RandomCacheStep) { string[] DummyFileParamsS = Params.Split(','); int[] DummyFileParamsI = new int[DummyFileParamsS.Length - 1]; for (int i = 0; i < (DummyFileParamsS.Length - 1); i++) { try { if ((i == 0) || (DummyFileParamsI[0] != 2)) { DummyFileParamsI[i] = int.Parse(DummyFileParamsS[i + 1]); } else { DummyFileParamsI[i] = 0; string StrHex = ""; for (int ii = 0; ii < DummyFileParamsS[i + 1].Length; ii++) { string C = DummyFileParamsS[i + 1][ii].ToString().ToUpperInvariant(); if ("0123456789ABCDEF".Contains(C)) { StrHex = StrHex + C; } else { ErrorMsg = "Dummy file definition error - the sequence " + DummyFileParamsS[i + 1] + " contains invalid characters"; return(null); } } if ((StrHex.Length % 2) == 1) { DummyFileParamsS[i + 1] = "0" + StrHex; ErrorMsg = "Dummy file definition error - length of the sequence " + DummyFileParamsS[i + 1] + " must be multiply of 2"; return(null); } DummyFileParamsS[i + 1] = StrHex; } } catch { ErrorMsg = "Dummy file definition error - cannot convert " + DummyFileParamsS[i] + " to integer"; return(null); } } try { RandomSequence.DummyFileSize = long.Parse(DummyFileParamsS[0]); } catch { ErrorMsg = "Dummy file size error - cannot convert " + DummyFileParamsS[0] + " to integer"; return(null); } RandomSequence _ = null; if (DummyFileParamsI[0] == 0) { if (DummyFileParamsI.Length != 6) { ErrorMsg = "Linear congruential generator requires exactly five parameters"; return(null); } _ = new RandomSequenceLCG(RandomCacheStep); ErrorMsg = ((RandomSequenceLCG)_).Init(DummyFileParamsI[1], DummyFileParamsI[2], DummyFileParamsI[3], DummyFileParamsI[4], DummyFileParamsI[5]); } if (DummyFileParamsI[0] == 1) { if (DummyFileParamsI.Length < 6) { ErrorMsg = "Fibonacci generator requires at least five parameters"; return(null); } _ = new RandomSequenceFib(RandomCacheStep); int[] DummyFileParamsVec = new int[DummyFileParamsI.Length - 5]; for (int i = 0; i < DummyFileParamsVec.Length; i++) { DummyFileParamsVec[i] = DummyFileParamsI[i + 5]; } ErrorMsg = ((RandomSequenceFib)_).Init(DummyFileParamsI[1], DummyFileParamsI[2], DummyFileParamsI[3], DummyFileParamsI[4], DummyFileParamsVec); } if (DummyFileParamsI[0] == 2) { if (DummyFileParamsI.Length != 3) { ErrorMsg = "Digest generator requires exactly two parameters"; return(null); } _ = new RandomSequenceDigest(RandomCacheStep); ErrorMsg = ((RandomSequenceDigest)_).Init(DummyFileParamsI[1], DummyFileParamsS[2], DummyFileParamsS[3]); } if (DummyFileParamsI[0] == 3) { if ((DummyFileParamsI.Length != 1) && (DummyFileParamsI.Length != 2)) { ErrorMsg = ".NET internal generator requires no parameters or exactly one parameter"; return(null); } _ = new RandomSequenceDotNet(RandomCacheStep); if (DummyFileParamsI.Length == 1) { ErrorMsg = ((RandomSequenceDotNet)_).Init(0, true); } if (DummyFileParamsI.Length == 2) { ErrorMsg = ((RandomSequenceDotNet)_).Init(DummyFileParamsI[1], false); } } if (_ == null) { ErrorMsg = "Supported generator types: 0, 1, 2, 3"; return(null); } if (ErrorMsg != "") { return(null); } return(_); }