Skip to content

Commit 62534aa

Browse files
author
seal
committed
add config info statistics
1 parent 4bf4bbc commit 62534aa

File tree

4 files changed

+98
-13
lines changed

4 files changed

+98
-13
lines changed

src/wu/seal/jsontokotlin/ConfigManager.kt

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package wu.seal.jsontokotlin
22

33
import com.intellij.ide.util.PropertiesComponent
4+
import wu.seal.jsontokotlin.statistics.sendConfigInfo
45

56
/**
67
* ConfigManager
@@ -33,36 +34,65 @@ interface IConfigManager {
3334
var isPropertiesVar: Boolean
3435
get() = if (isTestModel) TestConfig.isPropertiesVar else PropertiesComponent.getInstance().isTrueValue(IS_PROPERTIES_VAR_KEY)
3536
set(value) = if (isTestModel) {
36-
} else PropertiesComponent.getInstance().setValue(IS_PROPERTIES_VAR_KEY, value)
37+
} else {
38+
PropertiesComponent.getInstance().setValue(IS_PROPERTIES_VAR_KEY, value)
39+
Thread(){
40+
sendConfigInfo()
41+
}.start()
42+
}
3743

3844

3945
var isCommentOff: Boolean
4046
get() = if (isTestModel) TestConfig.isCommentOff else PropertiesComponent.getInstance().isTrueValue(IS_COMMENT_OFF)
4147
set(value) = if (isTestModel) {
42-
} else PropertiesComponent.getInstance().setValue(IS_COMMENT_OFF, value)
48+
} else {
49+
PropertiesComponent.getInstance().setValue(IS_COMMENT_OFF, value)
50+
Thread(){
51+
sendConfigInfo()
52+
}.start()
53+
}
4354

4455

4556
var targetJsonConverterLib: TargetJsonConverter
4657
get() = if (isTestModel) TestConfig.targetJsonConvertLib else TargetJsonConverter.valueOf(PropertiesComponent.getInstance().getValue(TARGET_JSON_CONVERTER_LIB_KEY) ?: TargetJsonConverter.None.name)
4758
set(value) = if (isTestModel) {
48-
} else PropertiesComponent.getInstance().setValue(TARGET_JSON_CONVERTER_LIB_KEY, value.name)
59+
} else {
60+
PropertiesComponent.getInstance().setValue(TARGET_JSON_CONVERTER_LIB_KEY, value.name)
61+
Thread(){
62+
sendConfigInfo()
63+
}.start()
64+
}
4965

5066
var isPropertyNullable: Boolean
5167
get() = if (isTestModel) TestConfig.isPropertyNullable else PropertiesComponent.getInstance().isTrueValue(IS_PROPERTY_NULLABLE_KEY)
5268
set(value) = if (isTestModel) {
53-
} else PropertiesComponent.getInstance().setValue(IS_PROPERTY_NULLABLE_KEY, value)
69+
} else {
70+
PropertiesComponent.getInstance().setValue(IS_PROPERTY_NULLABLE_KEY, value)
71+
Thread(){
72+
sendConfigInfo()
73+
}.start()
74+
}
5475

5576

5677
var initWithDefaultValue: Boolean
5778
get() = if (isTestModel) TestConfig.initWithDefaultValue else PropertiesComponent.getInstance().getBoolean(INIT_WITH_DEFAULT_VALUE_KEY)
5879
set(value) = if (isTestModel) {
59-
} else PropertiesComponent.getInstance().setValue(INIT_WITH_DEFAULT_VALUE_KEY, value)
80+
} else{
81+
PropertiesComponent.getInstance().setValue(INIT_WITH_DEFAULT_VALUE_KEY, value)
82+
Thread(){
83+
sendConfigInfo()
84+
}.start()
85+
}
6086

6187
var userUUID: String
6288
get() = if (isTestModel) "" else PropertiesComponent.getInstance().getValue(USER_UUID_KEY, "")
6389
set(value) = if (isTestModel) {
64-
} else PropertiesComponent.getInstance().setValue(USER_UUID_KEY, value)
65-
90+
} else {
91+
PropertiesComponent.getInstance().setValue(USER_UUID_KEY, value)
92+
Thread(){
93+
sendConfigInfo()
94+
}.start()
95+
}
6696
}
6797

6898
/**

src/wu/seal/jsontokotlin/JsonToKotlinApplication.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package wu.seal.jsontokotlin
22

33
import com.intellij.openapi.components.ApplicationComponent
4+
import wu.seal.jsontokotlin.statistics.sendConfigInfo
45
import wu.seal.jsontokotlin.statistics.sendHistoryExceptionInfo
56
import wu.seal.jsontokotlin.statistics.sendHistoryActionInfo
67

@@ -17,6 +18,7 @@ class JsonToKotlinApplication : ApplicationComponent {
1718

1819
println("init json to kotlin ")
1920
Thread() {
21+
sendConfigInfo()
2022
sendHistoryExceptionInfo()
2123
sendHistoryActionInfo()
2224
}.start()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package wu.seal.jsontokotlin.statistics
2+
3+
import com.google.gson.Gson
4+
import wu.seal.jsontokotlin.ConfigManager
5+
import wu.seal.jsontokotlin.PLUGIN_VERSION
6+
import wu.seal.jsontokotlin.isTestModel
7+
8+
/**
9+
*
10+
* Created by Seal.Wu on 2017/9/27.
11+
*/
12+
data class ConfigInfo(
13+
val uuid: String = UUID,
14+
val pluginVersion: String = PLUGIN_VERSION,
15+
val isPropertiesVar: Boolean = ConfigManager.isPropertiesVar,
16+
val isCommentOff: Boolean = ConfigManager.isCommentOff,
17+
val isPropertyNullable: Boolean = ConfigManager.isPropertyNullable,
18+
val initWithDefaultValue: Boolean = ConfigManager.initWithDefaultValue,
19+
val targetJsonConverterLib: String = ConfigManager.targetJsonConverterLib.name
20+
)
21+
22+
23+
fun main(args: Array<String>) {
24+
isTestModel =true
25+
println(Gson().toJson(ConfigInfo()))
26+
}

src/wu/seal/jsontokotlin/statistics/NetWork.kt

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package wu.seal.jsontokotlin.statistics
22

3+
import com.google.gson.Gson
4+
import wu.seal.jsontokotlin.isTestModel
35
import java.net.HttpURLConnection
46
import java.net.URL
57

@@ -10,19 +12,23 @@ import java.net.URL
1012

1113
const val actionInfoUrl = "http://jsontokotlin.sealwu.com:8008/sendActionInfo"
1214
const val exceptionLogUrl = "http://jsontokotlin.sealwu.com:8008/sendExceptionInfo"
15+
const val configLogUrl = "http://jsontokotlin.sealwu.com:8008/sendConfigInfo"
16+
//const val actionInfoUrl = "http://localhost:8008/sendActionInfo"
17+
//const val exceptionLogUrl = "http://localhost:8008/sendExceptionInfo"
18+
//const val configLogUrl = "http://localhost:8008/sendConfigInfo"
1319

1420
fun sendExceptionLog(log: String) {
1521
try {
1622
val connection = URL(exceptionLogUrl).openConnection() as HttpURLConnection
1723
connection.doOutput = true
18-
connection.doInput=true
19-
connection.addRequestProperty("Content-Type","application/text")
24+
connection.doInput = true
25+
connection.addRequestProperty("Content-Type", "application/text")
2026
val outputStream = connection.outputStream
2127
val writer = outputStream.writer()
2228
writer.write(log)
2329
writer.flush()
2430
if (connection.responseCode != 200) {
25-
println(connection.responseMessage+"\n"+connection.errorStream.reader().readText())
31+
println(connection.responseMessage + "\n" + connection.errorStream.reader().readText())
2632
}
2733
} catch(e: Exception) {
2834
e.printStackTrace()
@@ -36,14 +42,14 @@ fun sendActionInfo(actionInfo: String) {
3642
val connection = URL(actionInfoUrl).openConnection() as HttpURLConnection
3743
connection.doOutput = true
3844
connection.requestMethod = "POST"
39-
connection.addRequestProperty("Content-Type","application/json;charset=UTF-8")
45+
connection.addRequestProperty("Content-Type", "application/json;charset=UTF-8")
4046

4147
val outputStream = connection.getOutputStream()
4248
val writer = outputStream.writer()
4349
writer.write(actionInfo)
4450
writer.flush()
4551
if (connection.responseCode != 200) {
46-
println(connection.responseMessage+"\n"+connection.errorStream.reader().readText())
52+
println(connection.responseMessage + "\n" + connection.errorStream.reader().readText())
4753
}
4854
} catch(e: Exception) {
4955
e.printStackTrace()
@@ -71,10 +77,31 @@ fun sendHistoryActionInfo() {
7177
PersistCache.deleteAllActionInfo()
7278
}
7379

80+
fun sendConfigInfo() {
81+
try {
82+
val connection = URL(configLogUrl).openConnection() as HttpURLConnection
83+
connection.doOutput = true
84+
connection.requestMethod = "POST"
85+
connection.addRequestProperty("Content-Type", "application/json;charset=UTF-8")
86+
87+
val outputStream = connection.getOutputStream()
88+
val writer = outputStream.writer()
89+
writer.write(Gson().toJson(ConfigInfo()))
90+
writer.flush()
91+
if (connection.responseCode != 200) {
92+
println(connection.responseMessage + "\n" + connection.errorStream.reader().readText())
93+
}
94+
} catch(e: Exception) {
95+
e.printStackTrace()
96+
}
97+
}
7498

7599
fun main(args: Array<String>) {
76-
val demeoActionInfo =""" {"id":0,"uuid":"214fdsafsafafsdf","pluginVersion":"1.2.1","actionType":"start","time":"1234231434124324","daytime":"2017-09-27"}"""
100+
isTestModel = true
77101

102+
val demeoActionInfo = """ {"id":0,"uuid":"214fdsafsafafsdf","pluginVersion":"1.2.1","actionType":"start","time":"1234231434124324","daytime":"2017-09-27"}"""
78103
sendExceptionLog("hello,I am exception")
79104
sendActionInfo(demeoActionInfo)
105+
106+
sendConfigInfo()
80107
}

0 commit comments

Comments
 (0)