yatta
yatta
CC#
Created by yatta on 10/22/2024 in #help
Metro MahApps checkbox content change color when hovered.
No description
2 replies
CC#
Created by yatta on 9/27/2024 in #help
Powershell script to automate run exe file
No description
6 replies
CC#
Created by yatta on 9/24/2024 in #help
ServiceController refuse to run on window platform
No description
2 replies
CC#
Created by yatta on 9/4/2024 in #help
✅ ObservableCollection.Add() takes too long.
No description
8 replies
CC#
Created by yatta on 7/4/2024 in #help
Cannot use AvalonDock Metro theme for ResourceDictionary after upgraded to .net5
I have a Styling library with the ResourceDictionary like this:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Cobalt.xaml" />
<ResourceDictionary Source="pack://application:,,,/Xceed.Wpf.AvalonDock.Themes.Metro;component/Theme.xaml"/>
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Cobalt.xaml" />
<ResourceDictionary Source="pack://application:,,,/Xceed.Wpf.AvalonDock.Themes.Metro;component/Theme.xaml"/>
</ResourceDictionary.MergedDictionaries>
After I upgraded my application to .net5 and migrated to MahAppsv2. I got the error: FileNotFoundException: Could not load file or assembly 'Xceed.Wpf.AvalonDock.Themes.Metro, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. I need to fix this so I can get my desired UI for my application, could anyone give me some suggestions ?
1 replies
CC#
Created by yatta on 6/20/2024 in #help
UI modification
No description
3 replies
CC#
Created by yatta on 3/6/2024 in #help
Frontend not working
No description
32 replies
CC#
Created by yatta on 1/23/2024 in #help
Seeding data from csv file
I have a model like this:
public class Record
{
public int Id { get; set; }
public long caller_id { get; set; }
public long recipient { get; set; }
public DateTime call_date { get; set; }
public DateTime endtime { get; set; }
public int duration { get; set; }
public double cost { get; set; }
public string reference { get; set; }
public string currency { get; set; }
}
public class Record
{
public int Id { get; set; }
public long caller_id { get; set; }
public long recipient { get; set; }
public DateTime call_date { get; set; }
public DateTime endtime { get; set; }
public int duration { get; set; }
public double cost { get; set; }
public string reference { get; set; }
public string currency { get; set; }
}
I try to seeding data from my csv file like this:
public void SeedDataContext()
{
if (!_ctx.Record.Any())
{
var filePath = "C:/techtest_cdr.csv";

var csvData = System.IO.File.ReadAllLines(filePath).Skip(1);

var datas = new List<Record>();

foreach (var line in csvData)
{
var values = line.Split(',');

var record = new Record
{
caller_id = long.Parse(values[0]),
recipient = long.Parse(values[1]),
call_date = DateTime.ParseExact(values[2], "dd/MM/yyyy",CultureInfo.InvariantCulture),
endtime = DateTime.ParseExact(values[3], "HH/mm/ss", CultureInfo.InvariantCulture),
duration = int.Parse(values[4]),
cost = double.Parse(values[5]),
reference = values[6],
currency = values[7].ToUpper()
};

datas.Add(record);
}

_ctx.Record.AddRange(datas);
_ctx.SaveChanges();
}
}
public void SeedDataContext()
{
if (!_ctx.Record.Any())
{
var filePath = "C:/techtest_cdr.csv";

var csvData = System.IO.File.ReadAllLines(filePath).Skip(1);

var datas = new List<Record>();

foreach (var line in csvData)
{
var values = line.Split(',');

var record = new Record
{
caller_id = long.Parse(values[0]),
recipient = long.Parse(values[1]),
call_date = DateTime.ParseExact(values[2], "dd/MM/yyyy",CultureInfo.InvariantCulture),
endtime = DateTime.ParseExact(values[3], "HH/mm/ss", CultureInfo.InvariantCulture),
duration = int.Parse(values[4]),
cost = double.Parse(values[5]),
reference = values[6],
currency = values[7].ToUpper()
};

datas.Add(record);
}

_ctx.Record.AddRange(datas);
_ctx.SaveChanges();
}
}
When I run the program, I got the error: Unhandled exception. System.FormatException: String '' was not recognized as a valid DateTime. The format for date time for call_date in my csv file is dd/mm/yyyy. The format for endtime in my csv file is HH/mm/ss.
22 replies
CC#
Created by yatta on 1/22/2024 in #help
HTTPPut url
No description
5 replies
CC#
Created by yatta on 1/11/2024 in #help
The value '' is invalid. for primary key in MVC
No description
24 replies
CC#
Created by yatta on 12/25/2023 in #help
Add new field in ASP.Net
So im learning ASP.Net from Microsoft doc, and when I com to this documentation: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/new-field?view=aspnetcore-8.0&tabs=visual-studio I've done everything the doc said, but the Rating doesn't show anything. When I think it suppose to display the Rating "R" when I hardcoded it in the program. Also, the doc says I should able to perform other CRUD command with the Rating attribute, but I can't at all. Is it like how it suppose to work, or I actually have done something wrong ?
4 replies
CC#
Created by yatta on 10/9/2023 in #help
❔ Interview preparation
No description
15 replies
CC#
Created by yatta on 8/26/2023 in #help
❔ Cannot create a .net core application
22 replies
CC#
Created by yatta on 6/6/2023 in #help
❔ What could possibly be the reason when I run database -update but no tabled added ?
10 replies
CC#
Created by yatta on 2/4/2023 in #help
Fibonacci in recursive ?
127 replies
CC#
Created by yatta on 11/14/2022 in #help
❔ How to get an attribute from xml file
7 replies
CC#
Created by yatta on 11/10/2022 in #help
❔ How to write Process name into XML file ?
I try to write my Process name into xml file like this:
foreach(var process in Process.GetProcessesByName(ProcessName))
{
XmlNode startTimeNode = processedData.CreateElement("StartTime");
startTimeNode.AppendChild(processedData.CreateTextNode(process.StartTime.ToString()));
processNode.AppendChild(startTimeNode);
}
foreach(var process in Process.GetProcessesByName(ProcessName))
{
XmlNode startTimeNode = processedData.CreateElement("StartTime");
startTimeNode.AppendChild(processedData.CreateTextNode(process.StartTime.ToString()));
processNode.AppendChild(startTimeNode);
}
but when I try to run the code, it skip the process name for first 2 records, and only from 3rd record onwards, it write down enough information of it.
3 replies
CC#
Created by yatta on 11/10/2022 in #help
❔ How to set a time interval in a timer ?
This is the class:
public string ProcessName { get; set; }
public int MaximumLifeTime { get; set; }
public int Frequency { get; set; }
public ProcessKiller(string name, int maximumLifeTime, int frequency)
{
this.ProcessName = name;
this.MaximumLifeTime = maximumLifeTime;
this.Frequency = frequency;
}
public bool KillProcess()
{
TimeSpan lifeTime = default;

foreach (var process in Process.GetProcessesByName(ProcessName))
{
lifeTime = DateTime.Now - process.StartTime;
if (lifeTime.TotalMinutes >= MaximumLifeTime)
{
process.Kill();
WriteLog();
}
}

return true;
}
public string ProcessName { get; set; }
public int MaximumLifeTime { get; set; }
public int Frequency { get; set; }
public ProcessKiller(string name, int maximumLifeTime, int frequency)
{
this.ProcessName = name;
this.MaximumLifeTime = maximumLifeTime;
this.Frequency = frequency;
}
public bool KillProcess()
{
TimeSpan lifeTime = default;

foreach (var process in Process.GetProcessesByName(ProcessName))
{
lifeTime = DateTime.Now - process.StartTime;
if (lifeTime.TotalMinutes >= MaximumLifeTime)
{
process.Kill();
WriteLog();
}
}

return true;
}
And this is the Main class that calls the class
public class Program
{
public static int MinuteCount { get; set; }
public static void Main(string[] args)
{
string name = args[0];
int maxLifeTime = Convert.ToInt32(args[1]);
int freq = Convert.ToInt32(args[2]);
var killer = new ProcessKiller(name, maxLifeTime, freq);

//Rerun the function after every "intervalTime" minute
var timer = new System.Timers.Timer(freq * 60000);
timer.Elapsed += (s, e) =>
{
killer.KillProcess();
MinuteCount++;
if (MinuteCount == 1)
{
Console.WriteLine("One minute passed !");
MinuteCount = 0;
}
};
//timer.Elapsed += Timer_Elapsed;
timer.Enabled = true;
timer.AutoReset = true;
timer.Start();
Console.WriteLine("Press any key to stop the program");
Console.ReadKey();
}

}
public class Program
{
public static int MinuteCount { get; set; }
public static void Main(string[] args)
{
string name = args[0];
int maxLifeTime = Convert.ToInt32(args[1]);
int freq = Convert.ToInt32(args[2]);
var killer = new ProcessKiller(name, maxLifeTime, freq);

//Rerun the function after every "intervalTime" minute
var timer = new System.Timers.Timer(freq * 60000);
timer.Elapsed += (s, e) =>
{
killer.KillProcess();
MinuteCount++;
if (MinuteCount == 1)
{
Console.WriteLine("One minute passed !");
MinuteCount = 0;
}
};
//timer.Elapsed += Timer_Elapsed;
timer.Enabled = true;
timer.AutoReset = true;
timer.Start();
Console.WriteLine("Press any key to stop the program");
Console.ReadKey();
}

}
I have my program above to check after an interval time, if a process have running longer than the allowed duration or not, and if it is the program will kill the process. The problem I got now is the time take pretty long than I expected. This is the first time I use the timer so Im sure how to adjust the time with it.
48 replies
CC#
Created by yatta on 11/8/2022 in #help
How to kill a process ?
I just know about process killing and try to test it, here is my code:
using System.Diagnostics;

var processes = Process.GetProcessesByName("Sublime Text ");
foreach(var process in processes)
{
process.Kill();
}
Console.WriteLine("Process is killed");
using System.Diagnostics;

var processes = Process.GetProcessesByName("Sublime Text ");
foreach(var process in processes)
{
process.Kill();
}
Console.WriteLine("Process is killed");
When I run the program, there's no error occurred but the Sublime Text process doesn't killed, isn't killing a process means we have it vanished in Task Manager ?. Since there is no error so I have no idea where i'm wrong
12 replies
CC#
Created by yatta on 11/4/2022 in #help
How to create a linked list ?
13 replies