UWInfo Blog
發表新文章
[Join] | [忘記密碼] | [Login]
搜尋

搜尋意見
文章分類-#Author#
[所有文章分類]
所有文章分類
  • ASP.NET (48)
  • ASP.NET2.0 (15)
  • ASP.NET4.0 (34)
  • JavaScript (49)
  • jQuery (26)
  • FireFox (4)
  • UW系統設定 (3)
  • SQL (39)
  • SQL 2008 (25)
  • mirror (4)
  • SVN (4)
  • IE (9)
  • IIS (20)
  • IIS6 (1)
  • 閒聊 (7)
  • W3C (6)
  • 作業系統 (9)
  • C# (24)
  • CSS (12)
  • FileServer (1)
  • HTML 5 (11)
  • CKEditor (3)
  • UW.dll (13)
  • Visual Studio (16)
  • Browser (8)
  • SEO (1)
  • Google Apps (3)
  • 網站輔助系統 (4)
  • DNS (5)
  • SMTP (4)
  • 網管 (11)
  • 社群API (3)
  • SSL (4)
  • App_Inventor (1)
  • URLRewrite (2)
  • 開發工具 (6)
  • JSON (1)
  • Excel2007 (1)
  • 試題 (3)
  • LINQ (1)
  • bootstrap (0)
  • Vue (3)
  • IIS7 (3)
  • foodpanda (2)
  • 編碼 (2)
  • 資安 (3)
  • Sourcetree (1)
  • MAUI (1)
  • CMD (1)
  • my sql (1)
最新回應
  • Newtonsoft.Json.JsonConvert.DeserializeObject 失敗的情況
    test...more
  • dotnet ef dbcontext scaffold
    ...more
  • [ASP.NET] 利用 aspnet_regiis 加密 web.config
    ...more
  • IIS ARR (reverse proxy) 服務安裝
    ...more
  • [錯誤訊息] 請加入 ScriptResourceMapping 命名的 jquery (區分大小寫)
    ...more
  • 用 Javascript 跨網頁讀取 cookie (Cookie cross page, path of cookie)
    ...more
  • 線上客服 - MSN
    本人信箱被盜用以致資料外洩,是否可以請貴平台予以協助刪除該信箱之使用謝謝囉...more
  • 插入文字到游標或選取處
    aaaaa...more
  • IIS 配合 AD (Active Directory) 認証, 使用 .Net 6.0
    太感謝你了~~~你救了我被windows 認證卡了好幾天QQ...more
  • PostgreSQL 的 monitor trigger
    FOR EACH ROW 可能要改為 FOR EACH STATEMENT ...more
標籤
  • 280
  • orm
  • sp_
  • 加密
  • 472
  • net
  • Big5
  • 交易記錄已滿
  • 12
  • [t]
  • -9328
  • datetime
  • js UNION A
  • InvalidOpe
  • NPOI 弱點
  • 8942121121
  • 黑貓 egs
  • server job
  • checkbox
  • c
  • loopback
  • imvnOSCt
  • requestval
  • Encode
  • 空格
  • Config
  • USER
  • request
  • ses
  • ARR
  • Line
  • end
  • deploy
  • 28
  • sqlcmd
  • sln
  • 1552
  • 484
  • 310
  • PDQ
  • 4987
  • 906
  • SQL
  • ajax
  • CK
  • [u2]
  • ad
  • if
  • 問題
  • 安裝
搜尋 node 結果:
合併兩個 Expression -- Combining two expressions (Expression>)
找了很久,原來就在 梨子給的範例裡。

假設有兩個 expression: e1, e2

            var combineBody = Expression.AndAlso(e1.Body, Expression.Invoke(e2, e1.Parameters[0]));
            var finalExpression = Expression.Lambda<Func<TestClass, bool>>(combineBody, e1.Parameters).Compile();


同理,把上面的 AndAlso 換成 OrElse 就可以用 Or 合併。

即使只有兩行,還是不太可能背起來,所以當然要來做一下擴充

    public static class ExpressionExtension
    {
        public static Expression<Func<T, bool>> AndAlso<T>(this Expression<Func<T, bool>> e1, Expression<Func<T, bool>> e2)
        {
            var combineE = Expression.AndAlso(e1.Body, Expression.Invoke(e2, e1.Parameters[0]));

            return Expression.Lambda<Func<T, bool>>(combineE, e1.Parameters);
        }

        public static Expression<Func<T, bool>> OrElse<T>(this Expression<Func<T, bool>> e1, Expression<Func<T, bool>> e2)
        {
            var combineE = Expression.OrElse(e1.Body, Expression.Invoke(e2, e1.Parameters[0]));

            return Expression.Lambda<Func<T, bool>>(combineE, e1.Parameters);
        }
    }


使用範例:

            Expression<Func<Market, bool>> e1 = e => e.Is_Deleted == isDelete;

            Expression<Func<Market, bool>> e2 = e => string.IsNullOrEmpty(marketNo) || e.MarketNo.ToUpper().Contains(marketNo.ToUpper());

            return new
            {
                andMarkets = Ds.PageContext.ShopBandContext.Markets.Where(e1.AndAlso(e2)).ToList(),
                orMarkets = Ds.PageContext.ShopBandContext.Markets.Where(e1.OrElse(e2)).ToList(),
            };



 再補兩個擴充, 可以把多個 Expression 用 AndAlso 或 OrElse 串在一起:

        public static Expression<Func<T, bool>> OrElseAll<T>(this IEnumerable<Expression<Func<T, bool>>> exps)
        {
            if (exps.Count() == 1)
            {
                return exps.First();
            }

            var e0 = exps.First();

            var orExp = exps.Skip(1).Aggregate(e0.Body, (x, y) => Expression.OrElse(x, Expression.Invoke(y, e0.Parameters[0])));

            return Expression.Lambda<Func<T, bool>>(orExp, e0.Parameters);
        }

        public static Expression<Func<T, bool>> AndAlsoAll<T>(this IEnumerable<Expression<Func<T, bool>>> exps)
        {
            if (exps.Count() == 1)
            {
                return exps.First();
            }

            var e0 = exps.First();

            var orExp = exps.Skip(1).Aggregate(e0.Body, (x, y) => Expression.AndAlso(x, Expression.Invoke(y, e0.Parameters[0])));

            return Expression.Lambda<Func<T, bool>>(orExp, e0.Parameters);
        }


使用範例:

            Expression<Func<Market, bool>> q = e =>
            e.Is_Deleted == "N"
            && (string.IsNullOrEmpty(marketNo) || e.MarketNo.ToLower().Contains(marketNo.ToLower()))
            && (string.IsNullOrEmpty(isCombination) || isCombination != "Y" || e.TypeEnum == 200);

            if (!string.IsNullOrEmpty(name))
            {
                var nameList = name.Split(',').Select(e => e.Trim())
                    .Where(e => !string.IsNullOrEmpty(e));

                if (nameList.Any())
                {
                    q = q.AndAlso(nameList
                        .Select(s => (Expression<Func<Market, bool>>)(e => e.Name.ToLower().Contains(s.ToLower())))
                        .OrElseAll());
                }
            }






另外在 google,整理了 stackoverflow 幾篇文章之後得到的另一個方法,比較複雜, 不過可以讓人理解一下 Expression 比較底層的東西,也留下來參考一下。

    internal class MergeTool : ExpressionVisitor
    {
        private readonly ParameterExpression _parameter;

        protected override Expression VisitParameter(ParameterExpression node)
        {
            return base.VisitParameter(_parameter);
        }

        internal MergeTool(ParameterExpression parameter)
        {
            _parameter = parameter;
        }

        public static Expression<Func<T, bool>> MergedExpression<T>(Expression<Func<T, bool>> e1, Expression<Func<T, bool>> e2)
        {
            ParameterExpression param = Expression.Parameter(typeof(T));

            BinaryExpression MergeBody = Expression.AndAlso(e1.Body, e2.Body);

            var ReplacedBody = (BinaryExpression)new MergeTool(param).Visit(MergeBody);

            return Expression.Lambda<Func<T, bool>>(ReplacedBody, param);
        }
    }

使用時要 Compile

            var mergedExpression = MergeTool.MergedExpression(e1, e2);

            var list = testList.Where(mergedExpression.Compile());

More...
Bike, 2022/8/13 下午 05:53:28
windows 2008R2 大量工作排程的匯出備份以及匯入
由於工作排程往往有數十個甚至百來個 因此需要一個方法能快速備份及移轉到其他 server 的方法
查了一下,好像也只能這樣做

---- 使用指令把全部排程匯出 ----
參考網址
https://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

schtasks /query /XML > all_tasks.xml  
schtasks /query /FO CSV /V >sched_tasks.csv

** xml 比較有用,可以用來匯入到其他server排程,但還要額外處理才能匯入
** csv 只是用來看看目前有哪些排程 可以用來做報表看看
** 這些是全部排程,還要特別處理把 Microsoft 及其他軟體建的排程移除

--------------------------------------------------------------

----如何匯入工作排程到其他 server --------

** 需再寫程式把 all_tasks.xml 拆解成所有排程的單一 xml
   並且生成指令 bat

** 注意 xml 必須是 UTF-16 (unicode) 
   因為 "schtasks /query /XML > all_tasks.xml"產生 xml 是 ansi 

參考網址
https://serverfault.com/questions/325569/how-do-i-import-multiple-tasks-from-a-xml-in-windows-server-2008
** /TN "排程名稱" --- 排程名稱可以是路徑名 
D:\>schtasks.exe /create /TN "\2016JOB\Global\CountryMonthlyStats" /XML "D:\one_task.xml"
** 下面程式碼只是下面程式碼只是參考 還沒實作過
=====================================

var taskXML = new XmlDocument();
taskXML.Load(@"d:\temp\schedtasksBackup.xml");
var batbody = new StringBuilder();

XmlNodeList tasks = taskXML.DocumentElement.GetElementsByTagName("Task");

string strFileName = "d:\\temp\\Task";

for (int i = 0; i < tasks.Count; i++) {
    string onetaskXML = tasks[i].OuterXml;

    //Create the New File. With a little more extra effort
    //you can get the name from a comment above the task -> 應該把註解裡的名稱抓出
    XmlWriter xw = XmlWriter.Create(strFileName + "_" + (i+1) + ".xml");
    batbody.AppendLine(string.Format("schtasks.exe /create /TN \"{0}\" /XML \"{1}\"", "Task " + (i+1) + " Name", strFileName + "_" + (i+1) + ".xml"));

    //Write the XML
    xw.WriteRaw(onetaskXML.ToString());
    xw.Close();

    // Write a bat to import all the tasks
    var batfile = new System.IO.StreamWriter("d:\\temp\\importAllTasks.bat");
    batfile.WriteLine(batbody.ToString());
    batfile.Close();

}
=====================================

#微軟的排程備份真是有夠爛沒有辦法用介面一鍵搞定


More...
darren, 2017/5/5 下午 12:07:30
SPDY and HTTP/2

對於網頁加速的問題,已經被廣泛的討論了
主要在於減少 request 數以及減低網路傳輸的時間
也因此發展出一些技巧或技術,例如 css sprite, 資料gzip 等
瀏覽器也把連線數限制從2條變成6條,以加快網頁顯示的速度
然而若要網頁能有本質上的提升,則是該把 HTTP 這個老通訊協定升級了
(目前是HTTP/1.1, 1999年)

由Google Chrome推廣的 SPDY 標準,已經改良並訂為 HTTP/2 的標準 (2015年初定案)
他的重點在於 (如果我理解得沒錯的話,歡迎指正)
1. http header 也可壓縮 (HTTP1.1 header 無法壓縮)
2. 一個 connection 可以傳輸多個Content (HTTP1.1 一個request 一個 content)
3. 可以 Server Push 資料
4. 可以向下相容 1.1
實測上,可以讓網頁載入速度提升約 30%

目前,大部分瀏覽器已經支援 HTTP/2 標準,然而 Server 端的步調就緩慢許多
微軟的 IIS 要到 10 才支援,目前只有 windows 10 才有
Windows Server則要明年 2016 才有支援
相反於微軟,其他非微軟的開發速度上就快多了 例如 Node.js

---------------------------------------------------------
測試上,可以用 Chrome 的開發模式 把 protocol 欄位勾選顯示



h2 就是 http/2
More...
darren, 2015/8/31 上午 11:09:11
.NET Html Parser (HtmlAgilityPack)
之前做一些專案時,會有需要去爬別人的網站。
例如找出網頁某個區塊把他截錄到資料庫
HtmlAgility Pack 是不錯的工具
http://msdn.microsoft.com/zh-tw/evalcenter/ee787055.aspx

使用上,就有點像是操作 XmlDocument 一樣
一些常用的語法 SelectNodes, SelectSingleNode 幾乎一樣
也有跟 XPath 一樣的操作方法,很方便

'載入物件,bin/ 要放入 .dll
Imports HtmlAgilityPack

'*********************
Dim html As New HtmlDocument()
html.LoadHtml("...一大塊HTML,可以是整個網頁,也可以是html區塊...")

'找出所有img tag
Dim imgNodes As HtmlNodeCollection = html.DocumentNode.SelectNodes("//img")
For Each node As HtmlNode In imgNodes
    Dim strUrl As String = node.GetAttributeValue("src", "")
    ......
Next
​
More...
darren, 2014/9/23 下午 02:35:23
Firefox 抓滑鼠在HTML Element上的位置
Firefox 沒有 offsetX 和 offsetY,解決方法是從父層把left 和top做累加。
    function getOffset(e) {
        /*e: Mousemove Event*/
        if (e.target.offsetLeft == undefined) {
            /*firefox only*/
            e.target = target.parentNode;
        }
        var tarPos = getTarPos(e.target);
        var tarMousePos = { x: window.pageXOffset + e.clientX, y: window.pageYOffset + e.clientY     };
        var offset = { offsetX: tarMousePos.x - tarPos.x, offsetY: tarMousePos.y - tarPos.y };
        return offset;
    }
    function getTarPos(el) {
        var page = { x: 0, y: 0 };
        while (el) {
            page.x += el.offsetLeft;
            page.y += el.offsetTop;
            el = el.offsetParent;
        }
        return page;
    }
More...
瞇瞇, 2012/5/31 下午 12:59:46
~ Uwinfo ~