1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| public bool LoadPictures(string searchType, string searchWord)
{
switch (searchType)
{
case "Most Recent":
this.url=MOST_RECENT;
break;
case "Interesting":
this.url=INTERESTING;
break;
case "By Search Word":
this.url = ENTER_TAG + searchWord;
break;
default :
this.url = MOST_RECENT;
break;
}
try
{
var xraw = XElement.Load(url);
var xroot = XElement.Parse(xraw.Xml);
//select the RSS data from Flickr, and use standard LINQ projection
//to store it within a new PhotoInfo which is an object of my own
//making
var photos = (from photo in xroot.Element("photos").Elements("photo")
select new PhotoInfo
{
Id = (string)photo.Attribute("id"),
Owner = (string)photo.Attribute("owner"),
Title = (string)photo.Attribute("title"),
Secret = (string)photo.Attribute("secret"),
Server = (string)photo.Attribute("server"),
Farm = (string)photo.Attribute("Farm"),
}).Skip(pageIndex * columns * rows).Take(columns * rows);
//set the allowable next/prev states
int count = photos.Count();
if (pageIndex == 0)
{
this.prevAvail = false;
this.nextAvail = true;
}
else
{
this.prevAvail = true;
}
//see if there are less photos than sum(Columns * Rows) if there are
//less cant allow next operation
if (count < columns * rows)
{
this.nextAvail = false;
}
//then write results out to a file, which can then be used by XPF
//Application
XDocument photosDoc = new XDocument();
XElement photosElement = new XElement("photos", from pi in photos
select new XElement("photo",
new XElement("url", pi.PhotoUrl(false)),
new XElement("title", pi.Title))
);
photosDoc.Add(photosElement);
photosDoc.Save(@"c:\photos.xml");
return true;
}
catch (Exception ex)
{
return false;
}
} |
Partager