public string GetDomain(FileContentEntity filesContent, List <Codedentity> codes) { if (filesContent.domainCode != null) { string[] words = filesContent.domainCode.Split('.'); if (words.Length > 1) { string code = words[words.Length - 1]; if (code == "") { return(codes[0].description); } else { var result = codes.Find(x => x.code == code); return(result.description); } } else { return(codes[0].description); } } return(""); }
public string GetLanguage(FileContentEntity filesContent, List <Codedentity> codes) { if (filesContent.domainCode != null) { string[] words = filesContent.domainCode.Split('.'); if (words.Length > 1) { string code = words[words.Length - 1]; if (code == "") { return(words[0]); } else { var result = codes.Find(x => x.code == code); if (result.listSubdomains != null && result.listSubdomains.Count > 0) { var subDomain = result.listSubdomains.Find(x => x == words[0]); if (subDomain != null) { return("en"); } else { return(words[0]); } } else { return(result.code); } } } else { return(words[0]); } } else { return(""); } }
public async Task <List <FileContentEntity> > ReadFileAsync(string path, string period) { try { switch (path) { case "": throw new ArgumentException("Empty path name is not legal.", nameof(path)); case null: throw new ArgumentNullException(nameof(path)); } using var sourceStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true); using var streamReader = new StreamReader(sourceStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true); // detectEncodingFromByteOrderMarks allows you to handle files with BOM correctly. // Otherwise you may get chinese characters even when your text does not contain any int counter = 0; string line; var fileContentList = new List <FileContentEntity>(); // Read the file and display it line by line. while ((line = await streamReader.ReadLineAsync()) != null) { var fileContent = new FileContentEntity(); string[] subs = line.Split(' '); fileContent.domainCode = subs[0]; fileContent.period = period; fileContent.pageTitle = subs[1]; fileContent.viewCount = Int32.Parse(subs[2]); fileContent.size = Double.Parse(subs[3]); fileContentList.Add(fileContent); counter++; } streamReader.Close(); return(fileContentList);// } catch (Exception) { throw; } }