自定义 SimpleSyncProvider 创建零字节文件

发布于 2024-09-11 14:44:03 字数 1448 浏览 5 评论 0原文

我有一个 FileSyncProvider,并且编写了 FullEnumerationSimpleSyncProvider 的自定义实现。当文件从 FullEnumerationSimpleSyncProvider 同步到 FileSyncProvider 时,它们会正确创建,但为零字节。

当在另一个方向同步(FileSyncProvider 作为源)时,一切都会按预期进行。

这是我的 IFileDataRetriever 实现。我已在 FileStream 属性 setter 和 getter 上设置断点,并且 StreamSize 属性始终正确,从不为零。实际的Stream本身是一个MemoryStream,这会导致任何问题吗?

public class FileDataRetriever : IFileDataRetriever
{

    private System.IO.Stream fileStream;

    public string AbsoluteSourceFilePath
    {
        get
        {
            throw new NotImplementedException("AbsoluteSourceFilePath is not supported for this implementation of IFileDataRetriever");
        }
    }

    public FileData FileData { get; set; }

    public System.IO.Stream FileStream
    {
        get
        {
            return this.fileStream;
        }
        set
        {
            this.fileStream = value;
        }
    }

    public string RelativeDirectoryPath { get; set; }
}

更新:

如果作为实验,我修改代码如下,则会创建一个 5 字节文件:

    public System.IO.Stream FileStream
    {
        get
        {
            return new MemoryStream(new byte[] { 1, 2, 3, 4, 5 });
        }
        set
        {
            this.fileStream = value;
        }
    }

所以这告诉我它应该与 MemoryStream 一起正常工作。如果我在 getter 上放置一个断点,那么无论何时调用它,它看起来总是有效的 - 它具有正确的大小等,而不是 0 大小。

I have a FileSyncProvider and I've written a custom implementation of the FullEnumerationSimpleSyncProvider. When files are synced from the FullEnumerationSimpleSyncProvider to the FileSyncProvider they are created correctly, but are zero bytes.

When synchronising in the other direction (FileSyncProvider as source) everything works as expected.

This is my IFileDataRetriever implementation. I've put breakpoints on the FileStream property setter and getter and the Size property of the Stream is always correct, never zero. The actual Stream itself is a MemoryStream, could that be causing any problems?

public class FileDataRetriever : IFileDataRetriever
{

    private System.IO.Stream fileStream;

    public string AbsoluteSourceFilePath
    {
        get
        {
            throw new NotImplementedException("AbsoluteSourceFilePath is not supported for this implementation of IFileDataRetriever");
        }
    }

    public FileData FileData { get; set; }

    public System.IO.Stream FileStream
    {
        get
        {
            return this.fileStream;
        }
        set
        {
            this.fileStream = value;
        }
    }

    public string RelativeDirectoryPath { get; set; }
}

Update:

If, as an experiment, I modify the code as below, a 5 byte file is created:

    public System.IO.Stream FileStream
    {
        get
        {
            return new MemoryStream(new byte[] { 1, 2, 3, 4, 5 });
        }
        set
        {
            this.fileStream = value;
        }
    }

So this tells me that it should work fine with a MemoryStream. If I put a breakpoint on the getter, it always looks valid whenever it's called - it has the correct size etc, not 0 as the size.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷鸟归林 2024-09-18 14:44:03

我明白了!我所需要做的就是将流的位置重置为 0。它位于流的末尾,因此写入 0 字节。

I've got it! All I needed to do was reset the Position of the Stream to 0. It was at the end of the stream, hence writing 0 bytes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文