Exemplo n.º 1
0
        public static ICreateProblemViewModel GetProblemByType(ProblemTypes problemType)
        {
            if (!_mapping.ContainsKey(problemType))
            {
                throw new Exception($"{problemType} is not found");
            }

            return(_mapping[problemType]);
        }
Exemplo n.º 2
0
 public SolutionObject(Int32 ProblemID, Int32 SolutionID,
                       ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT,
                       string RelativePathToFile, string FileName)
 {
     this.ProblemID          = ProblemID;
     this.SolutionID         = SolutionID;
     this.PL                 = PL;
     this.TF                 = TF;
     this.PT                 = PT;
     this.RelativePathToFile = RelativePathToFile;
     this.FileName           = FileName;
 }
Exemplo n.º 3
0
        public void Test(Int32 ProblemID, Int32 SolutionID, string SolutionName,
                         ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT,
                         out TestResults Result, out int Score, out List <Tuple <long, long, TestResults> > testResults)
        {
            CanTest.Wait();
            AllDone.Reset();
            Interlocked.Increment(ref threadCount);

            logger.Debug("Start {0} thread", threadCount);
            if (logger.IsDebugEnabled)
            {
                Console.WriteLine(DateTime.Now.ToString(culture) + " - Start {0} thread", threadCount);
            }

            // TODO: FL
            Result      = TestResults.RTE;
            Score       = 0;
            testResults = null;

            logger.Trace("Start testing solution {0}", SolutionID);
            if (logger.IsTraceEnabled)
            {
                Console.WriteLine(DateTime.Now.ToString(culture) + " - Start testing solution {0}", SolutionID);
            }

            try
            {
                switch (PT)
                {
                case ProblemTypes.Standart:
                    TestStandart(ProblemID, SolutionID, SolutionName, PL, TF, out Result, out Score, out testResults);
                    break;

                case ProblemTypes.Open:
                    TestOpen(ProblemID, SolutionID, SolutionName, PL, TF, out Result, out Score);
                    break;
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error occurred on solution {0} testing: {1}", SolutionID, ex.Message);
                Console.WriteLine(DateTime.Now.ToString(culture) + " - Error occurred on solution {0} testing: {1}", SolutionID, ex.Message);
            }

            Interlocked.Decrement(ref threadCount);
            if (threadCount == 0)
            {
                AllDone.Set();
            }
        }
Exemplo n.º 4
0
        public Problem(ProblemTypes type, string description)
        {
            if (IsProblemExisting(description))
            {
                return;
            }

            Type        = type;
            Description = description;

            Log.WriteLine(Type.ToString() + ": " + description);
            Problems.Add(this);
            Program.main.AddProblem(this);
        }
Exemplo n.º 5
0
        private static void SaveSolution(byte[] Data,
                                         out int ProblemID,
                                         out int SolutionID,
                                         out string FileName,
                                         out ProgrammingLanguages PL,
                                         out TournamentFormats TF,
                                         out ProblemTypes PT)
        {
            ProblemID  = BitConverter.ToInt32(Data, 8);
            SolutionID = BitConverter.ToInt32(Data, 12);
            PL         = (ProgrammingLanguages)BitConverter.ToInt32(Data, 16);
            TF         = (TournamentFormats)BitConverter.ToInt32(Data, 20);
            PT         = (ProblemTypes)BitConverter.ToInt32(Data, 24);
            Int32 FileNameLength = BitConverter.ToInt32(Data, 28);

            FileName = Encoding.ASCII.GetString(Data, 32, FileNameLength);

            try
            {
                if (!Directory.Exists(LocalPath.SolutionsDirectory))
                {
                    Directory.CreateDirectory(LocalPath.SolutionsDirectory);
                }

                if (Directory.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString()))
                {
                    Directory.Delete(LocalPath.SolutionsDirectory + SolutionID.ToString(), true);
                }
                Directory.CreateDirectory(LocalPath.SolutionsDirectory + SolutionID.ToString());

                using (BinaryWriter bw = new BinaryWriter(
                           File.Open(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\" + FileName, FileMode.Create)))
                {
                    bw.Write(Data, FileNameLength + 32, Data.Length - FileNameLength - 32);
                }

                logger.Trace("Solution {0} saved", SolutionID);
                if (logger.IsTraceEnabled)
                {
                    Console.WriteLine(DateTime.Now.ToString(culture) + " - Solution {0} saved", SolutionID);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error occurred on solution {0} saving: {1}", SolutionID, ex.Message);
                Console.WriteLine(DateTime.Now.ToString(culture) + " - Error occurred on solution {0} saving: {1}", SolutionID, ex.Message);
            }
        }
Exemplo n.º 6
0
        public void Test(Int32 ProblemID, Int32 SolutionID, string SolutionName, 
            ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT,
            out TestResults Result, out int Score, out List<Tuple<long, long, TestResults>> testResults)
        {
            CanTest.Wait();
            AllDone.Reset();
            Interlocked.Increment(ref threadCount);

            logger.Debug("Start {0} thread", threadCount);
            if (logger.IsDebugEnabled)
                Console.WriteLine(DateTime.Now.ToString(culture) + " - Start {0} thread", threadCount);

            // TODO: FL
            Result = TestResults.RTE;
            Score = 0;
            testResults = null;

            logger.Trace("Start testing solution {0}", SolutionID);
            if (logger.IsTraceEnabled)
                Console.WriteLine(DateTime.Now.ToString(culture) + " - Start testing solution {0}", SolutionID);

            try
            {
                switch (PT)
                {
                    case ProblemTypes.Standart:
                        TestStandart(ProblemID, SolutionID, SolutionName, PL, TF, out Result, out Score, out testResults);
                        break;
                    case ProblemTypes.Open:
                        TestOpen(ProblemID, SolutionID, SolutionName, PL, TF, out Result, out Score);
                        break;

                }

            }
            catch (Exception ex)
            {
                logger.Error("Error occurred on solution {0} testing: {1}", SolutionID, ex.Message);
                Console.WriteLine(DateTime.Now.ToString(culture) + " - Error occurred on solution {0} testing: {1}", SolutionID, ex.Message);
            }

            Interlocked.Decrement(ref threadCount);
            if (threadCount == 0)
                AllDone.Set();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add solution for checking
        /// </summary>
        public void AddSolutionForChecking(Int32 problemID, Int32 solutionID,
                                           ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT,
                                           string relativePathToFile, string fileName)
        {
            lock (this._lockSolutionsQueue)
            {
                _solutionsQueue.Enqueue(new SolutionObject(problemID, solutionID, PL, TF, PT, relativePathToFile, fileName));
                _solutionAdded.Set();

                _logger.Info("Solution " + solutionID + " for problem " + problemID + " on PL " + PL + " added to queue");
            }
        }
Exemplo n.º 8
0
 public ProblemType Get(ProblemTypes type)
 {
     return(_typeRepository.Get(x => x.Type.ToString() == type.ToString()).Adapt <ProblemType>());
 }
Exemplo n.º 9
0
        private static void SaveSolution(byte[] Data, 
            out int ProblemID, 
            out int SolutionID, 
            out string FileName, 
            out ProgrammingLanguages PL,
            out TournamentFormats TF,
            out ProblemTypes PT)
        {
            ProblemID = BitConverter.ToInt32(Data, 8);
            SolutionID = BitConverter.ToInt32(Data, 12);
            PL = (ProgrammingLanguages)BitConverter.ToInt32(Data, 16);
            TF = (TournamentFormats)BitConverter.ToInt32(Data, 20);
            PT = (ProblemTypes)BitConverter.ToInt32(Data, 24);
            Int32 FileNameLength = BitConverter.ToInt32(Data, 28);
            FileName = Encoding.ASCII.GetString(Data, 32, FileNameLength);

            try
            {
                if (!Directory.Exists(LocalPath.SolutionsDirectory))
                {
                    Directory.CreateDirectory(LocalPath.SolutionsDirectory);
                }

                if (Directory.Exists(LocalPath.SolutionsDirectory + SolutionID.ToString()))
                {
                    Directory.Delete(LocalPath.SolutionsDirectory + SolutionID.ToString(), true);
                }
                Directory.CreateDirectory(LocalPath.SolutionsDirectory + SolutionID.ToString());

                using (BinaryWriter bw = new BinaryWriter(
                    File.Open(LocalPath.SolutionsDirectory + SolutionID.ToString() + "\\" + FileName, FileMode.Create)))
                {
                    bw.Write(Data, FileNameLength + 32, Data.Length - FileNameLength - 32);
                }

                logger.Trace("Solution {0} saved", SolutionID);
                if (logger.IsTraceEnabled)
                    Console.WriteLine(DateTime.Now.ToString(culture) + " - Solution {0} saved", SolutionID);
            }
            catch (Exception ex)
            {
                logger.Error("Error occurred on solution {0} saving: {1}", SolutionID, ex.Message);
                Console.WriteLine(DateTime.Now.ToString(culture) + " - Error occurred on solution {0} saving: {1}", SolutionID, ex.Message);
            }
        }
Exemplo n.º 10
0
        public static void Read(string AbsolutePathToProblemDirectory,
                                out string Name,
                                out double TimeLimit,
                                out int MemoryLimit,
                                out ProblemTypes PT,
                                out string Description,
                                out string InputFormat,
                                out string OutputFormat)
        {
            Name      = Description = InputFormat = OutputFormat = null;
            TimeLimit = MemoryLimit = -1;
            PT        = ProblemTypes.Standart;
            DateTime LastModifiedTime = DateTime.MinValue; // not used

            if (!System.IO.File.Exists(AbsolutePathToProblemDirectory + "/problem.xml"))
            {
                throw new ArgumentException(AbsolutePathToProblemDirectory + "/problem.xml not found");
            }
            if (!System.IO.File.Exists(AbsolutePathToProblemDirectory + "/Description"))
            {
                throw new ArgumentException(AbsolutePathToProblemDirectory + "/Description not found");
            }
            if (!System.IO.File.Exists(AbsolutePathToProblemDirectory + "/InputFormat"))
            {
                throw new ArgumentException(AbsolutePathToProblemDirectory + "/InputFormat not found");
            }
            if (!System.IO.File.Exists(AbsolutePathToProblemDirectory + "/OutputFormat"))
            {
                throw new ArgumentException(AbsolutePathToProblemDirectory + "/OutputFormat not found");
            }

            using (XmlReader reader = XmlReader.Create(
                       AbsolutePathToProblemDirectory + "/problem.xml"))
            {
                while (reader.Read())
                {
                    // Only detect start elements.
                    if (reader.IsStartElement())
                    {
                        // Get element name and switch on it.
                        switch (reader.Name)
                        {
                        case "Name":
                            if (reader.Read())
                            {
                                Name = reader.Value.Trim();
                            }
                            break;

                        case "LastModifiedTime":
                            if (reader.Read())
                            {
                                DateTime temp;
                                DateTime.TryParse(reader.Value.Trim(), out temp);
                                LastModifiedTime = temp;
                            }
                            break;

                        case "TimeLimit":
                            if (reader.Read())
                            {
                                double temp;
                                Double.TryParse(reader.Value.Trim(), out temp);
                                TimeLimit = temp;
                            }
                            break;

                        case "MemoryLimit":
                            if (reader.Read())
                            {
                                int temp;
                                Int32.TryParse(reader.Value.Trim(), out temp);
                                MemoryLimit = temp;
                            }
                            break;

                        case "PT":
                            if (reader.Read())
                            {
                                int temp;
                                Int32.TryParse(reader.Value.Trim(), out temp);
                                PT = (ProblemTypes)temp;
                            }
                            break;
                        }
                    }
                }
            }

            using (StreamReader sr = new StreamReader(AbsolutePathToProblemDirectory + "/Description"))
            {
                Description = sr.ReadToEnd();
            }
            using (StreamReader sr = new StreamReader(AbsolutePathToProblemDirectory + "/InputFormat"))
            {
                InputFormat = sr.ReadToEnd();
            }
            using (StreamReader sr = new StreamReader(AbsolutePathToProblemDirectory + "/OutputFormat"))
            {
                OutputFormat = sr.ReadToEnd();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Add solution for checking
        /// </summary>
        public void AddSolutionForChecking(Int32 problemID, Int32 solutionID, 
            ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT,
            string relativePathToFile, string fileName)
        {
            lock (this._lockSolutionsQueue)
            {
                _solutionsQueue.Enqueue(new SolutionObject(problemID, solutionID, PL, TF, PT, relativePathToFile, fileName));
                _solutionAdded.Set();

                _logger.Info("Solution " + solutionID + " for problem " + problemID + " on PL " + PL + " added to queue");
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Send information about solution to client.
        /// </summary>
        public void SendSolutionFile(Int32 problemID, Int32 solutionID,
                                     ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT,
                                     string relativePathToFile, string fileName)
        {
            _canSendRequest.Wait();
            ClientFreeThreadsCount--;

            string absolutePath = Path.Combine(LocalPath.RootDirectory, relativePathToFile);

            if (!File.Exists(absolutePath))
            {
                throw new FileNotFoundException(absolutePath);
            }

            string extension = Path.GetExtension(fileName);

            if (extension == "")
            {
                switch (PL)
                {
                case ProgrammingLanguages.C:
                    extension = ".c";
                    break;

                case ProgrammingLanguages.CPP:
                    extension = ".cpp";
                    break;

                case ProgrammingLanguages.CS:
                    extension = ".cs";
                    break;

                case ProgrammingLanguages.Pascal:
                    extension = ".pas";
                    break;

                case ProgrammingLanguages.Python:
                    extension = ".py";
                    break;

                case ProgrammingLanguages.VB:
                    extension = ".vb";
                    break;

                default:
                    _logger.Warn("Send solution " + solutionID + " file without extension");
                    break;
                }
            }


            string fName = PL == ProgrammingLanguages.Java ? fileName : solutionID.ToString() + extension;

            byte[] name        = Encoding.ASCII.GetBytes(fName);
            byte[] fileData    = File.ReadAllBytes(absolutePath);
            byte[] clientData  = new byte[4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + name.Length + fileData.Length];
            byte[] fileNameLen = BitConverter.GetBytes(name.Length);
            BitConverter.GetBytes(clientData.Length).CopyTo(clientData, 0);
            BitConverter.GetBytes((Int32)RequestCodes.SolutionFile).CopyTo(clientData, 4);
            BitConverter.GetBytes(problemID).CopyTo(clientData, 8);
            BitConverter.GetBytes(solutionID).CopyTo(clientData, 12);
            BitConverter.GetBytes((Int32)PL).CopyTo(clientData, 16);
            BitConverter.GetBytes((Int32)TF).CopyTo(clientData, 20);
            BitConverter.GetBytes((Int32)PT).CopyTo(clientData, 24);
            fileNameLen.CopyTo(clientData, 28);
            name.CopyTo(clientData, 32);
            fileData.CopyTo(clientData, 32 + name.Length);

            Send(clientData, clientData.Length);

            _logger.Debug(Address + ": Send solution " + solutionID + " file");
        }
Exemplo n.º 13
0
        protected void solutionChecked(byte[] data, IRepository repository)
        {
            ClientFreeThreadsCount++;
            SolutionChecked.Set();

            int solutionID = BitConverter.ToInt32(data, 8);

            _logger.Info("Begin saving solution checked info from " + Address + ", for solution " + solutionID);

            Solution solution = repository.Solutions.FirstOrDefault(s => s.SolutionID == solutionID);

            ProblemTypes pt         = (ProblemTypes)BitConverter.ToInt32(data, 12);
            TestResults  result     = (TestResults)BitConverter.ToInt32(data, 16);
            int          score      = BitConverter.ToInt32(data, 20);
            int          testsCount = BitConverter.ToInt32(data, 24);

            _logger.Debug("Received " + testsCount + " tests results");

            solution.Result = result;
            solution.Score  = score;

            if (pt == ProblemTypes.Standart)
            {
                int errorOnTest = 0;
                SolutionTestResult str;
                for (int i = 0; i < testsCount; i++)
                {
                    str = new SolutionTestResult()
                    {
                        SolutionID = solutionID,
                        Time       = BitConverter.ToInt64(data, 28 + 20 * i),
                        Memory     = BitConverter.ToInt64(data, 36 + 20 * i),
                        Result     = (TestResults)BitConverter.ToInt32(data, 44 + 20 * i)
                    };

                    if (str.Result != TestResults.OK && errorOnTest == 0)
                    {
                        errorOnTest = i + 1;
                    }

                    repository.AddSolutionTestResult(str);
                }

                solution.ErrorOnTest = errorOnTest;
            }

            if (solution.Result == TestResults.OK)
            {
                solution.User.NotSolvedProblems.Remove(solution.Problem);
                solution.User.SolvedProblems.Add(solution.Problem);
            }
            else
            {
                if (!solution.User.SolvedProblems.Contains(solution.Problem))
                {
                    solution.User.NotSolvedProblems.Add(solution.Problem);
                }
            }
            repository.SaveSolution(solution);

            _logger.Info("Solution checked info from " + Address + ", for solution " + solutionID + " saved");
            _logger.Info("Solution " + solutionID + " checked: Result " + result + ", Score " + score);
        }
Exemplo n.º 14
0
        public static void Read(string AbsolutePathToProblemDirectory,
            out string Name,
            out double TimeLimit,
            out int MemoryLimit,
            out ProblemTypes PT,
            out string Description,
            out string InputFormat,
            out string OutputFormat)
        {
            Name = Description = InputFormat = OutputFormat = null;
            TimeLimit = MemoryLimit = -1;
            PT = ProblemTypes.Standart;
            DateTime LastModifiedTime = DateTime.MinValue; // not used

            if (!System.IO.File.Exists(AbsolutePathToProblemDirectory + "/problem.xml"))
            {
                throw new ArgumentException(AbsolutePathToProblemDirectory + "/problem.xml not found");
            }
            if (!System.IO.File.Exists(AbsolutePathToProblemDirectory + "/Description"))
            {
                throw new ArgumentException(AbsolutePathToProblemDirectory + "/Description not found");
            }
            if (!System.IO.File.Exists(AbsolutePathToProblemDirectory + "/InputFormat"))
            {
                throw new ArgumentException(AbsolutePathToProblemDirectory + "/InputFormat not found");
            }
            if (!System.IO.File.Exists(AbsolutePathToProblemDirectory + "/OutputFormat"))
            {
                throw new ArgumentException(AbsolutePathToProblemDirectory + "/OutputFormat not found");
            }

            using (XmlReader reader = XmlReader.Create(
                AbsolutePathToProblemDirectory + "/problem.xml"))
            {
                while (reader.Read())
                {
                    // Only detect start elements.
                    if (reader.IsStartElement())
                    {
                        // Get element name and switch on it.
                        switch (reader.Name)
                        {
                            case "Name":
                                if (reader.Read())
                                {
                                    Name = reader.Value.Trim();
                                }
                                break;
                            case "LastModifiedTime":
                                if (reader.Read())
                                {
                                    DateTime temp;
                                    DateTime.TryParse(reader.Value.Trim(), out temp);
                                    LastModifiedTime = temp;
                                }
                                break;
                            case "TimeLimit":
                                if (reader.Read())
                                {
                                    double temp;
                                    Double.TryParse(reader.Value.Trim(), out temp);
                                    TimeLimit = temp;
                                }
                                break;
                            case "MemoryLimit":
                                if (reader.Read())
                                {
                                    int temp;
                                    Int32.TryParse(reader.Value.Trim(), out temp);
                                    MemoryLimit = temp;
                                }
                                break;
                            case "PT":
                                if (reader.Read())
                                {
                                    int temp;
                                    Int32.TryParse(reader.Value.Trim(), out temp);
                                    PT = (ProblemTypes)temp;
                                }
                                break;
                        }
                    }
                }
            }

            using (StreamReader sr = new StreamReader(AbsolutePathToProblemDirectory + "/Description"))
            {
                Description = sr.ReadToEnd();
            }
            using (StreamReader sr = new StreamReader(AbsolutePathToProblemDirectory + "/InputFormat"))
            {
                InputFormat = sr.ReadToEnd();
            }
            using (StreamReader sr = new StreamReader(AbsolutePathToProblemDirectory + "/OutputFormat"))
            {
                OutputFormat = sr.ReadToEnd();
            }
        }
Exemplo n.º 15
0
        public static void Write(string AbsolutePathToProblemDirectory,
            string Name,
            double TimeLimit,
            int MemoryLimit,
            DateTime LastModifiedTime,
            ProblemTypes PT,
            string Description,
            string InputFormat,
            string OutputFormat)
        {
            if (!Directory.Exists(AbsolutePathToProblemDirectory))
            {
                Directory.CreateDirectory(AbsolutePathToProblemDirectory);
            }

            if (File.Exists(AbsolutePathToProblemDirectory + "/problem.xml"))
                File.Delete(AbsolutePathToProblemDirectory + "/problem.xml");

            using (XmlWriter writer = XmlWriter.Create(
                AbsolutePathToProblemDirectory + "/problem.xml"))
            {
                writer.WriteStartDocument();

                writer.WriteStartElement("Problem");
                writer.WriteElementString("Name", Name);
                writer.WriteElementString("TimeLimit", TimeLimit.ToString());
                writer.WriteElementString("MemoryLimit", MemoryLimit.ToString());
                writer.WriteElementString("PT", ((int)PT).ToString());
                writer.WriteElementString("LastModifiedTime", LastModifiedTime.ToString());
                writer.WriteEndElement();

                writer.WriteEndDocument();
            }

            using (StreamWriter sw = new StreamWriter(
                AbsolutePathToProblemDirectory + "/Description", false))
            {
                if (Description != null)
                {
                    sw.WriteLine(Description.Trim());
                }
            }
            using (StreamWriter sw = new StreamWriter(
                AbsolutePathToProblemDirectory + "/InputFormat", false))
            {
                if (InputFormat != null)
                {
                    sw.WriteLine(InputFormat.Trim());
                }
            }
            using (StreamWriter sw = new StreamWriter(
                AbsolutePathToProblemDirectory + "/OutputFormat", false))
            {
                if (OutputFormat != null)
                {
                    sw.WriteLine(OutputFormat.Trim());
                }
            }
        }
Exemplo n.º 16
0
 public SolutionObject(Int32 ProblemID, Int32 SolutionID, 
     ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT,
     string RelativePathToFile, string FileName)
 {
     this.ProblemID = ProblemID;
     this.SolutionID = SolutionID;
     this.PL = PL;
     this.TF = TF;
     this.PT = PT;
     this.RelativePathToFile = RelativePathToFile;
     this.FileName = FileName;
 }
Exemplo n.º 17
0
        /// <summary>
        /// Send information about solution to client.
        /// </summary>
        public void SendSolutionFile(Int32 problemID, Int32 solutionID,
            ProgrammingLanguages PL, TournamentFormats TF, ProblemTypes PT,
            string relativePathToFile, string fileName)
        {
            _canSendRequest.Wait();
            ClientFreeThreadsCount--;

            string absolutePath = Path.Combine(LocalPath.RootDirectory, relativePathToFile);

            if (!File.Exists(absolutePath))
            {
                throw new FileNotFoundException(absolutePath);
            }

            string extension = Path.GetExtension(fileName);
            if (extension == "")
            {
                switch (PL)
                {
                    case ProgrammingLanguages.C:
                        extension = ".c";
                        break;
                    case ProgrammingLanguages.CPP:
                        extension = ".cpp";
                        break;
                    case ProgrammingLanguages.CS:
                        extension = ".cs";
                        break;
                    case ProgrammingLanguages.Pascal:
                        extension = ".pas";
                        break;
                    case ProgrammingLanguages.Python:
                        extension = ".py";
                        break;
                    case ProgrammingLanguages.VB:
                        extension = ".vb";
                        break;
                    default:
                        _logger.Warn("Send solution " + solutionID + " file without extension");
                        break;
                }
            }

            string fName = PL == ProgrammingLanguages.Java ? fileName : solutionID.ToString() + extension;
            byte[] name = Encoding.ASCII.GetBytes(fName);
            byte[] fileData = File.ReadAllBytes(absolutePath);
            byte[] clientData = new byte[4 + 4 + 4 + 4 + 4 + 4 + 4 + 4 + name.Length + fileData.Length];
            byte[] fileNameLen = BitConverter.GetBytes(name.Length);
            BitConverter.GetBytes(clientData.Length).CopyTo(clientData, 0);
            BitConverter.GetBytes((Int32)RequestCodes.SolutionFile).CopyTo(clientData, 4);
            BitConverter.GetBytes(problemID).CopyTo(clientData, 8);
            BitConverter.GetBytes(solutionID).CopyTo(clientData, 12);
            BitConverter.GetBytes((Int32)PL).CopyTo(clientData, 16);
            BitConverter.GetBytes((Int32)TF).CopyTo(clientData, 20);
            BitConverter.GetBytes((Int32)PT).CopyTo(clientData, 24);
            fileNameLen.CopyTo(clientData, 28);
            name.CopyTo(clientData, 32);
            fileData.CopyTo(clientData, 32 + name.Length);

            Send(clientData, clientData.Length);

            _logger.Debug(Address + ": Send solution " + solutionID + " file");
        }
Exemplo n.º 18
0
        public static void Write(string AbsolutePathToProblemDirectory,
                                 string Name,
                                 double TimeLimit,
                                 int MemoryLimit,
                                 DateTime LastModifiedTime,
                                 ProblemTypes PT,
                                 string Description,
                                 string InputFormat,
                                 string OutputFormat)
        {
            if (!Directory.Exists(AbsolutePathToProblemDirectory))
            {
                Directory.CreateDirectory(AbsolutePathToProblemDirectory);
            }

            if (File.Exists(AbsolutePathToProblemDirectory + "/problem.xml"))
            {
                File.Delete(AbsolutePathToProblemDirectory + "/problem.xml");
            }

            using (XmlWriter writer = XmlWriter.Create(
                       AbsolutePathToProblemDirectory + "/problem.xml"))
            {
                writer.WriteStartDocument();

                writer.WriteStartElement("Problem");
                writer.WriteElementString("Name", Name);
                writer.WriteElementString("TimeLimit", TimeLimit.ToString());
                writer.WriteElementString("MemoryLimit", MemoryLimit.ToString());
                writer.WriteElementString("PT", ((int)PT).ToString());
                writer.WriteElementString("LastModifiedTime", LastModifiedTime.ToString());
                writer.WriteEndElement();

                writer.WriteEndDocument();
            }

            using (StreamWriter sw = new StreamWriter(
                       AbsolutePathToProblemDirectory + "/Description", false))
            {
                if (Description != null)
                {
                    sw.WriteLine(Description.Trim());
                }
            }
            using (StreamWriter sw = new StreamWriter(
                       AbsolutePathToProblemDirectory + "/InputFormat", false))
            {
                if (InputFormat != null)
                {
                    sw.WriteLine(InputFormat.Trim());
                }
            }
            using (StreamWriter sw = new StreamWriter(
                       AbsolutePathToProblemDirectory + "/OutputFormat", false))
            {
                if (OutputFormat != null)
                {
                    sw.WriteLine(OutputFormat.Trim());
                }
            }
        }