Exemplo n.º 1
0
        public void Cut(string mFilePath, List <FilePiece> mQueeue)
        {
            m_ThreadPieceList = mQueeue;
            m_FilePath        = mFilePath;
            // найдем все якоря, чтобы потом считывать инфу в потоках
            var anchorList = new List <long>();

            using (var reader = new FileStream(mFilePath, FileMode.Open, FileAccess.Read))
            {
                while (reader.Position < reader.Length)
                {
                    long anchor = reader.Position;
                    var  buffer = new byte[8];
                    reader.Read(buffer, 0, 8);
                    var compressedBlockLength = BitConverter.ToInt32(buffer, 4);
                    reader.Position += compressedBlockLength - 8;
                    anchorList.Add(anchor);
                }
            }

            var prop = AppPropertiesSingle.GetInstance();
            var elementsEachThread = anchorList.Count / prop.ProcessorCount;

            // распределим на разные списки для распараллеливания
            m_AnchorListThread = anchorList
                                 .Select((x, i) => new { Index = i, Value = x })
                                 .GroupBy(x => x.Index / elementsEachThread)
                                 .Select(x => x.Select(v => v.Value).ToList())
                                 .ToList();

            // параллелим процесс
            foreach (var unused in m_AnchorListThread)
            {
                m_ThreadPieceList.Add(new FilePiece(""));
                m_ProgressList.Add(1);
            }
            int pathsCount = m_AnchorListThread.Count;
            var threadList = new List <Thread>();

            for (int i = 0; i < pathsCount; i++)
            {
                threadList.Add(new Thread(CutPath));
                threadList[i].IsBackground = true;
                threadList[i].Start(i);
            }
            while (threadList.Any(w => w.IsAlive))
            {
                NotifyProgress?.Invoke(PercentageCalculate.GetPercentAverage(m_ProgressList).ToString());
                Thread.Sleep(100);
            }
            foreach (var thread in threadList)
            {
                thread.Join();
            }
        }
Exemplo n.º 2
0
        public void Cut(string mFilePath, List <FilePiece> mQueeue)
        {
            m_ThreadPieceList = mQueeue;
            m_FilePath        = mFilePath;
            // разрежем файл на части, чтобы распараллелить процесс разрезания на кусочки
            var app     = AppPropertiesSingle.GetInstance();
            var prCount = app.ProcessorCount;

            var info       = new FileInfo(mFilePath);
            var fileLength = info.Length;

            m_StreamLength = long.Parse((fileLength / prCount).ToString()) + 100;

            // параллелим процесс
            int pathsCount = prCount;

            for (int i = 0; i < prCount; i++)
            {
                m_ThreadPieceList.Add(new FilePiece(""));
                m_ProgressList.Add(1);
            }
            var threadList = new List <Thread>();

            for (int i = 0; i < pathsCount; i++)
            {
                threadList.Add(new Thread(CutPath));
                threadList[i].IsBackground = true;
                threadList[i].Start(i);
            }
            while (threadList.Any(w => w.IsAlive))
            {
                NotifyProgress?.Invoke(PercentageCalculate.GetPercentAverage(m_ProgressList).ToString());
                Thread.Sleep(100);
            }
            foreach (var thread in threadList)
            {
                thread.Join();
            }
        }