Edi Wang

All Posts 295


Use ICMP Ping in .NET Core 2.0

In classic .NET Framework applications, we have used System.Net.NetworkInformation.Ping class to Ping a host address. This API is not included by default in .NET Core, even in version 2.0. Here is how to do it in a .NET Core way. First, we need to reference a package System.Net.Ping Install-Package System.Net.Ping This will give us the same API set as .NET Framework. Then, in your .NET Core...

.NET Core Ping ICMP

Use NLog in ASP.NET Core 2.0

Recently I am porting a classic ASP.NET MVC 5 project to .NET Core 2.0, in order to run it on Linux. One of the parts that has differences between .NET Fx and .NET Core is logging. I choose NLog as my logging providor, let's see how to port this to .NET Core. 1. Migrating Configuration File First, let's see the .NET Framework version of nlog.config.  This basic...

.NET Core NLog

Automatically Set Text Color on Accent Background in UWP

Windows 10 allows users to set accent color for the system, and in UWP apps, we usually honor those settings by using XAML pre-defined resource keys like {ThemeResource SystemControlBackgroundAccentBrush}. But regardless of how the user set default app mode to dark or light, when we apply text on accent colors, it may have some problems. For example, when the App is in light mode, the default...

XAML UWP

Get Client IP Address in ASP.NET Core 2.0

In classic ASP.NET we used to get client IP Address by Request.UserHostAddress. But this does not apply to ASP.NET Core 2.0. We need a different way to retrieve HTTP Request information. 1. Define a variable in your MVC controller private IHttpContextAccessor _accessor; 2.  DI into the controller's constructor public SomeController(IHttpContextAccessor accessor) { _accessor = accessor;...

ASP.NET .NET Core

Configure VSTS Build for UWP Apps

UWP Apps usually require a lot of time to compile a "release" package for submitting to Windows Store, and if you are working in a team, TFS/VSTS can help your team ensure that each check-in has a success build, and make it easier for deployment and testing. Let's see a basic example of how to setup a CI build for a UWP App on VSTS. Important Pre-condition: Before you do that, please ensure...

UWP VSTS

Windows 10 UWP: Switching Languages in Your App

By default, a UWP App's UI language is automatically fits the system current language settings. However, what if the user need the ability to set a particular UI language just for your App without having to change system language? In my App, I supports Simplified Chinese and English. The user can override the system language in App's settings page: So how to do it? First, you need to have res...

UWP Localization

Windows 10 UWP: How to Read and Save Settings Easily

In the UWP Application model, reading and saving settings are very similar to WinRT API. The class we are using is ApplicationData.Current.LocalSettings It is using key-value-pair to store settings. LocalSettings will stay on the user's current computer, and not being synced with thier Microsoft account. The API to save settings is: LocalSettings.Values[key] = value; To read settings:  if (Lo...

Windows 10 UWP

Windows 10 UWP: How to Debug OnFileActivated Launch Failure

Today I am working on my Image Portray App, and I get my code blown up. The problem is, when the App is already started, it can open .ink file with double click from a file. But when the App is not launched, opening a .ink file to start the App will make it crash. As other UWP that supports file type association, I also use OnFileActivated event to launch my App. This kind of problem could not be...

Debug Visual Studio UWP

10 Tricks and Tools for Windows 10 UWP Development

After Windows 10's launch. More and more UWP applications are coming as well as more Windows developers. I am doing UWP development besides my job for more then 2 years. Today, I will share some tips and tricks from my UWP development experience as well as some handy tools, so that you can do your development more quicker and easier. 1. Automatically Set Color to Title Bar The default color...

UWP

一个死忠软粉亲身经历的Surface产品的品控和售后

这几天关于Surface硬件质量差的问题,在国内闹得沸沸扬扬,起因是美国消费者协会因为发现25%的Surface用户在使用2年内机器都会爆,所以将Surface系列移出了推荐。加上国内大环境本来就是吹苹果黑微软的多,这下可真够热闹的。然而这一次,我觉得Surface真是自找的,尤其是国内。今天我就整理一下我亲身经历过的品控事件。 首先,我保证本文的内容均为可以考证的100%事实,不吹不黑。我本人是个死忠软粉,拥有Surface RT, Surface Pro 3, Surface Pro 4, Surface Pro 2017, Surface Laptop, Lumia 520, 625, 640, 720, 928, 1520, 950XL, 正版Windows自费购买5份,国内没有的我还专门美国代购过,都是Pro版, Office 365(家庭版), Visio, Proj...

Surface