自定义 SimpleSyncProvider 创建零字节文件
我有一个 FileSyncProvider,并且编写了 FullEnumerationSimpleSyncProvider 的自定义实现。当文件从 FullEnumerationSimpleSyncProvider 同步到 FileSyncProvider 时,它们会正确创建,但为零字节。
当在另一个方向同步(FileSyncProvider 作为源)时,一切都会按预期进行。
这是我的 IFileDataRetriever 实现。我已在 FileStream 属性 setter 和 getter 上设置断点,并且 Stream 的 Size 属性始终正确,从不为零。实际的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我明白了!我所需要做的就是将流的位置重置为 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.