小编Ant*_*lia的帖子

我应该在每次更改后调用一次SaveChanges吗?

我需要在我的控制器中对我的数据库进行一些更改.

foreach (var valueStream in model.ListValueStream)
{
    ValueStreamProduct vsp = new ValueStreamProduct(valueStream.Id, product.Id);
    db.ValueStreamProduct.Add(vsp);
}
db.SaveChanges();
Run Code Online (Sandbox Code Playgroud)

Shoul我在最后或每次做出更改时都会调用SaveChanges?

c# asp.net asp.net-mvc entity-framework

7
推荐指数
2
解决办法
3957
查看次数

在 Angular 中下载文件时无法获取进度和文件

我有一个 Angular 应用程序,我只想下载一个文件。

到目前为止,这是我的代码:

this.fileNavigationService.downloadFile(element).subscribe(result => {
    this.generateDownload(result);
});
Run Code Online (Sandbox Code Playgroud)

还有我的服务:

downloadFile(file: FileElement) {
    return this.http.get(this.apiUrl + '/downloadFile', { params: file.name, responseType: 'blob' });
}
Run Code Online (Sandbox Code Playgroud)

现在,我想在下载文件时显示进度。在网上查了一下,发现了一个很有用的东西。我的服务现在看起来像这样:

downloadFile(file: FileElement) {
    const req = new HttpRequest('GET', '/downloadFile?path=' + file.name, {
      reportProgress: true,
    });

    return this.http.request(req).subscribe(event => {
      if (event.type === HttpEventType.DownloadProgress) {
        const percentDone = Math.round(100 * event.loaded / event.total);
        console.log(`File is ${percentDone}% downloaded.`);
      } else if (event instanceof HttpResponse) {
        console.log('File is completely downloaded!');
      }
    });
}
Run Code Online (Sandbox Code Playgroud)

我可以在控制台中清楚地看到进度,但是,我现在有两个问题:

  • if即使下载似乎达到 100%,我的代码也不会进入最后一次
  • 我的组件中的代码显然在 …

observable rxjs angular angular-httpclient

6
推荐指数
1
解决办法
3794
查看次数

如何对现有合约运行 truffle 测试?

我正在开发一个简单的以太坊合约,它是松露测试的对应部分,但我遇到的问题是我需要测试来调用合约的旧部署,而不是每次都重新部署它。

在truffle文档中,它说当要重新部署合约时应使用contract()函数,而在所有其他情况下应使用mocha的describe()函数,但即使使用describe,geth客户端也会报告每次重新部署合约。

这是测试:

var md5 = require('md5');
var AuditRecord = artifacts.require("AuditRecord");

describe('AuditRecord', function() {

    before(function() {

        audit = AuditRecord.at('0x30ad3ceaf3f04696d1f7c8c4fbb9cfe4f7041822');

            for (var i = 0; i < 10; ++i) {
                if (Math.random() < 0.3) {
                    audit.enter(i, i, md5("test"), md5("data"), Date.now().toFixed());
                } else {
                    audit.enter(i, i, md5("special_case"), md5("data"), Date.now().toFixed());
                }
            }

            return audit.LogRecord({}, { fromBlock: 0, toBlock: 'latest'});
        });
    it("should read data", function() {
        auditLog = AuditRecord.at('0x30ad3ceaf3f04696d1f7c8c4fbb9cfe4f7041822').LogRecord({}, { fromBlock: 0, toBlock: 'latest'});


        auditLog.get(function(err, data) {
                console.log("\n\n\n\t.:::: testing lookup:\n")
                if (err) {
                    console.log(err); …
Run Code Online (Sandbox Code Playgroud)

mocha.js ethereum truffle

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

下载文件时浏览器不显示进度条

我有一个带有 ASP.NET Web API 的 Angular 应用程序。

我想下载存储在我的服务器上的文件。目前,这是我的代码:

[HttpGet]
[Route("downloadFile")]
[JwtAuthentication] //Only a connected user can download the file
public async Task<HttpResponseMessage> DownloadFile(string path)
{
    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
    var fileStream = File.OpenRead(path);
    result.Content = new StreamContent(fileStream);
    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
    result.Content.Headers.ContentLength = fileStream.Length;
    result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
    {
        FileName = fileStream.Name,
        Size = fileStream.Length
    };
    return result;
}
Run Code Online (Sandbox Code Playgroud)

在我的角度代码中:

// file-navigation.service.ts
downloadFile(file: FileElement) {
    const data = { path: this.formatPath(true) + file.name };
    return this.http.get(this.apiUrl + '/downloadFile', { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net file asp.net-web-api angular

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

Spring boot,角度 7 下载 pdf 时 JSON 中 JSON.parse 位置 0 处的意外标记 %

这是我的后端:

public ResponseEntity getTestByURL(String filename) throws IOException {

    File myExport = new File(location + filename);

    HttpHeaders header = new HttpHeaders();
    header.add("Content-disposition", "attachment; filename=" + filename);

    String absolutePath = myExport.getAbsolutePath();
    InputStreamResource resource = new InputStreamResource(new FileInputStream(absolutePath));

    return ResponseEntity.ok()
            .headers(header)
            .contentLength(myExport.length())
            .contentType(MediaType.parseMediaType("application/pdf"))
            .body(resource);
}

@RequestMapping(value = "/url/{url}", produces = MediaType.APPLICATION_PDF_VALUE, method = GET)
public ResponseEntity<InputStreamResource> getTestByURL(@PathVariable(value = "url") String url) throws IOException {
    return testService.getTestByURL(url);
}
Run Code Online (Sandbox Code Playgroud)

和前端:

getPDF(url: string): Observable<HttpResponse<Blob>> {
    return this.http.get<HttpResponse<Blob>>(`${this.urlPDF}` + '/' + url, {
        headers: new HttpHeaders({
        'Content-Type': …
Run Code Online (Sandbox Code Playgroud)

spring json angular

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

设置为从 CloudTrail 触发的 CloudWatch 规则不会触发 Lambda 函数,除非我创建一个 Trail 将 CloudTrail 日志存储在 S3 存储桶中

我尝试RequestCertificate在 AWS Certificate Manager 中引发事件时触发 Lambda 函数。

为此,我使用以下语法创建了一个 CloudWatch 规则:

{
  "source": [
    "aws.acm"
  ],
  "detail-type": [
    "AWS API Call via CloudTrail"
  ],
  "detail": {
    "eventSource": [
      "acm.amazonaws.com"
    ],
    "eventName": [
      "RequestCertificate"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

该规则以 Lambda 函数作为目标。我已确保 Lambda 函数拥有正确执行所需的所有权限。

但是,当我在 ACM 上请求证书时,即使该RequestCertificate事件出现在 CloudTrail 事件历史记录中,Lambda 也根本不会触发。

为了解决这个问题,我必须创建一个 Trail,将 CloudTrail 日志存储在 S3 存储桶中。完成此操作后,Lambda 现在可以正确触发。

问题是,此处的文档中未指定这一点:使用 AWS CloudTrail 创建在 AWS API 调用上触发的 CloudWatch Events 规则

因此,我想知道这是否是预期行为,或者我的 CloudWatch 规则是否存在问题。

谢谢。

amazon-s3 amazon-web-services amazon-cloudwatch amazon-cloudtrail aws-lambda

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

Android - 包裹:无法编组价值

我正在尝试通过Parcelable的活动传递数据.这是我的代码:

public class Player implements Parcelable {

public static final Parcelable.Creator<Player> CREATOR = new Parcelable.Creator<Player>() {
    public Player createFromParcel(Parcel in) {
        return new Player(in);
    }

    public Player[] newArray(int size) {
        return new Player[size];
    }
};
private String name;
private List<Card> listCards;

public Player(String namePlayer) {
    name = namePlayer;
    listCards = new ArrayList<>();
}

private Player(Parcel in) {
    // This order must match the order in writeToParcel()
    name = in.readString();
    in.readList(listCards, null);
    // Continue doing this for the rest of your …
Run Code Online (Sandbox Code Playgroud)

android parcel parcelable

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

我很好奇为什么我们在这段代码中使用cache [n]

我是JS新手,遇到了以下代码:

let cache={};

function memoizedAddTo80(n) {
    if (n in cache) {
        return cache[n]
    } else {
        cache[n]= n+80;
        return cache[n]
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是什么是cache [n] ?,我的意思是,为什么我们在缓存后使用[n]。是否cache [n]等于cache.n或?

javascript

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

C# 只获取 X 个文件

我想一次只处理 X 个文件以进行以下无限循环。下面的代码一次给我所有文件,如何只获得 X 个文件?

while (true)
{
    var files = new DirectoryInfo(@"path")
                .GetFiles()
                .OrderBy(p => p.LastWriteTimeUtc)
                .ToList();

    foreach (var f in files)
    {
        //do some processing
        Console.WriteLine(f.Name);

        f.Delete();
    }

    Thread.Sleep(5000);
}
Run Code Online (Sandbox Code Playgroud)

c#

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

如何在 python 3.8.2 上安装 urllib.request

我在安装库时遇到问题urllib。我已经尝试过:

$ python -m pip install urllib

$ pip install urllib.request 

$ pip install urllib3

$ pip install urllib2

$ pip install urllib2.request
Run Code Online (Sandbox Code Playgroud)

但它们都不起作用。有人可以告诉我如何安装这个库吗?

我得到的错误是这样的:

ERROR: Could not find a version that satisfies the requirement urllib

ERROR: No matching distribution found for urllib
Run Code Online (Sandbox Code Playgroud)

python pip

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