-
Notifications
You must be signed in to change notification settings - Fork 1
resource
muune edited this page Mar 6, 2019
·
24 revisions
- i18n : Ch.i18n.add()
- font : Ch.style.addFont()
- style : Ch.style.add()
- shape : Ch.drawable.shape()
- api : Ch.net.add()
- ruleset : Ch.ruleset.add()
- query : Ch.sql.addDb()
- db : Ch.sql.addQuery()
- Ch 생성자에서 두번째 인자로 받은 path에서 각각의 resource(i18n, font, style, shape, api, ruleset, query, db)가 처리된다.
- 처음에 로컬파일에 있는 json을 읽어오고, 각각의 resource에 따라 리소스가 Res형태로 생성되서 DB에 id와 내용이 들어간다.
- 인터넷이 사용이 안 되는 환경이면 이 로컬파일의 내용들로만 실행이 된다.
- 호스트 코드에서 gateway로 선언한 api로 통신해서 json을 불러오고 이 내용으로 리소스가 Res형태로 DB에 삭제, 변경, 추가된다. * 아래 Ch.res.load() 참고
- 참고 Chela init
//App.kt
//Ch(application:Application, path:String = "")
Ch(this, "setting.json")
// setting.json
// "inited"가 db에 저장될 때의 key
{
"inited": {
"api": {
"gateway": {
"url": "http://www.bsidesoft.com:9980/seller2/api/gateway",
"method": "POST",
"requestTask": "akey|sheader|gateway|aes",
"responseTask": "pkey|aes|json|error|data",
"request": {
"id": {}
}
}
},
"i18n": {
"language": "en",
"footer": {
"ver": 1,
"isOne": "en",
"data": {
"en": {
"footer": "2019 ©Zalagar Seoul All Rights Reserved."
}
}
}
},
"shape": {
"inputFocus": {
"corner": "5dp",
"strokeWidth": "1.5dp",
"strokeColor": "#18ba9b",
"solid": "#ffffff"
}
},
"font": {
"nn": "https://www.bsidesoft.com/hika/nanum.png"
},
"style": {
"actionbar": {
"background": "#18ba9b"
},
"alert": {
"background": "#fa635c",
"textColor": "#ffffff",
"textSize": "12dp"
}
},
"db": {
"seller": {
"isDefault": true,
"asset": "seller.mp4",
"keyProvider": "base"
}
}
}
}
Ch.res.load(res:JSONObject)
- Resource json을 불러온다.
- 각각의 Resource(i18n, font, style, shape, api, ruleset, query, db)에 따라 리소스가 Res형태로 생성되서 DB에 내용이 들어가게 된다.
- "remove"에 삭제할 key를 적어주면 해당하는 데이터는 다 지워준다.
//http://www.bsidesoft.com:9980/seller2/api/gateway의 내용
// "gateway#1"가 db에 저장될 때의 key
{
"data": {
"remove": [
"old1",
"old2"
],
"gateway#1": {
"api": {
"base": "https://seller2.bsidesoft.com/",
"islogin": {
"url": "/api/?member/islogin",
"method": "POST",
"requestTask": "sheader",
"responseTask": "json|data",
"request": {
"authtoken": {}
}
},
"login": {
"url": "/api/?member/signin",
"method": "POST",
"requestTask": "sheader|jsonBody",
"responseTask": "json|authtoken|error|data[us.slab.seller.vo.User]",
"request": {
"userid": {
"name": "userid",
"rules": "se.userid"
},
"pass": {
"name": "userpw",
"rules": "se.pass"
}
}
}
},
"ruleset": {
"se": {
"userid": "string|firstlower|lowernum|minLength[4]|maxLength[30]",
"useridInput": "string|firstlower|lowernum|maxLength[30]",
"pass": "string|noblank|minLength[4]|maxLength[30]",
"passInput": "string|noblank|maxLength[30]",
"name": "string|minLength[1]|maxLength[255]",
"email": "string|email|minLength[4]|maxLength[255]",
"phone": "string|maxLength[255]",
"authtoken": "string|maxLength[255]"
}
},
"query": {
"se_add": [
"REPLACE into seller(userid,name,email,phone,authtoken)values(",
"@userid:se.userid@, @name:se.name@, @email:se.email@, @phone:se.phone@, @authtoken:se.authtoken@)"
],
"se_get": "select userid,name,email,phone,authtoken,regdate from seller limit 1"
}
}
}
}
if(Ch.net.isOn()){
App.isLoading(true)
Log.i("ch", "Ch.res.ids - ${Ch.res.ids}")
val result = Ch.net.api("gateway", "id" to Ch.res.ids){
Ch.res.load(it.result as JSONObject)
go()
}
if(result.isFail()){
Log.i("ch", result.msg )
go()
}
}