我很抱歉,如果这是一个愚蠢的问题,但我可以诚实地想不出它没有设立某种形式的ASCII码 - >字符映射器我自己,我不认为是这样做的正确方法.
所以目前我正在与Scala和Akka一起制作一个"聊天应用程序",我使用一个单独的客户端和服务器实体.客户端连接到服务器,发送消息,服务器对其执行某些操作.
我收到了发送消息的工作,但现在我一直在阅读服务器端的消息.每当我收到一条消息时,我都会得到一个ByteString,其中包含消息中字符的ASCII值.如何将此ByteString转换为实际的String?
相关代码(服务器端):
package chatapp.server
import java.net.InetSocketAddress
import akka.actor.{Actor, ActorSystem}
import akka.io.Tcp._
import akka.io.{IO, Tcp}
/**
* Created by Niels Bokmans on 30-3-2016.
*/
class ServerActor(actorSystem: ActorSystem) extends Actor {
val Port = 18573
val Server = "localhost"
IO(Tcp)(actorSystem) ! Bind(self, new InetSocketAddress("localhost", Port))
def receive: Receive = {
case CommandFailed(_: Bind) =>
println("Failed to start listening on " + Server + ":" + Port)
context stop self
actorSystem.terminate()
case Bound(localAddress: InetSocketAddress) =>
println("Started listening on " …Run Code Online (Sandbox Code Playgroud) 我一直在尝试实施Lucene,以便更快地在我的网站上进行搜索.
我的代码目前有效,但是,我认为我没有正确使用Lucene.现在,我的搜索查询是productName:asterisk(input)asterisk- 我无法想象这是你应该做的找到所有productName包含的产品input.我认为这与我将字段保存到文档的方式有关.
我的代码:
LuceneHelper.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Entity.Migrations.Model;
using System.Linq;
using System.Threading.Tasks;
using Lucene.Net;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Rentpro.Models;
using RentPro.Models.Tables;
using RentProModels.Models;
namespace RentPro.Helpers
{
public class LuceneHelper
{
private const Lucene.Net.Util.Version Version = Lucene.Net.Util.Version.LUCENE_30;
private bool IndicesInitialized;
private List<Language> Languages = new List<Language>();
public void BuildIndices(DB db)
{
Languages = GetLanguages(db);
Analyzer analyzer = new StandardAnalyzer(Version); …Run Code Online (Sandbox Code Playgroud) 我正在尝试在iOS应用程序和Android应用程序之间同步数据.Android应用程序可以从Realm中读取就好了,但是我的Swift程序正在挣扎,并且错误信息不是很有用.
我收到此错误消息:
2016-11-08 08:53:43.919 iOSRealm[2629:65667] Sync: Connection[1]: Session[1]: Bad changeset received: Assertion failed: left().nullable == right().nullable
Run Code Online (Sandbox Code Playgroud)
我不知道它意味着什么或如何解决它.这是我使用Realm Object服务器验证自己的方式:
private func synchronouslyLogInUser() throws {
SyncUser.authenticateWithCredential(Credential.usernamePassword(username, password: password, actions:.UseExistingAccount), authServerURL: authURL) { (user, error) in
print("sent login request")
if let user = user {
print("user was not nil")
self.setDefaultRealmConfiguration(user)
}
if let error = error where error.code == SyncError.HTTPStatusCodeError.rawValue && (error.userInfo["statusCode"] as? Int) == 400 {
print("invalid user and pass")
} else {
print(error)
}
}
}
private func setDefaultRealmConfiguration(user: SyncUser) { …Run Code Online (Sandbox Code Playgroud) 是的,我知道还有其他问题要涵盖这个警告意味着什么以及如何解决它,但是,我对异步编程的最佳实践有疑问.
我有一个服务层,处理数据层和表示层之间的数据传输.此服务包含几种查询数据库的方法,并返回结果.
我一直在尝试使用异步编程.一个例子:
public async Task<SiteTemplateResource[]> GetResources(int siteTemplateId, string extension)
{
return await Database.FindBy<SiteTemplateResource>(str => str.SiteTemplateId == siteTemplateId && str.HashedFile.EndsWith(extension)).ToArrayAsync();
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,我实际上并没有等待任何事情,除了ToArrayAsync电话,我真的不需要.
我应该继续使用async/await吗?我将如何为此函数等待任何事情:
public async Task<int> SiteTemplateBySiteIdAsync(int siteId)
{
return Database.First<SiteSiteTemplate>(sst => sst.SiteId == siteId).SiteTemplateId;
}
Run Code Online (Sandbox Code Playgroud)
我不等待该函数中的任何内容,但我也不需要调用ToArrayAsync,所以在上述情况下如何避免警告"方法缺少'await'运算符"?
提前致谢.
我遇到了在我看来使用 asp-for 标签助手时丢失小数位的问题。它似乎总是四舍五入到 2 位小数,而我想让它四舍五入到 3 位小数(在这种情况下)。
这是我的表单视图,你可以看到没有什么特别的事情发生(asp-has-error标签助手是这个项目的自定义标签助手):
<div class="form-group row">
<label asp-for="RatePercentage" class="col-lg-4 col-form-label"></label>
<div class="col-lg-8">
<input asp-for="RatePercentage" asp-has-error="@Html.HasErrorFor(m => m.RatePercentage)" class="form-control"/>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
有什么想法可以让我在这里显示 3 个小数位吗?
我有一个片段,包含用于搜索输入的EditText和一个ListView.我有搜索部分工作,但现在我想在用户点击EditText之外的屏幕时关闭键盘.我也想使用click事件(因为它是一个ListView,如果我不使用click事件,用户可能会意外地点击他们不想打开的ListView项目)
我知道如何在一个活动中做到这一点,但对于片段来说似乎有所不同.
到目前为止我尝试过的:
实现View.OnClickListener在片段和实施的onClick这样:
@Override
public void onClick(View v) {
System.out.println("onClick true");
if (!(v instanceof EditText)) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.
INPUT_METHOD_SERVICE);
if (getActivity().getCurrentFocus() != null) {
imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
}
}
}
Run Code Online (Sandbox Code Playgroud)当我点击时,这似乎永远不会发布"onClick true".
覆盖片段活动中的onTouchEvent并实现onTouchEvent:
@Override
public boolean onTouchEvent(final MotionEvent event) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.
INPUT_METHOD_SERVICE);
if (getCurrentFocus() != null) {
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
return true;
}
Run Code Online (Sandbox Code Playgroud)任何帮助将不胜感激.提前致谢.
c# ×2
akka ×1
android ×1
asp.net-core ×1
asp.net-mvc ×1
async-await ×1
listener ×1
listview ×1
lucene ×1
realm ×1
scala ×1
swift ×1