Inheritance: AbstractFile, ILocalDirectoryItem
Esempio n. 1
0
        public SearchResultInfo SearchFiles(string query)
        {
            IDbCommand       command;
            DataSet          ds;
            int              x;
            SearchResultInfo result;

            var directories = new List <string>();
            var files       = new List <SharedFileListing>();

            result = new SearchResultInfo();

            var queryNode     = UserQueryParser.Parse(query, FieldSet);
            var queryFragment = queryNode.ToSql(FieldSet);

            var sb = new StringBuilder();

            sb.Append("SELECT * FROM directoryitems WHERE ");
            sb.Append(queryFragment);
            sb.AppendFormat(" LIMIT {0}", MAX_RESULTS.ToString());

            UseConnection(connection =>
            {
                command             = connection.CreateCommand();
                command.CommandText = sb.ToString();

                ds = ExecuteDataSet(command);

                for (x = 0; x < ds.Tables[0].Rows.Count; x++)
                {
                    if (ds.Tables[0].Rows[x]["type"].ToString() == "F")
                    {
                        files.Add(new SharedFileListing(LocalFile.FromDataRow(ds.Tables[0].Rows[x]), false));
                    }
                    else
                    {
                        LocalDirectory dir = LocalDirectory.FromDataRow(ds.Tables[0].Rows[x]);
                        // FIXME: Ugly: Remove '/local' from begining of path
                        string path = "/" + string.Join("/", dir.FullPath.Split('/').Slice(2));
                        directories.Add(path);
                    }
                }
            });

            result.Files       = files.ToArray();
            result.Directories = directories.ToArray();

            return(result);
        }
Esempio n. 2
0
 static internal LocalFile ById(int id)
 {
     return(Core.FileSystem.UseConnection <LocalFile>(delegate(IDbConnection connection) {
         IDbCommand cmd = connection.CreateCommand();
         cmd.CommandText = "SELECT * FROM directoryitems WHERE id=@id AND type = 'F' LIMIT 1";
         Core.FileSystem.AddParameter(cmd, "@id", id);
         DataSet ds = Core.FileSystem.ExecuteDataSet(cmd);
         if (ds.Tables[0].Rows.Count > 0)
         {
             return LocalFile.FromDataRow(ds.Tables[0].Rows[0]);
         }
         else
         {
             return null;
         }
     }));
 }
        public SharedFileListing(LocalFile file, bool includePieces)
        {
            if (file.InfoHash == null) {
                throw new ArgumentException("File must have InfoHash");
            }

            this.name = file.Name;
            this.fullPath =  "/" + String.Join("/", file.FullPath.Split('/').Slice(2));
            this.size = file.Size;
            this.infoHash = file.InfoHash;
            this.sha1 = file.SHA1;
            this.type = FileType.Other; // FIXME: Use real file type.
            this.pieceLength = file.PieceLength;

            if (includePieces)
                this.pieces = file.Pieces;
        }
Esempio n. 4
0
 public Message CreateFileDetailsMessage(Node sendTo, LocalFile file)
 {
     Message message = new Message(network, MessageType.FileDetails);
     message.To = sendTo.NodeID;
     message.Content = new SharedFileListing(file, true);
     return message;
 }
Esempio n. 5
0
        internal static LocalFile[] ListByParentId(Nullable<int> parent_id)
        {
            return Core.FileSystem.UseConnection<LocalFile[]>(delegate(IDbConnection connection) {
                IDbCommand command = connection.CreateCommand();
                string query = null;
                if (parent_id.Equals(null)) {
                    query = "SELECT * FROM directoryitems WHERE parent_id ISNULL AND type = 'F'";
                } else {
                    query = "SELECT * FROM directoryitems WHERE parent_id = @parent_id AND type = 'F'";
                    Core.FileSystem.AddParameter(command, "@parent_id", parent_id);
                }
                command.CommandText = query;
                DataSet ds = Core.FileSystem.ExecuteDataSet(command);

                LocalFile[] results = new LocalFile[ds.Tables[0].Rows.Count];
                for (int x = 0; x < ds.Tables[0].Rows.Count; x++) {
                    results[x] = new LocalFile(ds.Tables[0].Rows[x]);
                }
                return results;
            });
        }
Esempio n. 6
0
 internal void SendFileDetails(Node to, LocalFile file)
 {
     Message m = MessageBuilder.CreateFileDetailsMessage(to, file);
     this.SendRoutedMessage(m);
 }