Пример #1
0
        private void RenameHandler(Event currentEvent)
        {
            // Have to stop and consider what if the file is not in the database?
            String originalTransientFolderPath = FileSystemUtilities.GetTransientFolderPath(currentEvent.File.Path);

            Console.WriteLine("Original Path: " + originalTransientFolderPath);
            // If file never existed, don't need to do anything
            if (!SystemFile.Exists(originalTransientFolderPath))
            {
                return;
            }
            String newTransientFolderPath = FileSystemUtilities.GetTransientFolderPath(currentEvent.File.NewPath);

            FileSystemUtilities.MoveFile(originalTransientFolderPath, newTransientFolderPath);
            SendRenameRequest(currentEvent.File);
        }
Пример #2
0
        private void SendOpenRequest(File file)
        {
            NameValueCollection data = new NameValueCollection()
            {
                { "file_name", file.Name },
                { "file_path", FileSystemUtilities.GetTransientFolderPath(file.Path) },
                { "date", file.LastModified.ToString() }
            };

            byte[] response = PostDataToServer(data, "open/");
            if (response == null)
            {
                Console.WriteLine("An Error occured while posting Open Event to server");
            }
            else
            {
                Console.WriteLine("Successfully sent open event on {0} to server", file.Name);
            }
        }
Пример #3
0
        private bool SendMoveRequest(File file)
        {
            // Send the old path and the new path, that's it ;)
            NameValueCollection data = new NameValueCollection()
            {
                { "old_path", FileSystemUtilities.GetTransientFolderPath(file.Path) },
                { "new_path", FileSystemUtilities.GetTransientFolderPath(file.NewPath) }
            };

            byte[] response = PostDataToServer(data, "move/");
            if (response == null)
            {
                return(false);
            }
            else
            {
                String responseString = System.Text.Encoding.Default.GetString(response);
                return(responseString.Equals("Exists") ? true : false);
            }
        }
Пример #4
0
        private void MoveHandler(Event currentEvent)
        {
            // Have to stop and consider what if the file is not in the database? Should first send the request.
            // If the server says it's unimportant we can skip it
            String originalTransientFolderPath = FileSystemUtilities.GetTransientFolderPath(currentEvent.File.Path);

            Console.WriteLine("Original Path: " + originalTransientFolderPath);
            String newTransientFolderPath = FileSystemUtilities.GetTransientFolderPath(currentEvent.File.NewPath);

            Console.WriteLine("New Path: " + newTransientFolderPath);
            // If the original file existed then move it and send a put request otherwise do nothing
            if (!SystemFile.Exists(originalTransientFolderPath))
            {
                return;
            }
            // Create the directories of destination if doesn't exist
            String directories = newTransientFolderPath.Substring(0, newTransientFolderPath.LastIndexOf(@"\"));

            System.IO.Directory.CreateDirectory(directories);
            FileSystemUtilities.MoveFile(originalTransientFolderPath, newTransientFolderPath);
            SendMoveRequest(currentEvent.File);
        }
Пример #5
0
        private void SendModifyRequest(File file)
        {
            Console.WriteLine(FileSystemUtilities.GetTransientFolderPath(file.Path));
            NameValueCollection data = new NameValueCollection()
            {
                { "name", file.Name },
                { "path", FileSystemUtilities.GetTransientFolderPath(file.Path) },
                { "expiration_date", file.LastModified.ToString() },
                { "identifier", Environment.UserName },
                { "file_size", new System.IO.FileInfo(file.Path).Length.ToString() }
            };

            byte[] response = PostDataToServer(data, "modify/");
            if (response == null)
            {
                Console.WriteLine("An Error occured while posting data to server");
            }
            else
            {
                Console.WriteLine("Successfully created file {0} on server", file.Name);
            }
        }