This commit is contained in:
crusader 2018-09-06 00:13:31 +09:00
parent 4dde0f3aca
commit 69535f452d
5 changed files with 19 additions and 100 deletions

View File

@ -1,7 +1,5 @@
import { import {
Type,
PropertyKeyType, PropertyKeyType,
Annotation,
DecoratorHelper, DecoratorHelper,
} from '@overflow/core-js'; } from '@overflow/core-js';
@ -19,14 +17,10 @@ export function RPCSubscriber(attribute: RPCSubscriberDecoratorAttribute): Metho
} }
// import { // import {
// Type,
// PropertyKeyType, // PropertyKeyType,
// } from '@loafer/core';
// import {
// Decorator, // Decorator,
// DecoratorFactory, // DecoratorHelper
// } from '@loafer/decorator'; // } from '@overflow/core-js';
// export interface RPCSubscriberDecoratorAttribute { // export interface RPCSubscriberDecoratorAttribute {
// method: string; // method: string;
@ -43,4 +37,4 @@ export function RPCSubscriber(attribute: RPCSubscriberDecoratorAttribute): Metho
// } // }
// export const RPCSubscriber = DecoratorFactory.create<RPCSubscriberDecoratorAttribute>(RPCSubscriberDecorator); // export const RPCSubscriber = DecoratorHelper.create<RPCSubscriberDecoratorAttribute>(RPCSubscriberDecorator);

View File

@ -41,8 +41,8 @@
"@ngrx/schematics": "^6.1.0", "@ngrx/schematics": "^6.1.0",
"@ngrx/store": "^6.1.0", "@ngrx/store": "^6.1.0",
"@ngrx/store-devtools": "^6.1.0", "@ngrx/store-devtools": "^6.1.0",
"@overflow/core-js": "0.0.6", "@overflow/core-js": "0.0.7",
"@overflow/rpc-js": "0.0.5", "@overflow/rpc-js": "0.0.7",
"@types/fs-extra": "^5.0.4", "@types/fs-extra": "^5.0.4",
"@types/jasmine": "~2.8.6", "@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3", "@types/jasminewd2": "~2.0.3",
@ -83,4 +83,4 @@
"webpack-node-externals": "^1.7.2", "webpack-node-externals": "^1.7.2",
"zone.js": "^0.8.26" "zone.js": "^0.8.26"
} }
} }

View File

@ -67,26 +67,6 @@ export class HomePageComponent implements OnInit {
}; };
this.probeService.send('DiscoveryService.DiscoverHost', requesterID, zone, discoverHost); this.probeService.send('DiscoveryService.DiscoverHost', requesterID, zone, discoverHost);
// this.probeService.call<Interface>('MachineService.Interfaces').pipe(
// map((ifaces: Interface[]) => {
// console.log(ifaces);
// this.addresses = [];
// ifaces.forEach(iface => {
// iface.addresses.forEach(address => {
// this.addresses.push({
// label: address.address,
// value: address.address,
// });
// });
// });
// }),
// catchError(error => {
// console.log(error);
// return of();
// }),
// take(1),
// ).subscribe();
} }
/** /**
@ -125,8 +105,8 @@ export class HomePageComponent implements OnInit {
* DiscoverHost * DiscoverHost
*/ */
@RPCSubscriber({ method: 'DiscoveryService.DiscoveryStop' }) @RPCSubscriber({ method: 'DiscoveryService.DiscoveryStop' })
public DiscoveryStop(elapsed: number) { public DiscoveryStop(stopDate: Date) {
console.log('DiscoveryStop', elapsed); console.log('DiscoveryStop', stopDate);
} }
/** /**

View File

@ -7,7 +7,7 @@ import {
JSONClientCodec JSONClientCodec
} from '@overflow/rpc-js'; } from '@overflow/rpc-js';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { TypeUtil, Class, Annotation, PropertyKeyType, Method } from '@overflow/core-js'; import { TypeUtil, Class, Annotation, PropertyKeyType, Method, ReflectionUtil } from '@overflow/core-js';
import { RPCSubscriberDecoratorAttribute } from '@overflow/commons/ui/decorator/RPCSubscriber'; import { RPCSubscriberDecoratorAttribute } from '@overflow/commons/ui/decorator/RPCSubscriber';
export const requesterID = 'scannerUser'; export const requesterID = 'scannerUser';
@ -71,7 +71,7 @@ export class ProbeService extends Client {
} }
subscriberMethods.forEach((subscriberMethod) => { subscriberMethods.forEach((subscriberMethod) => {
try { try {
const args = this.converParams(params, subscriberMethod.parameterTypes); const args = this.converNotificationParams(params, subscriberMethod.parameterTypes);
subscriberMethod.method.invoke(subscriberMethod.instance, ...args); subscriberMethod.method.invoke(subscriberMethod.instance, ...args);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@ -122,7 +122,7 @@ export class ProbeService extends Client {
this.subscriberMethodMap.set(subscriberMethodName, subscriberMethods); this.subscriberMethodMap.set(subscriberMethodName, subscriberMethods);
} }
const paramTypes = this.getParamTypes(method); const paramTypes = ReflectionUtil.getParamTypeStrings(method);
const subscriberMethod: SubscriberMethod = { const subscriberMethod: SubscriberMethod = {
className: clazz.getName(), className: clazz.getName(),
@ -160,61 +160,4 @@ export class ProbeService extends Client {
}); });
} }
private getParamTypes(method: Method): string[] {
if (undefined === method || null === method || 0 === method.getParameterCount()) {
return [];
}
const parameters = method.getParameters();
const results: string[] = [];
for (let indexI = 0; indexI < parameters.length; indexI++) {
const paramType = parameters[indexI].getType();
results.push(paramType.name);
}
return results;
}
private converParams(params: string[], paramTypes: string[]): any[] {
const results: any[] = [];
if (undefined === params || null === params || 0 === params.length) {
return results;
}
if (undefined === paramTypes || null === paramTypes || 0 === paramTypes.length) {
return results;
}
if (params.length !== paramTypes.length) {
throw new SubscriberParameterError(`Count is not same from server[${params.length}] and method[${paramTypes.length}]`);
}
for (let indexI = 0; indexI < params.length; indexI++) {
const param = params[indexI];
const type = paramTypes[indexI];
switch (type) {
case 'Object':
case 'Array':
case 'Map':
results.push(JSON.parse(param));
break;
case 'String':
results.push(param);
break;
case 'Number':
results.push(Number(param));
break;
case 'Boolean':
results.push(Boolean(param));
break;
case 'Date':
results.push(new Date(Number(param)));
break;
case 'Function':
throw new SubscriberParameterError(`Function type [${indexI}] is not allowed`);
default:
throw new SubscriberParameterError(`${type} type parameter[${indexI}] is not allowed`);
}
}
return results;
}
} }

View File

@ -224,15 +224,17 @@
tree-kill "^1.0.0" tree-kill "^1.0.0"
webpack-sources "^1.1.0" webpack-sources "^1.1.0"
"@overflow/core-js@0.0.6": "@overflow/core-js@0.0.7", "@overflow/core-js@^0.0.7":
version "0.0.6" version "0.0.7"
resolved "https://nexus.loafle.net/repository/npm-all/@overflow/core-js/-/core-js-0.0.6.tgz#432be1ef1b561cd802b261b6b73c5b9a71570aa3" resolved "https://nexus.loafle.net/repository/npm-all/@overflow/core-js/-/core-js-0.0.7.tgz#07463557b77d967a011d2f7f6a6f7ab5b2df9252"
dependencies: dependencies:
reflect-metadata "^0.1.12" reflect-metadata "^0.1.12"
"@overflow/rpc-js@0.0.5": "@overflow/rpc-js@0.0.7":
version "0.0.5" version "0.0.7"
resolved "https://nexus.loafle.net/repository/npm-all/@overflow/rpc-js/-/rpc-js-0.0.5.tgz#9b406d90a7b034cbd679985c1f7a117d17a8983e" resolved "https://nexus.loafle.net/repository/npm-all/@overflow/rpc-js/-/rpc-js-0.0.7.tgz#3f800359653db92324976fa92fcae35b70053ccb"
dependencies:
"@overflow/core-js" "^0.0.7"
"@schematics/angular@0.7.3": "@schematics/angular@0.7.3":
version "0.7.3" version "0.7.3"