2019年12月20日 星期五
[C#] 推薦分析程式工具
推薦暗黑大筆記 : 重構筆記 - .NET 壞味道補充包
裡面有NDepend 套件內的依些壞味道rule
一些常見的壞味道
1.一個類別太大 200行以上
2.方法太大太複雜
3.方法參數過多
還有很多值得學習與思考的地方
強烈推薦可以去研究看看
2019年12月19日 星期四
[sql] 將特定欄位當作 column
最近遇到要把 資料庫某個欄位當作 column 使用
所以就查詢了一下,目前有兩種方式
1.使用PIVOT, 轉置table, 但是原始column name 不能跟欄位裡面的值重複, 不然會出錯
說明: 先動態取得要轉置成column的欄位, ColumnGroup , 組成需要的字串, 再用PIVOT轉置TABLE
所以就查詢了一下,目前有兩種方式
1.使用PIVOT, 轉置table, 但是原始column name 不能跟欄位裡面的值重複, 不然會出錯
說明: 先動態取得要轉置成column的欄位, ColumnGroup , 組成需要的字串, 再用PIVOT轉置TABLE
2019年12月13日 星期五
2019年11月21日 星期四
[Nlog] 簡易config
<?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="true" throwExceptions="false" internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> <!-- optional, add some variables https://github.com/nlog/NLog/wiki/Configuration-file#variables --> <variable name="myvar" value="myvalue"/> <!-- See https://github.com/nlog/nlog/wiki/Configuration-file for information on customizing logging rules and outputs. --> <targets> <!-- add your targets here See https://github.com/nlog/NLog/wiki/Targets for possible targets. See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers. --> <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" /> </targets> <rules> <!-- add your logging rules here --> <logger name="*" minlevel="Trace" writeTo="f" /> <!-- Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f" <logger name="*" minlevel="Debug" writeTo="f" /> --> </rules> </nlog>
補充 :
如果想要自訂參數 ex.${event-context:item=Name}
程式中記得自訂log level 與參數即可
private static void WriteLog(string msg) { LogEventInfo ei = new LogEventInfo(NLog.LogLevel.Trace, "", ""); ei.Properties["Name"] = Guid.NewGuid(); ei.Properties["msg"] = msg; logger.Log(ei); }
config 加入 event-context 參數即可
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}/${event-context:item=appName}.log" layout="${longdate} |${uppercase:${level}}| ${event-context:item=msg}" /> </targets>
[pdf] [C#] 網頁匯出PDF - PuppeteerSharp
最近遇到需要將頁面轉PDF
這裡推薦一個套件,真的滿厲害的
比起自己用itext刻快多了~
參考範例 :
特別說明,如果要讓pdf完整套用跟畫面一致,請記得設定參數唷
new PdfOptions() { PrintBackground = true, PreferCSSPageSize = true }
參考
黑暗blog :https://blog.darkthread.net/blog/headless-chrome/
Api說明 : https://www.puppeteersharp.com/api/PuppeteerSharp
這裡推薦一個套件,真的滿厲害的
比起自己用itext刻快多了~
參考範例 :
特別說明,如果要讓pdf完整套用跟畫面一致,請記得設定參數唷
new PdfOptions() { PrintBackground = true, PreferCSSPageSize = true }
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions() { Headless = true })) { //參考頁面 https://www.puppeteersharp.com/api/PuppeteerSharp.ScreenshotOptions.html using (var page = await browser.NewPageAsync()) { var loginPath = $"https://google.com"; await page.GoToAsync(loginPath); await page.EmulateMediaTypeAsync(PuppeteerSharp.Media.MediaType.Screen); //透過SetViewport控制視窗大小決定抓圖尺寸 await page.SetViewportAsync(new ViewPortOptions { Width = 1024, Height = 768 }); var outputFile = $"test.pdf"; await page.PdfAsync(outputFile, new PdfOptions() { PrintBackground = true, PreferCSSPageSize = true }); } }
參考
黑暗blog :https://blog.darkthread.net/blog/headless-chrome/
Api說明 : https://www.puppeteersharp.com/api/PuppeteerSharp
2019年10月25日 星期五
[deploy] 遠端發佈 error - 处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler”
錯誤訊息 : 处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler”
解法 : 發現結果是沒有安裝 .net 4.6, 再安裝即可
1.進windows功能 啟用 .net 4.6
2.管理者權限進入 cmd
32位元:C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
64位位元:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
ref :https://www.cnblogs.com/mrma/p/3529859.html
解法 : 發現結果是沒有安裝 .net 4.6, 再安裝即可
1.進windows功能 啟用 .net 4.6
2.管理者權限進入 cmd
32位元:C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
64位位元:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
ref :https://www.cnblogs.com/mrma/p/3529859.html
2019年10月18日 星期五
[sql] 切開同一欄位用逗點隔開的資訊
遇到一個狀況,資料庫顯示為
| CODE | FK |
-----------------------
| A | 1,2,3 |
我需要轉如下才能關聯....| CODE | FK |
-----------------------
| A | 1 |
| A | 2 |
| A | 3 |
解法 :
參考 : https://stackoverflow.com/questions/13527537/sql-query-to-split-column-data-into-rows
先建立sql function
create FUNCTION [dbo].[Split](@String varchar(MAX), @Delimiter char(1))
returns @temptable TABLE (items varchar(MAX))
as
begin
declare @idx int
declare @slice varchar(8000)
select @idx = 1
if len(@String)<1 or @String is null return
while @idx!= 0
begin
set @idx = charindex(@Delimiter,@String)
if @idx!=0
set @slice = left(@String,@idx - 1)
else
set @slice = @String
if(len(@slice)>0)
insert into @temptable(Items) values(@slice)
set @String = right(@String,len(@String) - @idx)
if len(@String) = 0 break
end
return
end;
然後下以下sql 句即可
select t1.Code, s.items FK
from [table] t1
outer apply dbo.Split(t1.FK, ',') s
outer apply : 說明參考 https://ithelp.ithome.com.tw/articles/10195219
訂閱:
文章 (Atom)
