Пример #1
0
        public ListResult GetListResult(ListingElements listingElements)
        {
            ListResult ret = new ListResult(this);

            string msg;

            ret.Entries = GetListingEntries(listingElements, out msg);

            ret.Status = Status;
            ret.ListingAgentMessage = msg;

            return(ret);
        }
Пример #2
0
        protected override List <ListingEntry> GetListingEntries(ListingElements elements, out string message)
        {
            List <ListingEntry> ret = new List <ListingEntry>();

            Status = ListingAgentStatus.Listing;

            string container = "";

            try
            {
                container = Azure.Authentication.ContainerFromPath(Path);
                string prefix = Azure.Authentication.PrefixFromPath(Path);

                if (ListingType == ListingType.File || ListingType == ListingType.All)
                {
                    List <IListBlobItem> files = _Auth.ListObjects(container, prefix, ListingType.File, Recurse, SubpathFilter, FileFilter);

                    foreach (IListBlobItem file in files)
                    {
                        if (elements == ListingElements.None)
                        {
                            ret.Add(new ListingEntry {
                                Name = Azure.Authentication.ToString(file), ItemType = ItemType.File
                            });
                        }
                        else
                        {
                            FileInfo i = _Auth.GetFileInfo(Azure.Authentication.ToString(file));

                            if (i != null)
                            {
                                if (elements == ListingElements.LastWriteTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = Azure.Authentication.ToString(file), ItemType = ItemType.File, LastWriteTimeUtc = i.LastWriteTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else if (elements == ListingElements.CreationTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = Azure.Authentication.ToString(file), ItemType = ItemType.File, CreationTimeUtc = i.CreationTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else if (elements == ListingElements.LastAccessTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = Azure.Authentication.ToString(file), ItemType = ItemType.File, LastAccessTimeUtc = i.LastAccessTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else
                                {
                                    ret.Add(new ListingEntry {
                                        CreationTimeUtc = i.CreationTimeUtc, LastAccessTimeUtc = i.LastAccessTimeUtc, LastWriteTimeUtc = i.LastWriteTimeUtc, Size = i.Size, Name = Azure.Authentication.ToString(file), ItemType = ItemType.File
                                    });
                                }
                            }
                        }
                    }
                }


                if (ListingType == ListingType.Directory || ListingType == ListingType.All)
                {
                    List <IListBlobItem> directories = _Auth.ListObjects(container, prefix, ListingType.Directory, Recurse, SubpathFilter, "*");

                    foreach (IListBlobItem dir in directories)
                    {
                        if (elements == ListingElements.None)
                        {
                            ret.Add(new ListingEntry {
                                Name = Azure.Authentication.ToString(dir), ItemType = ItemType.Directory
                            });
                        }
                        else
                        {
                            DirectoryInfo i = _Auth.GetDirectoryInfo(Azure.Authentication.ToString(dir));

                            if (i != null)
                            {
                                if (elements == ListingElements.LastWriteTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = Azure.Authentication.ToString(dir), ItemType = ItemType.Directory, LastWriteTimeUtc = i.LastWriteTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else if (elements == ListingElements.CreationTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = Azure.Authentication.ToString(dir), ItemType = ItemType.Directory, CreationTimeUtc = i.CreationTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else if (elements == ListingElements.LastAccessTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = Azure.Authentication.ToString(dir), ItemType = ItemType.Directory, LastAccessTimeUtc = i.LastAccessTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else
                                {
                                    ret.Add(new ListingEntry {
                                        CreationTimeUtc = i.CreationTimeUtc, LastAccessTimeUtc = i.LastAccessTimeUtc, LastWriteTimeUtc = i.LastWriteTimeUtc, Name = Azure.Authentication.ToString(dir), ItemType = ItemType.Directory
                                    });
                                }
                            }
                        }
                    }
                }

                message = "";
            }
            catch (Exception ex)
            {
                Status  = ListingAgentStatus.Error;
                message = ex.Message;
            }
            finally
            {
                if (Status == ListingAgentStatus.Listing)
                {
                    Status = ListingAgentStatus.Waiting;
                }
            }

            return(ret);
        }
Пример #3
0
        protected override List <ListingEntry> GetListingEntries(ListingElements elements, out string message)
        {
            List <ListingEntry> ret = new List <ListingEntry>();

            Status = ListingAgentStatus.Listing;

            string bucket = "";

            try
            {
                string path = Path;
                if (!path.EndsWith("/", StringComparison.Ordinal) && !path.EndsWith("\\", StringComparison.Ordinal))
                {
                    path = path + "/";
                }

                bucket = S3.Authentication.BucketFromPath(path);
                string prefix = S3.Authentication.PrefixFromPath(path);

                List <S3Object> files = _Auth.ListObjects(bucket, prefix, ListingType.File, Recurse, SubpathFilter, FileFilter, _Auth.LimitListResults);

                List <string> folders = files.Select(i => STEM.Sys.IO.Path.GetDirectoryName(i.Key).Replace("\\", "/").TrimEnd('/') + '/').Distinct().ToList();

                folders = folders.Select(i => System.IO.Path.Combine(System.IO.Path.DirectorySeparatorChar.ToString() + System.IO.Path.DirectorySeparatorChar.ToString() + bucket, i.Replace('/', System.IO.Path.DirectorySeparatorChar)).TrimEnd(System.IO.Path.DirectorySeparatorChar)).ToList();

                folders.Add(System.IO.Path.Combine(System.IO.Path.DirectorySeparatorChar.ToString() + System.IO.Path.DirectorySeparatorChar.ToString() + bucket));

                if (ListingType == ListingType.File || ListingType == ListingType.All)
                {
                    foreach (S3Object file in files)
                    {
                        if (elements == ListingElements.None)
                        {
                            ret.Add(new ListingEntry {
                                Name = S3.Authentication.ToString(file), ItemType = ItemType.File
                            });
                        }
                        else
                        {
                            FileInfo i = _Auth.GetFileInfo(S3.Authentication.ToString(file));

                            if (i != null)
                            {
                                if (elements == ListingElements.LastWriteTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = S3.Authentication.ToString(file), ItemType = ItemType.File, LastWriteTimeUtc = i.LastWriteTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else if (elements == ListingElements.CreationTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = S3.Authentication.ToString(file), ItemType = ItemType.File, CreationTimeUtc = i.CreationTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else if (elements == ListingElements.LastAccessTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = S3.Authentication.ToString(file), ItemType = ItemType.File, LastAccessTimeUtc = i.LastAccessTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else
                                {
                                    ret.Add(new ListingEntry {
                                        CreationTimeUtc = i.CreationTimeUtc, LastAccessTimeUtc = i.LastAccessTimeUtc, LastWriteTimeUtc = i.LastWriteTimeUtc, Size = i.Size, Name = S3.Authentication.ToString(file), ItemType = ItemType.File
                                    });
                                }
                            }
                        }
                    }
                }

                if (ListingType == ListingType.Directory || ListingType == ListingType.All)
                {
                    foreach (string folder in folders)
                    {
                        if (elements == ListingElements.None)
                        {
                            ret.Add(new ListingEntry {
                                Name = folder, ItemType = ItemType.Directory
                            });
                        }
                        else
                        {
                            DirectoryInfo i = _Auth.GetDirectoryInfo(folder);

                            if (i != null)
                            {
                                if (elements == ListingElements.LastWriteTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = folder, ItemType = ItemType.Directory, LastWriteTimeUtc = i.LastWriteTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else if (elements == ListingElements.CreationTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = folder, ItemType = ItemType.Directory, CreationTimeUtc = i.CreationTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else if (elements == ListingElements.LastAccessTimeUtc)
                                {
                                    try
                                    {
                                        ret.Add(new ListingEntry {
                                            Name = folder, ItemType = ItemType.Directory, LastAccessTimeUtc = i.LastAccessTimeUtc
                                        });
                                    }
                                    catch { }
                                }
                                else
                                {
                                    ret.Add(new ListingEntry {
                                        CreationTimeUtc = i.CreationTimeUtc, LastAccessTimeUtc = i.LastAccessTimeUtc, LastWriteTimeUtc = i.LastWriteTimeUtc, Name = folder, ItemType = ItemType.Directory
                                    });
                                }
                            }
                        }
                    }
                }

                message = "";
            }
            catch (Exception ex)
            {
                Status  = ListingAgentStatus.Error;
                message = ex.Message;
            }
            finally
            {
                if (Status == ListingAgentStatus.Listing)
                {
                    Status = ListingAgentStatus.Waiting;
                }
            }

            return(ret);
        }
Пример #4
0
        protected override List <ListingEntry> GetListingEntries(ListingElements elements, out string message)
        {
            List <ListingEntry> ret   = new List <ListingEntry>();
            Impersonation       token = null;

            Status = ListingAgentStatus.Listing;

            try
            {
                if (_Auth != null)
                {
                    _Auth.Impersonate(out token);
                }

                if (ListingType == ListingType.File || ListingType == ListingType.All)
                {
                    List <string> files = STEM.Sys.IO.Directory.STEM_GetFiles(Path, FileFilter, SubpathFilter, Recurse ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly, false);

                    if (elements == ListingElements.None)
                    {
                        ret = files.Select(file => new ListingEntry {
                            Name = file, ItemType = ItemType.File
                        }).ToList();
                    }
                    else if (elements == ListingElements.LastWriteTimeUtc)
                    {
                        foreach (string file in files)
                        {
                            try
                            {
                                ret.Add(new ListingEntry {
                                    Name = file, ItemType = ItemType.File, LastWriteTimeUtc = System.IO.File.GetLastWriteTimeUtc(file)
                                });
                            }
                            catch { }
                        }
                    }
                    else if (elements == ListingElements.CreationTimeUtc)
                    {
                        foreach (string file in files)
                        {
                            try
                            {
                                ret.Add(new ListingEntry {
                                    Name = file, ItemType = ItemType.File, CreationTimeUtc = System.IO.File.GetCreationTimeUtc(file)
                                });
                            }
                            catch { }
                        }
                    }
                    else if (elements == ListingElements.LastAccessTimeUtc)
                    {
                        foreach (string file in files)
                        {
                            try
                            {
                                ret.Add(new ListingEntry {
                                    Name = file, ItemType = ItemType.File, LastAccessTimeUtc = System.IO.File.GetLastAccessTimeUtc(file)
                                });
                            }
                            catch { }
                        }
                    }
                    else
                    {
                        foreach (string file in files)
                        {
                            try
                            {
                                System.IO.FileInfo i = new System.IO.FileInfo(file);
                                ret.Add(new ListingEntry {
                                    CreationTimeUtc = i.CreationTimeUtc, LastAccessTimeUtc = i.LastAccessTimeUtc, LastWriteTimeUtc = i.LastWriteTimeUtc, Size = i.Length, Name = file, ItemType = ItemType.File
                                });
                            }
                            catch { }
                        }
                    }
                }

                if (ListingType == ListingType.Directory || ListingType == ListingType.All)
                {
                    List <string> directories = STEM.Sys.IO.Directory.STEM_GetDirectories(Path, SubpathFilter, Recurse ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly, false);

                    if (elements == ListingElements.None)
                    {
                        ret = directories.Select(dir => new ListingEntry {
                            Name = dir, ItemType = ItemType.Directory
                        }).ToList();
                    }
                    else if (elements == ListingElements.LastWriteTimeUtc)
                    {
                        foreach (string dir in directories)
                        {
                            try
                            {
                                ret.Add(new ListingEntry {
                                    Name = dir, ItemType = ItemType.Directory, LastWriteTimeUtc = System.IO.Directory.GetLastWriteTimeUtc(dir)
                                });
                            }
                            catch { }
                        }
                    }
                    else if (elements == ListingElements.CreationTimeUtc)
                    {
                        foreach (string dir in directories)
                        {
                            try
                            {
                                ret.Add(new ListingEntry {
                                    Name = dir, ItemType = ItemType.Directory, CreationTimeUtc = System.IO.Directory.GetCreationTimeUtc(dir)
                                });
                            }
                            catch { }
                        }
                    }
                    else if (elements == ListingElements.LastAccessTimeUtc)
                    {
                        foreach (string dir in directories)
                        {
                            try
                            {
                                ret.Add(new ListingEntry {
                                    Name = dir, ItemType = ItemType.Directory, LastAccessTimeUtc = System.IO.Directory.GetLastAccessTimeUtc(dir)
                                });
                            }
                            catch { }
                        }
                    }
                    else
                    {
                        foreach (string dir in directories)
                        {
                            try
                            {
                                System.IO.DirectoryInfo i = new System.IO.DirectoryInfo(dir);
                                ret.Add(new ListingEntry {
                                    CreationTimeUtc = i.CreationTimeUtc, LastAccessTimeUtc = i.LastAccessTimeUtc, LastWriteTimeUtc = i.LastWriteTimeUtc, Name = dir, ItemType = ItemType.Directory
                                });
                            }
                            catch { }
                        }
                    }
                }

                message = "";
            }
            catch (Exception ex)
            {
                Status  = ListingAgentStatus.Error;
                message = ex.Message;
            }
            finally
            {
                if (Status == ListingAgentStatus.Listing)
                {
                    Status = ListingAgentStatus.Waiting;
                }

                if (_Auth != null)
                {
                    _Auth.Unimpersonate(token);
                }
            }

            return(ret);
        }
Пример #5
0
 protected abstract List <ListingEntry> GetListingEntries(ListingElements elements, out string message);
Пример #6
0
        protected override List <ListingEntry> GetListingEntries(ListingElements elements, out string message)
        {
            List <ListingEntry> ret = new List <ListingEntry>();

            Status = ListingAgentStatus.Listing;

            try
            {
                List <Renci.SshNet.Sftp.SftpFile> items = _Auth.ListDirectory(Path, ListingType, Recurse, SubpathFilter, FileFilter);

                foreach (Renci.SshNet.Sftp.SftpFile item in items)
                {
                    ItemType it = item.IsDirectory ? ItemType.Directory : ItemType.File;

                    if (elements == ListingElements.None)
                    {
                        ret.Add(new ListingEntry {
                            Name = _Auth.ToString(item), ItemType = it
                        });
                    }
                    else if (elements == ListingElements.LastWriteTimeUtc)
                    {
                        ret.Add(new ListingEntry {
                            LastWriteTimeUtc = item.LastWriteTimeUtc, Name = _Auth.ToString(item), ItemType = it
                        });
                    }
                    else if (elements == ListingElements.CreationTimeUtc)
                    {
                        ret.Add(new ListingEntry {
                            CreationTimeUtc = item.LastWriteTimeUtc, Name = _Auth.ToString(item), ItemType = it
                        });
                    }
                    else if (elements == ListingElements.LastAccessTimeUtc)
                    {
                        ret.Add(new ListingEntry {
                            LastAccessTimeUtc = item.LastAccessTimeUtc, Name = _Auth.ToString(item), ItemType = it
                        });
                    }
                    else
                    {
                        ret.Add(new ListingEntry {
                            CreationTimeUtc = item.LastWriteTimeUtc, LastAccessTimeUtc = item.LastAccessTimeUtc, LastWriteTimeUtc = item.LastWriteTimeUtc, Size = item.Length, Name = _Auth.ToString(item), ItemType = it
                        });
                    }
                }

                message = "";
            }
            catch (Exception ex)
            {
                Status  = ListingAgentStatus.Error;
                message = ex.Message;
            }
            finally
            {
                if (Status == ListingAgentStatus.Listing)
                {
                    Status = ListingAgentStatus.Waiting;
                }
            }

            return(ret);
        }
Пример #7
0
        protected override List <ListingEntry> GetListingEntries(ListingElements elements, out string message)
        {
            List <ListingEntry> ret = new List <ListingEntry>();

            Status = ListingAgentStatus.Listing;

            try
            {
                List <FluentFTP.FtpListItem> items = _Auth.ListDirectory(Path, ListingType, Recurse, SubpathFilter, FileFilter);

                foreach (FluentFTP.FtpListItem item in items)
                {
                    ItemType it = item.Type == FluentFTP.FtpFileSystemObjectType.File ? ItemType.File : ItemType.Directory;

                    if (elements == ListingElements.None)
                    {
                        ret.Add(new ListingEntry {
                            Name = _Auth.ToString(item), ItemType = it
                        });
                    }
                    else if (elements == ListingElements.LastWriteTimeUtc)
                    {
                        ret.Add(new ListingEntry {
                            LastWriteTimeUtc = item.Modified, Name = _Auth.ToString(item), ItemType = it
                        });
                    }
                    else if (elements == ListingElements.CreationTimeUtc)
                    {
                        ret.Add(new ListingEntry {
                            CreationTimeUtc = item.Created, Name = _Auth.ToString(item), ItemType = it
                        });
                    }
                    else if (elements == ListingElements.LastAccessTimeUtc)
                    {
                        ret.Add(new ListingEntry {
                            LastAccessTimeUtc = item.Modified, Name = _Auth.ToString(item), ItemType = it
                        });
                    }
                    else
                    {
                        ret.Add(new ListingEntry {
                            CreationTimeUtc = item.Created, LastAccessTimeUtc = item.Modified, LastWriteTimeUtc = item.Modified, Size = item.Size, Name = _Auth.ToString(item), ItemType = it
                        });
                    }
                }

                message = "";
            }
            catch (Exception ex)
            {
                Status  = ListingAgentStatus.Error;
                message = ex.Message;
            }
            finally
            {
                if (Status == ListingAgentStatus.Listing)
                {
                    Status = ListingAgentStatus.Waiting;
                }
            }

            return(ret);
        }