Beispiel #1
0
        public override void SaveFile(string relativePath, Stream source)
        {
            if (FileExists(relativePath))
                DeleteFile(relativePath);
            else
            {
                string path = string.Empty;
                var directoryName = Path.GetDirectoryName(relativePath);
                if (directoryName != null)
                {
                    string[] directories = directoryName.Split(Path.DirectorySeparatorChar);
                    if (directories.Length > 0)
                        foreach (string t in directories)
                        {
                            path = Path.Combine(path, t);
                            CreateDirectory(path);
                        }
                }
                else
                    throw new NullReferenceException("Incorrect relative path");
            }

            FtpWebRequest request = CreateRequest(Path.Combine(_root, relativePath)
                , WebRequestMethods.Ftp.UploadFile);
            using (Stream stream = request.GetRequestStream())
                source.CopyTo(stream);
            ExecuteRequest(request);

            var item = new RelativeFile {RelativePath = relativePath, Time = DateTime.UtcNow};
            Files.Add(item);
        }
Beispiel #2
0
        void FillItems(string relativePath)
        {
            string fullPath = GetFullPath(relativePath);

            if (_context.Exists(fullPath))
            {
                foreach (string path in Directory.GetDirectories(fullPath))
                {
                    string name = Path.GetFileName(path);
                    if (name != null)
                    {
                        FillItems(Path.Combine(relativePath, name));
                    }
                }

                foreach (string path in Directory.GetFiles(fullPath))
                {
                    string name = Path.GetFileName(path);
                    if (name != null)
                    {
                        var item = new RelativeFile
                        {
                            RelativePath = Path.Combine(relativePath, name),
                            Time         = File.GetLastWriteTimeUtc(path),
                            Size         = new FileInfo(path).Length
                        };
                        Files.Add(item);
                    }
                }
            }
            else
            {
                _context.CreateDirectory(fullPath); // To create /shared/ and /private/ directories
            }
        }
        public override void SaveFile(string relativePath, Stream source)
        {
            var path = GetFullPath(relativePath);
            string dir = Path.GetDirectoryName(path);
            if (dir == null)
                throw new NullReferenceException("Cannot combine url");

            _context.CreateDirectory(dir);

            using (var stream = _context.FileStream(path, FileMode.OpenOrCreate))
                source.CopyTo(stream);

            var item = new RelativeFile
            {
                RelativePath = relativePath,
                Time = File.GetLastWriteTimeUtc(path)
            };
            Files.Add(item);
        }
Beispiel #4
0
        public override void SaveFile(string relativePath, Stream source)
        {
            if (FileExists(relativePath))
            {
                DeleteFile(relativePath);
            }
            else
            {
                string path          = string.Empty;
                var    directoryName = Path.GetDirectoryName(relativePath);
                if (directoryName != null)
                {
                    string[] directories = directoryName.Split(Path.DirectorySeparatorChar);
                    if (directories.Length > 0)
                    {
                        foreach (string t in directories)
                        {
                            path = Path.Combine(path, t);
                            CreateDirectory(path);
                        }
                    }
                }
                else
                {
                    throw new NullReferenceException("Incorrect relative path");
                }
            }

            FtpWebRequest request = CreateRequest(Path.Combine(_root, relativePath)
                                                  , WebRequestMethods.Ftp.UploadFile);

            using (Stream stream = request.GetRequestStream())
                source.CopyTo(stream);
            ExecuteRequest(request);

            var item = new RelativeFile {
                RelativePath = relativePath, Time = DateTime.UtcNow
            };

            Files.Add(item);
        }
Beispiel #5
0
        protected static RelativeFile ParseItems(string message)
        {
            string[] splitted = message.Split('|');
            var      item     = new RelativeFile();

            string[] fileDirectories = splitted[0].Split('\\');
            item.RelativePath = Path.Combine(fileDirectories);
            string   dt   = splitted[1];
            DateTime time = DateTime.ParseExact(dt, @"yyyy\.MM\.dd hh:mm:ss", CultureInfo.GetCultureInfo("ru-RU"));

            item.Time = time;
            if (splitted.Length > 2)
            {
                long size;
                if (long.TryParse(splitted[2], out size))
                {
                    item.Size = size;
                }
            }
            return(item);
        }
Beispiel #6
0
        public override void SaveFile(string relativePath, Stream source)
        {
            var    path = GetFullPath(relativePath);
            string dir  = Path.GetDirectoryName(path);

            if (dir == null)
            {
                throw new NullReferenceException("Cannot combine url");
            }

            _context.CreateDirectory(dir);

            using (var stream = _context.FileStream(path, FileMode.OpenOrCreate))
                source.CopyTo(stream);

            var item = new RelativeFile
            {
                RelativePath = relativePath,
                Time         = File.GetLastWriteTimeUtc(path)
            };

            Files.Add(item);
        }
        void FillItems(string relativePath)
        {
            string fullPath = GetFullPath(relativePath);

            if (_context.Exists(fullPath))
            {
                foreach (string path in Directory.GetDirectories(fullPath))
                {
                    string name = Path.GetFileName(path);
                    if (name != null)
                        FillItems(Path.Combine(relativePath, name));
                }

                foreach (string path in Directory.GetFiles(fullPath))
                {
                    string name = Path.GetFileName(path);
                    if (name != null)
                    {
                        var item = new RelativeFile
                        {
                            RelativePath = Path.Combine(relativePath, name),
                            Time = File.GetLastWriteTimeUtc(path),
                            Size = new FileInfo(path).Length
                        };
                        Files.Add(item);
                    }
                }
            }
            else
                _context.CreateDirectory(fullPath); // To create /shared/ and /private/ directories
        }