我有一个JSON对象,附带一长串区号.不幸的是,每个区域代码都是Data对象列表中的对象名称.如何创建一个允许RestSharp反序列化内容的类?
以下是我班级现在的样子:
public class phaxioResponse
{
public string success { get; set; }
public string message { get; set; }
public List<areaCode> data { get; set; }
public class areaCode
{
public string city { get; set; }
public string state { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
这是JSON内容:
{
success: true
message: "277 area codes available."
data: {
201: {
city: "Bayonne, Jersey City, Union City"
state: "New Jersey"
}
202: {
city: "Washington"
state: "District Of Columbia"
} [...] …Run Code Online (Sandbox Code Playgroud) 我们正在使用Mongo DB的C#驱动程序(1.9.1).如果DB不可访问,我们有一些需要运行的回退逻辑,但是默认超时太长.我们试图改变它,但我们放置的值被忽略了.对于测试,我们使用的是无响应机器的IP.
我们尝试在连接字符串中设置超时:
<add key="Mongo" value="mongodb://xxx.xxx.xxx.xxx:27017/?socketTimeoutMS=2000&connectTimeoutMS=2000&waitqueuetimeoutms=2000"/>
Run Code Online (Sandbox Code Playgroud)
或者通过代码:
var client = new MongoClient(new MongoClientSettings
{
Server = new MongoServerAddress("xxx.xxx.xxx.xxx"),
SocketTimeout = new TimeSpan(0, 0, 0, 2),
WaitQueueTimeout = new TimeSpan(0, 0, 0, 2),
ConnectTimeout = new TimeSpan(0, 0, 0, 2)
});
Run Code Online (Sandbox Code Playgroud)
两次请求在平均约20秒后超时.
我们设置超时选项的方式可能有什么问题.
我正在为我的控制器和服务层(C#,MVC)进行单元测试.我正在使用Moq DLL来模拟单元测试中的真实/依赖对象.
但是我对于模拟依赖项或真实对象有点困惑.让我们举一个以下单元测试方法的例子: -
[TestMethod]
public void ShouldReturnDtosWhenCustomersFound_GetCustomers ()
{
// Arrrange
var name = "ricky";
var description = "this is the test";
// setup mocked dal to return list of customers
// when name and description passed to GetCustomers method
_customerDalMock.Setup(d => d.GetCustomers(name, description)).Returns(_customerList);
// Act
List<CustomerDto> actual = _CustomerService.GetCustomers(name, description);
// Assert
Assert.IsNotNull(actual);
Assert.IsTrue(actual.Any());
// verify all setups of mocked dal were called by service
_customerDalMock.VerifyAll();
}
Run Code Online (Sandbox Code Playgroud)
在上面的单元测试方法中,我正在模拟GetCustomers方法并返回一个客户列表.哪个已定义.看起来如下:
List<Customer> _customerList = new List<Customer>
{
new Customer { CustomerID …Run Code Online (Sandbox Code Playgroud) 我在名为music的mongo数据库中有以下对象.
我想更新类型是哪里Grunge
乐队名称是Nirvana
专辑名称是Nevermind
音轨顺序是1
并将曲目的名称改为"Smells Like Teen Spirit!".
我已经尝试过使用位置运算符,但无法弄清楚这一点.
{
genre : "Grunge",
bands : [ {
name : "Nirvana",
albums : [ {
name : "Nevermind",
tracks : [ {
name : "Smell Like Teen Spirit",
order : 1,
duration : 301
},
{
name : "In Bloom",
order : 2,
duration : 254
} ]
},
{
name : "In Utero",
tracks : [ {
name : "Server the Servants",
order : 1,
duration : 216
}, …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个 SignalR 集线器,以便能够通过网络将通知推送到一堆 WPF 客户端。我尝试遵循基本指南和教程,并创建了一个 WPF SignalR 服务器(仅用于测试目的)。它已放在我局域网中的服务器上,它的外观如下:
启动文件
class Startup
{
public void Configuration(IAppBuilder app)
{
HubConfiguration hc = new HubConfiguration();
hc.EnableDetailedErrors = true;
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR(hc);
}
}
Run Code Online (Sandbox Code Playgroud)
主窗口.xaml.cs
public IDisposable SignalR { get; set; }
const string ServerURI = "http://localhost:8554";
private void StartServer()
{
try
{
SignalR = WebApp.Start(ServerURI);
}
catch (TargetInvocationException)
{
WriteToConsole("A server is already running at " + ServerURI);
return;
}
this.Dispatcher.Invoke(() => btnStopHub.IsEnabled = true);
}
Run Code Online (Sandbox Code Playgroud)
临时集线器
public class AdHocHub : Hub
{
public …Run Code Online (Sandbox Code Playgroud) 我的node.js托管有一个API ,heroku并且我的前端应用是在Vue.js上编写的hostinger。我想知道是否可以用puppeteer生成PDF文件并将其立即发送到前端客户端,而无需先将其保存到磁盘上?如果是,您能给我一些例子吗?
目前我的功能是这样的:
exports.gerarPDFAvaliacao = async (dadosAvaliacao) => {
try {
const compile = async (fileName, data) => {
const filePath = path.join(process.cwd(), 'src/templates/client/operation/', `${fileName}.hbs`);
const html = await fs.readFile(filePath, 'utf-8');
return await hbs.compile(html)(data);
}
const browser = await puppeteer.launch();
const page = await browser.newPage();
let content = await compile('avaliations', dadosAvaliacao);
await page.goto(`data:text/html,${content}`, { waitUntil: 'networkidle0' });
await page.emulateMedia('screen');
await page.pdf({
path: 'src/dist/pdf/' + dadosAvaliacao.arquivo + '.pdf',
format: 'A4',
printBackground: true
}) …Run Code Online (Sandbox Code Playgroud) 我正在研究大型企业AEM项目的登录时间缓慢和一些配置文件同步问题。该系统拥有约150万用户。该网站由10个发布者提供服务。
该项目的构建方式是,他们为所有这些最终用户启用了SAML_login,并且我假设有一个第三方IDP,我认为这与SAML_login进行了对话。我不是SSO-SAML_login流程的专家,所以我试图了解这是否是第一步的正确方法。
由于此设置和用户数量的限制,SAML_login调用平均需要15秒。随着用户数量的增加,这种情况一天天变得令人无法接受。更重要的是,这10个发布者之间的同步有时会失败,因此某些用户有时无法按预期使用该系统。
由于用户存储在SAML_login的JCR中,因此您甚至无法通过crx浏览器检查home / users文件夹。由于无法一次显示150万行,因此超时。我的有根据的猜测是,这就是SAML_login调用花费这么长时间的原因。
我到处都有介绍如何在AEM上设置SAML_login的文章,这使在这种情况下使用它听起来合法。但是我认为这是有史以来最糟糕的设置,因为对于这种使用场景,JCR并不是设计合理的快速访问数据存储。
到目前为止,我的理解是,这种方法可能效果很好,但是仅适用于有限数量的用户,但是对于这么多的用户,这是不适用的解决方案。所以我的第一个问题是:我说的对吗?:)
如果我做错了,那么肯定存在我尚不了解的瓶颈,那么该瓶颈有待改善吗?
我在构造函数中打开连接。考虑这段代码:
public abstract class DataContext : DbContext, IDataContext
{
static DataContext()
{
if (DataContextConfiguration.UseSafePersian)
{
DbInterception.Add(new SafePersianInterceptor());
}
}
private readonly bool _saveChangesOnModify = false;
protected DataContext(string nameOrConnectionString)
: base(nameOrConnectionString)
{
this.OpenConnection();
}
internal void OpenConnection()
{
if (((IObjectContextAdapter)this).ObjectContext.Connection.State != ConnectionState.Open)
((IObjectContextAdapter)this).ObjectContext.Connection.Open();
}
}
Run Code Online (Sandbox Code Playgroud)
当我显式打开连接时是否应该关闭连接?
我用的是Entity Framework版本6。
更新
我收到此错误并且经常发生:
超时已过。从池中获取连接之前超时时间已过。发生这种情况的原因可能是所有池连接都在使用中并且已达到最大池大小。
是我,还是这里讨厌的东西NotifyIcon.无论我给方法的timeout参数什么,NotifyIcon.ShowBalloonTip它只显示一定的时间.在win7上大约9秒,在Windows Server 2008 r2上赢得8.1和大约4秒.这些是我到目前为止尝试的操作系统.
我尝试了两种重载,NotifyIcon.ShowBalloonTip但我得到了相同的结果.
//this is only shown for 9 seconds
notifyIcon1.ShowBalloonTip(15000);
Run Code Online (Sandbox Code Playgroud)
还有这个
//this is only shown for 9 seconds too :)
notifyIcon1.ShowBalloonTip(15000, "1 sec", "shown for one sec", ToolTipIcon.Info);
Run Code Online (Sandbox Code Playgroud)
在msdn上它说:
最小和最大超时值由操作系统强制执行,通常分别为10秒和30秒,但这可能因操作系统而异.
好的,但我们对此没有任何说法吗?如果是预设值,为什么会有这个timeout参数?
我希望我错过了一些愚蠢的东西.(我正在使用.net 4.5)
我有很多 dotnet lambda 微服务使用 SSM 参数存储进行配置。由于我在不同的微服务之间共享大量配置,因此环境变量非常冒险。尽管最近我开始挑战它的极限。它现在影响了我的吞吐量,并且成本开始超出我的预期。
我考虑过使用 dotnet 配置管理器的 amazon 扩展,但它达不到我的要求。我需要热插拔配置,以保持微服务在高正常运行时间下健康运行。当前的实施不会发生这种情况。仅仅为了配置更改而部署所有微服务也不是一个选择。
这促使我研究一种缓存解决方案,该解决方案至少能够从外部使缓存失效,但我无法找到任何与 SSM 参数存储配合使用的开箱即用的东西。
最坏的情况是,我需要提出另一个微服务,它有自己的数据库来处理配置,但我不想走这条路。
这种场景使用的一般方法是什么?
configuration caching .net-core aws-lambda aws-parameter-store