/// <summary> /// Sends a request to the moss server. /// </summary> /// <param name="data">Parameter object for the Moss request parameters</param> /// <param name="folder">Folder containing the submissions</param> /// <param name="baseFolder">Folder containing the base files</param> /// <exception href="NotSupportedException"> /// If the entered language is not supported by Moss. /// </exception> /// <exception href="FileNotFoundException"> /// IIf the submission or base file folder aren't found. /// </exception> /// <exception href="Exception"> /// If the Moss server returns a result that isn't a working link. /// </exception> /// <returns>The results URL</returns> public string SendRequest(MossData data, bool testMode = false) { data.Language = data.Language.ToLower(); if (!IsSupported(data.Language)) { throw new NotSupportedException($"The langauge {data.Language} isn't supported."); } if (!Directory.Exists(data.SubmissionsFolder)) { throw new FileNotFoundException("Submissions folder not found."); } if (!Directory.Exists(data.BaseFilesFolder) && data.BaseFilesFolder != null) { throw new FileNotFoundException("Base files folder not found."); } // Converts inapropriate values into default values data.MaxFound = (data.MaxFound < 2 ? DEF_MAX_FOUND : data.MaxFound); data.MatchesShow = (data.MatchesShow < 1 ? DEF_SHOW : data.MatchesShow); string result; sema.WaitOne(); using (MossRequestor request = new MossRequestor(data, testMode)) { request.Connect(); request.SendHeader(); request.UploadBaseFiles(); request.UploadSubmissions(); result = request.GetResult(); } sema.Release(); if (!CheckUrl(result)) { // Console.WriteLine(result); throw new Exception(result); } return(result); }
/// <summary> /// Constructor. Takes MossData object. /// </summary> /// <param name="d">The parameters of the moss request.</param> public MossRequestor(MossData d, bool test = false) { _data = d; socket = new ApiSocket(); socket.TestMode = test; }