String[] split = split2(message.body); String[] dashIdAndTargetIdString = split2Device(split[0]); int dashId = Integer.parseInt(dashIdAndTargetIdString[0]); int deviceId = Integer.parseInt(dashIdAndTargetIdString[1]); String[] splitBody = split3(split[1]);
public void sendToApps(short cmd, int msgId, int dashId, int deviceId, String body) { if (isAppConnected()) { String finalBody = prependDashIdAndDeviceId(dashId, deviceId, body); sendToApps(cmd, msgId, dashId, finalBody); } }
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, User user, StringMessage message) { String[] messageParts = StringUtils.split3(message.body); if (messageParts.length < 2) { throw new IllegalCommandException("Wrong income message format."); } String[] dashIdAndDeviceId = split2Device(messageParts[0]); int dashId = Integer.parseInt(dashIdAndDeviceId[0]); long widgetId = Long.parseLong(messageParts[1]); int streamIndex = -1; if (message.body.length() == 3) { streamIndex = Integer.parseInt(messageParts[2]); } int targetId = -1; if (dashIdAndDeviceId.length == 2) { targetId = Integer.parseInt(dashIdAndDeviceId[1]); } DashBoard dash = user.profile.getDashByIdOrThrow(dashId); Widget widget = dash.getWidgetById(widgetId); if (widget == null) { widget = dash.getWidgetByIdInDeviceTilesOrThrow(widgetId); } Superchart enhancedHistoryGraph = (Superchart) widget; if (streamIndex == -1 || streamIndex > enhancedHistoryGraph.dataStreams.length - 1) { delete(holder, ctx.channel(), message.id, user, dash, targetId, enhancedHistoryGraph.dataStreams); } else { delete(holder, ctx.channel(), message.id, user, dash, targetId, enhancedHistoryGraph.dataStreams[streamIndex]); } }
/** * Expecting only strings like "1.2.2" */ private static int parseToSingleInt(String version) { try { var parts = split3('.', version); return parse(parts); } catch (Exception e) { log.debug("Error parsing app versionSingleNumber {}. Reason : {}.", version, e.getMessage()); } return 0; }
@Override public boolean setProperty(WidgetProperty property, String propertyValue) { switch (property) { case OPACITY : this.opacity = Integer.parseInt(propertyValue); return true; case SCALE : this.scale = Integer.parseInt(propertyValue); return true; case ROTATION : this.rotation = Integer.parseInt(propertyValue); return true; case URLS : this.urls = propertyValue.split(StringUtils.BODY_SEPARATOR_STRING); return true; case URL : String[] split = StringUtils.split2(propertyValue); if (split.length == 2) { int index = Integer.parseInt(split[0]) - 1; if (index >= 0 && index < urls.length) { this.urls = ArrayUtil.copyAndReplace(this.urls, split[1], index); return true; } } return false; default: return super.setProperty(property, propertyValue); } }
public static void messageReceived(Holder holder, ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { String[] messageParts = StringUtils.split2(message.body); String[] dashIdAndDeviceId = split2Device(messageParts[0]); int dashId = Integer.parseInt(dashIdAndDeviceId[0]); User user = state.user;
public static void messageReceived(ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { String[] dashIdAndTargetIdString = split2Device(message.body); int dashId = Integer.parseInt(dashIdAndTargetIdString[0]); int targetId = MobileSyncWidget.ANY_TARGET; User user = state.user; DashBoard dash = user.profile.getDashByIdOrThrow(dashId); if (dashIdAndTargetIdString.length == 2) { targetId = Integer.parseInt(dashIdAndTargetIdString[1]); } ctx.write(ok(message.id), ctx.voidPromise()); Channel appChannel = ctx.channel(); MobileStateHolder mobileStateHolder = getAppState(appChannel); boolean isNewSyncFormat = mobileStateHolder != null && mobileStateHolder.isNewSyncFormat(); user.profile.sendAppSyncs(dash, appChannel, targetId, isNewSyncFormat); ctx.flush(); }
public String getDeviceName(DashBoard dash, int deviceId) { Device device = getDeviceById(dash, deviceId); if (device != null) { return truncateFileName(device.name); } return ""; }
public String formatForFileName() { if (label == null || label.isEmpty()) { return pinType.pinTypeString + pin; } return StringUtils.truncate(label.replaceAll("[^a-zA-Z0-9]", ""), 16); }
public String getCSVDeviceName(DashBoard dash, int deviceId) { Device device = getDeviceById(dash, deviceId); if (device == null) { return String.valueOf(deviceId); } String deviceName = device.name; if (deviceName == null || deviceName.isEmpty()) { return String.valueOf(deviceId); } return StringUtils.escapeCSV(deviceName); }
private static void createSuperUser(Holder holder) { ServerProperties props = holder.props; String url = props.getAdminUrl(props.host); String email = props.getProperty("admin.email", "admin@blynk.cc"); String pass = props.getProperty("admin.pass"); if (!holder.userDao.isSuperAdminExists()) { if (pass == null || pass.isEmpty()) { System.out.println("Admin password not specified. Random password generated."); pass = StringUtils.randomPassword(24); } System.out.println("Your Admin url is " + url); System.out.println("Your Admin login email is " + email); System.out.println("Your Admin password is " + pass); String hash = SHA256Util.makeHash(pass, email); holder.userDao.add(email, hash, AppNameUtil.BLYNK, true); String vendorEmail = props.vendorEmail; if (vendorEmail != null) { String subj = "Your private Blynk server for " + props.productName + " is up!"; String body = buildServerUpEmailBody(url, email, pass); holder.blockingIOProcessor.messagingExecutor.execute(() -> { try { holder.mailWrapper.sendHtml(vendorEmail, subj, body); } catch (Exception e) { e.printStackTrace(); } }); } } }
private static void syncSpecificPins(ChannelHandlerContext ctx, String messageBody, int msgId, Profile profile, DashBoard dash, int deviceId) { String[] bodyParts = messageBody.split(StringUtils.BODY_SEPARATOR_STRING); if (bodyParts.length < 2 || bodyParts[0].isEmpty()) { ctx.writeAndFlush(illegalCommand(msgId), ctx.voidPromise()); return; } PinType pinType = PinType.getPinType(bodyParts[0].charAt(0)); if (StringUtils.isReadOperation(bodyParts[0])) { for (int i = 1; i < bodyParts.length; i++) { short pin = NumberUtil.parsePin(bodyParts[i]); Widget widget = dash.findWidgetByPin(deviceId, pin, pinType); if (ctx.channel().isWritable()) { if (widget == null) { PinStorageValue pinStorageValue = profile.pinsStorage.get(new DashPinStorageKey(dash.id, deviceId, pinType, pin)); if (pinStorageValue != null) { for (String value : pinStorageValue.values()) { String body = DataStream.makeHardwareBody(pinType, pin, value); ctx.write(makeUTF8StringMessage(HARDWARE, msgId, body), ctx.voidPromise()); } } } else if (widget instanceof HardwareSyncWidget) { ((HardwareSyncWidget) widget).sendHardSync(ctx, msgId, deviceId); } } } ctx.flush(); } }
public static void messageReceived(ChannelHandlerContext ctx, MobileStateHolder state, StringMessage message) { var splitBody = StringUtils.split3(message.body); var dashId = Integer.parseInt(splitBody[0]); var uid = splitBody[1]; var token = splitBody[2]; var dash = state.user.profile.getDashByIdOrThrow(dashId); var notification = dash.getNotificationWidget(); if (notification == null) { log.error("No notification widget."); ctx.writeAndFlush(notAllowed(message.id), ctx.voidPromise()); return; } switch (state.version.osType) { case ANDROID : notification.androidTokens.put(uid, token); break; case IOS : notification.iOSTokens.put(uid, token); break; } ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); } }
public static void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = split2(message.body); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } int dashId = Integer.parseInt(split[0]); int tagId = Integer.parseInt(split[1]); Profile profile = user.profile; DashBoard dash = profile.getDashByIdOrThrow(dashId); log.debug("Deleting tag with id {}.", tagId); profile.deleteTag(dash, tagId); user.lastModifiedTs = System.currentTimeMillis(); ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }
public void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String[] messageParts = message.body.split(BODY_SEPARATOR_STRING); if (messageParts.length < 2) { throw new IllegalCommandException("Wrong income message format."); } String[] dashIdAndDeviceId = split2Device(messageParts[0]); int dashId = Integer.parseInt(dashIdAndDeviceId[0]); int targetId = -1; if (dashIdAndDeviceId.length == 2) { targetId = Integer.parseInt(dashIdAndDeviceId[1]); } DashBoard dash = user.profile.getDashByIdOrThrow(dashId); long widgetId = Long.parseLong(messageParts[1]); Widget widget = dash.getWidgetById(widgetId); if (widget == null) { widget = dash.getWidgetByIdInDeviceTilesOrThrow(widgetId); } if (widget instanceof Superchart) { Superchart enhancedHistoryGraph = (Superchart) widget; blockingIOProcessor.executeHistory( new ExportEnhancedHistoryGraphJob(ctx, dash, targetId, enhancedHistoryGraph, message.id, user) ); } else { throw new IllegalCommandException("Passed wrong widget id."); } }
try (ZipOutputStream zipStream = new ZipOutputStream(Files.newOutputStream(output)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(zipStream, REPORT_ENCODING), size)) { String fileName = truncateFileName(report.getReportName()) + ".csv"; ZipEntry zipEntry = new ZipEntry(fileName); zipStream.putNextEntry(zipEntry);
String[] split = split2(message.body); String[] dashIdAndTargetIdString = split2Device(split[0]); int dashId = Integer.parseInt(dashIdAndTargetIdString[0]); case 'u' : String[] splitBody = split3(split[1]); processDeviceSelectorCommand(ctx, session, state.user.profile, dash, message, splitBody); break; case 'w' : splitBody = split3(split[1]);
@Override public PinStorageKey deserializeKey(String key, DeserializationContext ctx) { //parsing "123-v24" String[] split = StringUtils.split3(StringUtils.DEVICE_SEPARATOR, key); int deviceId = Integer.parseInt(split[0]); PinType pinType = PinType.getPinType(split[1].charAt(0)); short pin = 0; try { pin = NumberUtil.parsePin(split[1].substring(1)); } catch (NumberFormatException e) { //special case for outdated data format. return new PinStorageKey(deviceId, pinType, pin); } if (split.length == 3) { WidgetProperty widgetProperty = WidgetProperty.getProperty(split[2]); if (widgetProperty == null) { widgetProperty = WidgetProperty.LABEL; } return new PinPropertyStorageKey(deviceId, pinType, pin, widgetProperty); } else { return new PinStorageKey(deviceId, pinType, pin); } } }
public static void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = StringUtils.split2(message.body); int dashId = Integer.parseInt(split[0]); int deviceId = Integer.parseInt(split[1]); DashBoard dash = user.profile.getDashByIdOrThrow(dashId); Device device = user.profile.getDeviceById(dash, deviceId); if (device == null) { ctx.writeAndFlush(illegalCommandBody(message.id), ctx.voidPromise()); } else { if (ctx.channel().isWritable()) { ctx.writeAndFlush(makeUTF8StringMessage(MOBILE_GET_DEVICE, message.id, device.toString()), ctx.voidPromise()); } } }