Пример #1
0
        private void RefreshChildsOfDirectory(IStorageProviderSession session, ICloudDirectoryEntry dir)
        {
            // get the creds
            ICredentials creds = ((GenericNetworkCredentials)session.SessionToken).GetCredential(null, null);

            // get the uri
            String resSource = GetResourceUrl(session, dir.Parent, dir.Name);

            // clear all childs
            GenericStorageProviderFactory.ClearAllChilds(dir);

            // we need to request a directory list here
            using (MemoryStream data = _ftpService.PerformSimpleWebCall(resSource, WebRequestMethodsEx.Ftp.ListDirectoryDetails, creds, null))
            {
                using (StreamReader r = new StreamReader(data))
                {
                    while (!r.EndOfStream)
                    {
                        String ftpline = r.ReadLine();

                        Match m = GetMatchingRegexFromFTPLine(ftpline);

                        if (m == null)
                        {
                            //failed
                            throw new ApplicationException("Unable to parse line: " + ftpline);
                        }
                        else
                        {
                            // get the filename
                            String filename = m.Groups["name"].Value;

                            // get teh modified date
                            DateTime fileDateTime = DateTime.MinValue;
                            try
                            {
                                fileDateTime = System.DateTime.Parse(m.Groups["timestamp"].Value);
                            }
                            catch (Exception)
                            { }

                            // evaluate if we have a directory
                            string _dir = m.Groups["dir"].Value;
                            if ((!string.IsNullOrEmpty(_dir) & _dir != "-"))
                            {
                                GenericStorageProviderFactory.CreateDirectoryEntry(session, filename, fileDateTime, dir);
                            }
                            else
                            {
                                // get the size
                                long size = Convert.ToInt64(m.Groups["size"].Value);

                                // create the file object
                                GenericStorageProviderFactory.CreateFileSystemEntry(session, filename, fileDateTime, size, dir);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// This method creates a file in the cloud storage
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public virtual ICloudFileSystemEntry CreateFile(ICloudDirectoryEntry parent, string name)
        {
            // build the parent
            if (parent == null)
            {
                parent = GetRoot();
            }

            // build the file entry
            var newEntry = GenericStorageProviderFactory.CreateFileSystemEntry(_Session, name, parent);

            return(newEntry);
        }