Edi Wang

.NET and Azure Developer

全部文章

Windows 10 UWP开发:如何定时触发后台任务

今天在爆UWP的定时后台任务,坑有点多,爆出屎来了。有的坑在很多网上的文章里都没提到,非常的坑。刚刚开荒成功了,把经验写出来分享: 1. 写一个后台任务的类,继承IBackgroundTask接口 通常,在设计应用程序结构的时候,我们会建类库项目(Class Library)放这些类。比如 FarkBackgroundTask.Core 因为是UWP工程,所以建的类库也要是Universal Windows的。注意,这里我们已经埋下了一个巨坑,稍后会解释。 我们的类代码如下: public class SayFarkTask : IBackgroundTask { public void Run(IBackgroundTaskInstance taskInstance) { Debug.Write("================ Fark the …
Windows Timer UWP Task

Windows 10 UWP开发:如何弹出消息通知

在UWP的App中,弹出消息通知的方法和WinRT一致,注意是App内的消息通知(toast notification)而不是从服务器端推送的通知。主要有几个步骤: 1. 创建XML定义 // 1. create element ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01; XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); 这里面的消息模板有好几种: // // Summary: // 指定要在消息通知中使用的模版。 [ContractVersion(typeof(UniversalApiContract), 65536)] public enum …
Windows UWP

Windows 10 UWP开发:如何实现WP8的Pivot效果

UWP的Pivot控件动画效果和以前Windows 8, Windows Phone 8的Pivot不一样,在切换PivotItem的时候,当前选择的Item的Header并不会跑到第一个去,而是单纯的像Tab选项卡那样高亮当前的Tab而已。 我个人喜欢Windows 8的Pivot,即下面这个GIF这样的(这是我正在开发的一个UWP应用)。如果你也喜欢传统风格的Pivot,可以参考以下方法。 实现方法特别简单,只要拿Blend从WP8.1 Runtime的Pivot里把默认样式导出来,稍微改下就行: 把这个style塞在App.xaml的Resources下面就可以全局使用了。 我改了这么几个地方: 一个是所有的PhoneOOXXBrush,我都换成了对应的UWP的Bursh比如PivotForegroundThemeBrush不然运行时候直接爆炸。 另一个是 给 …
Windows UWP

How to Redirect Old Domain URL to New Domain in IIS

When you change the domain name for your website, you are definitely going to solve the migration problem. You cannot just stop DNS on your old domain, because this will cause your indexed pages to be deleted by search engines. The correct way is to tell the search engine that you have a new domain name now, which is when the user accesses an old URL, redirect it to the new URL. Take my blog …
IIS URL URL Rewrite

Windows 10 UWP开发:自定义标题栏

UWP和WPF以及以前Windows 8.1的WinRT应用有些不一样的地方。首先就是标题栏,以前Windows 8.1的应用都是全屏的,没有标题栏,Windows 10里面应用可以窗口化运行,所以我们也能够利用标题栏做一些定制。本文针对初学者,可能写的比较啰嗦。 一、首先是最基本的,如何改变标题栏及按钮的颜色 标题栏的对象位于Windows.UI.ViewManagement.ApplicationView类里,有个属性是 public ApplicationViewTitleBar TitleBar { get; } 为了能够访问这个属性,我们需要先取得当前应用窗口的view: var view = ApplicationView.GetForCurrentView(); 拿到view对象后,就能对TitleBar属性操作了,标题栏的活动和非活动状态的前景色和背景色可以这样设置, …
Windows UWP

Fix Visual Studio 2015 Razor Editor Blow Up

Visual Studio 2015 has been RTM for one month. However, it blows up very often, such as Razor editor. When I try to open any .cshtml file, it blows up with this error, then the syntax highlight is gone. I tried to uninstall all add-on, even repair install VS2015 can't get it working. The detailed error message is: System.Reflection.TargetInvocationException: Exception has been thrown by the …
Razor

How to Manage Azure App Service in IIS Manager (inetmgr)

The website we created on Azure seems can be only managed in the web portal or in the Server Explorer of Visual Studio. If we would like to use IIS to manage more powerful scenarios, seems VM is the only way. But that's not true. First, the IIS comes with Windows 8.1 can't connect to Azure by default. We need to install an extension http://www.iis.net/downloads/microsoft/iis-manager After install. …
IIS Azure

Azure Website Showing 404 for .woff Fonts in IE

If you are using Website on Microsoft Azure (Currently renamed to Web Apps), you will find the .woff web font is not working in IE, it returns 404. Based on my experience, this is because IIS is not configured to use the correct MimeType. However, we can not operate the IIS on Azure, there's no RDP into an Azure Web Apps backend machine. How can we do that? In fact, after IIS7, the MineType is …
IIS Azure

如何高逼格读取Web.config中的AppSettings

先插句题外话,下版本的ASP.NET貌似把web.config撸掉了,都变成json了。所以本文讨论的内容可能以后用不到了,但是一些设计思想还是可以用的~ 直接进入正题,在ASP.NET网站里(也包括其他有web.config, app.config)的.NET工程里,读AppSettings的值是个很常见的场景。比如: 在代码里读的时候就会用到: ConfigurationManager.AppSettings["EnableAzureWebTrace"]; 这个[]索引器返回的是string类型。所以下一步我们通常需要类型转换才能在代码里拿来用。比如这个例子里,我们就要转换成bool。其他时候,可能要转换为int等类型。 string enableAzureWebTraceConfig = ConfigurationManager.AppSettings[" …
ASP.NET

Azure SQL数据库如何做定期自动备份

Azure上的数据库可以通过手工export来备份,方法我在博客里写过。但是如果要求定期做的话,需要人工参与。偷懒的做法是用Azure自带的定期备份功能。 1. 在Azure Portal点开你的数据库,切换到CONFIGURE页面。 Automated Export的意思就是自动导出数据库(bacpac格式),默认是NONE,也就是不自动备份。选择AUTOMATIC。 2. 选完之后,下面会出来详细设置。 STORAGE ACCOUNT选你要保存备份文件的存储账户。FREQUENCY是频率,这个例子里我选择每28天备份一次,从2015年4月2日12:00A.M.开始。保留90天内的备份(这个选项的意思就是备份文件多久以后会被自动删除) 另外,还需要填写SQL数据库服务器的登录账户和密码。然后保存设置就完成了! 3. 一旦到了指定时间,触发了备份。你就能在你刚才设置的存储账户里找到一个 …
SQL Azure