Skip to content

Commit

Permalink
Document Analysy method is mark done
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdurahmon0412 committed Aug 24, 2023
1 parent 3c3fead commit e6875e9
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 6 deletions.
13 changes: 11 additions & 2 deletions Homeworks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N28_HT2", "N28_HT2\N28_HT2.
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N29", "N29", "{16C59686-F473-4CC1-8B20-BC77DCD71AF9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N29_HT1", "N29_HT1\N29_HT1.csproj", "{2134C7A8-2A49-4FBF-99A0-31C4C9F00430}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N29_HT1", "N29_HT1\N29_HT1.csproj", "{2134C7A8-2A49-4FBF-99A0-31C4C9F00430}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N29_HT2", "N29_HT2\N29_HT2.csproj", "{4C02A3B2-C889-4899-9E42-15E266F16C93}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N29_HT2", "N29_HT2\N29_HT2.csproj", "{4C02A3B2-C889-4899-9E42-15E266F16C93}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "N30", "N30", "{B205911E-8F8D-40C2-9EC1-48FAF86B101F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N30_HT1", "N30_HT1\N30_HT1.csproj", "{799244FD-D270-4279-B1CE-45490D723511}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -435,6 +439,10 @@ Global
{4C02A3B2-C889-4899-9E42-15E266F16C93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C02A3B2-C889-4899-9E42-15E266F16C93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C02A3B2-C889-4899-9E42-15E266F16C93}.Release|Any CPU.Build.0 = Release|Any CPU
{799244FD-D270-4279-B1CE-45490D723511}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{799244FD-D270-4279-B1CE-45490D723511}.Debug|Any CPU.Build.0 = Debug|Any CPU
{799244FD-D270-4279-B1CE-45490D723511}.Release|Any CPU.ActiveCfg = Release|Any CPU
{799244FD-D270-4279-B1CE-45490D723511}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -520,6 +528,7 @@ Global
{7D7BB6C9-8345-4E72-B850-964595368BD0} = {E6E92740-DD55-44C4-B9EC-6AF5A9FBE806}
{2134C7A8-2A49-4FBF-99A0-31C4C9F00430} = {16C59686-F473-4CC1-8B20-BC77DCD71AF9}
{4C02A3B2-C889-4899-9E42-15E266F16C93} = {16C59686-F473-4CC1-8B20-BC77DCD71AF9}
{799244FD-D270-4279-B1CE-45490D723511} = {B205911E-8F8D-40C2-9EC1-48FAF86B101F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8B77269B-B20D-4860-9637-2E2771096EE6}
Expand Down
29 changes: 25 additions & 4 deletions N29_HT2/EmployeeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,54 @@ public class EmployeeService
private string fileNameToken = "{{firstname}}_{lastname}}'s employment contract.docs";
public async Task HireAsync(Employee employee)
{
#region
Console.WriteLine($"HireAsync thread - {Thread.CurrentThread.ManagedThreadId}");

var fullname = employee.FirstName + employee.LastName;
var taskcofirmation = SendConfirmationEmail(employee.EmailAddress, _confirmSubject, _cofirmbody, fullname);


var taskCreatefile = CreateEmployeeFile(employee.FirstName, employee.LastName);

await Task.WhenAll(taskcofirmation);

var taskWilcomeEmail = SendWelcomeEmail(employee.EmailAddress, _welcomeEmailsubject,_welcomeEmailbody, fullname);


await Task.WhenAll(taskCreatefile);
var taskWriteFileContract = WriteFileContract(_contractText, employee.FirstName, employee.LastName);

var taskWriteFileContract = Task.Run(() => WriteFileContract(_contractText, employee.FirstName, employee.LastName));

await Task.WhenAll(taskWilcomeEmail);

var taskfinally = SendOfficePoliceEmail(employee.EmailAddress, _officeposiciesEmailSubject, _officeposiciesEmailbody, fullname);

await Task.WhenAll(taskfinally);
#endregion
}

private async Task<bool> SendConfirmationEmail(string recevieremail, string subject, string body,string fullname)
{

var result = await emailService.SendAsync(recevieremail, subject, body.Replace("{{Employee}}", fullname));
//Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
return result;
}

private async Task<FileStream> CreateEmployeeFile(string firstname,string lastname)
private Task<FileStream> CreateEmployeeFile(string firstname,string lastname)
{
var fileStream = File.Create($"{firstname}_{lastname}'s employment contract.docs");
return fileStream;
//Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
return Task.FromResult(fileStream);
}

private async Task<bool> SendWelcomeEmail(string recevemail, string subject, string body,string fullname)
{
Console.WriteLine($"SendWelcomeEmail thread before await - {Thread.CurrentThread.ManagedThreadId}");
var result = await emailService.SendAsync(recevemail, subject, body.Replace("{{Employee}}", fullname));
Console.WriteLine($"SendWelcomeEmail thread after await - {Thread.CurrentThread.ManagedThreadId}");

//Console.WriteLine(Thread.CurrentThread.ManagedThreadId);

return result;
}

Expand All @@ -92,11 +110,14 @@ private async Task WriteFileContract(string text,string firstname, string lastna
var pathreplace = $"{firstname}_{lastname}";
var path = fileNameToken.Replace("{{firstname}}_{lastname}}", pathreplace);
await File.WriteAllTextAsync(path, text);
//Console.WriteLine(Thread.CurrentThread.ManagedThreadId);

}

private async Task<bool> SendOfficePoliceEmail(string recevemail, string subject, string body, string fullname)
{
var result = await emailService.SendAsync(recevemail, subject, body.Replace("{{Employee}}", fullname));
//Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
return result;

}
Expand Down
94 changes: 94 additions & 0 deletions N30_HT1/DocumentAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace N30_HT1
{
public class DocumentAnalyzer
{
public int Analyze(string filePath)
{
int _essayScore = 100;
var Text = File.ReadAllText(filePath);
var words = Text.Split(' ');
var sentances = Text.Split('?', '.', '!');
var task1 = Task.Run(() => { ValidLenghtAsync(ref _essayScore, words); });
Task.Run(() => { OneWordCountIsValidAsync(ref _essayScore, words); });
var task2 = Task.Run(() => { SentenceOneWordIsCapitalAsync(ref _essayScore, sentances); });
var task3 = Task.Run(() => { AllwordsIscapitalAsync(ref _essayScore, sentances); });
var task4 = Task.Run(() => { AnyWordInvalidAsync(ref _essayScore, words); });

Task.WaitAll(task1, task2, task3 , task4);
return _essayScore;
}


public Task ValidLenghtAsync(ref int score , in string[] words)
{

if (words.Length < 500)
{
score -= 5;
}
return Task.FromResult(score);
}

public Task OneWordCountIsValidAsync(ref int score, string[] words)
{
var count = words.Length * 0.20F;
Dictionary<string, int> countWord = new Dictionary<string, int>();
foreach (var word in words)
{
if (!countWord.ContainsKey(word))
countWord.Add(word, 1);
else
countWord[word]++;
}

foreach (var word in countWord)
{
if (word.Value > count)
{
score -= 5;
}
}
return Task.FromResult(score);
}

public Task SentenceOneWordIsCapitalAsync(ref int score, string[] sentences)
{
foreach (var sentence in sentences)
if (!string.IsNullOrWhiteSpace(sentence) && !(sentence.Trim()[0] >= 'A' && sentence.Trim()[0] <= 'Z'))
score -= 5;
return Task.FromResult(score);
}

public Task AllwordsIscapitalAsync(ref int score, string[] sentences)
{
foreach (var sentenc in sentences)
{
var sentence = sentenc.Trim().Split(',', ' ');

for (var wordB = 1; wordB < sentence.Length; wordB++)
if (sentence[wordB] != sentence[wordB].ToLower())
{
score -= 10;
break;
}
}
return Task.FromResult(score);
}

public Task AnyWordInvalidAsync(ref int score, string[] words)
{
foreach (var word in words)
if(word.Length > 20)
score -= 20;
return Task.FromResult(score);
}
}
}
10 changes: 10 additions & 0 deletions N30_HT1/N30_HT1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
22 changes: 22 additions & 0 deletions N30_HT1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

using N30_HT1;

string InsideFile = "Loremsd;akldj;askldfdskadlkasdjf[asdkfsjafljkq[ae ipsum dolor sit amet consectetur adipisicing elit. quaerat est quas commodi quibusdam labore, nihil " +
"doloribus quam temporibus inventore optio expedita consectetur voluptatem QUIDEM nulla soluta earum. Numquam rem alias minima" +
" culpa iste distinctio. Eum similique est consequuntur minus, odio nisi recusandae iure asperiores facere, reiciendis voluptate " +
"maiores! Repellat, dolorum!";

var wait = Task.Run(() =>
{
for (int i = 1; i < 11; i++)
{
File.WriteAllText($"{i}.txt", InsideFile);
}
});

Task.WaitAll(wait);
var documentAnalyser = new DocumentAnalyzer();
for(int i = 1 ; i < 11 ; i++)
{
Console.WriteLine(documentAnalyser.Analyze($"{i}.txt"));
}

0 comments on commit e6875e9

Please sign in to comment.