linmasaki / WebTool

C# WebTool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Webtool

  • Google Tool
  • Common Tool
  • Other Extra Kit
  • ...

Google Tool

Google Url Shortening

使用此API時,您必須先向Google申請相關的憑證

To convert longUrl to shortUrl:

using WebTool.Google;

//Generate short URLs
var urlShortener = new UrlShortener("Your Google Api Key");
var shortUrl = urlShortener.GetShorten("Souece URL");

To convert shortUrl to sourceUrl:

using WebTool.Google;

//Generate short URLs
var urlShortener = new UrlShortener("Your Google Api Key");
var sourceUrl = urlShortener.GetExpand("Short URL");

Common Tool

Image Tool

Convert image to new size image:

using WebTool.Common;

//Resize target image
System.Drawing.Image image = Image.FromStream(postedFile.InputStream, true, true);
image = image.Resize(width, height, ImageTool.ResizeMode.Normal);
  • ResizeMode :
    1.Normal : 維持原本的圖片比例,以指定寬高中比例較小的一方為基準去做等比例放大或縮小
    2.Stretch : 以指定的寬高來放大或縮小圖片
    3.Crop : 以指定寬高中比例較大的一方為基準去做等比例縮放後(維持原本的圖片比例),再做剪裁
    4.Fill : 以指定寬高中比例較小的一方為基準去做等比例縮放後(維持原本的圖片比例),不足部分將以空白補上
    5.Designation : 以指定的寬高及位置來對圖片做剪裁

Add watermark text to image:

File Tool

List files by target directory:

using WebTool.Common;

//Resize target image
List<string> fileList = FileTool.ListFiles((string)dirPath, (bool)showSub, (bool)showHidden);
  • 參數解說:
    dirPath : 目標目錄路徑
    showSub : 是否包含子目錄下的檔案   (default:true)
    showHidden : 是否包含隱藏檔案   (default:true)

Other Extra Kit

Snapshoter Web Host By Url

使用此工具首先必須先在Web專案下加入 Awesomium 相關套件

Awesomium.Core.dll (Core assembly)
Awesomium.Core.XML (XML Documentation used by VS IntelliSense)
avcodec-53.dll
avformat-53.dll
avutil-51.dll
awesomium.dll
awesomium_process
icudt.dll
libEGL.dll
libGLESv2.dll
xinput9_1_0.dll
inspector.pak (Awesomium Inspector assets)
pdf_js.pak

接著需在Web專案下的 Global.asax 裡加入以下程式碼

Global.asax:

void Application_Start(object sender, EventArgs e)
{
	// 在應用程式啟動時執行的程式碼
    Thread awesomiumThread = new Thread(Snapshoter.AwesomiumThread);
    awesomiumThread.Start();

    // Wait for the WebCore to start.
    while (!Snapshoter.webCoreStarted)
    	Thread.Sleep(10);
}

使用方式請參考
/WebTool.Web/Ajax/SnapshoterHandler.ashx
/WebTool.Web/App_Code/Snapshoter.cs

Awesomium套件及參考來源: http://www.awesomium.com/

Amazon S3 Storage Tool

使用此工具首先必須先從NUGET安裝AWSSDK, 接著再web.config 或 app.config 裡加入以下片段

  <configSections>
    <section name="aws" type="Amazon.AWSSection, AWSSDK"/>
  </configSections>
  <aws profileName="developer" region="ap-northeast-1" profilesLocation="D:\credentials" />

credentials檔案內容格式如下

[default]
aws_access_key_id = AKIAIXX123J6LYYRC5SW
aws_secret_access_key = uYFH6FNkP0tyuJJp9fAxxxxx0.......
[developer]
aws_access_key_id = AKIAIXX123J6LYYRC5F1
aws_secret_access_key = uYFH6FNkP0tyuJJp9fAxxxxx1.......

使用方式請參考
/WebTool.Web/Ajax/Amazon/
/WebTool.Web/App_Code/Amazon/S3StorageTool

Amazon套件設定參考

About

C# WebTool


Languages

Language:C# 77.4%Language:ASP 22.6%