Posts

Create and register window service

Image
 Visual Studio: Create New Project Select Worker Service Target .NET 6/7/8 Modify Program.cs file: using Microsoft . Extensions . Hosting ; Host . CreateDefaultBuilder ( args ) . UseWindowsService () // Important . ConfigureServices (( hostContext , services ) => { services . AddHostedService < Worker > (); }) . Build () . Run (); using Microsoft . Extensions . DependencyInjection ; Implement Database Update Logic using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Data.SqlClient; using System; using System.Threading; using System.Threading.Tasks; public class Worker : BackgroundService {     private readonly ILogger<Worker> _logger;     private readonly string _connectionString =         "Server=YOUR_SERVER;Database=YOUR_DB;Trusted_Connection=True;";     public Worker(ILogger<Worker> logger)     {         _logger = logger; ...

Key points while writting prompt for AI

  1️⃣ Be Clear & Specific Don’t be vague. Say exactly what you want. ❌ “Extract details from this text” ✅ “Extract vehicle registration number, make, and damage details from the text and return JSON” 2️⃣ Define the Role of the AI Tell the AI who it should act as . ✅ “You are a police incident data extractor” ✅ “Act as a senior Python developer reviewing extraction logic” This sets context and improves accuracy. 3️⃣ Specify the Output Format Always mention how the response should look . JSON / Table / Bullet points Field names Yes/No instead of true/false e.g: Return the output in strict JSON with no extra text. 4️⃣ Add Rules & Constraints Very important for consistency. What must be included What must not be done Edge cases Example: Do NOT merge vehicles Capture vehicles even if repeated in different sections 5️⃣ Handle Edge Cases Explicitly AI guesses if you don’t guide it. ✅ “If registration number is missing, set it to null” ...

Implement Dot net watcher

Dot Net Watcher. 1.  Set Up the .NET Core API If you don’t already have an API project, create one: dotnet new webapi -n FileWatcherApi  cd  FileWatcherApi 2.  Add the FileSystemWatcher Implementation Open the project in your favorite editor (e.g., Visual Studio, VS Code). Create a new service class to manage file watching. For example: Add a new folder named  Services . Create a file named  FileWatcherService.cs . Implement the  FileWatcherService : using System; using System.IO; namespace FileWatcherApi.Services {     public class FileWatcherService     {         private readonly FileSystemWatcher _fileWatcher;         public FileWatcherService(string pathToWatch)         {             if (!Directory.Exists(pathToWatch))             {                 throw new DirectoryNotF...

what are props and how use them in react js

  Props (properties) are how you pass data from a parent component to a child component . They are read-only — the child component can use them but should not change them. Passing props (Parent ➜ Child) Parent component function App ( ) { return ( < Greeting name = "Achla" message = "Welcome to React!" /> ); } Child component (receiving props) function Greeting ( props ) { return ( < h2 >Hello {props.name} — {props.message} </ h2 > ); } Passing numbers, arrays, objects & functions function App ( ) { const user = { name : "Achla" , age : 25 }; return ( < Profile user = {user} hobbies = {[ " reading ", " traveling "]} onLogin = {() => alert("Logged in!")} /> ); } Child: function Profile ( { user, hobbies, onLogin } ) { return ( <> < p >{user.name} — {user.age} </ p > < p >Hobbies: {hobb...

Book teams appointment with email notification

 using System; using System.Net; using System.Net.Mail; using System.Text; class Program {     static void Main()     {         string teamsLink = "https://teams.microsoft.com/l/meetup-join/xxxxxxxx";         DateTime startUtc = new DateTime(2026, 1, 10, 10, 0, 0, DateTimeKind.Utc);         DateTime endUtc = startUtc.AddMinutes(30);         string ics = $@" BEGIN:VCALENDAR PRODID:-//YourApp//EN VERSION:2.0 METHOD:REQUEST BEGIN:VEVENT UID:{Guid.NewGuid()} DTSTAMP:{DateTime.UtcNow:yyyyMMddTHHmmssZ} DTSTART:{startUtc:yyyyMMddTHHmmssZ} DTEND:{endUtc:yyyyMMddTHHmmssZ} SUMMARY:Project Discussion DESCRIPTION:Join the Teams meeting:\n\n{teamsLink} LOCATION:Microsoft Teams Meeting ORGANIZER;CN=Organizer:mailto:organizer@example.com ATTENDEE;ROLE=REQ-PARTICIPANT:mailto:user@example.com STATUS:CONFIRMED URL:{teamsLink} END:VEVENT END:VCALENDAR";         var mail = new MailMe...

How Create API in python using flask library

 from flask import Flask, request, jsonify app = Flask(__name__) # In-memory database items = {} # Get all items @app.route('/items', methods=['GET']) def get_items():     return jsonify(list(items.values())), 200 # Get a single item by ID @app.route('/items/<int:item_id>', methods=['GET']) def get_item(item_id):     item = items.get(item_id)     if item:         return jsonify(item), 200     return jsonify({'error': 'Item not found'}), 404 # Create a new item @app.route('/items', methods=['POST']) def create_item():     data = request.json     item_id = len(items) + 1     items[item_id] = {'id': item_id, 'name': data.get('name'), 'description': data.get('description')}     return jsonify(items[item_id]), 201 # Update an existing item @app.route('/items/<int:item_id>', methods=['PUT']) def update_item(item_id):     if item_id not in items:       ...

How implement serilog in dot net core

  Serilog in .NET Core, here's a quick guide: Steps to Implement Serilog in .NET Core: Install Serilog NuGet Packages Run the following command in your project:        dotnet add package Serilog.AspNetCore        dotnet add package Serilog.Sinks.Console         dotnet add package Serilog.Sinks.File       2. Configure Serilog in Program.cs Add the following code to set up logging: using Serilog; var builder = WebApplication.CreateBuilder(args); // Configure Serilog Log.Logger = new LoggerConfiguration()     .WriteTo.Console()     .WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Day)     .CreateLogger(); builder.Host.UseSerilog(); var app = builder.Build(); app.Run();     3.  Use Logging in Your Application Inject ILogger<T> into your services or controllers: public class MyService {     private readonly ILogger<MyService...