Skip to content

Instantly share code, notes, and snippets.

View PatrickKalkman's full-sized avatar
🏠
Working from home

Patrick Kalkman PatrickKalkman

🏠
Working from home
View GitHub Profile
@PatrickKalkman
PatrickKalkman / PlaylistIdStringTest.cs
Created February 1, 2019 07:09
Test for parsing the tag id of the HLS Playlist
[TestCase("#EXTM3U")]
[TestCase("#EXTM3U:")]
[TestCase("#EXTM3U\n")]
[TestCase("#EXTM3U\n#EXTM3U")]
public void ShouldParseStringThatStartsWithPoundAsPlaylistTag(string input)
{
string tagId = PlaylistGrammar.TagIdStringParser.Parse(input);
Assert.AreEqual("EXTM3U", tagId);
}
@PatrickKalkman
PatrickKalkman / PlaylistGrammerPart1.cs
Created February 1, 2019 10:14
First part of the parser to parse a Playlist
public class PlaylistGrammar
{
public static readonly Parser<string> TagIdStringParser =
from tagStartDelimiter in Parse.Char('#').Once()
from tagId in Parse.AnyChar.Until(Parse.Char(':')).Text()
.Or(Parse.AnyChar.Until(Parse.LineTerminator)).Text()
select tagId;
}
@PatrickKalkman
PatrickKalkman / PlaylistGrammerPart2.cs
Created February 1, 2019 13:18
Combining parsers to parse Tag attributes
public static readonly Parser<PlaylistTagAttribute> TagAttributeParser =
from attribute in AttributeWithQuotesParser
.Or(AttributeWithoutQuotesParser)
.Or(AttributeWithSingleValueParser)
select attribute;
public static readonly Parser<List<PlaylistTagAttribute>> MultipleTagAttributesParser =
from attributes in TagAttributeParser.Many()
select new List<PlaylistTagAttribute>(attributes);
@PatrickKalkman
PatrickKalkman / MultipleTagAttributesTest.cs
Last active February 1, 2019 13:28
Test for testing parsing multiple Tag attributes
[Test]
public void MultipleTagAttributesAreParsed()
{
var input = @"TYPE=AUDIO,GROUP-ID=""audio"",NAME=""audio"",DEFAULT=YES";
List<PlaylistTagAttribute> tagAttributes =
PlaylistGrammar.MultipleTagAttributesParser.Parse(input);
Assert.That(tagAttributes.Count, Is.EqualTo(4));
Assert.AreEqual("TYPE", tagAttributes[0].Key);
Assert.AreEqual("AUDIO", tagAttributes[0].Value);
Assert.AreEqual("GROUP-ID", tagAttributes[1].Key);
@PatrickKalkman
PatrickKalkman / CopySnapshotToStorageAccount.ps1
Created February 23, 2019 06:50
Copy an exported snapshot to a storage account
$storageAccountName = "destinationStorageAccountName"
$storageAccountKey = "destinationStorageAccountKey"
$absoluteUri = "The URL of the exported snapshot"
$destContainer = "vhds"
$blobName = "sb-prd-sql-disk-os.vhd"
$destContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
Start-AzureStorageBlobCopy -AbsoluteUri $absoluteUri -DestContainer $destContainer -DestContext $destContext -DestBlob $blobName
@PatrickKalkman
PatrickKalkman / CreateVM.ps1
Last active February 23, 2019 07:08
Create an Azure VM using an exported Snapshot via PowerShell
$virtualNetwork = New-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $ResourceGroupNameProd -Location $Location -AddressPrefix "10.0.0.0/16"
$backendSubnet = Add-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix "10.0.0.0/24" -VirtualNetwork $virtualNetwork
$virtualNetwork | Set-AzureRmVirtualNetwork
$pip = New-AzureRmPublicIpAddress -Name $IpAddressName -ResourceGroupName $ResourceGroupNameProd -Location $Location -AllocationMethod Dynamic
$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $ResourceGroupNameProd -Location $Location -SubnetId "yoursubnetid" -PublicIpAddressId $pip.Id -PrivateIpAddress 10.0.0.101
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $VMSize
$vm = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id
$osDisk = New-AzureRmDisk -DiskName $osDiskName
@PatrickKalkman
PatrickKalkman / Client.cs
Created February 27, 2019 12:35
WCF client
EndpointAddress endpointAddress = new EndpointAddress(Configuration.CreateServerUriString());
ChannelFactory<IMessageSender> channelFactory = new ChannelFactory<IMessageSender>(Configuration.CreateBinding(), endpointAddress);
IMessageSender messageSender = channelFactory.CreateChannel(endpointAddress);
messageSender.ShowMessage("Test message");
((IChannel)messageSender).Close();
@PatrickKalkman
PatrickKalkman / Server.cs
Created February 27, 2019 12:36
WCF Server
Server singleServerInstance = new Server();
Uri baseUri = new Uri(Configuration.CreateServerUriString());
ServiceHost serviceHost = new ServiceHost(singleServerInstance, baseUri);
serviceHost.AddServiceEndpoint(typeof(IMessageSender), Configuration.CreateBinding(), baseUri);
serviceHost.Open();
Console.ReadLine();
serviceHost.Close();
public static class Configuration
{
public static Binding CreateBinding()
{
NetTcpBinding binding = new NetTcpBinding();
binding.MaxReceivedMessageSize = 25 * 1024 * 1024;
binding.ReceiveTimeout = new TimeSpan(0, 2, 0);
return new NetTcpBinding();
}
}
public interface IWcfConfiguration
{
string RetrieveUriString();
int RetrievePortNumber();
TimeSpan RetrieveTimeOut();
}