Skip to content

Instantly share code, notes, and snippets.

View kstrauss's full-sized avatar

Karl Strauss kstrauss

  • Realgy LLC
  • Hartford area, CT
View GitHub Profile
void Main()
{
var fsw = new FileSystemWatcher(@"c:\"){
IncludeSubdirectories = true
};
fsw.EnableRaisingEvents = true;
var created = Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(h=>fsw.Created+=h,h=>fsw.Created-=h);
var changed = Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(h=>fsw.Changed+=h,h=>fsw.Changed-=h);
var deleted = Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(h=>fsw.Deleted+=h,h=>fsw.Deleted-=h);
var renamed = Observable.FromEventPattern<RenamedEventHandler, FileSystemEventArgs>(h=>fsw.Renamed+=h,h=>fsw.Renamed-=h);
@kstrauss
kstrauss / Additional Notes
Last active December 14, 2021 01:28
Example of publishing simple ETW events (no manifest and therefore EventLog) and consuming them in a realtime fashion
All need the Microsoft.Diagnostics.Tracing.TraceEvent nuget package
Shows how you can both produce some simple ETW events (these are not written to the eventlog)
A couple of ways to consume said events.
1. using standard tooling like perfview, xperf, etc.
2. create your own EventListener class as demonstrated by ProducerAndSimpleListener, which allows you to do pretty much anything
3. listen in realtime as done in RealTimeListener
4. Others do similar things I believe like tx.windows
namespace EventStoreDTCFirstTry
{
public class EventStoreDistributedTransaction
{
private static readonly Guid ResourceManagerId = new Guid("F6049197-5B56-4C90-ACA9-39A2516C547A");
private readonly EventStoreConnection _connection;
private readonly EventStoreTransaction _esTransaction;
public EventStoreDistributedTransaction(EventStoreConnection connection, string stream, int expectedVersion)
@kstrauss
kstrauss / SaveAll
Last active August 29, 2015 14:17
Write to eventStore with ExpectedVersion.Any
// stripped out some comments
foreach (var ag in _unitOfWork.GetChanges()){
AggregateMetaData ag1 = ag;
var events = ag.Root.GetChanges().Select((o, i) => _serializer.Serialize(o, origEventId, srvcName, ag1.Identifier, i,metaData)).ToList();
// taken out code that checks to make sure the events we write are not too big for GES
var t = _connection.AppendToStreamAsync(ag1.Identifier, ExpectedVersion.Any , events);
try
{
t.Wait();
if (t.IsFaulted)
@kstrauss
kstrauss / DownloadRssMediaAsync
Last active August 29, 2015 14:20
just need the appropriate rss feed
# found the rss feed for the resolution i liked
$r=Invoke-WebRequest http://channel9.msdn.com/Shows/Windows-Azure-Friday/feed/wmvhigh
$nodes = [xml]$r.Content | % {$_.selectNodes("rss/channel/item/enclosure")}
$nodes.url | % { $dest=split-Path -leaf $_ ; Start-BitsTransfer -Source $_ -Destination $dest -Asynchronous}
Get-BitsTransfer
@kstrauss
kstrauss / gist:bb49b368d03f72084699
Last active October 4, 2016 16:51
GetEventstore (GES) powershell Http api examples
#$esCred = get-credential -UserName admin
<# Set automatic credentials - obviously just using the defaults#>
$username= "admin"
$password = "changeit"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$escred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
<#
Need to Reset the checkpoint for the RequestedAddition -> ContractAccepted service
@kstrauss
kstrauss / ReplaceText-Infile.ps1
Created May 11, 2015 15:44
Search & replace package hintpaths with the solutionDir variable.
Param(
[parameter(Mandatory=$true,ValueFromPipeline=$true)]
[System.IO.FileInfo] $inputFile,
[Parameter(Mandatory=$true)]
[String] $searchPattern,
[Parameter(Mandatory=$true)]
[String] $replaceText
)
Begin{}
@kstrauss
kstrauss / ConvertFromNugetToProjectReferences.ps1
Last active February 21, 2017 17:05
replace nuget references with project references
Import-Module VisualStudioProjectModifiers
$projs = dir -Recurse -filter *.csproj
# lookup of AssemblyName to projectFile
$lookup = @{}
$projs | % {
select-string '<AssemblyName>(.*)</AssemblyName>' $_.FullName } | %{
$lookup[$_.Matches.Groups[1].value] = $_.Path
}
@kstrauss
kstrauss / expressionTreeDemo.linq
Created January 11, 2016 23:56
Example For Mark on expression tree with mulitple parameters
void Main()
{
var l = new FileModel[] { new FileModel() { Filename = "pizza is great" },
new FileModel {Filename = "MarkyMark"},
new FileModel {Filename = "JeffyJeff"}
}.AsQueryable();
var subStrings = new string[] {"is", "pizza","pizza","pizza","Mark"};
l.MultiValueContainsAny(subStrings, t=>t.Filename).Dump("Filters to");
}
@kstrauss
kstrauss / ESQuery_ForGitHubIssue900.linq
Created April 26, 2016 18:11
Reproduction code for EventStore Issue #900
<Query Kind="Program">
<Connection>
<ID>e8afa357-aae4-40ae-a4ad-e4783f38f696</ID>
<Server>rdbtest2012</Server>
<Database>PackageMonitorReadModel_SGSpike-Main</Database>
<ShowServer>true</ShowServer>
</Connection>
<NuGetReference>EventStore.Client</NuGetReference>
<NuGetReference>Newtonsoft.Json</NuGetReference>
<NuGetReference>Rx-Linq</NuGetReference>