コード例 #1
0
 public static FileSystemItem FromFullName(string fullName, VirtualItemType type, IVirtualFolder parent)
 {
     if (fullName == null)
     {
         throw new ArgumentNullException("fullName");
     }
     if (type == VirtualItemType.Unknown)
     {
         if (!Directory.Exists(fullName))
         {
             if (!File.Exists(fullName))
             {
                 throw new FileNotFoundException(string.Format("Cannot discover '{0}' item type because no such file or folder found.", fullName), fullName);
             }
             type = VirtualItemType.File;
         }
         else
         {
             type = VirtualItemType.Folder;
         }
     }
     fullName = fullName.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
     if (type == VirtualItemType.Folder)
     {
         return new FileSystemFolder(fullName, parent);
     }
     if (VirtualItem.IsLink(fullName))
     {
         return new FileSystemShellLink(fullName, parent);
     }
     return new FileSystemFile(fullName, parent);
 }
コード例 #2
0
 public static IVirtualItem FromUri(Uri shellUri, VirtualItemType type)
 {
     if (shellUri == null)
     {
         throw new ArgumentNullException("shellUri");
     }
     if (shellUri.Scheme != UriScheme)
     {
         throw new ArgumentException("Unknown shellUri scheme (shell expected)");
     }
     string localPath = shellUri.LocalPath;
     if (localPath.StartsWith("/::", StringComparison.Ordinal))
     {
         localPath = localPath.Substring(1).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
     }
     SafeShellItem item = new SafeShellItem(IntPtr.Zero, localPath);
     if (type == VirtualItemType.Folder)
     {
         return new ShellFolder(item);
     }
     return ShellFolder.CreateShellItem(item, item.GetAttributesOf(SFGAO.SFGAO_FOLDER | SFGAO.SFGAO_STREAM), null);
 }
コード例 #3
0
        public static IVirtualItem FromUri(Uri nullUri, VirtualItemType type)
        {
            if (nullUri == null)
            {
                throw new ArgumentNullException("nullUri");
            }
            if (nullUri.Scheme != UriScheme)
            {
                throw new ArgumentException(string.Format(Resources.sErrorAnotherSchemeExpected, UriScheme, nullUri.Scheme));
            }
            if (nullUri.Host != ".")
            {
                throw new ArgumentException(string.Format(Resources.sErrorOnlyDotHostAccepted, nullUri.Host));
            }
            switch (type)
            {
                case VirtualItemType.Folder:
                    return new NullFolder(Path.GetFileName(nullUri.AbsolutePath));

                case VirtualItemType.File:
                    return new NullFile(Path.GetFileName(nullUri.AbsolutePath));
            }
            throw new ApplicationException("Cannot detect item type in null file system.");
        }
コード例 #4
0
 public static IVirtualItem FromUri(Uri absoluteUri, VirtualItemType type, IVirtualFolder parent)
 {
     return FtpItem.FromUri(new FtpContext(), absoluteUri, type, parent);
 }
コード例 #5
0
 public VirtualItemPopupAttritube(VirtualItemType typeInclude, bool allowNone = true)
 {
     this.TypeInclude = typeInclude;
     this.AllowNone   = allowNone;
 }
コード例 #6
0
        public static IVirtualItem FromUri(FtpContext context, Uri absoluteUri, VirtualItemType type, IVirtualFolder parent)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (absoluteUri == null)
            {
                throw new ArgumentNullException("absoluteUri");
            }
            if (!absoluteUri.IsAbsoluteUri)
            {
                throw new ArgumentException("This operation is not supported for a relative URI.");
            }
            if (type == VirtualItemType.Unknown)
            {
                if (absoluteUri.AbsolutePath.EndsWith("/", StringComparison.Ordinal))
                {
                    type = VirtualItemType.Folder;
                }
                else
                {
                    try
                    {
                        context.GetFileSize(absoluteUri);
                        type = VirtualItemType.File;
                    }
                    catch
                    {
                        try
                        {
                            context.PrintWorkingDirectory(absoluteUri);
                            type = VirtualItemType.Folder;
                        }
                        catch
                        {
                            throw new ArgumentException(string.Format("Cannot determine file type from uri ({0})", absoluteUri));
                        }
                    }
                }
            }
            switch (type)
            {
                case VirtualItemType.Folder:
                    return new FtpFolder(context, absoluteUri, parent);

                case VirtualItemType.File:
                    try
                    {
                        Uri baseUri = FtpItemInfo.GetParent(absoluteUri);
                        IVirtualItem item = null;
                        foreach (string str in context.ListDirectoryDetails(absoluteUri))
                        {
                            item = ParseListString(context, baseUri, str, parent);
                            break;
                        }
                        if (item != null)
                        {
                            return item;
                        }
                    }
                    catch (WebException)
                    {
                    }
                    return new FtpFile(context, absoluteUri, parent);
            }
            throw new InvalidEnumArgumentException("type", (int) type, typeof(VirtualItemType));
        }