Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.IO.Compression;
- using System.IO.Packaging;
- using System.Linq;
- using System.Net;
- using System.Security.Cryptography;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Xml.Linq;
- namespace Samples {
- class Program {
- const string CandidatesFilePath = "D:\\Candidates.csv";
- const string employeesDataFilePath = "D:\\e3s.epam.com-getData.har";
- const string notDataOutputFilePath = "D:\\NotFindedEmploees.csv";
- static string employeesDataContent;
- static Dictionary<string, string> tags = new Dictionary<string, string>{
- { "M&E", "M&E CV" },
- { "Corporate", "Corporate CV" },
- { "Bulgaria", "Bulgaria CV" },
- { "Google", "Google" }
- };
- static void Main(string[] args) {
- ReadEmploeesData();
- var notFindedEmployees = new List<string>();
- foreach (var condidate in ReadCandidates().Skip(2)) {
- var fields = condidate.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- if (fields.Length != 4) continue;
- fields[0] = Regex.Replace(fields[0], "[^a-zA-Z]", " ");
- var upsaId = GetUpsaId(fields[0]);
- if (upsaId == null) { notFindedEmployees.Add(condidate); continue; }
- var tag = tags[fields[2]];
- var postData = CreatePostData(upsaId, tag);
- var coockie = GetCockie();
- MakeRequest(postData, coockie);
- }
- WriteNotFinded(notFindedEmployees);
- }
- static void ReadEmploeesData() {
- using (var reader = new StreamReader(employeesDataFilePath)) {
- employeesDataContent = reader.ReadToEnd();
- }
- }
- static IEnumerable<string> ReadCandidates() {
- using (var reader = new StreamReader(CandidatesFilePath)) {
- string line;
- while ((line = reader.ReadLine()) != null) {
- yield return line;
- }
- }
- }
- static string GetUpsaId(string name) {
- string pattern = "{\\\\\"1\\\\\":\\\\\"(?<upsaId>\\d+)\\\\\",\\\\\"2\\\\\":\\\\\"" + name + "\\\\\"";
- var regex = new Regex(pattern);
- var match = regex.Match(employeesDataContent);
- return (string.IsNullOrEmpty(match.Value)) ? null : match.Groups["upsaId"].Value;
- }
- static string GetCockie() {
- string pattern = "\"name\": \"Cookie\",\\s+?\"value\": \"(?<coockie>.*?)\"";
- var regex = new Regex(pattern);
- var match = regex.Match(employeesDataContent);
- return match.Groups["coockie"].Value;
- }
- static string CreatePostData(string upsaId, string tag) {
- var timeSpan = GetTimestamp(DateTime.Now);
- var data = "{\"deleteIds\":[],\"update\":[],\"assign\":[{\"type\":1,\"entityId\":\"" + upsaId +
- "\",\"author\":\"Aliaksandr Orgish\",\"authorId\":\"4000741400003807640\",\"isPrivate\":false,\"name\":\"" + tag +
- "\"}],\"timestamp\":" + timeSpan + "}";
- return data;
- }
- static string GetTimestamp(DateTime value) {
- return value.ToString("yyyyMMddHHmmssfff");
- }
- static void MakeRequest(string data, string coockie) {
- throw new NotImplementedException();
- }
- static void WriteNotFinded(List<string> notFindedEmployees) {
- using (var writer = new StreamWriter(notDataOutputFilePath)) {
- foreach (var employee in notFindedEmployees) {
- writer.WriteLine(employee);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement