GSF.ServiceProcess.ServiceHelper.ManageFiles C# (CSharp) Method

ManageFiles() private method

private ManageFiles ( GSF.ServiceProcess.ClientRequestInfo requestInfo ) : void
requestInfo GSF.ServiceProcess.ClientRequestInfo
return void
        private void ManageFiles(ClientRequestInfo requestInfo)
        {
            if (requestInfo.Request.Arguments.ContainsHelpRequest || requestInfo.Request.Arguments.OrderedArgCount < 2)
            {
                StringBuilder helpMessage = new StringBuilder();

                helpMessage.Append("Manages files on the server.");
                helpMessage.AppendLine();
                helpMessage.AppendLine();
                helpMessage.Append("   Usage:");
                helpMessage.AppendLine();
                helpMessage.Append("       Files \"Source Path\" \"Target Path\" -options");
                helpMessage.AppendLine();
                helpMessage.AppendLine();
                helpMessage.Append("   Options:");
                helpMessage.AppendLine();
                helpMessage.Append("       -?".PadRight(20));
                helpMessage.Append("Displays this help message");
                helpMessage.AppendLine();
                helpMessage.Append("       -copy".PadRight(20));
                helpMessage.Append("Copies files from one location to another");
                helpMessage.AppendLine();
                helpMessage.Append("       -move".PadRight(20));
                helpMessage.Append("Moves files from one location to another");
                helpMessage.AppendLine();
                helpMessage.Append("       -overwrite".PadRight(20));
                helpMessage.Append("Overwrites files if they exist in the target location");
                helpMessage.AppendLine();
                helpMessage.AppendLine();

                UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Information, helpMessage.ToString());
            }
            else
            {
                string source = FilePath.GetAbsolutePath(requestInfo.Request.Arguments["orderedarg1"]);
                string target = FilePath.GetDirectoryName(FilePath.GetAbsolutePath(requestInfo.Request.Arguments["orderedarg2"]));
                string directory = FilePath.GetDirectoryName(source);
                string filePattern = FilePath.GetFileName(source);
                bool copy = requestInfo.Request.Arguments.Exists("copy");
                bool move = requestInfo.Request.Arguments.Exists("move");
                bool overwrite = requestInfo.Request.Arguments.Exists("overwrite");

                string targetFile;
                foreach (string sourceFile in Directory.GetFiles(directory, filePattern))
                {
                    targetFile = Path.Combine(target, FilePath.GetFileName(sourceFile));
                    if (!File.Exists(targetFile) || overwrite)
                    {
                        // File can be copied or moved.
                        if (copy)
                        {
                            // Copy the file.
                            UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Information, "Copying file '{0}'...\r\n\r\n", target);
                            File.Copy(sourceFile, targetFile, true);
                            UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Information, "File '{0}' copied successfully.\r\n\r\n", target);
                        }
                        else if (move)
                        {
                            // Move the file.
                            UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Information, "Moving file '{0}'...\r\n\r\n", target);
                            File.Delete(targetFile);
                            File.Move(sourceFile, targetFile);
                            UpdateStatus(requestInfo.Sender.ClientID, UpdateType.Information, "File '{0}' moved successfully.\r\n\r\n", target);
                        }
                        else
                        {
                            // Invalid command option specified.
                            UpdateStatus(UpdateType.Alarm, "Command option is not valid.\r\n\r\n");
                        }
                    }
                    else
                    {
                        // File already exists.
                        UpdateStatus(UpdateType.Alarm, "File '{0}' already exists.\r\n\r\n", targetFile);
                    }
                }
            }
        }
ServiceHelper