using System;
namespace FlickrNet
{
///
/// Summary description for PhotoSearchOptions.
///
public class PhotoSearchOptions
{
private string _userId;
private string _tags;
private TagMode _tagMode = TagMode.None;
private string _text;
private DateTime _minUploadDate = DateTime.MinValue;
private DateTime _maxUploadDate = DateTime.MinValue;
private DateTime _minTakenDate = DateTime.MinValue;
private DateTime _maxTakenDate = DateTime.MinValue;
private System.Collections.ArrayList _licenses = new System.Collections.ArrayList();
private PhotoSearchExtras _extras = PhotoSearchExtras.None;
private int _perPage = 0;
private int _page = 0;
private PhotoSearchSortOrder _sort = PhotoSearchSortOrder.None;
private PrivacyFilter _privacyFilter = PrivacyFilter.None;
private BoundaryBox _boundaryBox = new BoundaryBox();
///
/// Creates a new instance of the search options.
///
public PhotoSearchOptions()
{
}
///
/// Creates a new instance of the search options, setting the UserId property to the parameter
/// passed in.
///
/// The ID of the User to search for.
public PhotoSearchOptions(string userId) : this(userId, null, TagMode.AllTags, null)
{
}
///
/// Create an instance of the for a given user ID and tag list.
///
/// The ID of the User to search for.
/// The tags (comma delimited) to search for. Will match all tags.
public PhotoSearchOptions(string userId, string tags) : this( userId, tags, TagMode.AllTags, null)
{
}
///
/// Create an instance of the for a given user ID and tag list,
/// with the selected tag mode.
///
/// The ID of the User to search for.
/// The tags (comma delimited) to search for.
/// The to use to search.
public PhotoSearchOptions(string userId, string tags, TagMode tagMode) : this( userId, tags, tagMode, null)
{
}
///
/// Create an instance of the for a given user ID and tag list,
/// with the selected tag mode, and containing the selected text.
///
/// The ID of the User to search for.
/// The tags (comma delimited) to search for.
/// The to use to search.
/// The text to search for in photo title and descriptions.
public PhotoSearchOptions(string userId, string tags, TagMode tagMode, string text)
{
this.UserId = userId;
this.Tags = tags;
this.TagMode = tagMode;
this.Text = text;
}
///
/// The user Id of the user to search on. Defaults to null for no specific user.
///
public string UserId
{
get { return _userId; }
set { _userId = value; }
}
///
/// A comma delimited list of tags
///
public string Tags
{
get { return _tags; }
set { _tags = value; }
}
///
/// Tag mode can either be 'all', or 'any'. Defaults to
///
public TagMode TagMode
{
get { return _tagMode; }
set { _tagMode = value; }
}
internal string TagModeString
{
get
{
switch(_tagMode)
{
case TagMode.None:
return "";
case TagMode.AllTags:
return "all";
case TagMode.AnyTag:
return "any";
case TagMode.Boolean:
return "bool";
default:
return "all";
}
}
}
///
/// Search for the given text in photo titles and descriptions.
///
public string Text
{
get { return _text; }
set { _text = value; }
}
///
/// Minimum date uploaded. Defaults to which
/// signifies that the value is not to be used.
///
public DateTime MinUploadDate
{
get { return _minUploadDate; }
set { _minUploadDate = value; }
}
///
/// Maximum date uploaded. Defaults to which
/// signifies that the value is not to be used.
///
public DateTime MaxUploadDate
{
get { return _maxUploadDate; }
set { _maxUploadDate = value; }
}
///
/// Minimum date taken. Defaults to which
/// signifies that the value is not to be used.
///
public DateTime MinTakenDate
{
get { return _minTakenDate; }
set { _minTakenDate = value; }
}
///
/// Maximum date taken. Defaults to which
/// signifies that the value is not to be used.
///
public DateTime MaxTakenDate
{
get { return _maxTakenDate; }
set { _maxTakenDate = value; }
}
///
/// Only return licenses with the selected license number.
/// See http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html
/// for more details on the numbers to use.
///
[Obsolete("Use AddLicense/RemoveLicense to add/remove licenses")]
public int License
{
get
{
if( _licenses.Count == 0 )
return 0;
else
return (int)_licenses[0];
}
set
{
if( _licenses.Count == 0 )
_licenses.Add(value);
else
_licenses[0] = value;
}
}
///
/// Returns a copy of the licenses to be searched for.
///
public int[] Licenses
{
get
{
return (int[])_licenses.ToArray(typeof(int));
}
}
///
/// Adds a new license to the list of licenses to be searched for.
///
/// The number of the license to search for.
public void AddLicense(int license)
{
if( !_licenses.Contains(license) ) _licenses.Add(license);
}
///
/// Removes a license from the list of licenses to be searched for.
///
/// The number of the license to remove.
public void RemoveLicense(int license)
{
if( _licenses.Contains(license) ) _licenses.Remove(license);
}
///
/// Optional extras to return, defaults to all. See for more details.
///
public PhotoSearchExtras Extras
{
get { return _extras; }
set { _extras = value; }
}
///
/// Number of photos to return per page. Defaults to 100.
///
public int PerPage
{
get { return _perPage; }
set { _perPage = value; }
}
///
/// The page to return. Defaults to page 1.
///
public int Page
{
get { return _page; }
set
{
if( value < 0 ) throw new ArgumentOutOfRangeException("Page", value, "Must be greater than 0");
_page = value;
}
}
///
/// The sort order of the returned list. Default is .
///
public PhotoSearchSortOrder SortOrder
{
get { return _sort; }
set { _sort = value; }
}
///
/// The privacy fitler to filter the search on.
///
public PrivacyFilter PrivacyFilter
{
get { return _privacyFilter; }
set { _privacyFilter = value; }
}
///
/// The boundary box for which to search for geo location photos.
///
public BoundaryBox BoundaryBox
{
get { return _boundaryBox; }
set
{
if( value == null )
_boundaryBox = new BoundaryBox();
else
_boundaryBox = value;
}
}
///
/// The accuracy of the search for geo location photos.
///
///
/// Can also be set as a property of the property.
///
public GeoAccuracy Accuracy
{
get { return _boundaryBox==null?GeoAccuracy.None:_boundaryBox.Accuracy; }
set
{
if (_boundaryBox==null) { _boundaryBox = new BoundaryBox(); }
_boundaryBox.Accuracy = value;
}
}
internal string ExtrasString
{
get { return Utils.ExtrasToString(Extras); }
}
internal string SortOrderString
{
get { return Utils.SortOrderToString(_sort); }
}
}
}