Skip to content

Instantly share code, notes, and snippets.

@miteshsureja
miteshsureja / Program.cs
Created June 16, 2018 06:55
Visitor Design Pattern
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VisitorPattern
{
public enum Categories
{
@miteshsureja
miteshsureja / Program.cs
Last active July 5, 2023 12:27
How to execute PowerShell script or cmdlets from C# code?
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Management.Automation;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@miteshsureja
miteshsureja / App.xaml.cs
Last active May 27, 2018 13:09
How to run single instance of an application using Mutex?
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace WPFSingleInstanceApplication
@miteshsureja
miteshsureja / Import-csv.ps1
Created May 26, 2018 11:46
Import-Csv and Export-Csv PowerShell cmdlets
#export data using Export-CSV cmdlet
Get-EventLog Application -Newest 100 | Export-Csv logs.csv
Get-Content logs.csv
#import CSV data using Import-CSV cmdlet
#specify path
$path = "C:\PowerShell\logs.csv"
#import csv file and specify specific columns you want to import using -Header
$file = Import-Csv $path -Delimiter ","
#$file
@miteshsureja
miteshsureja / Program.cs
Created May 13, 2018 14:12
Template Method Design Pattern
using System;
namespace TemplatePattern
{
//Template abstract class
public abstract class OrderTemplate
{
public abstract void SelectProduct();
public abstract void Payment();
public abstract void Deliver();
@miteshsureja
miteshsureja / Program.cs
Last active May 13, 2018 14:15
Strategy Design Pattern
using System;
namespace StrategyPattern
{
//strategy
public interface IPaymentStrategy
{
void Pay(double amount);
}
//concrete strategy
@miteshsureja
miteshsureja / ReadFromExcel.Ps1
Created May 8, 2018 14:36
Read data from Excel file using PowerShell script
#select excel file you want to read
$file = "C:\PowerShell\MyContacts.xlsx"
$sheetName = "Sheet1"
#create new excel COM object
$excel = New-Object -com Excel.Application
#open excel file
$wb = $excel.workbooks.open($file)
@miteshsureja
miteshsureja / Program.cs
Last active May 13, 2018 14:21
State Design Pattern
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StatePattern
{
//state
public abstract class State
@miteshsureja
miteshsureja / IStockPriceWatcher.cs
Created May 5, 2018 06:14
Observer Design Pattern
using System;
using System.Collections.Generic;
namespace ObserverPattern
{
//Observer
public interface IStockPriceWatcher
{
string Name { get; set; }
Subject Subject { get; set; }
@miteshsureja
miteshsureja / Backup.cs
Created April 3, 2018 14:42
Memento Design Pattern Example
using System;
using System.Collections.Generic;
using System.Linq;
namespace MementoPattern
{
//Originator class
public class Backup
{
public string BackupName { get; set; }