Example #1
0
        public void GetFilePath_Should_Return_The_Expected_Path()
        {
            _fileInfoMock.GetSize(Arg.Is(expectedFilePath)).Returns(0);
            var path = _filepathProvider.GetFilePath();

            Assert.AreEqual(path, expectedFilePath);
        }
Example #2
0
        protected string BuildLongReply(string [] asFiles)
        {
            string sDirectory = this.GetPath(string.Empty);

            var stringBuilder = new StringBuilder();

            for (int nIndex = 0; nIndex < asFiles.Length; nIndex++)
            {
                string sFile = asFiles[nIndex];
                sFile = Path.Combine(sDirectory, sFile);

                IFileInfo info = this.ConnectionObject.FileSystemObject.GetFileInfo(sFile);

                if (info != null)
                {
                    string sAttributes = info.GetAttributeString();
                    stringBuilder.Append(sAttributes);
                    stringBuilder.Append(" 1 owner group");

                    if (info.IsDirectory())
                    {
                        stringBuilder.Append("            1 ");
                    }
                    else
                    {
                        string sFileSize = info.GetSize().ToString();
                        stringBuilder.Append(General.TextHelpers.RightAlignString(sFileSize, 13, ' '));
                        stringBuilder.Append(" ");
                    }

                    DateTime fileDate = info.GetModifiedTime();

                    string sDay = fileDate.Day.ToString();

                    stringBuilder.Append(TextHelpers.Month(fileDate.Month));
                    stringBuilder.Append(" ");

                    if (sDay.Length == 1)
                    {
                        stringBuilder.Append(" ");
                    }

                    stringBuilder.Append(sDay);
                    stringBuilder.Append(" ");
                    stringBuilder.Append(string.Format("{0:hh}", fileDate));
                    stringBuilder.Append(":");
                    stringBuilder.Append(string.Format("{0:mm}", fileDate));
                    stringBuilder.Append(" ");

                    stringBuilder.Append(asFiles[nIndex]);
                    stringBuilder.Append("\r\n");
                }
            }

            return(stringBuilder.ToString());
        }
Example #3
0
        public string GetFilePath()
        {
            string filePath   = path;
            long   nextNumber = 0;
            Regex  rgx        = new Regex(@"(\w{1,})\.(\w{1,})");

            while (_fileInfo.GetSize(filePath) >= maxFileSize)
            {
                string replacement = $"$1.{++nextNumber}.$2";
                filePath = rgx.Replace(filePath, replacement);
            }
            return(filePath);
        }
Example #4
0
        protected override string OnProcess(string sMessage)
        {
            string sPath = GetPath(sMessage);

            if (!ConnectionObject.FileSystemObject.FileExists(sPath))
            {
                return(GetMessage(550, string.Format("File doesn't exist ({0})", sPath)));
            }

            IFileInfo info = ConnectionObject.FileSystemObject.GetFileInfo(sPath);

            if (info == null)
            {
                return(GetMessage(550, "Error in getting file information"));
            }

            return(GetMessage(220, info.GetSize().ToString()));
        }
Example #5
0
        protected string GenerateEntry(IFileInfo info)
        {
            StringBuilder entry = new StringBuilder();

            bool isDirectory = info.IsDirectory();

            if (isDirectory)
            {
                entry.Append("Type=dir; ");
                string dirName = FileNameHelpers.GetDirectoryName(info.Path());
                entry.Append(dirName);
            }
            else
            {
                entry.Append(string.Format("Type=file;Size={0};Modify={1}; ", info.GetSize(), info.GetModifiedTime().ToString("yyyyMMddHHmmss")));
                entry.Append(FileNameHelpers.GetFileName(info.Path()));
            }

            return entry.ToString();
        }
        protected string GenerateEntry(IFileInfo info)
        {
            StringBuilder entry = new StringBuilder();

            bool isDirectory = info.IsDirectory();

            if (isDirectory)
            {
                entry.Append("Type=dir; ");
                string dirName = FileNameHelpers.GetDirectoryName(info.Path());
                entry.Append(dirName);
            }
            else
            {
                entry.Append(string.Format("Type=file;Size={0};Modify={1}; ", info.GetSize(), info.GetModifiedTime().ToString("yyyyMMddHHmmss")));
                entry.Append(FileNameHelpers.GetFileName(info.Path()));
            }

            return(entry.ToString());
        }
        private string GetLongProperty(IFileInfo info)
        {
            if (info == null)
                return null;

            var stringBuilder = new StringBuilder();

            // permissions
            string sAttributes = info.GetAttributeString();
            stringBuilder.Append(sAttributes);
            stringBuilder.Append(" 1 owner group");

            // check whether info is directory
            bool isDirectory = info.IsDirectory();

            // size
            string sFileSize = info.GetSize().ToString(); // if info is directory, the size will be 1
            stringBuilder.Append(TextHelpers.RightAlignString(sFileSize, 13, ' '));
            stringBuilder.Append(" ");

            // modify time
            DateTimeOffset fileDate = info.GetModifiedTime(); //if info is directory, the modify time will be the current time
            // month
            stringBuilder.Append(TextHelpers.Month(fileDate.Month));
            stringBuilder.Append(" ");
            // day
            string sDay = fileDate.Day.ToString();
            if (sDay.Length == 1)
                stringBuilder.Append(" ");
            stringBuilder.Append(sDay);
            stringBuilder.Append(" ");
            // year or hour:min
            if (fileDate.Year < DateTime.Now.Year)
            {
                stringBuilder.Append(" " + fileDate.Year);
            }
            else
            {
                stringBuilder.Append(string.Format("{0:hh}:{1:mm}", fileDate, fileDate));
            }
            stringBuilder.Append(" ");

            // filename
            string path = info.Path();
            if (isDirectory)
                stringBuilder.Append(FileNameHelpers.GetDirectoryName(path));
            else
                stringBuilder.Append(FileNameHelpers.GetFileName(path));

            // end
            stringBuilder.Append("\r\n");

            return stringBuilder.ToString();
        }
Example #8
0
        private string GetLongProperty(IFileInfo info)
        {
            if (info == null)
            {
                return(null);
            }

            var stringBuilder = new StringBuilder();

            // permissions
            string sAttributes = info.GetAttributeString();

            stringBuilder.Append(sAttributes);
            stringBuilder.Append(" 1 owner group");

            // check whether info is directory
            bool isDirectory = info.IsDirectory();

            // size
            string sFileSize = info.GetSize().ToString(); // if info is directory, the size will be 1

            stringBuilder.Append(TextHelpers.RightAlignString(sFileSize, 13, ' '));
            stringBuilder.Append(" ");

            // modify time
            DateTimeOffset fileDate = info.GetModifiedTime(); //if info is directory, the modify time will be the current time

            // month
            stringBuilder.Append(TextHelpers.Month(fileDate.Month));
            stringBuilder.Append(" ");
            // day
            string sDay = fileDate.Day.ToString();

            if (sDay.Length == 1)
            {
                stringBuilder.Append(" ");
            }
            stringBuilder.Append(sDay);
            stringBuilder.Append(" ");
            // year or hour:min
            if (fileDate.Year < DateTime.Now.Year)
            {
                stringBuilder.Append(" " + fileDate.Year);
            }
            else
            {
                stringBuilder.Append(string.Format("{0:hh}:{1:mm}", fileDate, fileDate));
            }
            stringBuilder.Append(" ");

            // filename
            string path = info.Path();

            if (isDirectory)
            {
                stringBuilder.Append(FileNameHelpers.GetDirectoryName(path));
            }
            else
            {
                stringBuilder.Append(FileNameHelpers.GetFileName(path));
            }

            // end
            stringBuilder.Append("\r\n");

            return(stringBuilder.ToString());
        }