Пример #1
0
 public void Cut(string mFilePath, List <FilePiece> mQueeue)
 {
     using (var reader = new FileStream(mFilePath, FileMode.Open, FileAccess.Read))
     {
         var  counter = 0;
         long oldPs   = 0;
         while (reader.Position < reader.Length)
         {
             var buffer = new byte[8];
             //читаем заголовок файла
             reader.Read(buffer, 0, 8);
             //выбираем из прочитанного размер блока
             var compressedBlockLength = BitConverter.ToInt32(buffer, 4);
             //Console.WriteLine(compressedBlockLength);
             var comressedBytes = new byte[compressedBlockLength + 1];
             buffer.CopyTo(comressedBytes, 0);
             reader.Read(comressedBytes, 8, compressedBlockLength - 8);
             var blockSize         = BitConverter.ToInt32(comressedBytes, compressedBlockLength - 4);
             var decompressedBytes = ProcessUnPacking.ProcessArchive(comressedBytes, blockSize);
             mQueeue.Add(new FilePiece(counter, decompressedBytes));
             counter++;
             long ps = reader.Position * 100 / reader.Length;
             if (ps != oldPs)
             {
                 oldPs = ps;
                 NotifyProgress?.Invoke(ps.ToString());
             }
         }
     }
 }
Пример #2
0
 public void Cut(string mFilePath, List <FilePiece> mQueeue)
 {
     using (var reader = new BinaryReader(new FileStream(mFilePath, FileMode.Open, FileAccess.Read)))
     {
         int  counter     = 0;
         var  BUFFER_SIZE = AppPropertiesSingle.GetInstance().m_BufferSize;
         long oldPs       = 0;
         while (reader.BaseStream.Position < reader.BaseStream.Length)
         {
             reader.BaseStream.Seek(counter * BUFFER_SIZE, SeekOrigin.Begin);
             var bufferSize = BUFFER_SIZE;
             if (reader.BaseStream.Length - reader.BaseStream.Position <= BUFFER_SIZE)
             {
                 bufferSize = (int)(reader.BaseStream.Length - reader.BaseStream.Position);
             }
             var arBytes         = reader.ReadBytes(bufferSize);
             var compressedBytes = ProcessPacking.ProcessArchive(arBytes);
             mQueeue.Add(new FilePiece(counter, compressedBytes));
             counter++;
             long ps = reader.BaseStream.Position * 100 / reader.BaseStream.Length;
             if (ps != oldPs)
             {
                 NotifyProgress?.Invoke(ps.ToString());
             }
             oldPs = ps;
         }
     }
 }
Пример #3
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();
            }
        }
Пример #4
0
        public async Task <SprintNode> LoadSprintGraph(Sprint sprint)
        {
            OnProgressChanged?.Invoke($"Loading issues for {sprint}", 0);

            var cache = new ConcurrentInMemoryCache <IssueNode>();
            List <IssueNode> sprintNodes = new List <IssueNode>();

            var issues = await _jiraIssueService.GetIssues(new SearchArgs(sprint : sprint.Name));

            int processed = 0;

            foreach (var issue in issues)
            {
                OnProgressChanged?.Invoke($"Loading {issue.Key}", (decimal)processed / (decimal)issues.Length);
                sprintNodes.Add(await ConstructNode(issue, cache, sprint));
                processed++;
            }

            var unique = sprintNodes.Where(s => !sprintNodes
                                           .Any(k => k != s && k.Contains(s)))
                         .ToArray();

            return(new SprintNode(sprint, unique));
        }
Пример #5
0
        /// <summary>
        /// Run a lot of commands on one connection
        /// </summary>
        /// <param name="commands">List of commands</param>
        /// <returns>0 if there was no error, command's index if there was an error</returns>
        public override int ExecMultiple(IList <DbCommand> commands)
        {
            var index = 0;

            try
            {
                using (var conn = new SqlConnection(ConnectionString))
                {
                    if (SendStatus != null)
                    {
                        conn.InfoMessage += ConnOnInfoMessage;
                    }

                    conn.Open();

                    for (index = 0; index < commands.Count; index++)
                    {
                        if (index % NotifyProgressSteps == 0)
                        {
                            NotifyProgress?.Invoke(index);
                        }

                        var cmd = commands[index];
                        cmd.Connection = conn;
                        if (_commandTimeOut != -1)
                        {
                            cmd.CommandTimeout = _commandTimeOut;
                        }
                        //cmd.Connection.Open();
                        //cmd.ExecuteNonQuery();
                        cmd.ExecuteScalar();
                    }


                    conn.Close();

                    return(0);
                }
            }
            catch //(Exception e)
            {
                return(index);
            }
        }
Пример #6
0
        public void Collect(List <FilePiece> mQueue, string mPathToSave)
        {
            m_PathToSave = mPathToSave;

            NotifyProgress?.Invoke("Читаю свободную оперативку...");
            long freeMemory = FreeRamMemory.GetFreeRamMemoryMb() * 1024 * 1024;

            // соберем все файлы вместе
            NotifyProgress?.Invoke("Соберем все из потоков вместе...0");
            long BUFFER_SIZE = freeMemory / 4;

            if (BUFFER_SIZE > int.MaxValue)
            {
                BUFFER_SIZE = int.MaxValue - 1;
            }

            using (var outFile = new FileStream(m_PathToSave, FileMode.Append, FileAccess.Write))
            {
                int fileCount = 0;
                foreach (var threadPath in mQueue)
                {
                    fileCount++;
                    NotifyProgress?.Invoke("Соберем все из потоков вместе..." + fileCount * 100 / mQueue.Count);
                    long counter = 0;
                    using (var reader = new BinaryReader(new FileStream(threadPath.FilePath, FileMode.Open, FileAccess.Read)))
                    {
                        while (reader.BaseStream.Position < reader.BaseStream.Length)
                        {
                            reader.BaseStream.Seek(counter * BUFFER_SIZE, SeekOrigin.Begin);
                            var bufferSize = BUFFER_SIZE;
                            if (reader.BaseStream.Length - reader.BaseStream.Position <= BUFFER_SIZE)
                            {
                                bufferSize = (int)(reader.BaseStream.Length - reader.BaseStream.Position);
                            }
                            var arBytes = reader.ReadBytes((int)bufferSize);
                            outFile.Write(arBytes, 0, arBytes.Length);
                            counter++;
                        }
                    }
                    File.Delete(threadPath.FilePath);
                }
            }
        }
Пример #7
0
        public void Collect(List <FilePiece> mQueue, string mPathToSave)
        {
            long oldPs = 0;

            using (var outFile = new FileStream(mPathToSave, FileMode.Create))
            {
                int counter = 0;
                foreach (var queueOfPart in mQueue)
                {
                    var buf = queueOfPart.GetContent();
                    outFile.Write(buf, 0, buf.Length);
                    counter++;
                    long ps = counter * 100 / mQueue.Count;
                    if (ps != oldPs)
                    {
                        oldPs = ps;
                        NotifyProgress?.Invoke(ps.ToString());
                    }
                }
            }
        }
Пример #8
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();
            }
        }
        /// <summary>
        /// Run a lot of commands on one connection in order of the list
        /// </summary>
        /// <param name="commands">List of commands</param>
        /// <returns>0 if there was no error, command's index if there was an error</returns>
        public override int ExecMultiple(IList <DbCommand> commands)
        {
            var index = 0;

            try
            {
                using (var conn = new NpgsqlConnection(ConnectionString))
                {
                    conn.Open();

                    for (index = 0; index < commands.Count; index++)
                    {
                        if (index % NotifyProgressSteps == 0)
                        {
                            NotifyProgress?.Invoke(index);
                        }

                        var cmd = commands[index];
                        cmd.Connection = conn;
                        if (_commandTimeOut != -1)
                        {
                            cmd.CommandTimeout = _commandTimeOut;
                        }
                        cmd.ExecuteNonQuery();
                    }

                    conn.Close();
                }

                return(0);
            }
            catch
            {
                return(index);
            }
        }
Пример #10
0
 private static void Progress_ProgressChanged(object sender, float e)
 {
     // Console.WriteLine(e.ToString()); System.Diagnostics.Debug.WriteLine(e);
     NotifyProgress?.Invoke(e);
 }
 /// <summary>
 /// Calls <see cref="IConnManager.NotifyProgress"/> (for testing purposes only)
 /// </summary>
 public virtual void TestNotifying()
 {
     NotifyProgress?.Invoke(98);
 }