2016年5月29日 星期日

[JSNLog] Log in the fron-end with AngularJS and NLog

 #JSNLog    #Front-end logger   #NLog


Introduction


JSNLog is a javascript client side logger, you can log the user behavior or exception in front-end to the back-end logger, such as NLog, Log4Net.

In the following sample, I am going to integrate JSNLog with .Net NLog and use JSNLog’s angular service.




Environment

l   JSNLog.NLog 2.17.1
l   AngularJS 1.5.5
l   logToSerer.js 1.0.1



Implement


Install NLog in the Web Application



Install JSNLog.NLog in the Web Application

After installing it, you will find the following setting in WebConfig. We can disable the logger or change the default path of “jsnlog.min.js”. The default path is /Scripts/ jsnlog.min.js

<configuration>
  <jsnlog productionLibraryPath="~/Scripts/Source/jsnlog.js/jsnlog.min.js" enabled="true">
  </jsnlog>
</configuration>


Download logToServer.js

logToServer.js is the AngulaJS service for JSNLog. However, if you are not using AngularJS, you can skip this step and use the pure javascript to call the logger.

Open the logToServer.js, we can change the default file name of the logger.




Start logging!

var app =
angular.module('app', ['logToServer'])
.controller('CustomerIndexCtrl', function ($scope, $http, $log, DeleteFactory, blockUI) {

    //$log Service
    $log.log("Trace!");
    $log.debug("Debug!");
    $log.info("Information!");
    $log.warn("Warning!");
    $log.error("Error!");

    //JS
    JL("MyPage").log("Trace!");
    JL("MyPage").debug("Debug!");
    JL("MyPage").info("Information!");
    JL("MyPage").warn("Warning!");
    JL("MyPage").error("Error!");
});


Here are the results! Works fine with log viewer.




The physical log texts.







Log AJAX ($http)

There is another useful method for JSNLog to log the Ajax when the response encounters Timout or delays.

Set the angular’s config like this.

app.config(['$httpProvider', function($httpProvider) {
    $httpProvider.interceptors.push('logToServerInterceptor');
}])


And the $http method …

$http({
                method:'GET',
                url:getUri,
                timeout:5000,
                warning: 1500
            }).error(function (status, headers, config) {
  
            }).then(function (response) {
                return response;
            }).catch(function (e) {
                throw e;
            });


If the request timeouts or delays, we will get a message like this,

Angular.Ajax | {"errorMessage":"timeout","status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://localhost:4321/api/XXX/Get","timeout":5000,"warning":1500,"headers":{"Accept":"application/json, text/plain, */*"},"msBeforeAjaxCall":1464481330322}} | 




Warning!

If you are using blockUI in the website, don’t forget to ignore the JSNLog http request! Or the website may encounters a blockUI deadlock!

app.config(function(blockUIConfig) {

    blockUIConfig.requestFilter = function(config) {
        if (config.url.match(/^\/jsnlog.logger($|\/).*/)) {
            return false; // ... don't block it.
        }
    };
})






Reference





[PMP] 2016 PMO Day與會心得

 #PMO    #PMP   #PMI-TW 


自從去年(2015/10)參加了PMI-TW舉辦的 PMO Day 就對這種Global mindset的講師和議題覺得非常有興趣, 所以一得知2016 PMO Day的消息,馬上就報名參加了!

上半場一開始的議題~

Why PMO? (MSOL 總裁 - Shinya Takahasi 先生)

PMO的腳色及重要性就不多說了。 Shinya Takahasi總裁做的總結很簡潔有力:

Why PMO?
ü   Transparency
ü   Quick decision
ü   The center of knowledge


PS. Transparency 在傳統專案統理或是Agile中都是很重要的, 完全透明的專案才能讓團隊溝通順暢互相信任。


Why your PMO doesn’t work in your organizations? (MSOL TW CEO – Toshinari Goto 先生)

此議題Toshinari Goto 先生一開始用圖文說明了PMOPM對立的情況; 包括實務中PM PMO視為監視專案的SPY PMO則視PM為總是將忙碌作為藉口,不遵循規範的麻煩分子。

小弟在先前工作上曾和乏善可陳的PMO交過手,那感覺的確如講師所述… lol


ProEver, a new kind of knowledge and talent search system for Project
Management.
(ProEver Inc., Masaki Furuya)

Masaki Furuya  先生應該是ProEverCTO :P 
這套專案管理工具使用Machine learning來分析上傳的文件內容並組織分類它們,並透過人類語意來做搜尋,未來將支援Media type的檔案!

ProEver 在專案建構管理及組織流程資產上應該幫助很大,有興趣的朋友可以到他們官網查看機器學習和人工智慧如何協助你的專案!



Strategic PMO for business value creation (MSOL資深顧問 Koji Shiota)

Architecture Management :

“Be a leader, not a controller!”



以下是下半場的議程~

跨國工程的專案管理平台 (宜眾資訊股份有限公司 張副總經理)

稱職的PM,除了基本的專業專案管理,最重要的是:溝通協調!
專案管理最難的部分還是在於

張副總和她的議題是個人覺得很棒的分享; 因為小弟比較喜歡聽講師在實務上的經驗分享J
而且 張副總提到的專案都是跨國性和跨專業的,這也是小弟努力的目標啦!!

副總從採購軟體開發工程師Team lead做到管理階層,讓身在軟體業的小弟,卓感佩服~ 見賢思齊! 在圓桌會議上,張副總也有提到她努力追求新知的敏感度和熱情, 也非常具有參考價值呢!


Leverage Taiwan PMO resource to make Macau project success (澳門博研有限公司CEO, PC Wong)


如果海外有更好的福利和工作機會,你會願意去嗎?
此場主講是PC先生的同事, 他說明了目前台灣環境薪資停滯不前及雇主為大的問題,海外就業是未來的趨勢,問題是你準備好挑戰了嗎?

順道一提,PC先生在下午的圓桌會議回答問題的效率和思路非常棒,可以很快和很有自信地將主持人或是學員的問題整理好,然後以系統組織化的方式回答~

                        



Global trend of green buildings & LEED certification at Shuter (美國綠建築顧問 簡碩賢先生)

主要分享綠建築在各國的發展狀態; 並以某知名咖啡品牌的綠建築計畫為例。


金融業因應Bank 4.0挑戰的專案佈局 (台新銀行副總經理 孫一仕先生)

孫副總主要介紹FinTech對於金融業的衝擊,包含微信支付寶等載具的崛起。
未來金融業需延伸價值鏈將觸角伸及客戶的日常生活。

客戶的忠誠度取決於他們的惰性。

相關參考



跨國企業的專案管理(台達集團 PMO Lead 廖庸智先生)

介紹PDLC(Project Development Life Cycle)及在跨國專案協同合作的方式,包含破冰訂立溝通方式風險管理。 並提到在跨國企業的專案,千萬不要分區域進行專案(Regional project),而是一開始就要以全球化的角度來進行(Global integration) 否則後續在整合上會出現非常大的GAP




以上是自己今天的重點整理~~ 非常感謝PMI-TWMSO主辦的PMO day,以及講師辛苦的準備和分享 J


2016年5月21日 星期六

[ASP.NET] Customize Authorize attribute

 ASP.NET   Windows Authentication   Identity   Authorize Attribute


Introduction


In ASP.NET MVC, we can confirm the permission of the current logon user by add the [Authorize] attribute. For example,

[Authorize(Roles ="Admin")]
public ActionResult Index(int? page)
{ … }

However, we will never want to maintain the Authorize attributes for every Action or Controller since the role name might changes or there might be other roles allowed for the Action.

We will override the Authorize attribute to make it more flexible by query the role of the user and then verify the permission of the role.


Implement



Implemnt a new attribute which inherits AuthorizeAttribute


[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class SetPermissionsAttribute : AuthorizeAttribute
{
        /// <summary>
        /// Controller name
        /// </summary>
        public string Controller { get; set; }
        /// <summary>
        /// Action name
        /// </summary>
        public string Action { get; set; }

        /// <summary>
        /// Authorize
        /// </summary>
        /// <param name="httpContext">HttpContextBase</param>
        /// <returns>Is authorized</returns>
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool isAuthorized = false;
            //Verify the user thru database
            //Step1. Get user id
            //Step2. Get the user’s roles
            //Step3. Check if the user’s roles have permissions on the Controller and Action
isAuthorized =
            return isAuthorized;
        }

        /// <summary>
        /// 攔截未授權的Request
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            // Returns HTTP 401 by default - see HttpUnauthorizedResult.cs.
            filterContext.Result = new RedirectToRouteResult(
            new RouteValueDictionary {
                { "action", "Index" },
                { "controller", "Home" },
                { "area", ""}
                //{ "parameterName", "YourParameterValue" }
            });
        }
    }

l   Override AuthorizeCore(HttpContextBase httpContext) to verify the user with the Controller name and Action name.

l   Override HandleUnauthorizedRequest(AuthorizationContext filterContext) to redirect the request or something else.

Usage

[SetPermissions(Controller="Hello", Action ="Index")]
public ActionResult Index(int? page)
{ … }



Redirect for Unauthorized requests

Furthermore, it’s better to add the following 401 redirect settings in WebConfig.

<system.web>
      <error statusCode="401" redirect="~/error401.html" />
    </customErrors>
</system.web>



Or capture the 401 request on Global.asax

protected void Application_EndRequest(object sender, System.EventArgs e)
{
     if (Response.StatusCode == 401)
     {
         String redirectUri = "~/Error401.html";
         Response.Redirect(redirectUri);
     }
}


Reference