Skip to content

Instantly share code, notes, and snippets.

@aelij
aelij / -Usage.cs
Last active March 29, 2024 14:26
IAsyncEnumerable Bridge for Service Fabric Reliable Collections
class MyService : StatefulService
{
private Task<IReliableDictionary<int, string>> AccountNames => StateManager.GetOrAddAsync<IReliableDictionary<int, string>>("AccountNames");
private Task<IReliableDictionary<int, string>> AccountData => StateManager.GetOrAddAsync<IReliableDictionary<int, string>>("AccountData");
public async Task<List<Account>> SearchAccountsByNameAsync(string name)
{
using (var txn = StateManager.CreateTransaction())
{
var accountNames = await AccountNames;
@aelij
aelij / ThemeManager.cs
Created July 4, 2016 10:14
WPF Theme Manager
using System;
using System.Reflection;
using System.Windows;
public static class ThemeManager
{
#region Fields
private const BindingFlags DefaultStaticFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
private const BindingFlags DefaultInstanceFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
@aelij
aelij / Download-ServiceFabricImageStoreContent.ps1
Created March 9, 2017 07:00
Cmdlet that downloads files from Service Fabric's image store
# Examples:
#
# List image store content:
# $connectionString = Get-ServiceFabricImageStoreConnectionString
# Get-ServiceFabricApplicationType | % { Get-ServiceFabricImageStoreContent -Application -ApplicationTypeName $_.ApplicationTypeName -ApplicationTypeVersion $_.ApplicationTypeVersion -ImageStoreConnectionString $connectionString }
# > StoreRelativePath : Store\Application1Type\Stateless1Pkg.Code.1.0.0
# > Type : Folder [5 files]
# > ServiceManifestName : Stateless1Pkg
# > ServiceManifestVersion : 1.0.0
# > ApplicationVersion : 1.0.0
@aelij
aelij / Create-ServiceFabricApplicationPackageSkeleton.ps1
Created March 9, 2017 09:09
Cmdlet to create a skeleton Service Fabric application package from the image store. Can be used for partial configuration/data packages upgrades.
function Create-ServiceFabricApplicationPackageSkeleton
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
[string] $ApplicationTypeName,
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
[string] $ApplicationTypeVersion,
@aelij
aelij / RoslynDeterministic.md
Last active March 7, 2024 16:09
Deterministic Builds in C#

Deterministic Builds in C#

Status

The C# compiler (Roslyn) supports deterministic builds since Visual Studio 2015. This means that compiling assemblies under the same conditions (permalink) would produce byte-for-byte equivalent binaries.

If you also intend on shipping non-portable (permalink) PDBs, you must also make sure that paths in the PDBs are absolute using path mapping. The recommended way would be to map the enlistment (repo) root to a fixed path, such as C:\.

For more information, see this blog post

@aelij
aelij / RoslynReflection.cs
Last active November 5, 2019 23:12
Reflection using Roslyn (without loading assemblies into the app domain)
var compilation = CSharpCompilation.Create("C")
.AddReferences(MetadataReference.CreateFromFile(pathToAssembly));
foreach (var type in
from assemblySymbol in compilation.SourceModule.ReferencedAssemblySymbols
from module in assemblySymbol.Modules
from n in module.GlobalNamespace.GetMembers()
where n.IsNamespace
from type in n.GetTypeMembers()
select type)
@aelij
aelij / CryptoUtility.cs
Created July 30, 2018 07:06
Encrypt/decrypt Service Fabric secrets without the Fabric runtime
// Add NuGet "System.Security.Cryptography.Pkcs"
using System;
using System.Text;
using System.Security.Cryptography;
using System.Security.Cryptography.Pkcs;
using System.Security.Cryptography.X509Certificates;
namespace Security
{