locked
Custom SimpleSyncProvider creating zero byte files RRS feed

  • Question

  • I have a FileSyncProvider and 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 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 { getset; }

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

            public string RelativeDirectoryPath { getset; }
        }

     

    • Edited by tjrobinson Tuesday, July 20, 2010 9:52 AM Clearer title
    Tuesday, July 20, 2010 9:50 AM

Answers

  • 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.
    • Marked as answer by tjrobinson Monday, July 26, 2010 4:43 PM
    Monday, July 26, 2010 4:43 PM

All replies

  • Hi tjrobinson,

    Can you look at the "File Sync with Simple Custom Provider" sample at http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sync&ReleaseId=3592 and see if that helps.

    Tuesday, July 20, 2010 9:27 PM
  • Thanks, the sample is useful and interesting. However my IFileDataRetriever implementation works differently as I can't use the AbsoluteSourceFilePath because the files are on a remote server, not the same filesystem. So I'm still stuck.
    Wednesday, July 21, 2010 8:54 AM
  • Can anyone help with this or suggest things to try? This problem is holding up the release of our product.
    Monday, July 26, 2010 8:51 AM
  • 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.

     

    Monday, July 26, 2010 4:32 PM
  • 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.
    • Marked as answer by tjrobinson Monday, July 26, 2010 4:43 PM
    Monday, July 26, 2010 4:43 PM