Наследование: MonkeyWrench.DataClasses.DBView
Пример #1
0
		/// <summary>
		/// Returns a READ-ONLY list of files
		/// </summary>
		/// <param name="db"></param>
		/// <param name="work_id"></param>
		/// <param name="include_hidden_files">If hidden files are included in the returned list. Note that any file named 'index.html' is always returned, even if it's hidden and this parameter is false.</param>
		/// <returns></returns>
		public static List<DBWorkFileView> GetFiles (DB db, int work_id, bool include_hidden_files)
		{
			List<DBWorkFileView> result = new List<DBWorkFileView> ();

			using (IDbCommand cmd = db.CreateCommand ()) {
				if (include_hidden_files) {
					cmd.CommandText = "SELECT * FROM WorkFileView WHERE work_id = @work_id;";
				} else {
					cmd.CommandText = "SELECT * FROM WorkFileView WHERE work_id = @work_id AND (hidden = false OR filename = 'index.html');";
				}
				DB.CreateParameter (cmd, "work_id", work_id);
				using (IDataReader reader = cmd.ExecuteReader ()) {
					while (reader.Read ()) {
						DBWorkFileView file = new DBWorkFileView (reader);
						result.Add (file);
					}
				}
			}

			return result;
		}
Пример #2
0
		public Stream Download (DBWorkFileView file)
		{
			return new DBFileStream (DBFile_Extensions.Create (this, file.file_id), this);
		}
		public static DBWorkFileView Find (DB db, string filename, string lane, string revision, string host)
		{
			DBWorkFileView result;

			if (lane == null)
				throw new ArgumentNullException ("lane");

			using (IDbCommand cmd = db.CreateCommand ()) {
				cmd.CommandText = @"
	SELECT 
		WorkFile.id, WorkFile.work_id, WorkFile.file_id, WorkFile.filename, WorkFile.hidden, 
		File.mime, File.compressed_mime, 
		Command.internal
	FROM WorkFile
		INNER JOIN File ON WorkFile.file_id = File.id
		INNER JOIN Work ON WorkFile.work_id = Work.id
		INNER JOIN Command ON Work.command_id = Command.id
		INNER JOIN RevisionWork ON Work.revisionwork_id = RevisionWork.id
		INNER JOIN Revision ON RevisionWork.revision_id = Revision.id
		INNER JOIN Lane ON RevisionWork.lane_id = Lane.id
		INNER JOIN Host ON RevisionWork.host_id = Host.id
	WHERE
		Lane.lane = @lane
		AND Revision.revision = @revision
		AND WorkFile.filename = @filename
		AND Host.host = @host;
";

				DB.CreateParameter (cmd, "filename", filename);
				DB.CreateParameter (cmd, "lane", lane);
				DB.CreateParameter (cmd, "revision", revision);
				DB.CreateParameter (cmd, "host", host);

				using (IDataReader reader = cmd.ExecuteReader ()) {
					if (!reader.Read ())
						return null;

					result = new DBWorkFileView (reader);


					int counter = 0;
					string ids = result.id.ToString ();
					while (reader.Read ()) {
						counter++;
						ids += ", " + reader ["id"];
					}

					if (counter > 0)
						throw new ApplicationException (string.Format ("Found more than one file ({0} too many: {1}).", counter, ids));
				}
			}

			return result;
		}