示例#1
0
 private SolutionDTO BindSolution(SqlDataReader row)
 {
     var binder = solBinder;
     var item = new SolutionDTO();
     item.SolutionId = binder.GetInt(row, "SolutionId");
     item.PuzzleREF = binder.GetInt(row, "PuzzleREF");
     item.CharPath = binder.GetString(row, "CharPath");
     item.HostMachine = binder.GetString(row, "HostMachine");
     item.TotalNodes = binder.GetInt(row, "TotalNodes");
     item.TotalSecs = binder.GetDecimal(row, "TotalSecs");
     item.SolverType = binder.GetString(row, "SolverType");
     item.SolverVersionMajor = binder.GetInt(row, "SolverVersionMajor");
     item.SolverVersionMinor = binder.GetInt(row, "SolverVersionMinor");
     item.SolverDescription = binder.GetString(row, "SolverDescription");
     item.Created = binder.GetDateTime(row, "Created");
     item.Modified = binder.GetDateTime(row, "Modified");
     item.Author = binder.GetString(row, "Author");
     item.URL = binder.GetString(row, "URL");
     item.Email = binder.GetString(row, "Email");
     item.Description = binder.GetString(row, "Description");
     item.Report = binder.GetString(row, "Report");
     return item;
 }
示例#2
0
 public void Store(SolutionDTO item)
 {
     item.SolutionId = DBHelper.ExecuteScalarCommand<int>(GetConnection(),
         @"INSERT INTO [Solution]
     (PuzzleREF, CharPath, HostMachine, TotalNodes, TotalSecs, SolverType, SolverVersionMajor, SolverVersionMinor, SolverDescription,
     Created, Modified, Author, URL, Email, Description, Report ) VALUES
     (
     {1},   -- PuzzleREF
     {2},   -- CharPath
     {3},   -- HostMachine
     {4},   -- TotalNodes
     {5},   -- TotalSecs
     {6},   -- SolverType
     {7},   -- SolverVersionMajor
     {8},   -- SolverVersionMinor
     {9},   -- SolverDescription
     {10},   -- Created
     {11},   -- Modified
     {12},   -- Author
     {13},   -- URL
     {14},   -- Email
     {15},   -- Description
     {16}   -- Report
     );
     SELECT CAST(@@IDENTITY AS int);",
         item.SolutionId, item.PuzzleREF, item.CharPath, item.HostMachine, item.TotalNodes,
         item.TotalSecs, item.SolverType, item.SolverVersionMajor, item.SolverVersionMinor,
         item.SolverDescription, item.Created, item.Modified, item.Author, item.URL, item.Email,
         item.Description, item.Report);
 }
示例#3
0
 public void Update(SolutionDTO item)
 {
     DBHelper.ExecuteCommand(GetConnection(),
       @"UPDATE [Solution] SET
     [PuzzleREF]={1},		-- int NOT NULL
     [CharPath]={2},		-- nvarchar(500)
     [HostMachine]={3},		-- nvarchar(500)
     [TotalNodes]={4},		-- int NOT NULL
     [TotalSecs]={5},		-- numeric NOT NULL
     [SolverType]={6},		-- nvarchar(500)
     [SolverVersionMajor]={7},		-- int NOT NULL
     [SolverVersionMinor]={8},		-- int NOT NULL
     [SolverDescription]={9},		-- nvarchar(500)
     [Created]={10},		-- datestamp NOT NULL
     [Modified]={11},		-- datestamp NOT NULL
     [Author]={12},		-- nvarchar(500)
     [URL]={13},		-- nvarchar(500)
     [Email]={14},		-- nvarchar(500)
     [Description]={15},		-- nvarchar(500)
     [Report]={16}		-- nvarchar(500)
     WHERE SolutionId={0}",
     item.SolutionId, item.PuzzleREF, item.CharPath, item.HostMachine, item.TotalNodes,
     item.TotalSecs, item.SolverType, item.SolverVersionMajor, item.SolverVersionMinor,
     item.SolverDescription, item.Created, item.Modified, item.Author, item.URL, item.Email,
     item.Description, item.Report
     );
 }
        private void StoreSolution(ISolver solver, PuzzleDTO dto, List<Path> solutions)
        {
            var best = solutions.OrderBy(x => x.Count).First();

            var sol = new SolutionDTO()
            {
                PuzzleREF = dto.PuzzleId,
                CharPath = best.ToString(),
                Created = DateTime.Now,
                Modified = DateTime.Now,
                HostMachine = Environment.MachineName,
                SolverType = solver.GetType().Name,
                SolverVersionMajor = solver.VersionMajor,
                SolverVersionMinor = solver.VersionMinor,
                SolverDescription = solver.VersionDescription,
                TotalNodes = solver.Statistics.First().TotalNodes,
                TotalSecs = (decimal) solver.Statistics.First().DurationInSec,
            };

            var exists = Repository.GetSolutions(dto.PuzzleId);
            if (exists.Any())
            {
                var thisMachine = exists.FindAll(x => x.HostMachine == sol.HostMachine && x.SolverType == sol.SolverType);
                if (thisMachine.Any())
                {
                    var exact = thisMachine.OrderByDescending(x => x.CharPath.Length).First();
                    // Is Better
                    if (exact.TotalSecs > sol.TotalSecs)
                    {
                        // Replace
                        sol.SolutionId = exact.SolutionId;
                        sol.Created = exact.Created;
                        Repository.Update(sol);
                    }
                }
                else
                {
                    Repository.Store(sol);
                }
            }
            else
            {
                Repository.Store(sol);
            }
        }