private FileSystemResponse Commit(FileSystemRequest request)
        {
            try
            {
                var file = request.FileStatus[0];
                request.FileStatus[0].FileName = request.FileStatus[0].FileName.Replace("%Date%", string.Empty);
                file.Content = worker.Read(request).FileStatus[0]?.Content;

                file.FileName         = (file.FileName.Replace(".txt", string.Empty) + $"_{DateTime.Now}" + ".txt").Replace(":", ".");
                file.FolderName      += "\\Backup";
                request.FileStatus[0] = file;

                var response = worker.Write(request);
                response.IsSuccess = true;

                return(response);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(new FileSystemResponse(request)
                {
                    IsSuccess = false
                });
            }
        }
Exemple #2
0
        public IStep Step(FileSystemRequest request)
        {
            try
            {
                var firstRequest = (FileSystemRequest)request.Clone();
                var command      = firstRequest.Command.Split();
                var fileName     = command[1].Split('.');
                firstRequest.FileStatus[0].FileName   = fileName[0] + "_" + (DateTime.Parse($"{command[2]} {command[3].Replace(".", ":")}")).ToString().Replace(":", ".") + ".txt";
                firstRequest.FileStatus[0].FolderName = request.FileStatus[0].FolderName + "\\Backup";

                var backupFile = worker.Read(firstRequest);
                request.FileStatus[0].Content = backupFile.FileStatus[0].Content;
                var response = worker.Write(request);

                Response           = response;
                Response.IsSuccess = true;
            }
            catch (Exception)
            {
                Response.IsSuccess = false;
            }

            return(this);
        }