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()));
}
}
}
};
}]);
之後會建立自己的 Mod
java class,所以可以 ExampleMod.java 刪掉或是把其中的 @Mod 那行刪掉,
被紅框框起來的部份是我自己建立的 Mod Class 檔: com.my.mode.MyMod.java,
接著要為此 Mod 決定一個 Mod 的名稱,也可以說是 Mod Id,只能英文小寫,
此例我們決定叫做 mymod,
決定好 Mod Id 後,要在
main/resources/META-INF/mods.toml
裡設定 Mod Id,在 mods.toml 中,紀錄著 Mod 的相關資訊,例如 Mod Id, Mod
的名稱、敘述、作者資料等資訊,在 Minecraft 的 Mod 資訊頁面上也會顯示這些東西。
為了簡單,我們不修改其他東西,因為並不影響自制 Mod 的功能,
只要把下列這行修改成自己的 Mod Id 即可:
# The modid of the mod
modId="mymod" #mandatory
以下直接看程式碼:
mods.toml
# This is an example mods.toml file. It contains the data relating to the loading mods.
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here: https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[35,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license="All rights reserved"
# A URL to refer people to when problems occur with this mod
issueTrackerURL="http://my.issue.tracker/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="mymod" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version="${file.jarVersion}" #mandatory
# A display name for the mod
displayName="My Mod" #mandatory
# A URL to query for updates for this mod. See the JSON update specification <here>
updateJSONURL="http://myurl.me/" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
displayURL="http://example.com/" #optional
# A file name (in the root of the mod JAR) containing a logo for display
logoFile="mymod.png" #optional
# A text field displayed in the mod UI
credits="Thanks for this example mod goes to Java" #optional
# A text field displayed in the mod UI
authors="Love, Cheese and small house plants" #optional
# The description text for the mod (multi line!) (#mandatory)
description='''
This is a long form description of the mod. You can write whatever you want here
Have some lorem ipsum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis lacinia magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis luctus odio eu tempus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque volutpat ligula eget lacus auctor sagittis. In hac habitasse platea dictumst. Nunc gravida elit vitae sem vehicula efficitur. Donec mattis ipsum et arcu lobortis, eleifend sagittis sem rutrum. Cras pharetra quam eget posuere fermentum. Sed id tincidunt justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.examplemod]] #optional
# the modid of the dependency
modId="forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
versionRange="[35,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
side="BOTH"
# Here's another dependency
[[dependencies.examplemod]]
modId="minecraft"
mandatory=true
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.16.4,1.17)"
ordering="NONE"
side="BOTH"