0 votes
by (160 points)

Hi,

I need to execute specific action when file is renamed. I'm currently using the FileServer's FileUploaded, but I don't see any FileRenamed equivalent. This library seems to be full of features, I doubt something this basic is not possible. Can anybody suggest a way to do it?

Using Rebex 6.0.8060

1 Answer

+1 vote
by (144k points)
selected by
 
Best answer

Hi,

This can be achieved using virtual file system API's notifier events.

When creating the FileServerUser object, instead of specifying the virtual path, use a LocalFileSystemProvider, associate it with the user, and register the RenameCompleted event:

Instead of this:

var user01 = new FileServerUser("user01", "password", virtualRootPath);

Use this:

var user01 = new FileServerUser("user01", "password");
var fs = new LocalFileSystemProvider(virtualRootPath);
user01.SetFileSystem(fs);

fs.GetFileSystemNotifier().RenameCompleted += (sender, args) =>
{
    Console.WriteLine("Renamed {0} -> {1}", args.OriginalNode.Path, args.ResultNode.Path);
};
by (160 points)
Thanks Lukas for the quick response. If I understand correctly, it's intended for FS Providers to be separate instances for each user? To rephrase the question, I will only get RenameCompleted events raised ONLY for users that have subscribed to the event in their fs instance, yes?

This would fit perfectly in my use-case as I need this functionality turned on only for some users.
by (5.1k points)
edited by
Hi Achobanov,
you are right. In the described case, events from the instance of the virtual file system provider are delivered only for the user associated with this instance of the virtual file system provider.

To be precise.

1) When the association between the virtual file system instance and the user is 1:1, and the user makes a change on the file system, then the registered event handler is called and Session.CurrentSession.User property contains the user associated with the virtual file system instance. This user is each time the same user who initiated the operation on the virtual file system and who is the 'owner ' of the virtual file system instance.

2) When the association between the virtual file system instance and users is 1:n. In other words, when the SAME (reference equals) virtual file system is shared between users, and ANY user associated with this instance makes a change on the virtual file system, then the registered event handler is called and Session.CurrentSession.User property contains a user who initiated the operation on the virtual file system.

I hope that the explanation makes sense.
by (160 points)
Yes, that's perfect, thanks.
...