Skip to content

Commit

Permalink
started implementing the FlickrSearch demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Duarte Nunes committed Feb 2, 2011
1 parent 0d10c1c commit 634fd40
Show file tree
Hide file tree
Showing 17 changed files with 9,374 additions and 17 deletions.
31 changes: 14 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
*.[Cc]ache
*.csproj.user
*.[Rr]e[Ss]harper*
*.sln.cache
*.suo
*.user
*.[Cc]ache
*.csproj.user
*.[Rr]e[Ss]harper*
*.sln.cache
*.suo
*.user
*.orig
*.pdb
*.userprefs
AssemblyInfo.cs
.DS_Store
deploy/
build/
[Bb]in/
[Dd]ebug/
[Oo]bj/
[Rr]elease/
_[Rr]e[Ss]harper.*/
*.vs10x
*.userprefs
_[Rr]e[Ss]harper.*/
.DS_Store
deploy/
build/
[Oo]bj
src/**/**/[Bb]in
Binary file added bin/AsyncCtpLibrary.dll
Binary file not shown.
2,572 changes: 2,572 additions & 0 deletions bin/AsyncCtpLibrary.xml

Large diffs are not rendered by default.

Binary file added bin/System.Threading.Tasks.Dataflow.dll
Binary file not shown.
6,217 changes: 6,217 additions & 0 deletions bin/System.Threading.Tasks.Dataflow.xml

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/FlickrSearch/FlickrSearch.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlickrSearch", "FlickrSearch\FlickrSearch.csproj", "{25EADCE3-0E78-4888-A124-FF29F7DFC822}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{25EADCE3-0E78-4888-A124-FF29F7DFC822}.Debug|x86.ActiveCfg = Debug|x86
{25EADCE3-0E78-4888-A124-FF29F7DFC822}.Debug|x86.Build.0 = Debug|x86
{25EADCE3-0E78-4888-A124-FF29F7DFC822}.Release|x86.ActiveCfg = Release|x86
{25EADCE3-0E78-4888-A124-FF29F7DFC822}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions src/FlickrSearch/FlickrSearch/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application x:Class="FlickrSearch.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
11 changes: 11 additions & 0 deletions src/FlickrSearch/FlickrSearch/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Windows;

namespace FlickrSearch
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
10 changes: 10 additions & 0 deletions src/FlickrSearch/FlickrSearch/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace FlickrSearch
{
public static class Extensions
{
public static string FormatWith(this string format, params object[] args)
{
return string.Format(format, args);
}
}
}
108 changes: 108 additions & 0 deletions src/FlickrSearch/FlickrSearch/FlickrSearch.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{25EADCE3-0E78-4888-A124-FF29F7DFC822}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FlickrSearch</RootNamespace>
<AssemblyName>FlickrSearch</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AsyncCtpLibrary">
<HintPath>..\..\..\bin\AsyncCtpLibrary.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Threading.Tasks.Dataflow">
<HintPath>..\..\..\bin\System.Threading.Tasks.Dataflow.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Extensions.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
23 changes: 23 additions & 0 deletions src/FlickrSearch/FlickrSearch/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Window x:Class="FlickrSearch.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Movie Finder" Height="537" Width="1000">
<DockPanel TextBlock.FontSize="28" TextBlock.Foreground="White">
<DockPanel.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF6C1919" Offset="0" />
<GradientStop Color="#FFE54343" Offset="1" />
</LinearGradientBrush>
</DockPanel.Background>
<DockPanel Height="80" DockPanel.Dock="Top">
<TextBlock DockPanel.Dock="Left" Text="Release year" VerticalAlignment="Center" Margin="30,0,0,0" />
<TextBox Name="textBox" Width="160" VerticalAlignment="Center" Margin="10,0,0,0" />
<Button Name="searchButton" Content="Search" DockPanel.Dock="Left" VerticalAlignment="Center" Width="120" Margin="10,0,0,0" Click="searchButton_Click" IsDefault="True" />
<Button Name="cancelButton" Content="Cancel" DockPanel.Dock="Left" VerticalAlignment="Center" Width="120" Margin="10,0,0,0" Click="cancelButton_Click" IsCancel="True" />
<TextBlock Name="statusText" DockPanel.Dock="Right" VerticalAlignment="Center" Margin="10,0,30,0" TextAlignment="Right" />
</DockPanel>
<ScrollViewer VerticalScrollBarVisibility="Auto" DockPanel.Dock="Top">
<WrapPanel Name="resultsPanel" HorizontalAlignment="Center" />
</ScrollViewer >
</DockPanel>
</Window>
111 changes: 111 additions & 0 deletions src/FlickrSearch/FlickrSearch/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Linq;

namespace FlickrSearch
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{

//
// Flickr photo search API: http://www.flickr.com/services/api/flickr.photos.search.html
//

private int _currentPage = 1;

private class Photo
{
public string Title { get; set; }
public string Url { get; set; }
}

CancellationTokenSource cts;

public MainWindow()
{
InitializeComponent();
textBox.Focus();
}

private void searchButton_Click(object sender, RoutedEventArgs e)
{
load_photos(textBox.Text);
}

private void cancelButton_Click(object sender, RoutedEventArgs e)
{
if (cts != null)
{
cts.Cancel();
statusText.Text = "Cancelled";
}
}

private void load_photos(string text)
{
const string apiKey = "";
const string query = "http://api.flickr.com/services/rest/?method=flickr.photos.search" +
"&api_key=" + apiKey + "&sort=interestingness-desc&page={0}&text={1}";

var webClient = new WebClient();
string content = webClient.DownloadString(query.FormatWith(_currentPage, text));

var document = XDocument.Parse(content);
var photos = get_photos(document);
//int totalPhotos = int.Parse(root.Attribute("total").Value);
display_photos(photos);
}

private static Photo[] get_photos(XDocument document)
{
//
// Flickr uses the following URL format:
// http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg
//

return document.Descendants("photo").Select(photo => new Photo
{
Url = "http://farm{0}.static.flickr.com/{1}/{2}_{3}.jpg".FormatWith(
photo.Attribute("farm").Value, photo.Attribute("server").Value,
photo.Attribute("id").Value, photo.Attribute("secret").Value),
Title = photo.Attribute("title").Value
}).ToArray();
}

void display_photos(IEnumerable<Photo> photos)
{
foreach (var photo in photos)
{
var bitmap = new BitmapImage(new Uri(photo.Url));
var image = new Image();
image.Source = bitmap;
image.Width = 110;
image.Height = 150;
image.Margin = new Thickness(5);
var tt = new ToolTip();
tt.Content = photo.Title;
image.ToolTip = tt;
var url = photo.Url;
image.MouseDown += (sender, e) => System.Diagnostics.Process.Start(url);
resultsPanel.Children.Add(image);
}
}
}
}
55 changes: 55 additions & 0 deletions src/FlickrSearch/FlickrSearch/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("FlickrSearch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("FlickrSearch")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.

//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]


[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]


// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 634fd40

Please sign in to comment.