Make it work
This commit is contained in:
parent
85f6b81334
commit
0b14c7ed7f
@ -1,16 +0,0 @@
|
|||||||
package ru.mipt.npm.controls.client
|
|
||||||
|
|
||||||
///**
|
|
||||||
// * Communicate with server in [Magix format](https://github.com/waltz-controls/rfc/tree/master/1) and dump messages at xodus entity store
|
|
||||||
// */
|
|
||||||
//public fun DeviceManager.connectToMagix(
|
|
||||||
// endpoint: MagixEndpoint<DeviceMessage>,
|
|
||||||
// endpointID: String = DATAFORGE_MAGIX_FORMAT,
|
|
||||||
// entityStore: PersistentEntityStore
|
|
||||||
//): Job = connectToMagix(endpoint, endpointID) { message ->
|
|
||||||
// if (message.payload is PropertyChangedMessage) {
|
|
||||||
// entityStore.executeInTransaction {
|
|
||||||
// message.toEntity(it)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -8,6 +8,7 @@ val xodusVersion = "1.3.232"
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(projects.controlsCore)
|
implementation(projects.controlsCore)
|
||||||
implementation(projects.magix.magixApi)
|
implementation(projects.magix.magixApi)
|
||||||
|
implementation(projects.controlsMagixClient)
|
||||||
implementation("org.jetbrains.xodus:xodus-entity-store:$xodusVersion")
|
implementation("org.jetbrains.xodus:xodus-entity-store:$xodusVersion")
|
||||||
implementation("org.jetbrains.xodus:xodus-environment:$xodusVersion")
|
implementation("org.jetbrains.xodus:xodus-environment:$xodusVersion")
|
||||||
implementation("org.jetbrains.xodus:xodus-vfs:$xodusVersion")
|
implementation("org.jetbrains.xodus:xodus-vfs:$xodusVersion")
|
||||||
|
@ -16,18 +16,7 @@ import space.kscience.dataforge.values.ValueType
|
|||||||
public fun PropertyChangedMessage.toEntity(transaction: StoreTransaction): Entity {
|
public fun PropertyChangedMessage.toEntity(transaction: StoreTransaction): Entity {
|
||||||
val entity = transaction.newEntity("PropertyChangedMessage")
|
val entity = transaction.newEntity("PropertyChangedMessage")
|
||||||
entity.setProperty("property", property)
|
entity.setProperty("property", property)
|
||||||
if (value.isLeaf) {
|
|
||||||
val v: Value = value.value ?: TODO()
|
|
||||||
when(v.type){
|
|
||||||
ValueType.NULL -> TODO()
|
|
||||||
ValueType.LIST -> TODO()
|
|
||||||
ValueType.NUMBER -> TODO()
|
|
||||||
ValueType.STRING -> TODO()
|
|
||||||
ValueType.BOOLEAN -> TODO()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
entity.setProperty("value", value.toString())
|
entity.setProperty("value", value.toString())
|
||||||
}
|
|
||||||
entity.setProperty("sourceDevice", sourceDevice.toString())
|
entity.setProperty("sourceDevice", sourceDevice.toString())
|
||||||
targetDevice?.let { entity.setProperty("targetDevice", it.toString()) }
|
targetDevice?.let { entity.setProperty("targetDevice", it.toString()) }
|
||||||
comment?.let { entity.setProperty("comment", it) }
|
comment?.let { entity.setProperty("comment", it) }
|
||||||
|
@ -2,8 +2,10 @@ package ru.mipt.npm.controls.xodus
|
|||||||
|
|
||||||
import jetbrains.exodus.entitystore.PersistentEntityStore
|
import jetbrains.exodus.entitystore.PersistentEntityStore
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import ru.mipt.npm.controls.api.DeviceMessage
|
||||||
import ru.mipt.npm.controls.api.PropertyChangedMessage
|
import ru.mipt.npm.controls.api.PropertyChangedMessage
|
||||||
import ru.mipt.npm.controls.controllers.DeviceManager
|
import ru.mipt.npm.controls.controllers.DeviceManager
|
||||||
import ru.mipt.npm.controls.controllers.hubMessageFlow
|
import ru.mipt.npm.controls.controllers.hubMessageFlow
|
||||||
@ -11,11 +13,9 @@ import ru.mipt.npm.controls.controllers.hubMessageFlow
|
|||||||
|
|
||||||
public fun DeviceManager.connectXodus(
|
public fun DeviceManager.connectXodus(
|
||||||
entityStore: PersistentEntityStore,
|
entityStore: PersistentEntityStore,
|
||||||
//filter: (DeviceMessage) -> Boolean = {it is PropertyChangedMessage}
|
filterCondition: suspend (DeviceMessage) -> Boolean = { it is PropertyChangedMessage }
|
||||||
): Job = hubMessageFlow(context).onEach { message ->
|
): Job = hubMessageFlow(context).filter(filterCondition).onEach { message ->
|
||||||
if (message is PropertyChangedMessage) {
|
|
||||||
entityStore.executeInTransaction {
|
entityStore.executeInTransaction {
|
||||||
message.toEntity(it)
|
(message as PropertyChangedMessage).toEntity(it)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.launchIn(context)
|
}.launchIn(context)
|
Loading…
Reference in New Issue
Block a user