public async Task CancelTask(int taskId)
        {
            var server = await WorkerRepository.GetServerByAssignedTaskId(taskId);

            _connectionService.SendBytes(Bytes.type["cancel_task"], server.IpAddress, server.Port);
            await TaskRepository.UpdateTaskStatus(taskId, "Disposed");
        }
        public async Task CollectResultIfReady(int taskId)
        {
            byte[] buffer = new byte[268435456];

            var server = await WorkerRepository.GetServerByAssignedTaskId(taskId);

            var task = await TaskRepository.GetTask(taskId);

            var matrix = new int[task.Size, task.Size];

            _connectionService.SendBytes(Bytes.type["collect_data"], server.IpAddress, server.Port);
            _connectionService.ReceiveBytes(ref buffer, server.IpAddress, server.Port);

            if (buffer[0] == Bytes.byteDef["ready_prefix"])
            {
                buffer = buffer.RemovePrefix();

                ByteConverter.SetMatrixFromBytes(buffer, ref matrix);

                StoreTaskResult(matrix, taskId);

                await TaskRepository.UpdateTaskStatus(taskId, "Done");

                await TaskRepository.UnAssignTask(taskId);
            }
            else if (buffer[0] == Bytes.byteDef["notyet_prefix"])
            {
                return;
            }
        }
        public async Task SendTask(int taskId)
        {
            await _locker.WaitAsync();

            try
            {
                int[,] task = await ReadStoredTask(taskId);

                byte[] matrixSize = ByteConverter.GetByteMatrixSize(task);
                byte[] matrix     = ByteConverter.GetBytes(task);
                byte[] buffer     = new byte[268435456];

                WorkerServerDto server = await WorkerRepository.GetServerByAssignedTaskId(taskId);

                matrixSize = matrixSize.AddPrefix(Bytes.byteDef["size_prefix"]);
                matrix     = matrix.AddPrefix(Bytes.byteDef["task_prefix"]);

                _connectionService.SendBytes(matrixSize, server.IpAddress, server.Port);
                _connectionService.ReceiveBytes(ref buffer, server.IpAddress, server.Port);

                _connectionService.SendBytes(matrix, server.IpAddress, server.Port);
                _connectionService.ReceiveBytes(ref buffer, server.IpAddress, server.Port);

                await TaskRepository.UpdateTaskStatus(taskId, "Working");
            }
            finally
            {
                _locker.Release();
            }
        }
        public async Task UpdateTaskProgress(int taskId)
        {
            byte[] buffer = new byte[268435456];
            var    server = await WorkerRepository.GetServerByAssignedTaskId(taskId);

            _connectionService.SendBytes(Bytes.type["progress_request"], server.IpAddress, server.Port);
            _connectionService.ReceiveBytes(ref buffer, server.IpAddress, server.Port);
            buffer = buffer.RemovePrefix();
            await TaskRepository.UpdateTaskPercent(taskId, buffer[0]);
        }