Skip to content

Commit 567fdf4

Browse files
committed
Initial commit
1 parent 9200d49 commit 567fdf4

File tree

153 files changed

+5795
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+5795
-0
lines changed

Diff for: .gitignore

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2+
[Bb]in/
3+
[Oo]bj/
4+
5+
# mstest test results
6+
TestResults
7+
8+
## Ignore Visual Studio temporary files, build results, and
9+
## files generated by popular Visual Studio add-ons.
10+
11+
# User-specific files
12+
*.suo
13+
*.user
14+
*.sln.docstates
15+
16+
# Build results
17+
[Dd]ebug/
18+
[Rr]elease/
19+
x64/
20+
*_i.c
21+
*_p.c
22+
*.ilk
23+
*.meta
24+
*.obj
25+
*.pch
26+
*.pdb
27+
*.pgc
28+
*.pgd
29+
*.rsp
30+
*.sbr
31+
*.tlb
32+
*.tli
33+
*.tlh
34+
*.tmp
35+
*.log
36+
*.vspscc
37+
*.vssscc
38+
.builds
39+
40+
# Visual C++ cache files
41+
ipch/
42+
*.aps
43+
*.ncb
44+
*.opensdf
45+
*.sdf
46+
47+
# Visual Studio profiler
48+
*.psess
49+
*.vsp
50+
*.vspx
51+
52+
# Guidance Automation Toolkit
53+
*.gpState
54+
55+
# ReSharper is a .NET coding add-in
56+
_ReSharper*
57+
58+
# NCrunch
59+
*.ncrunch*
60+
.*crunch*.local.xml
61+
62+
# Installshield output folder
63+
[Ee]xpress
64+
65+
# DocProject is a documentation generator add-in
66+
DocProject/buildhelp/
67+
DocProject/Help/*.HxT
68+
DocProject/Help/*.HxC
69+
DocProject/Help/*.hhc
70+
DocProject/Help/*.hhk
71+
DocProject/Help/*.hhp
72+
DocProject/Help/Html2
73+
DocProject/Help/html
74+
75+
# Click-Once directory
76+
publish
77+
78+
# Publish Web Output
79+
*.Publish.xml
80+
81+
# NuGet Packages Directory
82+
packages
83+
84+
# Windows Azure Build Output
85+
csx
86+
*.build.csdef
87+
88+
# Windows Store app package directory
89+
AppPackages/
90+
91+
# Others
92+
[Bb]in
93+
[Oo]bj
94+
sql
95+
TestResults
96+
[Tt]est[Rr]esult*
97+
*.Cache
98+
ClientBin
99+
[Ss]tyle[Cc]op.*
100+
~$*
101+
*.dbmdl
102+
Generated_Code #added for RIA/Silverlight projects
103+
104+
# Backup & report files from converting an old project file to a newer
105+
# Visual Studio version. Backup files are not needed, because we have git ;-)
106+
_UpgradeReport_Files/
107+
Backup*/
108+
UpgradeLog*.XML
109+
110+
111+
# nupkg for nuget
112+
*.nupkg
113+
114+
# Xamarin components
115+
[Cc]omponents
116+
117+
# Don't add ModernHttpClient binaries
118+
ModernHttpClient/vendor/MonoAndroid/*
119+
ModernHttpClient/vendor/MonoTouch/*
120+
121+
*.mdb

Diff for: MvvmLightSample.Core/MvvmLightSample.Core.csproj

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{1D5E415F-D8CB-44F9-8F19-91E06C7B80D3}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>MvvmLightSample.Core</RootNamespace>
12+
<AssemblyName>MvvmLightSample.Core</AssemblyName>
13+
<DefaultLanguage>en-US</DefaultLanguage>
14+
<FileAlignment>512</FileAlignment>
15+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
16+
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
17+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<!-- A reference to the entire .NET Framework is automatically included -->
38+
</ItemGroup>
39+
<ItemGroup>
40+
<Compile Include="..\MvxSample.Core\Models\*.cs">
41+
<Link>Models\Models</Link>
42+
</Compile>
43+
<Compile Include="..\MvxSample.Core\Models\Searx\*.cs">
44+
<Link>Models\Models\Searx</Link>
45+
</Compile>
46+
<Compile Include="..\MvxSample.Core\Models\DuckDuckGo\*.cs">
47+
<Link>Models\Models\DuckDuckGo</Link>
48+
</Compile>
49+
<Compile Include="Services\DuckDuckGoInstantAnswerSearchProvider.cs" />
50+
<Compile Include="Services\ISearchProvider.cs" />
51+
<Compile Include="Services\ISearchService.cs" />
52+
<Compile Include="Services\SearchService.cs" />
53+
<Compile Include="Services\SearxSearchProvider.cs" />
54+
<Compile Include="ViewModels\SearchDetailViewModel.cs" />
55+
<Compile Include="ViewModels\SearchViewModel.cs" />
56+
<Compile Include="ViewModels\ViewModelLocator.cs" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Compile Include="Properties\AssemblyInfo.cs" />
60+
</ItemGroup>
61+
<ItemGroup>
62+
<Reference Include="GalaSoft.MvvmLight">
63+
<HintPath>..\packages\MvvmLightLibs.5.1.1.0\lib\portable-net45+wp8+wpa81+netcore45+monoandroid1+xamarin.ios10\GalaSoft.MvvmLight.dll</HintPath>
64+
</Reference>
65+
<Reference Include="GalaSoft.MvvmLight.Extras">
66+
<HintPath>..\packages\MvvmLightLibs.5.1.1.0\lib\portable-net45+wp8+wpa81+netcore45+monoandroid1+xamarin.ios10\GalaSoft.MvvmLight.Extras.dll</HintPath>
67+
</Reference>
68+
<Reference Include="Microsoft.Practices.ServiceLocation">
69+
<HintPath>..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll</HintPath>
70+
</Reference>
71+
<Reference Include="ModernHttpClient">
72+
<HintPath>..\packages\modernhttpclient.2.2.0\lib\Portable-Net45+WinRT45+WP8+WPA81\ModernHttpClient.dll</HintPath>
73+
</Reference>
74+
<Reference Include="Newtonsoft.Json">
75+
<HintPath>..\packages\Newtonsoft.Json.7.0.1-beta1\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Newtonsoft.Json.dll</HintPath>
76+
</Reference>
77+
<Reference Include="System.Net.Http.Extensions">
78+
<HintPath>..\packages\Microsoft.Net.Http.2.2.28\lib\portable-net45+win8+wpa81\System.Net.Http.Extensions.dll</HintPath>
79+
</Reference>
80+
<Reference Include="System.Net.Http.Primitives">
81+
<HintPath>..\packages\Microsoft.Net.Http.2.2.28\lib\portable-net45+win8+wpa81\System.Net.Http.Primitives.dll</HintPath>
82+
</Reference>
83+
</ItemGroup>
84+
<ItemGroup>
85+
<None Include="packages.config" />
86+
</ItemGroup>
87+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
88+
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
89+
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
90+
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
91+
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
92+
</Target>
93+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
94+
Other similar extension points exist, see Microsoft.Common.targets.
95+
<Target Name="BeforeBuild">
96+
</Target>
97+
<Target Name="AfterBuild">
98+
</Target>
99+
-->
100+
</Project>

Diff for: MvvmLightSample.Core/Properties/AssemblyInfo.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Resources;
2+
using System.Reflection;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
6+
// General Information about an assembly is controlled through the following
7+
// set of attributes. Change these attribute values to modify the information
8+
// associated with an assembly.
9+
[assembly: AssemblyTitle("MvvmLightSample.Core")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("MvvmLightSample.Core")]
14+
[assembly: AssemblyCopyright("Copyright © 2015")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
[assembly: NeutralResourcesLanguage("en")]
18+
19+
// Version information for an assembly consists of the following four values:
20+
//
21+
// Major Version
22+
// Minor Version
23+
// Build Number
24+
// Revision
25+
//
26+
// You can specify all the values or you can default the Build and Revision Numbers
27+
// by using the '*' as shown below:
28+
// [assembly: AssemblyVersion("1.0.*")]
29+
[assembly: AssemblyVersion("1.0.0.0")]
30+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Net;
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using ModernHttpClient;
7+
using MvxSample.Core.Models;
8+
using MvxSample.Core.Models.DuckDuckGo;
9+
using Newtonsoft.Json;
10+
11+
namespace MvvmLightSample.Core.Services
12+
{
13+
public class DuckDuckGoInstantAnswerSearchProvider : ISearchProvider
14+
{
15+
16+
private const string DuckDuckGoQueryUrl = "http://api.duckduckgo.com/?format=json&q=";
17+
18+
public async Task<IEnumerable<SearchResult>> QueryAsync(string query)
19+
{
20+
var url = DuckDuckGoQueryUrl + WebUtility.UrlEncode(query);
21+
var client = new HttpClient(new NativeMessageHandler());
22+
var json = await client.GetStringAsync(url).ConfigureAwait(false);
23+
24+
var results = JsonConvert.DeserializeObject<DuckDuckGoResult>(json);
25+
var result = new List<SearchResult>();
26+
var first = results.Results.FirstOrDefault();
27+
if (first != null)
28+
result.Add(new SearchResult
29+
{
30+
Url = first.FirstURL,
31+
Title = first.Text,
32+
Content = first.Result
33+
});
34+
result.AddRange(results.RelatedTopics.Select(related => new SearchResult
35+
{
36+
Url = related.FirstURL, Title = related.Text, Content = related.Result
37+
}));
38+
39+
return result;
40+
}
41+
}
42+
}

Diff for: MvvmLightSample.Core/Services/ISearchProvider.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using MvxSample.Core.Models;
4+
5+
namespace MvvmLightSample.Core.Services
6+
{
7+
public interface ISearchProvider
8+
{
9+
Task<IEnumerable<SearchResult>> QueryAsync(string query);
10+
}
11+
}

Diff for: MvvmLightSample.Core/Services/ISearchService.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using MvxSample.Core.Models;
4+
5+
namespace MvvmLightSample.Core.Services
6+
{
7+
public enum SearchProvider
8+
{
9+
Searx,
10+
DuckDuckGo
11+
}
12+
13+
public interface ISearchService
14+
{
15+
Task<IEnumerable<SearchResult>> QueryAsync(string query, SearchProvider provider);
16+
}
17+
}

Diff for: MvvmLightSample.Core/Services/SearchService.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
using MvxSample.Core.Models;
4+
5+
namespace MvvmLightSample.Core.Services
6+
{
7+
public class SearchService : ISearchService
8+
{
9+
private readonly ISearchProvider _duckDuckGoProvider;
10+
private readonly ISearchProvider _searxProvider;
11+
12+
public SearchService()
13+
{
14+
_duckDuckGoProvider = new DuckDuckGoInstantAnswerSearchProvider();
15+
_searxProvider = new SearxSearchProvider();
16+
}
17+
18+
public Task<IEnumerable<SearchResult>> QueryAsync(string query, SearchProvider provider)
19+
{
20+
switch (provider)
21+
{
22+
case SearchProvider.DuckDuckGo:
23+
return _duckDuckGoProvider.QueryAsync(query);
24+
case SearchProvider.Searx:
25+
return _searxProvider.QueryAsync(query);
26+
}
27+
return null;
28+
}
29+
}
30+
}

Diff for: MvvmLightSample.Core/Services/SearxSearchProvider.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Net;
4+
using System.Net.Http;
5+
using System.Threading.Tasks;
6+
using ModernHttpClient;
7+
using MvxSample.Core.Models;
8+
using MvxSample.Core.Models.Searx;
9+
using Newtonsoft.Json;
10+
11+
namespace MvvmLightSample.Core.Services
12+
{
13+
public class SearxSearchProvider : ISearchProvider
14+
{
15+
private const string SearxQueryUrl = "http://searx.me/?format=json&q=";
16+
17+
public async Task<IEnumerable<SearchResult>> QueryAsync(string query)
18+
{
19+
var url = SearxQueryUrl + WebUtility.UrlEncode(query);
20+
var handler = new NativeMessageHandler(false, true);
21+
var client = new HttpClient(handler);
22+
var json = await client.GetStringAsync(url).ConfigureAwait(false);
23+
24+
var results = JsonConvert.DeserializeObject<SearxResultCollection>(json);
25+
26+
return results.results.Select(res => new SearchResult
27+
{
28+
Url = res.url, Title = res.title, Content = res.content
29+
});
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)