示例#1
0
        public override ICloudFileSystemEntry RequestResource(IStorageProviderSession session, string Name, ICloudDirectoryEntry parent)
        {
            //declare the requested entry
            ICloudFileSystemEntry fsEntry = null;

            // lets have a look if we are on the root node
            if (parent == null)
            {
                // just create the root entry
                fsEntry = GenericStorageProviderFactory.CreateDirectoryEntry(session, Name, parent);
            }
            else
            {
                // ok we have a parent, let's retrieve the resource
                // from his child list
                fsEntry = parent.GetChild(Name, false);
            }

            // now that we create the entry just update the chuld
            if (fsEntry != null && fsEntry is ICloudDirectoryEntry)
            {
                RefreshResource(session, fsEntry as ICloudDirectoryEntry);
            }

            // go ahead
            return(fsEntry);
        }
示例#2
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);
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// This method returns a filesystem object, this can be files or folders
        /// </summary>
        /// <param name="path"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public ICloudFileSystemEntry GetFileSystemObject(string path, ICloudDirectoryEntry parent)
        {
            /*
             * This section generates for every higher object the object tree
             */
            PathHelper ph = new PathHelper(path);

            String[] elements = ph.GetPathElements();

            // create the virtual root
            ICloudDirectoryEntry current = parent ?? GetRoot();

            // build the root

            // check if we request only the root
            if (path.Equals("/"))
            {
                return(current);
            }

            if (_Service.SupportsDirectRetrieve)
            {
                //Request directly
                return(_Service.RequestResource(_Session, path.TrimStart('/'), current));
            }

            // create the path tree
            for (int i = 0; i <= elements.Length - 1; i++)
            {
                String elem = elements[i];

                if (i == elements.Length - 1)
                {
                    return(current.GetChild(elem, false));
                }

                try
                {
                    current = current.GetChild(elem, true) as ICloudDirectoryEntry;
                }
                catch (SharpBoxException e)
                {
                    // if not found, create a virtual one
                    if (e.ErrorCode == SharpBoxErrorCodes.ErrorFileNotFound)
                    {
                        current = GenericStorageProviderFactory.CreateDirectoryEntry(_Session, elem, current);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            // looks like an error
            return(null);
        }
        public override ICloudFileSystemEntry CreateResource(IStorageProviderSession session, string name, ICloudDirectoryEntry parent)
        {
            // get credentials
            var creds = ((GenericNetworkCredentials)session.SessionToken).GetCredential(null, null);

            // build the full url
            var resFull = GetResourceUrl(session, parent, name);

            // create the director
            if (_ftpService.FtpCreateDirectory(resFull, creds))
            {
                // create the filesystem object
                var fsEntry = GenericStorageProviderFactory.CreateDirectoryEntry(session, name, parent);

                // go ahead
                return(fsEntry);
            }
            return(null);
        }
示例#5
0
        /// <summary>
        /// This method returns a filesystem object, this can be files or folders
        /// </summary>
        /// <param name="path"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public ICloudFileSystemEntry GetFileSystemObject(string path, ICloudDirectoryEntry parent)
        {
            /*
             * This section generates for every higher object the object tree
             */
            PathHelper ph = new PathHelper(path);

            String[] elements = ph.GetPathElements();

            // create the virtual root
            ICloudDirectoryEntry current = parent;

            // build the root
            if (current == null)
            {
                current = GetRoot();
            }

            // check if we request only the root
            if (path.Equals("/"))
            {
                return(current);
            }

            // create the path tree
            for (int i = 0; i <= elements.Length - 1; i++)
            {
                String elem = elements[i];

                if (i == elements.Length - 1)
                {
                    // get requested object
                    ICloudFileSystemEntry requestedObject = _Service.RequestResource(_Session, elem, current);

                    // go ahead on error
                    if (requestedObject == null)
                    {
                        return(null);
                    }
                    else
                    {
                        // go ahead
                        return(requestedObject);
                    }
                }
                else
                {
                    try
                    {
                        // try to get the child
                        current = current.GetChild(elem) as ICloudDirectoryEntry;
                    }
                    catch (SharpBoxException e)
                    {
                        // if not found, create a virtual one
                        if (e.ErrorCode == SharpBoxErrorCodes.ErrorFileNotFound)
                        {
                            current = GenericStorageProviderFactory.CreateDirectoryEntry(_Session, elem, current);
                        }
                        else
                        {
                            throw e;
                        }
                    }
                }
            }

            // looks like an error
            return(null);
        }