Beispiel #1
0
 public ReadOnlyFile(MemoryStream initialContent, FileInfo path, UpToDateFile.BackEnd backEnd)
 {
     m_upToDateFile              = new UpToDateFile(initialContent, path, s => { }, backEnd);
     m_backEnd                   = backEnd;
     m_upToDateFile.FileChanged += () => FileModifiedExternally.Execute();
     m_upToDateFile.FileDeleted += () => FileDeletedExternally.Execute();
 }
Beispiel #2
0
        public bool Move(FileInfo newPath, Func <bool> replace)
        {
            var oldFile = File;

            if (newPath.Exists)
            {
                if (replace())
                {
                    newPath.Delete();
                }
                else
                {
                    return(false);
                }
            }

            var stream = m_upToDateFile.Migrate();

            m_upToDateFile.Dispose();
            System.IO.File.Move(oldFile.FullName, newPath.FullName);
            m_upToDateFile              = new UpToDateFile(stream, newPath, s => { }, m_backEnd);
            m_upToDateFile.FileChanged += () => FileModifiedExternally.Execute();
            m_upToDateFile.FileDeleted += () => FileDeletedExternally.Execute();
            Moved.Execute(new Changed <FileInfo>(oldFile, File));
            return(true);
        }
Beispiel #3
0
        public bool Move(FileInfo newPath, Func <bool> replace)
        {
            var oldFile = File;

            if (newPath.Exists)
            {
                if (replace())
                {
                    newPath.Delete();
                }
                else
                {
                    return(false);
                }
            }
            var stream = m_upToDateFile.Migrate();

            newPath.Directory.EnsureExists(); //This can fail (returning false) if it does then we subsequently get a (hopefully) useful exception from File.Move
            System.IO.File.Move(File.FullName, newPath.FullName);
            m_upToDateFile.Dispose();
            m_upToDateFile              = new UpToDateFile(stream, newPath, m_saveTo, m_backEnd);
            m_upToDateFile.FileChanged += () => FileModifiedExternally.Execute();
            m_upToDateFile.FileDeleted += () => FileDeletedExternally.Execute();
            Moved.Execute(new Changed <FileInfo>(oldFile, File));
            return(true);
        }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="initialContent">Represents the current contents of the file. Reference is not held. A copy is made.</param>
 /// <param name="path"></param>
 /// <param name="saveTo"></param>
 protected SaveableFile(MemoryStream initialContent, FileInfo path, Action <Stream> saveTo, UpToDateFile.BackEnd backEnd)
 {
     m_upToDateFile              = new UpToDateFile(initialContent, path, saveTo, backEnd);
     m_upToDateFile.FileChanged += () => FileModifiedExternally.Execute();
     m_upToDateFile.FileDeleted += () => FileDeletedExternally.Execute();
     m_saveTo  = saveTo;
     m_backEnd = backEnd;
 }
Beispiel #5
0
 internal void FileDeleted(UpToDateFile upToDateFile)
 {
     lock (m_deleted)
     {
         m_deleted.Add(upToDateFile);
     }
     m_event.Set();
 }
Beispiel #6
0
 internal void FileChanged(UpToDateFile upToDateFile)
 {
     lock (m_modified)
     {
         m_modified.Add(upToDateFile);
     }
     m_event.Set();
 }
Beispiel #7
0
        public void GotMoved(FileInfo newPath)
        {
            var oldFile = File;

            m_upToDateFile              = new UpToDateFile(m_upToDateFile.Migrate(), newPath, s => { }, m_backEnd);
            m_upToDateFile.FileChanged += () => FileModifiedExternally.Execute();
            m_upToDateFile.FileDeleted += () => FileDeletedExternally.Execute();
            Moved.Execute(new Changed <FileInfo>(oldFile, File));
        }
Beispiel #8
0
 internal void Abort(UpToDateFile upToDateFile)
 {
     lock (m_modified)
     {
         m_modified.Remove(upToDateFile);
     }
     lock (m_deleted)
     {
         m_deleted.Remove(upToDateFile);
     }
 }
Beispiel #9
0
        public void SaveAs(FileInfo path)
        {
            var oldPath = File;

            m_upToDateFile.Dispose();
            using (MemoryStream m = new MemoryStream())
            {
                m_upToDateFile = new UpToDateFile(m, path, m_saveTo, m_backEnd);
            }
            m_upToDateFile.FileChanged += () => FileModifiedExternally.Execute();
            m_upToDateFile.FileDeleted += () => FileDeletedExternally.Execute();
            Save();
            Moved.Execute(new Changed <FileInfo>(oldPath, File));
        }