-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1c2552
commit a6badda
Showing
14 changed files
with
287 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
for (long q = 1; q < 100000000000; q += 5000000) | ||
{ | ||
Console.WriteLine(FormatBytes(q)); | ||
Thread.Sleep(5); | ||
} | ||
|
||
string FormatBytes(long bytes) | ||
{ | ||
string[] Suffix = { "B", "KB", "MB", "GB", "TB" }; | ||
int i; | ||
double dblSByte = bytes; | ||
for (i = 0; i < Suffix.Length && bytes >= 1024; i++, bytes /= 1024) | ||
{ | ||
dblSByte = bytes / 1024.0; | ||
} | ||
|
||
return String.Format("{0:0.##} {1}", dblSByte, Suffix[i]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
|
||
namespace UI.Models; | ||
|
||
public class ProcessDTO | ||
{ | ||
public string Name { get; set; } | ||
public long Memory { get; set; } | ||
public string MemoryStr | ||
{ | ||
get | ||
{ | ||
string[] Suffix = { "B", "KB", "MB", "GB", "TB" }; | ||
long bytes = Memory; | ||
double dblSByte = bytes; | ||
int i; | ||
|
||
for (i = 0; | ||
i < Suffix.Length && bytes >= 1024; | ||
i++, bytes /= 1024) | ||
{ | ||
dblSByte = bytes / 1024.0; | ||
} | ||
|
||
return String.Format("{0:0.#} {1}", dblSByte, Suffix[i]); | ||
} | ||
} | ||
|
||
public ProcessDTO(string name, long memory) | ||
{ | ||
Name = name; | ||
Memory = memory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using UI.Models; | ||
|
||
namespace UI.Services; | ||
|
||
public class ProcessService | ||
{ | ||
public ProcessDTO[] GetProcess() | ||
{ | ||
return MapProcesses(Process.GetProcesses()); | ||
} | ||
|
||
public ProcessDTO[] MapProcesses(Process[] p) | ||
{ | ||
ProcessDTO[] res = new ProcessDTO[p.Length]; | ||
|
||
for (int i = 0; i < p.Length; i++) | ||
{ | ||
var nP = new ProcessDTO(p[i].ProcessName, p[i].PrivateMemorySize64); | ||
res[i] = nP; | ||
} | ||
|
||
return res.OrderByDescending(x => x.Memory).ToArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UI.Models; | ||
|
||
namespace TaskManager.Services; | ||
|
||
public class Repository | ||
{ | ||
private readonly string path = Directory.GetCurrentDirectory() + @"\save.txt"; | ||
|
||
public void Save(List<TaskDTO> tasks) | ||
{ | ||
using (var sw = new StreamWriter(path)) | ||
{ | ||
sw.WriteLine(JsonConvert.SerializeObject(tasks, new JsonSerializerSettings() { Formatting = Formatting.Indented })); | ||
} | ||
} | ||
|
||
public List<TaskDTO> OnInit() | ||
{ | ||
List<TaskDTO> tasks; | ||
|
||
try | ||
{ | ||
using var sr = new StreamReader(path); | ||
tasks = JsonConvert.DeserializeObject<List<TaskDTO>>(sr.ReadToEnd(), new JsonSerializerSettings() { Formatting = Formatting.Indented })!; | ||
|
||
if (tasks.Count == 0) | ||
{ | ||
throw new Exception(); | ||
} | ||
} | ||
|
||
catch | ||
{ | ||
tasks = new List<TaskDTO> | ||
{ | ||
new TaskDTO("Opera"), | ||
new TaskDTO("Discord"), | ||
new TaskDTO("Telegram") | ||
}; | ||
|
||
using var sw = new StreamWriter(path); | ||
sw.WriteLine(JsonConvert.SerializeObject(tasks, new JsonSerializerSettings() { Formatting = Formatting.Indented })); | ||
} | ||
|
||
return tasks; | ||
} | ||
} |
Oops, something went wrong.