Exemple #1
0
        private void WriteNoteToPath(FilesystemNote note, string path)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(path));

            File.WriteAllText(path, note.Text);

            var info = new FileInfo(path);

            note.ModificationDate = info.LastWriteTime;
        }
        protected override BasicHierachicalNote CreateClone()
        {
            var n = new FilesystemNote(_id, _config);

            using (n.SuppressDirtyChanges())
            {
                n._text             = _text;
                n._title            = _title;
                n._path             = _path;
                n._pathRemote       = _pathRemote;
                n._creationDate     = _creationDate;
                n._modificationDate = _modificationDate;
                return(n);
            }
        }
Exemple #3
0
        private FilesystemNote ReadNoteFromPath(string path)
        {
            var info = new FileInfo(path);

            var note = new FilesystemNote(Guid.NewGuid(), _config);

            note.Title            = Path.GetFileNameWithoutExtension(info.FullName);
            note.Path             = FileSystemUtil.GetDirectoryPath(_config.Folder, info.DirectoryName);
            note.Text             = File.ReadAllText(info.FullName, _config.Encoding);
            note.CreationDate     = info.CreationTime;
            note.ModificationDate = info.LastWriteTime;
            note.PathRemote       = info.FullName;

            return(note);
        }
Exemple #4
0
        private void WriteNoteToPath(FilesystemNote note, string path)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(path));

            FileInfo fileBefore = new FileInfo(path);

            if (fileBefore.Exists && fileBefore.IsReadOnly)
            {
                fileBefore.IsReadOnly = false;
            }

            File.WriteAllText(path, note.Text);

            new FileInfo(path).IsReadOnly = note.IsLocked;

            note.ModificationDate = new FileInfo(path).LastWriteTime;
        }
Exemple #5
0
        public override RemoteDownloadResult UpdateNoteFromRemote(INote inote)
        {
            FilesystemNote note = (FilesystemNote)inote;

            var path = note.GetPath(_config);

            if (!File.Exists(path))
            {
                return(RemoteDownloadResult.DeletedOnRemote);
            }

            note.Title      = Path.GetFileNameWithoutExtension(path);
            note.Text       = File.ReadAllText(path, _config.Encoding);
            note.PathRemote = path;

            return(RemoteDownloadResult.Updated);
        }
        private FilesystemNote ReadNoteFromPath(string path)
        {
            var info = new FileInfo(path);

            var note = new FilesystemNote(Guid.NewGuid(), _config);

            using (note.SuppressDirtyChanges())
            {
                note.Title        = Path.GetFileNameWithoutExtension(info.FullName);
                note.Path         = ANFileSystemUtil.GetDirectoryPath(_config.Folder, info.DirectoryName);
                note.Text         = File.ReadAllText(info.FullName, _config.Encoding);
                note.CreationDate = info.CreationTime;
                note.SetModificationDate(info.LastWriteTime);
                note.PathRemote = info.FullName;
                note.IsLocked   = info.IsReadOnly;
            }

            return(note);
        }
Exemple #7
0
        public override RemoteDownloadResult UpdateNoteFromRemote(INote inote)
        {
            FilesystemNote note = (FilesystemNote)inote;

            var path = note.GetPath(_config);
            var fi   = new FileInfo(path);

            if (!fi.Exists)
            {
                return(RemoteDownloadResult.DeletedOnRemote);
            }

            using (note.SuppressDirtyChanges())
            {
                note.Title            = Path.GetFileNameWithoutExtension(path);
                note.Text             = File.ReadAllText(path, _config.Encoding);
                note.PathRemote       = path;
                note.ModificationDate = fi.LastWriteTime;
                note.IsLocked         = fi.IsReadOnly;
            }

            return(RemoteDownloadResult.Updated);
        }
Exemple #8
0
        public override RemoteUploadResult UploadNoteToRemote(ref INote inote, out INote conflict, ConflictResolutionStrategy strategy)
        {
            FilesystemNote note = (FilesystemNote)inote;

            var path = note.GetPath(_config);

            if (File.Exists(note.PathRemote) && path != note.PathRemote && !File.Exists(path))
            {
                _logger.Debug(FilesystemPlugin.Name, "Upload note to changed remote path");                 // path changed and new path does not exist

                WriteNoteToPath(note, path);
                conflict = null;
                ANFileSystemUtil.DeleteFileAndFolderIfEmpty(FilesystemPlugin.Name, _logger, _config.Folder, note.PathRemote);
                note.PathRemote = path;
                return(RemoteUploadResult.Uploaded);
            }
            else if (File.Exists(note.PathRemote) && path != note.PathRemote && File.Exists(path))
            {
                _logger.Debug(FilesystemPlugin.Name, "Upload note to changed remote path");                 // path changed and new path does exist

                var conf = ReadNoteFromPath(note.PathRemote);
                if (conf.ModificationDate > note.ModificationDate)
                {
                    conflict = conf;
                    if (strategy == ConflictResolutionStrategy.UseClientCreateConflictFile || strategy == ConflictResolutionStrategy.UseClientVersion || strategy == ConflictResolutionStrategy.ManualMerge)
                    {
                        WriteNoteToPath(note, path);
                        ANFileSystemUtil.DeleteFileAndFolderIfEmpty(FilesystemPlugin.Name, _logger, _config.Folder, note.PathRemote);
                        note.PathRemote = path;
                        return(RemoteUploadResult.Conflict);
                    }
                    else
                    {
                        note.PathRemote = path;
                        return(RemoteUploadResult.Conflict);
                    }
                }
                else
                {
                    WriteNoteToPath(note, path);
                    conflict = null;
                    ANFileSystemUtil.DeleteFileAndFolderIfEmpty(FilesystemPlugin.Name, _logger, _config.Folder, note.PathRemote);
                    note.PathRemote = path;
                    return(RemoteUploadResult.Uploaded);
                }
            }
            else if (File.Exists(path))             // normal update
            {
                var conf = ReadNoteFromPath(path);
                if (conf.ModificationDate > note.ModificationDate)
                {
                    conflict = conf;
                    if (strategy == ConflictResolutionStrategy.UseClientCreateConflictFile || strategy == ConflictResolutionStrategy.UseClientVersion)
                    {
                        WriteNoteToPath(note, path);
                        if (note.PathRemote != "")
                        {
                            ANFileSystemUtil.DeleteFileAndFolderIfEmpty(FilesystemPlugin.Name, _logger, _config.Folder, note.PathRemote);
                        }
                        note.PathRemote = path;
                        return(RemoteUploadResult.Conflict);
                    }
                    else
                    {
                        note.PathRemote = path;
                        return(RemoteUploadResult.Conflict);
                    }
                }
                else
                {
                    WriteNoteToPath(note, path);
                    conflict        = null;
                    note.PathRemote = path;
                    return(RemoteUploadResult.Uploaded);
                }
            }
            else             // new file
            {
                WriteNoteToPath(note, path);
                conflict        = null;
                note.PathRemote = path;
                return(RemoteUploadResult.Uploaded);
            }
        }