コード例 #1
0
        public static void AssertBufferFilter(int wordLength, bool removing, char[] original, FilterableBuffer primer)
        {
            var filter = new TextFilter(wordLength, removing, original.Length);

            filter.FilterBuffer(original);
            CustomAssert.AreEqual(filter, primer);
        }
コード例 #2
0
        public void Filter(object o)
        {
            var          args   = (FiltrationArgs)o;
            var          temp   = m_processes[args.ProcessID];
            StreamReader reader = null;
            StreamWriter writer = null;

            try
            {
                var targetDriveName = args.To.Split(new char[] { '\\', '/', ':' })[0];
                var freeSpace       = new DriveInfo(targetDriveName).AvailableFreeSpace;
                var fileSize        = new FileInfo(args.From).Length;
                if (freeSpace < fileSize)
                {
                    throw new Exception("Not enough space for " + args.To);
                }
                int bufferSize = (int)Math.Min(m_processRAM, fileSize);
                reader = new StreamReader(new FileStream(args.From, FileMode.Open, FileAccess.Read), Encoding.UTF8);
                writer = new StreamWriter(new FileStream(args.To, FileMode.CreateNew, FileAccess.ReadWrite), Encoding.UTF8);
                var filter    = new TextFilter(args.Length, args.Removing, bufferSize);
                int bytesRead = 0;
                while (!reader.EndOfStream)
                {
                    var readBuf = new char[bufferSize];
                    reader.Read(readBuf, 0, bufferSize);
                    bytesRead += Encoding.UTF8.GetByteCount(readBuf);
                    filter.FilterBuffer(readBuf);
                    writer.Write(filter.Buffer, 0, filter.Size);
                    int percentage = (int)((double)bytesRead * 100 / fileSize);
                    temp.Percentage = percentage;
                    if (percentage >= 100)
                    {
                        temp.IsDone = true;
                    }
                    lock (m_processesLock)
                        m_processes[args.ProcessID] = temp;
                    RaisePropertyChanged("Processes");
                }
            }
            catch (Exception ex)
            {
                temp.IsAborted = true;
                lock (m_processesLock)
                    m_processes[args.ProcessID] = temp;
                RaisePropertyChanged("Processes");
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Dispose();
                }
                if (reader != null)
                {
                    reader.Dispose();
                }
            }
        }
コード例 #3
0
        public static void AssertTwoBuffersFilter(int wordLength, bool removing, Tuple <char[], char[]> originals, Tuple <char[], char[]> primers)
        {
            var filter = new TextFilter(wordLength, removing, originals.Item1.Length);

            filter.FilterBuffer(originals.Item1);
            CustomAssert.AreEqual(filter.Buffer, primers.Item1);
            filter.FilterBuffer(originals.Item2);
            CustomAssert.AreEqual(filter.Buffer, primers.Item2);
        }