static TestBase() { Credentials data = JsonSerializer.Deserialize <Credentials>(File.ReadAllText("credentials.json")); GeocodeCredentials = new GeocodeCredentials() { Provider = GeocodeProvider.Google, ProviderKey = data.GeocodeProviderKey }; Client = new SovrenClient(data.AccountId, data.ServiceKey, new DataCenter("https://rest-local.sovren.com", "v10", true)); ParseResumeResponseValue parseResumeResponseValue = Client.ParseResume(new ParseRequest(TestData.Resume)).Result.Value; TestParsedResume = parseResumeResponseValue.ResumeData; parseResumeResponseValue = Client.ParseResume(new ParseRequest(TestData.ResumeWithAddress)).Result.Value; TestParsedResumeWithAddress = parseResumeResponseValue.ResumeData; ParseJobResponseValue parseJobResponseValue = Client.ParseJob(new ParseRequest(TestData.JobOrder)).Result.Value; TestParsedJob = parseJobResponseValue.JobData; parseJobResponseValue = Client.ParseJob(new ParseRequest(TestData.JobOrderWithAddress)).Result.Value; TestParsedJobWithAddress = parseJobResponseValue.JobData; parseJobResponseValue = Client.ParseJob(new ParseRequest(TestData.JobOrderTech)).Result.Value; TestParsedJobTech = parseJobResponseValue.JobData; }
/// <summary> /// Parses a batch of jobs /// </summary> /// <param name="apiClient">The API client to use to parse the files</param> /// <param name="parseOptions">Any parsing/indexing options</param> /// <param name="rules"> /// The rules that should be applied to whatever files are found prior to parsing. /// This is important to reduce the number of invalid parse API calls and reduce parsing costs. /// </param> /// <param name="directory">The directory containing the files to be parsed</param> /// <param name="searchOption"></param> /// <param name="successCallback">A callback for when a file is parsed successfully</param> /// <param name="partialSuccessCallback">A callback for when some error happened during/after parsing, but there is still usable data in the response</param> /// <param name="errorCallback">A callback for when an error occurred when parsing the file, and there is no usable data</param> /// <param name="generateDocumentIdFn">A callback so you can specify a DocumentId for each file that is parsed</param> /// <exception cref="SovrenInvalidBatchException">Thrown when the directory provided does not meet the <see cref="BatchParsingRules"/></exception> public static async Task ParseJobs( SovrenClient apiClient, ParseOptions parseOptions, BatchParsingRules rules, string directory, SearchOption searchOption, Func <JobBatchSuccessResult, Task> successCallback, Func <JobBatchPartialSuccessResult, Task> partialSuccessCallback, Func <BatchErrorResult, Task> errorCallback, Func <string, string> generateDocumentIdFn = null) { if (apiClient == null) { throw new ArgumentNullException(nameof(apiClient)); } IEnumerable <string> files = GetFiles(rules, directory, searchOption); //process the batch serially, since multi-threading could cause the customer to violate the AUP accidentally foreach (string file in files) { Document doc = new Document(file); string docId = generateDocumentIdFn == null?Guid.NewGuid().ToString() : generateDocumentIdFn(file); try { //set document id if we plan to index these documents if (parseOptions?.IndexingOptions != null) { parseOptions.IndexingOptions.DocumentId = docId; } ParseRequest request = new ParseRequest(doc, parseOptions); ParseJobResponse response = await apiClient.ParseJob(request); if (successCallback != null) { await successCallback(new JobBatchSuccessResult(file, docId, response)); } } catch (SovrenUsableJobException e) { //this happens when something wasn't 100% successful, but there still might be usable data if (partialSuccessCallback != null) { await partialSuccessCallback(new JobBatchPartialSuccessResult(file, docId, e)); } } catch (SovrenException e) { if (errorCallback != null) { //this happens where there is no usable data await errorCallback(new BatchErrorResult(file, docId, e)); } } } }