Exemple #1
0
            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);
 }
Exemple #3
0
        protected virtual void StartWritingPerformed(object sender, string text)
        {
            var args = new RandomDataGeneratinfields
            {
                Text = text
            };

            WritingPerformed?.Invoke(sender, args);
        }
Exemple #4
0
        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);
        }
Exemple #6
0
 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!"));
     }
 }