public void WriteBytes(string fileName, byte[] data, float percentageToFileEvent) { if (string.IsNullOrWhiteSpace(fileName)) { throw new ArgumentException(nameof(fileName)); } if (data == null) { throw new ArgumentException(nameof(data)); } if (percentageToFileEvent <= 0) { throw new ArgumentException(nameof(percentageToFileEvent)); } using (FileStream fs = File.OpenWrite(fileName)) { for (int i = 0; i < data.Length; i++) { fs.WriteByte(data[i]); if ((data[i] / 100.0 % percentageToFileEvent) == 10) //?? muthdimreminder { WritingPerformed?.Invoke(this, new WritingPerformedEventArgs(percentageToFileEvent)); } } WritingCompleted?.Invoke(this, data); } }
public void WriteBytes(string fileName, byte[] data, float percentageToFireEvent) { if (string.IsNullOrWhiteSpace(fileName)) { throw new ArgumentNullException(nameof(fileName)); } if (percentageToFireEvent < 0 && percentageToFireEvent > 1) { throw new ArgumentOutOfRangeException(nameof(percentageToFireEvent)); } if (data == null) { throw new ArgumentNullException(nameof(data)); } using var file = File.OpenWrite(fileName); for (int i = 1; i < data.Length; i++) { file.WriteByte(data[i]); float percentage = default; if (percentage <= ((i + 1) / (float)data.Length)) { percentage = i * percentageToFireEvent * 100; if (percentage < 100) { WritingPerformed?.Invoke(this, new WorkPerformedEventArgs(percentage)); } } } WritingCompleted?.Invoke(this, null); }
protected virtual void StartWritingPerformed(object sender, string text) { var args = new RandomDataGeneratinfields { Text = text }; WritingPerformed?.Invoke(sender, args); }
protected void OnWritingPerformed( object sender, double percentForNow) { var args = new WritingPerformedEventArgs { PercentForNow = percentForNow }; WritingPerformed?.Invoke(sender, args); }
protected virtual void OnWritingPerformed( object sender, int bytes) { var args = new WritingPerformedEventArgs { BytesDone = bytes }; WritingPerformed?.Invoke(sender, args); }
public void WriteBytes(string fileName, byte[] data, float percentageToFireEvent) { using (FileStream fs = File.OpenWrite(fileName)) { for (int i = 0; i <= data.Length; i++) { if (i != 0 && i % (GetNumber(data, percentageToFireEvent)) == 0) { fs.Write(data, i - (GetNumber(data, percentageToFireEvent)), (GetNumber(data, percentageToFireEvent))); WritingPerformed?.Invoke(this, new WritingPerformedEventArgs($"{fileName}", data, i / 100)); } } WritingCompleted?.Invoke(this, new WritingCompletedEventArgs("Writing Complited!")); } }