Esempio n. 1
0
 public FolderNode(FileSystemNode node, FileSystemMap.FileBuildType buildType, FTPConnection connection = null)
 {
     this.Name                    = node.Name;
     this.Modified                = node.Modified;
     this.IsDirectory             = true;
     this.RelativeParentDirectory = node.RelativeParentDirectory;
     this.Size                    = node.Size;
     SubdirectoyMap               = new FileSystemMap(Path.Combine(node.RelativeParentDirectory, Name), buildType, connection);
 }
Esempio n. 2
0
        public SyncPlan CompareContents(FolderNode localNode, FolderNode remoteNode)
        {
            SyncPlan plan = new SyncPlan();
            Dictionary <string, FileSystemNode> localMap  = new Dictionary <string, FileSystemNode>();
            Dictionary <string, FileSystemNode> remoteMap = new Dictionary <string, FileSystemNode>();
            List <string> keys = new List <string>();

            DigDeeper(localMap, localNode, keys);
            DigDeeper(remoteMap, remoteNode, keys);

            foreach (string key in keys)
            {
                FileSystemNode local  = localMap.ContainsKey(key) ? localMap[key] : null;
                FileSystemNode remote = remoteMap.ContainsKey(key) ? remoteMap[key] : null;

                if (local != null && remote != null)
                {
                    //If a both local and remote copies exist.
                    //TODO: Compare times, add newer node and upload/download instruction to plan.
                    if (local.IsNewerThan(remote))
                    {
                        //Upload the local node because it is newer.
                        plan.AddInstruction(_POST, local);
                    }
                    else
                    {
                        //Download the remote node because it is newer.
                        plan.AddInstruction(_GET, remote);
                    }
                }
                else if (local != null)
                {
                    //If a local copy exists and a remote does not.
                    //TODO: Add local node and upload instruction to plan.
                    plan.AddInstruction(_POST, local);
                }
                else if (remote != null)
                {
                    //If a remote copy exists and a local does not.
                    //TODO: Add remote node and download instruction to plan.
                    plan.AddInstruction(_GET, remote);
                }
            }

            return(plan);
        }
Esempio n. 3
0
        private void BuildFromLocal(string directory)
        {
            string[] folders = Directory.GetDirectories(directory);
            string[] files   = Directory.GetFiles(directory);

            foreach (string folder in folders)
            {
                FolderNode folderNode = new FolderNode(Directory.GetLastWriteTime(folder),
                                                       Path.GetFileName(folder),
                                                       true,
                                                       Path.GetDirectoryName(folder));
                _internalDict.Add(folderNode.Name, folderNode);
            }

            foreach (string file in files)
            {
                FileSystemNode fileNode = new FileSystemNode(Directory.GetLastWriteTime(file),
                                                             Path.GetFileName(file),
                                                             false,
                                                             Path.GetDirectoryName(file),
                                                             (uint)new FileInfo(file).Length);
                _internalDict.Add(fileNode.Name, fileNode);
            }
        }
Esempio n. 4
0
 public bool IsNewerThan(FileSystemNode comparedNode)
 {
     return(this.Modified > comparedNode.Modified);
 }
Esempio n. 5
0
 public void AddInstruction(SyncInstruction instruction, FileSystemNode node)
 {
     _instructions.Add(instruction);
     _syncedNodes.Add(node);
 }