Anduin

let today = new Beginning();

All Posts


Use JetBrains code quality analyzer to prevent checkin-in bad C# code

When we are using Azure DevOps to review PR, it's simple and easy to use. Usually, we only run tests and build tasks, like this: In my previous blog, I mentioned how to run test and generate code coverage for CI pipelines: Display code coverage information for .NET Core project using Azure DevOps. - Anduin Xue (aiursoft.com) -------------- JetBrains ReSharper and Rider are impressive C# grammar …

C# Azure DevOps JetBrains Resharper Code Quality Pipelines

FFmpeg 用法概览

用法概览 ffmpeg有两种用法,一种是复制流,一种是编码流。 复制流 如果采用复制流,其参数简单,工作效率会极高,而且处理器占用率极低,往往能够每秒复制几千帧,是视频播放速度的几百倍。这种方法非常推荐。 但是,复制流无法修改视频的码率、分辨率,也无法改变视频格式。 如果需要直播,建议先将视频编码为可以直播的视频,再使用复制流的方法推流。 其中, 一般RTMP直播服务器接受的视频格式有:h.264编码的所有视频,一般为mp4格式或flv格式。一般RTMP直播服务器接受的音频格式有:aac编码的所有视频,一般为aac格式或mp4格式。 警告:其中Lavc57.89编码器编码的所有mp3格式音频无法推流。 编码流 如果采用编码流,其参数复杂,工作效率极低,处理器占用率极高,一般能够达到和视频播放速度相当或显著低于视频播放速度。这种方法仅适合于非直播场景。 但是,编码流,可以修改流的码率、分辨率 …

bash FFmpeg

C# run tasks in a threads pool with fixed size

Imagine I have 100 tasks to run. But my machine has only 16 core. So I expect that every core will run one task in parallel. And once a core is idle, assign a new task to it. That will be very easy for C# with Task. But before starting, we gonna create a thread-safe queue for saving our tasks. public class SafeQueue<T> { private readonly Queue<T> queue = new Queue& …

C# Async Task Multi-Threading

Display code coverage information for .NET Core project using Azure DevOps.

Target. Display code coverage information on your own .NET Core project. First, create a build pipeline in your Azure DevOps. If you are using the classic designer, you need to add new .NET Core command line step. Make sure you publish the test result. As for the Arguments input, insert: --configuration $(buildConfiguration) --collect "Code coverage" Or if you are using YAML: Add …

.NET Core Azure DevOps .NET Test MSTest Integration Test Code coverage GitHub

ASP.NET Core Integration Test using MSTest

In the official document, there is only an example of the ASP.NET Core integration test using xunit. https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests But what if you don't like xunit? Can we replace that with MSTest? Yes. We can. Brief steps Uninstall xunit. Install MSTest instead. First, clear the project structure. Install MSTest for your test project. Start your …

ASP.NET Core C# .NET Core Test MSTest Functional Test Integration Test

Fire and forget in ASP.NET Core with dependency alive

C# fire and forget might not be suitable in ASP.NET Core To fire and forget in C#, it is really simple: Task.Run(() => FireAway()); But the same approach might not be suitable in ASP.NET Core Controller. Consider the following example: public class MyController : Controller { private readonly MyHeavyDependency _hd; public MyController(MyHeavyDependency hd) { _hd …

ASP.NET Core C# Async Fire and forget

How to serialize JSON object in C# without Newtonsoft Json

In many cases, we may not be able to access Newtonsoft.Json package. Like sometime there might be different packages using different versions of it, which may cause version conflict via build. That usually happens in some projects really large. So how can we play with JSON as while without it? In pure C#? First, copy the following class to your project: public static class MyJsonConverter { …

C# JSON .NET Newtonsoft.Json

Enable PowerShell remoting for Windows Server machines

Like you can use SSH to execute remote command on a remote Linux machine and you can also execute remote PowerShell on a target Windows Server. To enable it with a self-signed certificate, execute the following command: (Execute it on your server) > Get-ChildItem WSMan:\Localhost\listener | Remove-Item -Recurse # Remove old listeners > Cert = New-SelfSignedCertificate -CertstoreLocation …

PowerShell Windows Server Remote Management WMI

Best-practice for authentication after creating a new Linux server

This article helps you change the following items if your cloud provider didn't do that for you. Create your own account instead of root. Disable password login and force to use SSH key to log in. Disable root account. Enable sudo without password. Before starting the process, make sure you have a valid SSH key-pair locally. Fist, connect to the server. (With root password). you@local …

bash Linux Ubuntu SSH

Setup auto-renew wildcard HTTPS certificate on Azure virtual machine

Sometimes we might need to host a website in Azure. And there are so many options, like storage account, app service. But none of those supports wildcard HTTPS and auto-renew. An ideal configuration shall be static which means that it will never crash even when no one maintains it. Auto-renew is a must-have feature for HTTPS. Luckily, I got a solution based on win-acme: https://github.com/win- …

Azure Azure DNS Windows Server HTTPS Win-ACME Certificate letsencrypt ACME

C# Rotate the square matrix

This is one of my questions from an interview. The interviewer asked me to rotate a square matrix in C#. While it is not so hard for me and I have done it in 10 minutes, I'd share my solution to all developers who may need this. namespace Test { class Program { static void Main(string[] args) { var a = new int[][] { new int[] …

C# Algorithm Matrix Math

Creating a proxy to another URL with ASP.NET Core

This post talks about writing a simple HTTP proxy logic in C# or ASP.NET Core. And allowing your project to proxy the request to any other URL. It is not about deploying a proxy server for your ASP.NET Core project. Before starting, you need to be clear about the target you are going to proxy for. It shall be an URL. Add the following code anywhere of your project. public static …

ASP.NET Core Reverse Proxy Web Proxy