小编may*_*ran的帖子

TypeScript:意外的令牌; '构造函数,函数,访问器或变量'

我有下面的类用脚本编写的类.当我编译它时,它错误地说

"src\main\MqttClientWrapper.ts(24,2): error TS1068: Unexpected token. A construct or, method, accessor, or property was expected.".

以下是我的代码.

var mqtt :any = require('mqtt');

export interface IWillMessage {
  topic: string;
  payload: string;
  qos: number;
  retain: string;
}

export interface IMessageReceivedCallBack {
  onMessageReceived(message : string);
}

export interface IMqttOptions {
  clientId: string;
  keepAlive: number;
  clean: string;
  reconnectPeriod: string;
  will: IWillMessage;
}

export default class MqttClientWrapper {

 client : any;

constructor(url: string, mqttOptions : IMqttOptions, messageReceivedCallBack : IMessageReceivedCallBack) {
   client = mqtt.connect(url, mqttOptions);
   client.on('message',function(topic …
Run Code Online (Sandbox Code Playgroud)

javascript types typescript ecmascript-6 tslint

5
推荐指数
1
解决办法
2万
查看次数

如何在以下环境中确保线程安全?

我有一个名为processOutbox的方法.我希望它是线程安全的.当一个线程在它时,我不希望另一个线程调用此方法.我已经按照以下方式实现了它.我做得对吗?我的实施有漏洞吗?如果有,请告知我如何解决它.

this.start();
    outboxLock.lock();
    timer = new Timer();
    try{
    timer.scheduleAtFixedRate(new TimerTask() {
            public void run() {
               processOutbox();
            }
        }, 0, period);
    } finally{
        outboxLock.unlock();
    }
Run Code Online (Sandbox Code Playgroud)

java multithreading locking timer reentrantlock

4
推荐指数
1
解决办法
78
查看次数

不断获取“可能已访问以下记录器集”的日志

我正在使用logback登录我的应用程序,并且在运行该应用程序时,我不断收到以下警告。当我运行单元测试时,它会在每堂课上打印出来!

SLF4J: The following set of substitute loggers may have been accessed
SLF4J: during the initialization phase. Logging calls during this
SLF4J: phase were not honored. However, subsequent logging calls to these
SLF4J: loggers will work as normally expected.
SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger
SLF4J: com.kohls.kube.service.sdk.logging.CustomAppender
SLF4J: com.kohls.kube.service.sdk.logging.appender.mqtt.messaging.ClientMqttImpl
SLF4J: com.kohls.service.sdk.messaging.TCPMessager
SLF4J: com.kohls.service.sdk.logging.appender.mqtt.MQTTAppender
SLF4J: com.kohls.service.sdk.messaging.EdgeNodeMessager
SLF4J: com.kohls.service.sdk.messaging.SubscriptionTask
Run Code Online (Sandbox Code Playgroud)

我已经配置了logback,以在某个位置查找配置文件,下面是日志工厂类的外观。

public class LoggerFactory {

static {
    System.setProperty("logback.configurationFile", System.getProperty("user.dir") + "\\" + "logbackConfig.xml");
}

private LoggerFactory() {

}

public static Logger getLogger(Class className) {
    return …
Run Code Online (Sandbox Code Playgroud)

java logging intellij-idea logback slf4j

4
推荐指数
1
解决办法
1572
查看次数

尝试从jar文件运行时,Spring Boot应用程序将无法运行

我有一个Spring Boot应用程序,当通过intellij运行时可以正常工作。但是,当我从罐子中运行它时,出现以下异常。

        2017-02-13 05:18:28.596  WARN 8581 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    2017-02-13 05:18:28.606 ERROR 8581 --- [           main] o.s.boot.SpringApplication               : Application startup failed

    org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.1.RELEASE.jar!/:1.5.1.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.6.RELEASE.jar!/:4.3.6.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.1.RELEASE.jar!/:1.5.1.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar!/:1.5.1.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar!/:1.5.1.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar!/:1.5.1.RELEASE] …
Run Code Online (Sandbox Code Playgroud)

java spring jar maven spring-boot

4
推荐指数
2
解决办法
7824
查看次数

如何在没有任何提示的情况下使用Yarn运行Jest测试?

我试图在Team City中运行我的Jest单元测试,但最终总是得到如下所示的提示。

No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.
Run Code Online (Sandbox Code Playgroud)

我尝试运行yarn test a …

teamcity jenkins reactjs jestjs yarnpkg

4
推荐指数
2
解决办法
1818
查看次数

将CRC算法从C转换为Java

我有以下代码,我试图转换为Java.

WORD ComputeCRC16(BYTE *data, DWORD data_length)
{
   BYTE *ptr;
   BYTEWORD retval;

    /* Initialize the CRC */
    retval.w = 0xFFFF;

   /* Iterate through the data */
   for (ptr=data; ptr<data+data_length; ptr++)
   {
      // retval.w = IterateCRC16(ptr, retval);
      retval.w = retval.b.hi ^ (ccittrev_tbl[retval.b.lo ^ *ptr]);

   }

   /* Finalize the CRC */
   retval.w = ~retval.w;

   /* Done. */
   return retval.w;
}
Run Code Online (Sandbox Code Playgroud)

下面的内容是什么意思?

retval.w = retval.b.hi ^ (ccittrev_tbl[retval.b.lo ^ *ptr]);
Run Code Online (Sandbox Code Playgroud)

如果我转换为Java,retval应该是一个int吗?如果那么它怎么会有一个名为"w"的成员呢?请告诉我如何将上面的代码转换为Java?

我正在编辑问题,发布我错过的这部分内容.

typedef union
{
  WORD  w;
  struct
  {
     BYTE  lo,
        hi;
   } b;
} …
Run Code Online (Sandbox Code Playgroud)

c java crc xor crc16

3
推荐指数
1
解决办法
220
查看次数

使用 Burn Bootstrapper 项目内部获取应用程序版本

通常 EXE 版本在 Bundle.wxs 文件中设置。是否可以在编写安装程序后端引擎逻辑的 Bootstrapper 应用程序项目中获取此版本?我使用 WPF 创建了自定义 UI。我需要在用户界面中显示版本。我怎样才能做到这一点?请指教。下面是我的 Bootstrapper 应用程序代码。

    public class MainViewModel : ViewModelBase
    {
        private MINAClient minaClient;

        //constructor
        public MainViewModel(BootstrapperApplication bootstrapper)
        {

            this.IsThinking = false;

            this.Bootstrapper = bootstrapper;
            this.Bootstrapper.ApplyComplete += this.OnApplyComplete;
            this.Bootstrapper.DetectPackageComplete += this.OnDetectPackageComplete;
            this.Bootstrapper.PlanComplete += this.OnPlanComplete;
            this.Bootstrapper.DetectComplete += this.DetectComplete;

            this.Bootstrapper.CacheAcquireProgress += (sender, args) =>
            {
                this.cacheProgress = args.OverallPercentage;
                this.Progress = (this.cacheProgress + this.executeProgress) / 2;
            };
            this.Bootstrapper.ExecuteProgress += (sender, args) =>
            {
                this.executeProgress = args.OverallPercentage;
                this.Progress = (this.cacheProgress + this.executeProgress) / 2;
            };

            minaClient = …
Run Code Online (Sandbox Code Playgroud)

wpf wix bootstrapper burn wix3.10

3
推荐指数
1
解决办法
598
查看次数

如何从字符串中提取下面的模式?

我有一个字符串,如下所示.

{(firstName1,lastName1,College1,{(24,25)},{(Street,23)},City1,Country1)}
Run Code Online (Sandbox Code Playgroud)

我需要从上面提取细节/值并将它们添加到列表中.我的意思是:

 ["firstName1","lastName1","College1","24","25","Street","23","City1", "country1"]
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现上述目标?我尝试了下面的方法,但不知道如何将所有花括号和括号放入模式中.

private static String flattenPigBag(String pigdata) {
    String s = "";
    Pattern p = Pattern.compile("\\{(.*)}");
    Matcher m = p.matcher(pigdata);
    while (m.find()) {
        s = m.group(1);
        System.out.println("answer : " + s);
    }
    return s;
}
Run Code Online (Sandbox Code Playgroud)

java regex string matcher pattern-matching

3
推荐指数
1
解决办法
82
查看次数

解析 bash 脚本的输入参数时带有空格的参数

我编写了一个 bash 脚本,它按名称获取参数并读取键值对中的值。下面是我如何运行脚本的示例。

 sh test.sh param1='a' param2='b'
Run Code Online (Sandbox Code Playgroud)

然后,我在脚本中引用 $param1 和 $param2 等输入参数。下面是我为此编写的脚本。

for item in $@; do
case $item in
(*=*) eval $item;;
esac
done
Run Code Online (Sandbox Code Playgroud)

但是当参数值中有空格时,它只取空格之前的部分。

 param3='select * from'
Run Code Online (Sandbox Code Playgroud)

只会将“select”分配给 param3 而不是整个字符串。我怎样才能实现这个目标?任何帮助将非常感激。

编辑 :

伊尼安回答后

for item in $@; do
case "$item" in
(*=*) eval "$item";;
esac
done
Run Code Online (Sandbox Code Playgroud)

linux bash shell terminal ubuntu-16.04

3
推荐指数
1
解决办法
1078
查看次数

如何使用 Jackson 将一个 ObjectNode 作为子节点添加到另一个 ObjectNode 中?

我有下面的 ObjectNode。

handlerObjectNode -> {"Info":{"Brand":{"BrandName":"TOP OF THE WORLD"}}}
Run Code Online (Sandbox Code Playgroud)

我有另一个以下格式的 ObjectNode。

fieldObjects -> {"Description":"REGULAR BR"}
Run Code Online (Sandbox Code Playgroud)

如何从上面两个创建下面的 ObjectNode?

{
   "Info": {
       "Brand": {
           "BrandName": "TOP OF THE WORLD"
       }
   "Description": "REGULAR BR"
   }
 }
Run Code Online (Sandbox Code Playgroud)

我尝试了下面的代码。

handlerObjectNode.setAll(fieldObjects);
Run Code Online (Sandbox Code Playgroud)

但它会产生以下 ObjectNode。

{
   "Info": {
       "Brand": {
           "BrandName": "TOP OF THE WORLD"
       }
   },
   "Description": "REGULAR BR"
 }
Run Code Online (Sandbox Code Playgroud)

我正在使用 Jackson 的 com.fasterxml.jackson.databind.node.ObjectNode 。任何帮助将非常感激。

java data-binding json jackson fasterxml

3
推荐指数
1
解决办法
1万
查看次数