Ejemplo n.º 1
0
        public FileSystemResponse Write(FileSystemRequest request)
        {
            try
            {
                File.Delete($"{request.FileStatus[0].FolderName}\\{request.FileStatus[0].FileName}");
            }
            catch (Exception)
            {
            }

            using (FileStream fstream = new FileStream($"{request.FileStatus[0].FolderName}\\{request.FileStatus[0].FileName}", FileMode.OpenOrCreate))
            {
                byte[] array = System.Text.Encoding.Default.GetBytes(request.FileStatus[0].Content);
                fstream.Write(array, 0, array.Length);
            }

            var response = new FileSystemResponse(request)
            {
                FileStatus = new List <FileStatus>()
                {
                    new FileStatus()
                    {
                        FileName          = request.FileStatus[0].FileName,
                        FolderName        = request.FileStatus[0].FolderName,
                        Content           = request.FileStatus[0].Content,
                        FileStatusSetings = FileStatusSetings.Commit,
                    }
                }
            };

            return(response);
        }
Ejemplo n.º 2
0
        public IStep Step(FileSystemRequest request)
        {
            if (CheckRequest(request))
            {
                return nextStep.Step(request);
            }

            Response = new FileSystemResponse(request);
            Response.IsSuccess = false;
            return this;
        }
        public IStep Step(FileSystemRequest request)
        {
            if (IsCommited(request))
            {
                Response            = new FileSystemResponse(request);
                Response.FileStatus = request.FileStatus;
                Response.IsSuccess  = false;
            }
            else
            {
                Response = Commit(request);
            }

            return(this);
        }
Ejemplo n.º 4
0
        public FileSystemResponse Read(string folder)
        {
            string[] fileNames = null;

            try
            {
                fileNames = Directory.GetFiles(folder);
            }
            catch (DirectoryNotFoundException)
            {
                Directory.CreateDirectory(folder);
                fileNames = Directory.GetFiles(folder);
            }

            var files = new List <FileStatus>();

            foreach (var fileName in fileNames)
            {
                var fileStatus = new FileStatus()
                {
                    FileName   = fileName,
                    FolderName = folder,
                };

                using (FileStream fstream = File.OpenRead(fileName))
                {
                    byte[] array = new byte[fstream.Length];
                    fstream.Read(array, 0, array.Length);
                    fileStatus.Content           = System.Text.Encoding.Default.GetString(array);
                    fileStatus.FileStatusSetings = FileStatusSetings.Commit;
                }

                files.Add(fileStatus);
            }

            var respose = new FileSystemResponse(null);

            respose.FileStatus = files;
            respose.IsSuccess  = true;

            return(respose);
        }
Ejemplo n.º 5
0
        public FileSystemResponse Read(FileSystemRequest request)
        {
            string[] fileNames = null;
            var      folder    = request.FileStatus[0].FolderName;

            fileNames = GetFilesFromDirectory(folder);
            fileNames = GetFileNames(request, fileNames);

            // string content = null;
            List <FileStatus> files = new List <FileStatus>();

            foreach (var fileName in fileNames)
            {
                var fileStatus = new FileStatus()
                {
                    FileName   = fileName,
                    FolderName = folder,
                };

                fileStatus.Content = ReadContent(fileName);

                var splitFileName = fileName.Split('_')[0].Split('\\').Last();

                if (request.FileStatus[0].FileName.Contains(splitFileName))
                {
                    files.Add(fileStatus);
                }
            }

            var response = new FileSystemResponse(request)
            {
                FileStatus = files,
            };

            return(response);
        }
Ejemplo n.º 6
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);
        }
        public IStep Step(FileSystemRequest request)
        {
            var files  = worker.Read(request.FileStatus[0].FolderName);
            var status = new List <FileStatus>();

            foreach (var item in files.FileStatus)
            {
                if (IsCommited(item, request))
                {
                    item.FileStatusSetings = FileStatusSetings.Commit;
                }
                else
                {
                    item.FileStatusSetings = FileStatusSetings.Change;
                }

                status.Add(item);
            }

            files.FileStatus = status;
            Response         = files;

            return(this);
        }