plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'application'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
mainClassName = "main.Main"
repositories {
mavenCentral()
}
configurations {
externalLibs
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:28.0-jre'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
// https://mvnrepository.com/artifact/javax.mail/javax.mail-api
implementation group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.17.1'
//external libs, for example: xxx.dll
externalLibs files('xxxExternalLib1, xxxExternalLib2')
}
shadowJar{
transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer)
archiveFileName = "${baseName}.${extension}"
}
jar {
manifest {
attributes(
'Main-Class': 'main.Main',
"Multi-Release": true
)
}
from configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
from configurations.externalLibs.collect { it }
}
<package>
<job id=XXX>
<script language="VBScript">
parOutlookMsgFile("D:\testOutlookMail.msg")
parseOutlookInboxFolder(6)
'''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub parOutlookMsgFile(msgFilePath)
Dim objOutlook
'Dim objInBoxFolder
'Dim objNameSpace
Set objOutlook = CreateObject("Outlook.Application")
'Set objNameSpace = objOutlook.GetNamespace("MAPI")
'Set objInBoxFolder = objNameSpace.GetDefaultFolder(6)
Dim mail, recips, recip, email_single, pa
Set mail = objOutlook.CreateItemFromTemplate(msgFilePath)
Set recips = mail.Recipients
For Each recip In recips
Set pa = recip.PropertyAccessor
email_single = pa.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E")
WScript.Echo "Receiver Name: " & recip.Name & ", Receiver Email: " & email_single & ", type: " & recip.Type
Next
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub parseOutlookInboxFolder(inboxFolderType)
'inboxFolderType:
' received mail inbox: 6
' deleted mail inbox : 3
' sent mail inbox : 5
Dim objOutlook, objInBoxFolder, objNameSpace, objMailItems
Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objInBoxFolder = objNameSpace.GetDefaultFolder(inboxFolderType)
Set objMailItems = objInBoxFolder.Items
Dim i
i = 1
Dim totalMailCount
totalMailCount = objMailItems.count
While i <= totalMailCount
Set objMail = objMailItems.Item(i)
WScript.Echo objMail.Subject
i = i + 1
Wend
End Sub
</script>
</job>
</package>
說明:
程式碼中有兩個函式,分別是用來讀取單一 Msg 檔資訊的 parOutlookMsgFile()
和 讀取 Outlook 收件夾(或刪除的郵件、寄件備份等資料夾)裡的信件資訊的 parseOutlookInboxFolder()。
在 parOutlookMsgFile() 中,recip.Type 可能有 1 或 2 兩種值,
Type = 1 代表一般收件者,
Type = 2 代表 cc 副本的收件者。
parseOutlookInboxFolder() 函式可以接收收件夾 type (OlDefaultFolders 形別) 的值,
The Commons HttpClient project is now end of life, and is no longer being
developed. It has been replaced by the Apache HttpComponents project in its
HttpClient and HttpCore modules, which offer better performance and more
flexibility.
UploadFileTestjava:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.httpclient.util.EncodingUtil;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
public class UploadFileTest {
public static void main(String[] args) throws FileNotFoundException, IOException {
uploadFile_1("C:\\Users\\Hugo\\Pictures\\未命名.png", "http://localhost:8080/uploadFile.do");
uploadFile_2("C:\\Users\\Hugo\\Pictures\\未命名.png", "http://localhost:8080/uploadFile.do");
}
public static void uploadFile_1(String filePath, String uploadTo) throws FileNotFoundException, IOException {
File file = new File(filePath);
HttpPost httpPost = new HttpPost(uploadTo);
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
//Use RFC6532 mode to avoid encoding Mojibake (garbled text) of fileName
//使用 RFC6532 來避免中文等的檔案名稱在傳遞後變成亂碼
multipartEntityBuilder.setMode(HttpMultipartMode.RFC6532);
multipartEntityBuilder.addPart("uploadedFile", new FileBody(file, ContentType.create(URLConnection.guessContentTypeFromName(file.getName())) , file.getName()));
// multipartEntityBuilder.addPart("uploadedFile", new FileBody(file, ContentType.APPLICATION_OCTET_STREAM, file.getName()));
// multipartEntityBuilder.addBinaryBody("uploadedFile", file, ContentType.APPLICATION_OCTET_STREAM, file.getName());
multipartEntityBuilder.addPart("param1", new StringBody("中文", ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8)));
// multipartEntityBuilder.addTextBody("param1", "中文", ContentType.TEXT_PLAIN.withCharset(StandardCharsets.UTF_8));
HttpEntity httpEntity = multipartEntityBuilder.build();
httpPost.setEntity(httpEntity);
try (CloseableHttpClient httpClient = HttpClients.createDefault();
) {
CloseableHttpResponse httpResponse = httpClient.execute(httpPost);
String responseStr = EntityUtils.toString(httpResponse.getEntity());
} catch (IOException e) {
e.printStackTrace();
}
}
public static void uploadFile_2(String filePath, String uploadTo) {
File f = new File(filePath);
PostMethod filePost = new PostMethod(uploadTo);
filePost.getParams().setContentCharset("UTF-8");
// filePost.addRequestHeader("xx", "xxx"); // if you want to add any header
try {
Part[] parts = {
new StringPart("param1", "中文", "UTF-8")
, new FilePart("uploadedFile", f) {
@Override
protected void sendDispositionHeader(OutputStream out) throws IOException {
// override 掉sendDispositionHeader 方法以解決中文 fileName 傳送後會變成亂碼的問題
// 在原始碼中是用 getAsciiBytes(fileName),我們這裡改用utf-8 去 encode
// super.sendDispositionHeader(out) is overridden, use UTF-8 instead of Ascii to
// encode filename
// run code copied form Part.sendDispositionHeader() directly
out.write(CONTENT_DISPOSITION_BYTES);
out.write(QUOTE_BYTES);
out.write(EncodingUtil.getAsciiBytes(getName()));
out.write(QUOTE_BYTES);
String filename = getSource().getFileName();
if (filename != null) {
out.write(EncodingUtil.getAsciiBytes(FILE_NAME));
out.write(QUOTE_BYTES);
out.write(EncodingUtil.getBytes(filename, "utf-8"));
out.write(QUOTE_BYTES);
}
}
}
};
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
HttpClient client = new HttpClient();
int status = client.executeMethod(filePost);
String responseStr = filePost.getResponseBodyAsString();
}catch(IOException e) {
e.printStackTrace();
}
}
}
SELECT *
FROM myXxxServer.xxxDatabase.dbo.xxxTable
還可以做到跨 sql server 的 JOIN 等操作,非常方便,例如:
SELECT *
FROM myXxxServer.xxxDatabase.dbo.xxxTable A INNER JOIN
someTable B ON A.a = B.b
或是倒資料,例如:
INSERT INTO A(a1, a2)
SELECT b1, b2
FROM myXxxServer.xxxDatabase.dbo.B
最後再用以下語法登出 xxxServer
exec sp_dropserver 'myXxxServer', 'droplogins' -- free myXxxServer linked server
**補充:
如果要倒的資料欄位裡有主鍵 (Primary Key),
需要把禁止修改主鍵的功能關掉,Update 資料完後再開回來。
再來此時不能用星號 "*" 來代表所有欄位,要把欄位名稱一個個寫出來才能成功寫入。
例如:
SET IDENTITY_INSERT A ON;
INSERT INTO A(a1, a2)
SELECT b1, b2
FROM myXxxServer.xxxDatabase.dbo.B
SET IDENTITY_INSERT A OFF;
如果想要快速的得到欄位名稱的字串,可以用以下語法來得到 (以下為得到名為 A 這個 table 的所有欄位名稱,會用逗號分隔欄位名,最後用成一串字來輸出):
SELECT SUBSTRING(
(
SELECT ', ' + QUOTENAME(COLUMN_NAME)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'A'
ORDER BY ORDINAL_POSITION
FOR XML path('')
)
, 3, 200000
)
因為有使用到一些 jQuery 的 function,例如 innerHeight,所有需要先 include jQuery
直接上程式碼及範例:
html:
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
This <textarea> will change its height to contain content.
<div ng-app="app" ng-controller="controller as ctrl">
<textarea textarea-auto-resizer></textarea>
</div>
javascript:
angular.module("app", [])
.controller("controller", ["$scope", function($scope) {
var self = this;
self.text = "long words - long words - long words - long words - long words - long words - long words - long words - long words - long words - long words - long words - long words - long words - long words"
}])
.directive('textareaAutoResizer', ["$sce", function($sce) {
return {
link: function(scope, element, attrs, ngModel) {
autoResizeTextArea();
scope.$watch(attrs.ngModel, function(newValue, oldValue) {
autoResizeTextArea();
});
element.on("input", autoResizeTextArea);
function autoResizeTextArea(event) {
var dom = angular.element(element);
dom.css({
height: ""
});
if (dom.prop("scrollHeight") > dom.innerHeight()) {
//set dom height(without padding part) to scrollHeight - padding part
dom.height(dom.prop("scrollHeight") - (dom.innerHeight() - dom.height()));
}
}
}
};
}]);