/// <summary>
        /// Response for clients solution request
        /// </summary>
        /// <param name="networkAdapter"></param>
        /// <param name="message"></param>
        /// <param name="messageType"></param>
        /// <param name="timeout"></param>        
        public void HandleMessage(ServerNetworkAdapter networkAdapter, string message, MessageType messageType, TimeSpan timeout)
        {
            SolutionRequest request = MessageSerialization.Deserialize<SolutionRequest>(message);

            if (request == null)
                return;

            DvrpProblem.WaitEvent.WaitOne();

            if (!DvrpProblem.Problems.ContainsKey(request.Id))
            {
                DvrpProblem.WaitEvent.Set();
                return;
            }
            if (DvrpProblem.ProblemSolutions.ContainsKey(request.Id))
            {
                Solutions solution = DvrpProblem.ProblemSolutions[request.Id];

                DvrpProblem.ProblemsID.Remove(request.Id);
                DvrpProblem.Problems.Remove(request.Id);
                DvrpProblem.ProblemSolutions.Remove(request.Id);

                networkAdapter.Send(solution);
                DvrpProblem.WaitEvent.Set();
                return;
            }

            SolveRequest problem = DvrpProblem.Problems[request.Id];
            Solutions response = new Solutions();
            response.Id = request.Id;
            response.ProblemType = problem.ProblemType;
            response.CommonData = problem.Data;
            List<SolutionsSolution> solutionList = new List<SolutionsSolution>();

            if (DvrpProblem.PartialSolutions.ContainsKey(request.Id))
                solutionList.AddRange(DvrpProblem.PartialSolutions[request.Id]);

            if (DvrpProblem.PartialProblems.ContainsKey(request.Id))
                foreach (var element in DvrpProblem.PartialProblems[request.Id])
                    if (element.Value > 0)
                    {
                        SolutionsSolution sol = new SolutionsSolution();
                        sol.TaskId = element.Key.TaskId;
                        sol.Data = element.Key.Data;
                        sol.Type = SolutionsSolutionType.Ongoing;
                        solutionList.Add(sol);
                    }

            if (solutionList.Count > 0)
                response.Solutions1 = solutionList.ToArray();
            else
                response.Solutions1 = new SolutionsSolution[] { new SolutionsSolution { Data = new byte[1] } };

            networkAdapter.Send(response);
            DvrpProblem.WaitEvent.Set();
        }
        /// <summary>
        /// this will do something with final solution, e.g. printing it
        /// </summary>
        /// <param name="solution"></param>
        public void PrintSolutionResult(SolutionsSolution solution)
        {
            if (solution.Data == null)
            { 
                log.DebugFormat("Result - solution received is null");
                return;
            }

        DVRPPartialProblemInstance result = (DVRPPartialProblemInstance) _problemConverter.FromBytesArray(solution.Data);
            if (result.SolutionResult == SolutionResult.Impossible)
            {
                log.DebugFormat("Result - solution unknown - problem impossible to solve");
            }
            else if (result.SolutionResult == SolutionResult.NotSolved)
            {
                log.DebugFormat("Error of cluster computations. Cluster sent solution with field NotSolved");
            }
            else
                log.DebugFormat("Result - solution found, minimal cost = {0} ", result.PartialResult);
            return;
        }
        public void WorkProblemTimeoutTest()
        {
            var mock = new Mock <ClientNode>(MockBehavior.Default, new ClusterClient("-1",
                                                                                     -1, TcpClientAdapterFactory.Factory));

            mock.CallBase = true;
            SolutionRequest   solutionRequest = new SolutionRequest();
            SolutionsSolution solution        = new SolutionsSolution()
            {
                TimeoutOccured = true
            };

            mock.Setup(u => u.CheckComputations(solutionRequest)).Returns(
                new Solutions()
            {
                SolutionsList = new SolutionsSolution[] { solution }
            });
            var clientNode = mock.Object;

            var ret = clientNode.WorkProblem(solutionRequest);

            Assert.IsNull(ret);
        }
        public void WorkProblemGetFinalSolutionTest()
        {
            var mock = new Mock <ClientNode>(MockBehavior.Default, new ClusterClient("-1",
                                                                                     -1, TcpClientAdapterFactory.Factory));

            mock.CallBase = true;
            SolutionRequest   solutionRequest = new SolutionRequest();
            SolutionsSolution finalSolution   = new SolutionsSolution()
            {
                Type = SolutionsSolutionType.Final
            };

            mock.Setup(u => u.CheckComputations(solutionRequest)).Returns(
                new Solutions()
            {
                SolutionsList = new SolutionsSolution[] { finalSolution }
            });
            var clientNode = mock.Object;

            var ret = clientNode.WorkProblem(solutionRequest);

            Assert.AreEqual(ret, finalSolution);
        }
 internal void AddSolutionToIssue(ulong id, ulong taskId, SolutionsSolution solution)
 {
     _currentProblems[id].PartialSolutions[taskId] = solution;
     _currentProblems[id].SolutionsCount++;
 }