M B V R K
M B V R K
CC#
Created by M B V R K on 8/10/2024 in #help
Cache response time issue
Hi friends, I really don't know where to start :( I'm working on a project that implemented using Microservices, one of those services called ElectionService, this service is composed from 3 main projects ( ElectionService.Infrastructure, ElectionService.CQRS and ElectionService.API) The ElectionService.CQRS is the Application layer for this service, the ElectionService.API is an ASP.Net core 8 web api that represents the entry point for this service. As you will noticed the ElectionService.CQRS (Application layer) project is implemented using CQRS pattern. Recently I tried to add the caching mechanism to this service, so I used Distributed SqlServer Cache and this is the first time I deal with it.
31 replies
CC#
Created by M B V R K on 4/17/2024 in #help
Why the shortcut of my App in the Startup Folder not starts??
Hi guys, hope you're doing well, I have a Console App, in the program.cs I have the following code:
var worker = new Worker();

try
{
// Hide the console window
FreeConsole();

var currentProcess = Process.GetCurrentProcess();
currentProcess.PriorityClass = ProcessPriorityClass.BelowNormal;

// Path to the Startup folder
string startupFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

// Path to your application executable
string appExecutablePath = Process.GetCurrentProcess().MainModule.FileName;

// Create a WshShell object
var wshShell = new WshShell();

// Create a shortcut object
IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(
Path.Combine(startupFolderPath, "MBVRK.OfficeDRPC.lnk"));

// Set the target path of the shortcut
shortcut.TargetPath = appExecutablePath;

// Save the shortcut
shortcut.Save();

worker.Start();

// Keep the app running
Thread.Sleep(Timeout.Infinite);
}
catch (Exception ex)
{
var path = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), "log.txt");

// Open or create the log file and append text to it
using (StreamWriter writer = new StreamWriter(path, true))
{
writer.WriteLine(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + ex.Message);
}
}
finally
{
Environment.Exit(0);
}
var worker = new Worker();

try
{
// Hide the console window
FreeConsole();

var currentProcess = Process.GetCurrentProcess();
currentProcess.PriorityClass = ProcessPriorityClass.BelowNormal;

// Path to the Startup folder
string startupFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

// Path to your application executable
string appExecutablePath = Process.GetCurrentProcess().MainModule.FileName;

// Create a WshShell object
var wshShell = new WshShell();

// Create a shortcut object
IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(
Path.Combine(startupFolderPath, "MBVRK.OfficeDRPC.lnk"));

// Set the target path of the shortcut
shortcut.TargetPath = appExecutablePath;

// Save the shortcut
shortcut.Save();

worker.Start();

// Keep the app running
Thread.Sleep(Timeout.Infinite);
}
catch (Exception ex)
{
var path = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), "log.txt");

// Open or create the log file and append text to it
using (StreamWriter writer = new StreamWriter(path, true))
{
writer.WriteLine(DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + ex.Message);
}
}
finally
{
Environment.Exit(0);
}
Question: Please, why my App don't start when windows starts ??? Massive thanks in advance <3
1 replies
CC#
Created by M B V R K on 4/14/2024 in #help
Why Console App don't Auto Run at Windows Startup ?
Hi guys, hope you're doing well, My question is very simple, I have a Console App, in the program.cs, in the Main method I have wrote this code :
var worker = new Worker();

try
{
// Hide the console window
FreeConsole();

var currentProcess = Process.GetCurrentProcess();
currentProcess.PriorityClass = ProcessPriorityClass.BelowNormal;

// Register the app to be auto startup
using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key?.SetValue("MBVRK.OfficeDRPC", System.Reflection.Assembly.GetExecutingAssembly().Location);
}

worker.Start();

// Keep the app running
Thread.Sleep(Timeout.Infinite);
}
catch (Exception)
{
Environment.Exit(0);
}

Environment.Exit(0);
}
var worker = new Worker();

try
{
// Hide the console window
FreeConsole();

var currentProcess = Process.GetCurrentProcess();
currentProcess.PriorityClass = ProcessPriorityClass.BelowNormal;

// Register the app to be auto startup
using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key?.SetValue("MBVRK.OfficeDRPC", System.Reflection.Assembly.GetExecutingAssembly().Location);
}

worker.Start();

// Keep the app running
Thread.Sleep(Timeout.Infinite);
}
catch (Exception)
{
Environment.Exit(0);
}

Environment.Exit(0);
}
The issue is in the part where I add the application to the auto run programs when Windows startup using Registry
using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key?.SetValue("MBVRK.OfficeDRPC", System.Reflection.Assembly.GetExecutingAssembly().Location);
}
using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key?.SetValue("MBVRK.OfficeDRPC", System.Reflection.Assembly.GetExecutingAssembly().Location);
}
But it doesn't work and the app don't run when windows statup. I go to this Registry path Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run and I found that the app registred itself as the code written but windows don't auto start it up. Please any fix for this issue? Massive thanks in advance <3
8 replies
CC#
Created by M B V R K on 4/4/2024 in #help
How to hide the Console of a Worker Service application
I have made an application of type Worker Service. using .NET 8, The issue is I want that service to run without that console. Please is there any solution for that ????
4 replies
CC#
Created by M B V R K on 4/4/2024 in #help
System.ComponentModel.Win32Exception: 'Access is denied'
Hi guys, hope you're all doing well I'm working on a project, which needs to start and kill some proccesses, the issue is an excception always thrown when try to kill processes, and the exception always said :
System.ComponentModel.Win32Exception: 'Access is denied'
This is the file I have issue in : https://github.com/MbarkT3STO/OfficeDRPC/blob/main/OfficeDRPCCommander/Worker.cs The exception always happens in this part :
process[0].Kill();
process[0].Kill();
All the apps including the app which contains the issue are Console targetting .NET Framework 4.7.2 Please any help or solution for this issue ? Massive thanks in advance, with all love and respect <3
15 replies
CC#
Created by M B V R K on 4/1/2024 in #help
Marshal.GetActiveObject("Word.Application") fall in exception
I'm working on a .NET Framework console application, I have added the Microsoft.Office.Interop.Word as a reference I have wrote a line of code that get an object from the opening instance of Microsoft Word as following :
Application wordApp = Marshal.GetActiveObject("Word.Application") as Application;
Application wordApp = Marshal.GetActiveObject("Word.Application") as Application;
The issue: When I run the application, it always throw an exception for that line as shown in the attached video Please does anyone has any idea or solution for this issue ? Massive thanks in advance <3
3 replies
CC#
Created by M B V R K on 3/28/2024 in #help
How to redirect Angular requests to ASP.NET Core backend host
Hi guys, I'm working on a project using Microservices. One of the services called FrontEndService.WEB, it is a ASP.NET Core Angular project. The general idea about the project it is that the project is a URL Shortener. In that service, exactly in the Angular part, I have a page which the user enter then write the URL then the app shorten the url perfectly, at this point everything working fine. The issue : The Asp.net core backend working on this host https://localhost:7166/ and the Angular frontend working on the https://localhost:44482/ host (they're both on the same project) The real-issue here is I want for example after shorten an url for example https://github.com/MbarkT3STO to be https://localhost:44482/udRMtM2o, now I want every request to that shortened url to redirect the user to https://localhost:7166/udRMtM2o where localhost:7166 is the host of the ASP.NET Core backend. I hope that I well cleared my idea and issue. So, please is there any way to configure the Angular part to automatically redirect any localhost:44482/shortCode to localhost:7166/shortCode??? of course except the home shortening page on localhost:44482/Shorten Please if you have any idea to solve this issue share it with me and massive thanks in advance <3
34 replies
CC#
Created by M B V R K on 3/20/2024 in #help
Github Copilot won't sign in on VS Codde
Please I'm using VS Code, While I want to sign into my GitHub Copilot account I see the option from the chat panel. but even if I click nothing happening (supposed to show me a web page for login) Please watch the attached video to understand. I hope someone to provide any help about this issue, Massive thanks in advance <3
3 replies
CC#
Created by M B V R K on 3/11/2024 in #help
Why GRPC proto services generated classes not recognizable at compile-time ?
Hi friends, I'm working on a project using Microservices architecture, I have a shared project between services called Shared.Protos, thais project contains the shared Protos files between services. I have a service called DatabaseService, it is a GRpc service project, who depends on the Shared.Protos project. As you know to make a proto grpc service you need to create a .proto file for that service which contains some definitions, then building the project and then the Grpc.Tools lib will automatically generate the classes. The problem: Everything is fine, when I build the project everything fine and good, but VS Code shows some Compile-time errors that indicate that VS Code not found the new generated files/classes related to a new created proto service, and then VS Code don't show them in the Intellisense and this annoy me. Please take a look on the attached video to understand. Note : The attached video I provided is shows the issue, but after the project built in the video the errors disappeared, but in most cases they didn't disappear till some period of time passed mostly 5 to 10 mins. Please any help to fix this issue ? <3
3 replies
CC#
Created by M B V R K on 3/6/2024 in #help
IValueResolver won't work with AutoMapper
No description
10 replies
CC#
Created by M B V R K on 2/7/2024 in #help
Is Okay to Extend the Domain Services by Application Services while implementing DDD
Hi friends, I'm implementing a project using various advanced concepts, one of these concepts is DDD (Domain Driven Design). I have these layers Domain, Infrastructure and Application layers. In the Domain layer I have some Domain Services, In the Infrastructure as everyone knows I implemented the Repositories In the Application layer I have Application Services, but here the confusing point for me, beacuse I let the Application Services to extend the Domain Services ( by the inheritance ). Example: Domain Service:
public class ExpenseService : IExpenseService
{
// Some definition goes here
}
public class ExpenseService : IExpenseService
{
// Some definition goes here
}
Application Service:
public class AppliationExpenseService : ExpenseService
{
// Some definition goes here
}
public class AppliationExpenseService : ExpenseService
{
// Some definition goes here
}
Additional info: In the Application layer I have imlemented the CQRS ( Commands and Queries ) Question: I'm confusing about letting the implementation as I showed you, or do a better approach. I asked Github Copilot and it told me that the Application layer should not directly depend on Repositories instead it should depend on Domain Services and the Domain Services should depend on Repositories. Please share with me your experience about this topic. Massive thanks in advance <3
15 replies
CC#
Created by M B V R K on 2/3/2024 in #help
Why Events Inserted Twice by EF Core?
Hi guys hope you're doing well, I'm working on the following project : https://github.com/MbarkT3STO/ExpenovaApp This project implemented using Microservices Architecture I have a service called Event-Sourcerer Service, this service is responsible about applying event-sourcing for others services databases records, of course this services communicate with others using RabbitMQ and MassTransit. You can take a look on that service here : https://github.com/MbarkT3STO/ExpenovaApp/tree/main/Source/EventSourcererService This service contains some Message Consumers ( classes where each one responsible to consume/handle a specific Queue's messages ). This service uses EF Core with PostgreSQL as data persistence. After a Servie X published an Event that happened in it, and the Event Handler from that Service X will publish a copy of that event as a Message to RabbitMQ then the Consumers from the Event-Sourcerer Service will do their job by adding the message they are responsible for into the Event-Sources database. The issue: Is my consumers adding the event to database twice To fix this issue I have created a service to handle the Deduplication mechanism as separated class called DatabaseMessageDeduplicationService you could take a look at it here : https://github.com/MbarkT3STO/ExpenovaApp/blob/main/Source/EventSourcererService/Services/DatabaseMessageDeduplicationService.cs That class DatabaseMessageDeduplicationService is responsible about processing messages too. So, for proccessing messages this class contains a method called ProccessMessage as following:
public async Task ProcessMessage(Expression<Func<Task>> processMessageFunc)
{
await processMessageFunc.Compile().Invoke();
}
public async Task ProcessMessage(Expression<Func<Task>> processMessageFunc)
{
await processMessageFunc.Compile().Invoke();
}
This method take a func/method from a consumer, that method consumer will contains the code to process the message and this DatabaseMessageDeduplicationService only invoking it.
8 replies
CC#
Created by M B V R K on 12/25/2023 in #help
Ocelot json Help needed
Hi guys, I'm working on a project using Microservices architecture, as you know with Microservices mostly we need an Api Gateway, I use Ocelot for that purpose. I have the following ocelot.json:
{
"Routes": [
{
"DownstreamPathTemplate" : "/api/Categories",
"DownstreamHostAndPorts":[
{
"Host": "localhost",
"Port": 5196,
"Scheme": "http"
}
],
"UpstreamPathTemplate": "/ExpenseService/api/Categories"
}
]
}
{
"Routes": [
{
"DownstreamPathTemplate" : "/api/Categories",
"DownstreamHostAndPorts":[
{
"Host": "localhost",
"Port": 5196,
"Scheme": "http"
}
],
"UpstreamPathTemplate": "/ExpenseService/api/Categories"
}
]
}
The issue: The issue is the categories controller will contains many actions, so I think that maybe the Ocelot has a feature to tell it to automatically re-route /ExpenseService/api/Categories/{verb} to /api/Categories/{verb}. I have tried /ExpenseService/api/Categories/{everything} to /api/Categories/{everything}, but not working. Please is there any feature or a way to achieve that ?? Massive thanks in advance <3
4 replies
CC#
Created by M B V R K on 12/23/2023 in #help
Is this DDD Specification a good practice or not?
Hi friends, hope you're all doig well, I'm working on a project by implementing the DDD (Domain Driven Design), As you know that one of the core concepts of DDD is the Specification Pattern (Specifications), I have written the following Specification:
/// <summary>
/// Represents a specification that checks if a category with the same name for the same user already exists.
/// </summary>
public class IsUniqueCategoryNameSpecification: Specification<Category>
{
readonly ICategoryUniquenessChecker _categoryUniquenessChecker;

public IsUniqueCategoryNameSpecification(ICategoryUniquenessChecker categoryUniquenessChecker)
{
_categoryUniquenessChecker = categoryUniquenessChecker;
}

protected override void ConfigureConditions()
{
AddCondition(category =>
category.Id == Guid.Empty ? _categoryUniquenessChecker.IsUniqueCategoryNameAsync(category.Name, category.UserId).Result
: _categoryUniquenessChecker.IsUniqueCategoryNameAsync(category.Id, category.Name, category.UserId).Result, "Category name must be unique.");
}
}
/// <summary>
/// Represents a specification that checks if a category with the same name for the same user already exists.
/// </summary>
public class IsUniqueCategoryNameSpecification: Specification<Category>
{
readonly ICategoryUniquenessChecker _categoryUniquenessChecker;

public IsUniqueCategoryNameSpecification(ICategoryUniquenessChecker categoryUniquenessChecker)
{
_categoryUniquenessChecker = categoryUniquenessChecker;
}

protected override void ConfigureConditions()
{
AddCondition(category =>
category.Id == Guid.Empty ? _categoryUniquenessChecker.IsUniqueCategoryNameAsync(category.Name, category.UserId).Result
: _categoryUniquenessChecker.IsUniqueCategoryNameAsync(category.Id, category.Name, category.UserId).Result, "Category name must be unique.");
}
}
Please could you tell me if this is a good implementation for a specification, or this just wrong manner, because this is the first time I write a specification that needs to deal with database? Please share with me your experience guys, and massive thanks in advance <3 For more info and definition of the Specification<T> class take a look here : https://github.com/MbarkT3STO/ExpenovaApp/blob/main/Source/ExpenseService/ExpenseService.Domain/Specifications/Specification.cs
6 replies
CC#
Created by M B V R K on 12/20/2023 in #help
Is there any method to track opened file in Solution Explorer in VS Code?
No description
4 replies
CC#
Created by M B V R K on 12/19/2023 in #help
✅ Is this a correct way or I just mad things wrong?
Hi friends, hope you're doing well, I'm working on a project which using CQRS with MediatR, I have a PipelineBehavior for handling exception happened in the Commands and Queries, Lets talk in a brief manner about Commands, most of Commands in this project are returning a result ( type ) inherited from CommandResult<TValue, TCommandResultclass, that class used to implement the Result Pattern, How should this work usually? Before, every Command if executed successfully it should return a result ( its type inherited from CommandResult<TValue, TCommandResult) that represents a succeeded operation, but in an Exception situation the command should return a result ( its type inherited from CommandResult<TValue, TCommandResult) that represents a failed operation, and both Faild and Succeeededare the same type. What I did? I removed the exception handling from commands, and moved itt to that PiplineBehavior, So that behavior should execute the command, if it executed successfully, then its fine, but if an exception happened it will check which TResponse related to the request and create a Failed result then return iit. Please take a look on that behavior here : https://github.com/MbarkT3STO/ExpenovaApp/blob/20c83b6076e197af5097c6c862db6ad9e7d0d42e/Source/ExpenseService/ExpenseService.Application/Behaviors/ExceptionHandlingBehavior.cs Where is the issue here? The issue is a method called CreateFailedResult iit checks and returns the correct result, and the issue is that method checks all the commands and also queries, nd as you will notice that at this moment there are many ifs there, and in the future handreds of commands and queries will be added. The question: Is this technique I used here has a value or I just did things wrong ? Is there any other way to do the same ? Do you have any suggestion about this situation ? Massive thanks in advance, with love <3
5 replies
CC#
Created by M B V R K on 12/17/2023 in #help
✅ Why Serilog don't log errors???
Hi guys, I'm trying to logging using Serilog, the logging targeting File, Everything works fine, but when I log error it not logged, In my program.cs the registration of Serilog I did as the following:
// Configure Serilog
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Debug)
.Enrich.FromLogContext()
.WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
// Configure Serilog
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Debug)
.Enrich.FromLogContext()
.WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
Please any help to fix this issue, and massive thanks in advance <3
7 replies
CC#
Created by M B V R K on 12/16/2023 in #help
Is this a correct way or I just mad things wrong?
Hi friends, hope you're doing well, I'm working on a project which using CQRS with MediatR, I have a PipelineBehavior for handling exception happened in the Commands and Queries, Lets talk in a brief manner about Commands, most of Commands in this project are returning a result ( type ) inherited from CommandResult<TValue, TCommandResultclass, that class used to implement the Result Pattern, How should this work usually? Before, every Command if executed successfully it should return a result ( its type inherited from CommandResult<TValue, TCommandResult) that represents a succeeded operation, but in an Exception situation the command should return a result ( its type inherited from CommandResult<TValue, TCommandResult) that represents a failed operation, and both Faild and Succeeededare the same type. What I did? I removed the exception handling from commands, and moved itt to that PiplineBehavior, So that behavior should execute the command, if it executed successfully, then its fine, but if an exception happened it will check which TResponse related to the request and create a Failed result then return iit. Please take a look on that behavior here : https://github.com/MbarkT3STO/ExpenovaApp/blob/20c83b6076e197af5097c6c862db6ad9e7d0d42e/Source/ExpenseService/ExpenseService.Application/Behaviors/ExceptionHandlingBehavior.cs Where is the issue here? The issue is a method called CreateFailedResult iit checks and returns the correct result, and the issue is that method checks all the commands and also queries, nd as you will notice that at this moment there are many ifs there, and in the future handreds of commands and queries will be added. The question: Is this technique I used here has a value or I just did things wrong ? Is there any other way to do the same ? Do you have any suggestion about this situation ? Massive thanks in advance, with love <3
5 replies
CC#
Created by M B V R K on 12/15/2023 in #help
Logging code make my code a bit ugly
Hi friends, Hope you're doing well, I'm working on complex project, I use CQRS with MediatR, in the Application layer, also I'm using Serilog ( Console, and File) for logging, and here the issue, the lines of code I wrote to achieve a logging it makes my code a bit a ugly ( in my opinion), because in the Commands and Queries I wrote a logging at the beginning and a logging at the end . The following is a Handle method of a Command :
public override async Task<CreateCategoryCommandResult> Handle(CreateCategoryCommand request, CancellationToken cancellationToken)
{
try
{
Log.Information("CreateCategoryCommandHandler.Handle - Start Creating a new category with name: {Name}, description: {Description}, and user id: {UserId}", request.Name, request.Description, request.UserId);

// Some code goes here

Log.Information("CreateCategoryCommandHandler.Handle - End Creating a new category with name: {Name}, description: {Description}, and user id: {UserId}", request.Name, request.Description, request.UserId);

return result;
}
catch (Exception e)
{
var result = CreateCategoryCommandResult.Failed(e.Message);

Log.Error(e, "CreateCategoryCommandHandler.Handle - Failed to create a new category with name: {Name}, description: {Description}, and user id: {UserId}", request.Name, request.Description, request.UserId);

return result;
}
}
public override async Task<CreateCategoryCommandResult> Handle(CreateCategoryCommand request, CancellationToken cancellationToken)
{
try
{
Log.Information("CreateCategoryCommandHandler.Handle - Start Creating a new category with name: {Name}, description: {Description}, and user id: {UserId}", request.Name, request.Description, request.UserId);

// Some code goes here

Log.Information("CreateCategoryCommandHandler.Handle - End Creating a new category with name: {Name}, description: {Description}, and user id: {UserId}", request.Name, request.Description, request.UserId);

return result;
}
catch (Exception e)
{
var result = CreateCategoryCommandResult.Failed(e.Message);

Log.Error(e, "CreateCategoryCommandHandler.Handle - Failed to create a new category with name: {Name}, description: {Description}, and user id: {UserId}", request.Name, request.Description, request.UserId);

return result;
}
}
Please I want you to share with me your experience about this, <3
18 replies
CC#
Created by M B V R K on 12/9/2023 in #help
✅ What's the name of this font?
No description
9 replies