Exemplo n.º 1
0
        private void RefreshFolder(string path) {
			var explorer = new RemoteExplorer();

			//Get all pending share inventations and accept them
			List<ShareInventation> foundInventations = explorer.GetPendingShareInventations ();
			foreach (ShareInventation foundShareInventation in foundInventations) { //Accept all inventations
                explorer.AcceptShareInventation (foundShareInventation.Id);
			}

            var localData = database.GetTree(path);
			var remoteData = MapDataGroupToTreeNode(explorer.GetFiles(localData.Path), localData.Id, localData.LocalBoxId);

            List<string> inBoth = (from local in localData.Children
                join remote in remoteData
                on local.Path equals remote.Path
                select local.Path).ToList();

            List<TreeNode> updateNodes = (from local in localData.Children
                join remote in remoteData
                on local.Path equals remote.Path
                select new TreeNode{ Id = local.Id, Name = remote.Name, Type = local.Type, 
					ParentId = local.ParentId, Path = local.Path, IsDirectory = remote.IsDirectory, HasKeys = remote.HasKeys,
					IsFavorite = local.IsFavorite, IsShare = remote.IsShare, IsShared = remote.IsShared, IsWritable = remote.IsWritable, LocalBoxId = local.LocalBoxId, IV = local.IV, Key = local.Key, CheckedForKeys = local.CheckedForKeys} ).ToList();

            var toAdd = remoteData.Where(e => !inBoth.Contains(e.Path)).ToList();
            var toRemove = localData.Children.Where(e => !inBoth.Contains(e.Path)).ToList();

            updateNodes.ForEach(e => database.Update(e));
            toAdd.ForEach(e => database.AddNode(e));
            toRemove.ForEach(e =>  {
                DeleteLocalFileOrFolder(e);
                database.RemoveNode(e);
            });
        }