Skip to content

Commit

Permalink
Merge pull request #108 from nooperation/develop
Browse files Browse the repository at this point in the history
Develop to master
  • Loading branch information
nooperation authored Apr 22, 2018
2 parents dab542e + ff10280 commit a5f3eb0
Show file tree
Hide file tree
Showing 20 changed files with 306 additions and 72 deletions.
16 changes: 4 additions & 12 deletions AtlasView/AtlasView.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\LibSanBag.1.4.4\build\LibSanBag.props" Condition="Exists('..\packages\LibSanBag.1.4.4\build\LibSanBag.props')" />
<Import Project="..\packages\LibSanBag.1.5.0\build\LibSanBag.props" Condition="Exists('..\packages\LibSanBag.1.5.0\build\LibSanBag.props')" />
<Import Project="..\packages\SanTools.LibCRN.1.0.7\build\SanTools.LibCRN.props" Condition="Exists('..\packages\SanTools.LibCRN.1.0.7\build\SanTools.LibCRN.props')" />
<Import Project="..\packages\SanTools.LibUserPreferences.1.0.6\build\SanTools.LibUserPreferences.props" Condition="Exists('..\packages\SanTools.LibUserPreferences.1.0.6\build\SanTools.LibUserPreferences.props')" />
<Import Project="..\packages\SanTools.LibFSB.1.0.0\build\SanTools.LibFSB.props" Condition="Exists('..\packages\SanTools.LibFSB.1.0.0\build\SanTools.LibFSB.props')" />
Expand Down Expand Up @@ -42,8 +42,8 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="LibSanBag, Version=1.4.4.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\LibSanBag.1.4.4\lib\net46\LibSanBag.dll</HintPath>
<Reference Include="LibSanBag, Version=1.5.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\LibSanBag.1.5.0\lib\net46\LibSanBag.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand All @@ -69,7 +69,6 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ViewModels\AtlasViewModel.cs" />
<Compile Include="ViewModels\ErrorViewModel.cs" />
<Compile Include="ViewModels\ExperienceViewModel.cs" />
<Compile Include="ViewModels\MainWindowViewModel.cs" />
<Compile Include="Views\AtlasView.xaml.cs">
Expand All @@ -78,9 +77,6 @@
<Compile Include="Views\ExperienceView.xaml.cs">
<DependentUpon>ExperienceView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ErrorView.xaml.cs">
<DependentUpon>ErrorView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
</Compile>
Expand All @@ -100,10 +96,6 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\ErrorView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -154,6 +146,6 @@
<Error Condition="!Exists('..\packages\SanTools.LibFSB.1.0.0\build\SanTools.LibFSB.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SanTools.LibFSB.1.0.0\build\SanTools.LibFSB.props'))" />
<Error Condition="!Exists('..\packages\SanTools.LibUserPreferences.1.0.6\build\SanTools.LibUserPreferences.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SanTools.LibUserPreferences.1.0.6\build\SanTools.LibUserPreferences.props'))" />
<Error Condition="!Exists('..\packages\SanTools.LibCRN.1.0.7\build\SanTools.LibCRN.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SanTools.LibCRN.1.0.7\build\SanTools.LibCRN.props'))" />
<Error Condition="!Exists('..\packages\LibSanBag.1.4.4\build\LibSanBag.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibSanBag.1.4.4\build\LibSanBag.props'))" />
<Error Condition="!Exists('..\packages\LibSanBag.1.5.0\build\LibSanBag.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibSanBag.1.5.0\build\LibSanBag.props'))" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion AtlasView/Models/AtlasResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Meta
public int Page { get; set; }
public int PerPage { get; set; }
public int Total { get; set; }
public int TotalPages { get; set; }
public int Pages { get; set; }
}

public class Datum
Expand Down
41 changes: 26 additions & 15 deletions AtlasView/ViewModels/AtlasViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using LibSanBag;
Expand Down Expand Up @@ -163,8 +164,11 @@ private async void OnSelectedItemChanged()
CurrentAtlasView.DataContext = loadingViewModel;

var progress = new Progress<ProgressEventArgs>(args => {
loadingViewModel.BytesDownloaded = args.Downloaded;
loadingViewModel.TotalBytes = args.Total;
loadingViewModel.BytesDownloaded = args.BytesDownloaded;
loadingViewModel.CurrentResourceIndex = args.CurrentResourceIndex;
loadingViewModel.TotalResources = args.TotalResources;
loadingViewModel.Status = args.Status;
loadingViewModel.TotalBytes = args.TotalBytes;
loadingViewModel.DownloadUrl = args.Resource;
});

Expand All @@ -185,11 +189,11 @@ private async void OnSelectedItemChanged()
viewModel.InitFromStream(manifestStream);
}
}
catch (Exception e)
catch (Exception ex)
{
CurrentAtlasView = new ErrorView()
{
DataContext = new ErrorViewModel(e)
DataContext = new ErrorViewModel("Failed to select new item", ex)
};
}
}
Expand Down Expand Up @@ -218,15 +222,22 @@ public async void Search(string query, int page=1)
{
CurrentAtlasView = new LoadingView();

var perPage = 4;
var request = WebRequest.Create($"https://atlas.sansar.com/api/experiences?perPage={perPage}&q={query}&page={page}");
var response = await request.GetResponseAsync();
var loadingViewModel = new LoadingViewModel();
CurrentAtlasView.DataContext = loadingViewModel;

string responseJson;
using (var sr = new StreamReader(response.GetResponseStream()))
{
responseJson = sr.ReadToEnd();
}
var progress = new Progress<ProgressEventArgs>(args => {
loadingViewModel.BytesDownloaded = args.BytesDownloaded;
loadingViewModel.CurrentResourceIndex = args.CurrentResourceIndex;
loadingViewModel.TotalResources = args.TotalResources;
loadingViewModel.Status = args.Status;
loadingViewModel.TotalBytes = args.TotalBytes;
loadingViewModel.DownloadUrl = args.Resource;
});

var perPage = 4;
var client = new HttpClientProvider();
var responseBytes = await client.GetByteArrayAsync($"https://atlas.sansar.com/api/experiences?perPage={perPage}&q={query}&page={page}", progress);
var responseJson = Encoding.ASCII.GetString(responseBytes);

var results = JsonConvert.DeserializeObject<AtlasResponse>(responseJson);
var tempSearchResults = new List<ExperienceView>();
Expand All @@ -239,19 +250,19 @@ public async void Search(string query, int page=1)
}
SearchResults = tempSearchResults;

TotalPages = results.Meta.TotalPages;
TotalPages = results.Meta.Pages;
LastQuery = query;

_currentPage = page;
OnPropertyChanged(nameof(CurrentPage));

CurrentAtlasView = null;
}
catch (Exception e)
catch (Exception ex)
{
CurrentAtlasView = new ErrorView()
{
DataContext = new ErrorViewModel(e)
DataContext = new ErrorViewModel("Failed to search", ex)
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion AtlasView/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LibSanBag" version="1.4.4" targetFramework="net46" />
<package id="LibSanBag" version="1.5.0" targetFramework="net46" />
<package id="Newtonsoft.Json" version="11.0.1" targetFramework="net462" />
<package id="SanTools.LibCRN" version="1.0.7" targetFramework="net46" />
<package id="SanTools.LibFSB" version="1.0.0" targetFramework="net46" />
Expand Down
24 changes: 20 additions & 4 deletions CommonUI/CommonUI.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\LibSanBag.1.4.4\build\LibSanBag.props" Condition="Exists('..\packages\LibSanBag.1.4.4\build\LibSanBag.props')" />
<Import Project="..\packages\LibSanBag.1.5.0\build\LibSanBag.props" Condition="Exists('..\packages\LibSanBag.1.5.0\build\LibSanBag.props')" />
<Import Project="..\packages\SanTools.LibCRN.1.0.7\build\SanTools.LibCRN.props" Condition="Exists('..\packages\SanTools.LibCRN.1.0.7\build\SanTools.LibCRN.props')" />
<Import Project="..\packages\SanTools.LibUserPreferences.1.0.6\build\SanTools.LibUserPreferences.props" Condition="Exists('..\packages\SanTools.LibUserPreferences.1.0.6\build\SanTools.LibUserPreferences.props')" />
<Import Project="..\packages\SanTools.LibFSB.1.0.0\build\SanTools.LibFSB.props" Condition="Exists('..\packages\SanTools.LibFSB.1.0.0\build\SanTools.LibFSB.props')" />
Expand Down Expand Up @@ -44,8 +44,8 @@
<Reference Include="HelixToolkit.Wpf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=52aa3500039caf0d, processorArchitecture=MSIL">
<HintPath>..\packages\HelixToolkit.Wpf.1.0.0\lib\net45\HelixToolkit.Wpf.dll</HintPath>
</Reference>
<Reference Include="LibSanBag, Version=1.4.4.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\LibSanBag.1.4.4\lib\net46\LibSanBag.dll</HintPath>
<Reference Include="LibSanBag, Version=1.5.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\LibSanBag.1.5.0\lib\net46\LibSanBag.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down Expand Up @@ -88,6 +88,7 @@
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResourceUtils\Utils.cs" />
<Compile Include="ViewModels\ErrorViewModel.cs" />
<Compile Include="ViewModels\ExportViewModel.cs" />
<Compile Include="ViewModels\LoadingViewModel.cs" />
<Compile Include="ViewModels\ResourceViewModel.cs" />
Expand All @@ -97,12 +98,16 @@
<Compile Include="ViewModels\ResourceViewModels\ManifestResourceViewModel.cs" />
<Compile Include="ViewModels\ResourceViewModels\RawImageViewModel.cs" />
<Compile Include="ViewModels\ResourceViewModels\RawResourceViewModel.cs" />
<Compile Include="ViewModels\ResourceViewModels\ScriptResourceViewModel.cs" />
<Compile Include="ViewModels\ResourceViewModels\UserPreferencesViewModel.cs" />
<Compile Include="ViewModels\ResourceViewModels\ScriptMetadataResourceViewModel.cs" />
<Compile Include="ViewModels\ResourceViewModels\RawTextResourceViewModel.cs" />
<Compile Include="ViewModels\ResourceViewModels\ScriptSourceTextViewModel.cs" />
<Compile Include="ViewModels\ResourceViewModels\SoundResourceViewModel.cs" />
<Compile Include="ViewModels\ResourceViewModels\TextureResourceViewModel.cs" />
<Compile Include="Views\ErrorView.xaml.cs">
<DependentUpon>ErrorView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ExportView.xaml.cs">
<DependentUpon>ExportView.xaml</DependentUpon>
</Compile>
Expand All @@ -127,6 +132,9 @@
<Compile Include="Views\ResourceViews\RawResourceView.xaml.cs">
<DependentUpon>RawResourceView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ResourceViews\ScriptResourceView.xaml.cs">
<DependentUpon>ScriptResourceView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ResourceViews\UserPreferencesView.xaml.cs">
<DependentUpon>UserPreferencesView.xaml</DependentUpon>
</Compile>
Expand All @@ -147,6 +155,10 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Page Include="Views\ErrorView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\ExportView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -179,6 +191,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\ResourceViews\ScriptResourceView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ResourceViews\UserPreferencesView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -218,6 +234,6 @@
<Error Condition="!Exists('..\packages\SanTools.LibFSB.1.0.0\build\SanTools.LibFSB.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SanTools.LibFSB.1.0.0\build\SanTools.LibFSB.props'))" />
<Error Condition="!Exists('..\packages\SanTools.LibUserPreferences.1.0.6\build\SanTools.LibUserPreferences.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SanTools.LibUserPreferences.1.0.6\build\SanTools.LibUserPreferences.props'))" />
<Error Condition="!Exists('..\packages\SanTools.LibCRN.1.0.7\build\SanTools.LibCRN.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\SanTools.LibCRN.1.0.7\build\SanTools.LibCRN.props'))" />
<Error Condition="!Exists('..\packages\LibSanBag.1.4.4\build\LibSanBag.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibSanBag.1.4.4\build\LibSanBag.props'))" />
<Error Condition="!Exists('..\packages\LibSanBag.1.5.0\build\LibSanBag.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LibSanBag.1.5.0\build\LibSanBag.props'))" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace AtlasView.ViewModels
namespace CommonUI.ViewModels
{
class ErrorViewModel : INotifyPropertyChanged
public class ErrorViewModel : INotifyPropertyChanged
{
private string _errorMessage;
public string ErrorMessage
Expand All @@ -22,9 +22,9 @@ public ErrorViewModel()
ErrorMessage = "Error";
}

public ErrorViewModel(Exception ex)
public ErrorViewModel(string errorMessage, Exception ex)
{
ErrorMessage = ex.Message;
ErrorMessage = errorMessage + ": " + ex.Message;
}

public ErrorViewModel(string errorMessage)
Expand Down
75 changes: 71 additions & 4 deletions CommonUI/ViewModels/LoadingViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;
using LibSanBag.Providers;

namespace CommonUI.ViewModels
{
Expand All @@ -14,7 +16,7 @@ public string DownloadUrl
{
_downloadUrl = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ProgressText));
OnPropertyChanged(nameof(ProgressTextMinor));
}
}

Expand All @@ -26,7 +28,7 @@ public long BytesDownloaded
{
_bytesDownloaded = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ProgressText));
OnPropertyChanged(nameof(ProgressTextMinor));
}
}

Expand All @@ -38,16 +40,81 @@ public long TotalBytes
{
_totalBytes = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ProgressText));
OnPropertyChanged(nameof(ProgressTextMinor));
}
}

public string ProgressText => $"{BytesDownloaded} / {TotalBytes}";
private int _currentResourceIndex;
public int CurrentResourceIndex
{
get => _currentResourceIndex;
set
{
_currentResourceIndex = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ProgressTextMajor));
}
}

private int _totalResources;
public int TotalResources
{
get => _totalResources;
set
{
_totalResources = value;
OnPropertyChanged();
OnPropertyChanged(nameof(ProgressTextMajor));
}
}

private ProgressStatus _status;
public ProgressStatus Status
{
get => _status;
set
{
_status = value;
OnPropertyChanged();
OnPropertyChanged(nameof(StatusColor));
}
}

public Brush StatusColor
{
get
{
switch (Status)
{
case ProgressStatus.Idling:
return Brushes.Gray;
case ProgressStatus.Connecting:
return Brushes.White;
case ProgressStatus.Downloading:
case ProgressStatus.Commpleted:
return Brushes.PaleGreen;
default:
return Brushes.Red;
}
}
}

public string ProgressTextMajor
{
get
{
return $"{CurrentResourceIndex} / {TotalResources} Resources";
}
}

public string ProgressTextMinor => $"{BytesDownloaded} / {TotalBytes} Bytes";

public LoadingViewModel()
{
BytesDownloaded = 0;
TotalBytes = 1;
TotalResources = 1;
CurrentResourceIndex = 0;
DownloadUrl = "Waiting...";
}

Expand Down
Loading

0 comments on commit a5f3eb0

Please sign in to comment.