小编Jef*_*ake的帖子

如何平铺CALayer的内容?

我想在CALayer上绘制一个CGImage,但它似乎只想拉伸它.

示例代码:

 self.background = [UIImage imageNamed: @"Background.png"];
 [documentDisplay.layer setContents: self.background.CGImage];
Run Code Online (Sandbox Code Playgroud)

如果可以,我想避免继承子类.

iphone macos cocoa calayer

10
推荐指数
2
解决办法
6231
查看次数

在 ASP.Net Core 中,是否可以开始流式传输 JSON 结果?

我正在使用 ASP.Net Core WebAPI。

我有一种方法可以一次从数据库中检索 10000 个结果,但我注意到“等待”需要 1.17 秒,实际传输需要 0.3 秒(基于 Chrome 的网络图)。

将来自数据库(postgres)的结果通过 DataReader 进行迭代并转换为结构体,添加到列表中,最终作为 JsonResult 返回。

我不知道对选项的确切期望,但我希望能够尽快开始返回以降低总请求。我也是第一次在这个平台上这样做,所以我可能没有以最好的方式做事。

    [HttpGet("{turbine:int}")]
    public IActionResult GetBearingTemperature(int turbine)
    {
        using (var connection = Database.GetConnection())
        {
            connection.Open();

            int? page = GetPage();

            var command = connection.CreateCommand();

            if (page.HasValue)
            {
                command.CommandText = @"select turbine, timestamp, mainbearingtemperature from readings where turbine = :turbine limit 10000 offset :offset;";
                command.Parameters.AddWithValue("offset", NpgsqlTypes.NpgsqlDbType.Integer, page.Value * 10000);
            } else
            {
                command.CommandText = @"select turbine, timestamp, mainbearingtemperature from readings where turbine = :turbine limit …
Run Code Online (Sandbox Code Playgroud)

c# asp.net postgresql json asp.net-web-api

8
推荐指数
2
解决办法
6969
查看次数

标题栏按钮和自定义标题栏

我为一个变黑的NSWindow(样式0)创建了一个自定义标题栏视图,这样我就能以类似于Quicktime X的方式消失它.唯一的问题是,按钮不响应鼠标悬停和鼠标移动动作在标题栏上可以结合按下按钮.

完整的源代码如下:https://github.com/iaefai/OrganicUI Classes/ORTitleBar.m和ORWindow.m.

按钮是此方法的标准:

self.closeButton = [NSWindow standardWindowButton: NSWindowCloseButton 
                           forStyleMask:NSTexturedBackgroundWindowMask];
Run Code Online (Sandbox Code Playgroud)

然后定位:

[self.closeButton setFrame: __frame];
Run Code Online (Sandbox Code Playgroud)

然后添加到标题栏:

[self addSubview: self.closeButton];
Run Code Online (Sandbox Code Playgroud)

这里可以看到一个消失的标题栏的小视频:http: //web.me.com/iaefai/OrganicUI/ORWindow.html

macos cocoa titlebar nswindow

5
推荐指数
0
解决办法
7895
查看次数

在 .Net Core 3.1 中,如何从字典生成 JsonElement 而不必序列化和反序列化?

我正在从 DocuSign 添加一些身份验证并更新代码以使用 .Net Core 3.1。

原始代码有:

var user = JObject.Parse(await response.Content.ReadAsStringAsync());

user.Add("access_token", context.AccessToken);
user.Add("refresh_token", context.RefreshToken);
user.Add("expires_in", DateTime.Now.Add(context.ExpiresIn.Value).ToString());

context.RunClaimActions(user);  
Run Code Online (Sandbox Code Playgroud)

其中 user 是来自 newtonsoft 的 JObject。在 .net core 3.1 中更新的是 RunClaimActions 采用 JsonElement。

在查看并尝试使用一些可用的更新对象后,它们似乎是不可变的。在不知道可能来自响应内容的所有内容的情况下,将其转换为字典并添加原始代码中的项目似乎是合乎逻辑的。(注意代码尚未测试)

var userDocument = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());

var user = userDocument.RootElement.EnumerateObject()
            .ToDictionary(property => property.Name, property => property.Value.GetString());

user.Add("access_token", context.AccessToken);
user.Add("refresh_token", context.RefreshToken);
user.Add("expires_in", DateTime.Now.Add(context.ExpiresIn.Value).ToString(new CultureInfo("en-US")));

Run Code Online (Sandbox Code Playgroud)

但是似乎没有直接的方法可以从中生成 JsonElement,所以到目前为止我能想到的最好的方法是:

   context.RunClaimActions(JsonDocument.Parse(JsonSerializer.Serialize(user)).RootElement);
Run Code Online (Sandbox Code Playgroud)

有什么我完全缺少的东西可能会使这更容易吗?

原始源代码在 github 上

json asp.net-core-3.1

5
推荐指数
0
解决办法
530
查看次数

Nx 和 Angular 中的模块联合在加载 styles.js 时生成错误

我正在关注描述设置模块联合的文章:https ://nx.dev/l/a/guides/setup-mfe-with-angular

从生成工作区开始,添加角度插件,然后添加仪表板应用程序。

在提供仪表板应用程序时,我从 styles.js 收到错误:

 Uncaught SyntaxError: Cannot use 'import.meta' outside a module
Run Code Online (Sandbox Code Playgroud)

它正在加载为:

<script src="styles.js" defer></script>
Run Code Online (Sandbox Code Playgroud)

进行一些快速搜索似乎表明这个东西应该有 type="module" 。

然而,我似乎找不到任何类型的配置来修改添加到index.html 的行。

我已经检查了 Angular 生成的常规模板,它对所有内容都使用 defer 样式,因此其他 js 文件条目在某个地方被更改为 type="module" 。普通的 styles.js 也不包含任何“import.meta”字符串。

任何解决方案都会有帮助。

angular nrwl-nx webpack-module-federation

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

在打字稿中,我可以使用键列表从对象中删除未定义和空类型吗?

我创建了一个函数,它执行检查 null 和 undefined 是否为 true 的运行时要求:

 function hasFields<T>(obj: T | T[], ...fields: (keyof T)[]): boolean {
    const inObj: { (obj: T): boolean } = (obj) => fields.every((f) => obj[f] != null);

    if (Array.isArray(obj)) {
        return obj.every((o) => inObj(o));
    } else {
        return inObj(obj);
    }
}
Run Code Online (Sandbox Code Playgroud)

但我真正想要的是能够返回具有更新类型的 obj,或者能够在 if 语句中使用它并能够在 if 语句的上下文中更新类型。

我见过这样的问题:Typescript type RequireSome<T, K extends keyof T> moving undefined AND null from properties 但它不会对字段列表执行此操作。

如果有帮助的话,这些字段在编译时是已知的。

metaprogramming typescript

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