This commit is contained in:
Javier Suárez Ruiz 2016-03-25 21:09:17 +01:00
Родитель dee2136d28
Коммит cd6956db85
28 изменённых файлов: 15721 добавлений и 0 удалений

Двоичные данные
Advertising/.vs/Advertising/v14/.suo Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,40 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Advertising", "Advertising\Advertising.csproj", "{E6B2A981-9EF6-4400-9B4A-83E421D325EE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM = Release|ARM
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Debug|ARM.ActiveCfg = Debug|ARM
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Debug|ARM.Build.0 = Debug|ARM
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Debug|ARM.Deploy.0 = Debug|ARM
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Debug|x64.ActiveCfg = Debug|x64
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Debug|x64.Build.0 = Debug|x64
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Debug|x64.Deploy.0 = Debug|x64
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Debug|x86.ActiveCfg = Debug|x86
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Debug|x86.Build.0 = Debug|x86
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Debug|x86.Deploy.0 = Debug|x86
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Release|ARM.ActiveCfg = Release|ARM
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Release|ARM.Build.0 = Release|ARM
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Release|ARM.Deploy.0 = Release|ARM
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Release|x64.ActiveCfg = Release|x64
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Release|x64.Build.0 = Release|x64
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Release|x64.Deploy.0 = Release|x64
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Release|x86.ActiveCfg = Release|x86
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Release|x86.Build.0 = Release|x86
{E6B2A981-9EF6-4400-9B4A-83E421D325EE}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,158 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{E6B2A981-9EF6-4400-9B4A-83E421D325EE}</ProjectGuid>
<OutputType>AppContainerExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Advertising</RootNamespace>
<AssemblyName>Advertising</AssemblyName>
<DefaultLanguage>es-ES</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.10586.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<PackageCertificateKeyFile>Advertising_TemporaryKey.pfx</PackageCertificateKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\Dialog\DialogService.cs" />
<Compile Include="Services\Dialog\IDialogService.cs" />
<Compile Include="ViewModels\Base\DelegateCommand.cs" />
<Compile Include="ViewModels\Base\DelegateCommandAsync.cs" />
<Compile Include="ViewModels\Base\ViewModelBase.cs" />
<Compile Include="ViewModels\Base\ViewModelLocator.cs" />
<Compile Include="ViewModels\MainViewModel.cs" />
<Compile Include="Views\Base\PageBase.cs" />
<Compile Include="Views\MainView.xaml.cs">
<DependentUpon>MainView.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
<None Include="Advertising_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\Square150x150Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<SDKReference Include="Microsoft.Advertising.Xaml, Version=10.0">
<Name>Microsoft Advertising SDK for XAML</Name>
</SDKReference>
<SDKReference Include="Microsoft.VCLibs, Version=14.0">
<Name>Visual C++ 2015 Runtime for Universal Windows Platform Apps</Name>
</SDKReference>
</ItemGroup>
<ItemGroup>
<Page Include="Views\MainView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.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>

Двоичные данные
Advertising/Advertising/Advertising_TemporaryKey.pfx Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,16 @@
<Application
x:Class="Advertising.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Advertising"
xmlns:locator="using:Advertising.ViewModels.Base"
RequestedTheme="Light">
<Application.Resources>
<ResourceDictionary>
<!-- ViewModelLocator -->
<locator:ViewModelLocator x:Key="Locator" />
</ResourceDictionary>
</Application.Resources>
</Application>

Просмотреть файл

@ -0,0 +1,96 @@
using Advertising.Views;
using System;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace Advertising
{
/// <summary>
/// Proporciona un comportamiento específico de la aplicación para complementar la clase Application predeterminada.
/// </summary>
sealed partial class App : Application
{
/// <summary>
/// Inicializa el objeto de aplicación Singleton. Esta es la primera línea de código creado
/// ejecutado y, como tal, es el equivalente lógico de main() o WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}
/// <summary>
/// Se invoca cuando el usuario final inicia la aplicación normalmente. Se usarán otros puntos
/// de entrada cuando la aplicación se inicie para abrir un archivo específico, por ejemplo.
/// </summary>
/// <param name="e">Información detallada acerca de la solicitud y el proceso de inicio.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif
Frame rootFrame = Window.Current.Content as Frame;
// No repetir la inicialización de la aplicación si la ventana tiene contenido todavía,
// solo asegurarse de que la ventana está activa.
if (rootFrame == null)
{
// Crear un marco para que actúe como contexto de navegación y navegar a la primera página.
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Cargar el estado de la aplicación suspendida previamente
}
// Poner el marco en la ventana actual.
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// Cuando no se restaura la pila de navegación, navegar a la primera página,
// configurando la nueva página pasándole la información requerida como
//parámetro de navegación
rootFrame.Navigate(typeof(MainView), e.Arguments);
}
// Asegurarse de que la ventana actual está activa.
Window.Current.Activate();
}
/// <summary>
/// Se invoca cuando la aplicación la inicia normalmente el usuario final. Se usarán otros puntos
/// </summary>
/// <param name="sender">Marco que produjo el error de navegación</param>
/// <param name="e">Detalles sobre el error de navegación</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
/// <summary>
/// Se invoca al suspender la ejecución de la aplicación. El estado de la aplicación se guarda
/// sin saber si la aplicación se terminará o se reanudará con el contenido
/// de la memoria aún intacto.
/// </summary>
/// <param name="sender">Origen de la solicitud de suspensión.</param>
/// <param name="e">Detalles sobre la solicitud de suspensión.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Guardar el estado de la aplicación y detener toda actividad en segundo plano
deferral.Complete();
}
}
}

Двоичные данные
Advertising/Advertising/Assets/LockScreenLogo.scale-200.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичные данные
Advertising/Advertising/Assets/SplashScreen.scale-200.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.5 KiB

Двоичные данные
Advertising/Advertising/Assets/Square150x150Logo.scale-200.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.9 KiB

Двоичные данные
Advertising/Advertising/Assets/Square44x44Logo.scale-200.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.6 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.2 KiB

Двоичные данные
Advertising/Advertising/Assets/StoreLogo.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.4 KiB

Двоичные данные
Advertising/Advertising/Assets/Wide310x150Logo.scale-200.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 3.1 KiB

Просмотреть файл

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
IgnorableNamespaces="uap mp">
<Identity
Name="fd9d106b-3fd7-4fce-8c49-87e2ce449c64"
Publisher="CN=javie"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="fd9d106b-3fd7-4fce-8c49-87e2ce449c64" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>Advertising</DisplayName>
<PublisherDisplayName>javie</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="Advertising.App">
<uap:VisualElements
DisplayName="Advertising"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
Description="Advertising"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
</Package>

Просмотреть файл

@ -0,0 +1,29 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 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("Advertising")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Advertising")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 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")]
[assembly: ComVisible(false)]

Просмотреть файл

@ -0,0 +1,30 @@
<!--
This file contains Runtime Directives used by .NET Native. The defaults here are suitable for most
developers. However, you can modify these parameters to modify the behavior of the .NET Native
optimizer.
Runtime Directives are documented at http://go.microsoft.com/fwlink/?LinkID=391919
To fully enable reflection for App1.MyClass and all of its public/private members
<Type Name="App1.MyClass" Dynamic="Required All"/>
To enable dynamic creation of the specific instantiation of AppClass<T> over System.Int32
<TypeInstantiation Name="App1.AppClass" Arguments="System.Int32" Activate="Required Public" />
Using the Namespace directive to apply reflection policy to all the types in a particular namespace
<Namespace Name="DataClasses.ViewModels" Seralize="All" />
-->
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<!--
An Assembly element with Name="*Application*" applies to all assemblies in
the application package. The asterisks are not wildcards.
-->
<Assembly Name="*Application*" Dynamic="Required All"/>
<!-- Add your application specific runtime directives here. -->
</Application>
</Directives>

Просмотреть файл

@ -0,0 +1,15 @@
using System;
using System.Threading.Tasks;
using Windows.UI.Popups;
namespace Advertising.Services.Dialog
{
public class DialogService : IDialogService
{
public async Task ShowAsync(string message)
{
var messageDialog = new MessageDialog(message);
await messageDialog.ShowAsync();
}
}
}

Просмотреть файл

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace Advertising.Services.Dialog
{
public interface IDialogService
{
Task ShowAsync(string message);
}
}

Просмотреть файл

@ -0,0 +1,131 @@
namespace Advertising.ViewModels.Base
{
using System;
using System.Windows.Input;
/// <summary>
/// This class allows us to delegate command execution to viewmodels.
/// </summary>
public class DelegateCommand : ICommand
{
private readonly Action _execute;
private readonly Func<bool> _canExecute;
/// <summary>
/// Constructor not using canExecute.
/// </summary>
/// <param name="execute"></param>
public DelegateCommand(Action execute) : this(execute, null) { }
/// <summary>
/// Constructor using both execute and canExecute.
/// </summary>
/// <param name="execute"></param>
/// <param name="canExecute"></param>
public DelegateCommand(Action execute, Func<bool> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
/// <summary>
/// This method is called from XAML to evaluate if the command can be executed.
/// </summary>
/// <param name="parameter"></param>
/// <returns></returns>
public bool CanExecute(object parameter)
{
if (_canExecute != null)
return _canExecute();
return true;
}
/// <summary>
/// This method is called from XAML to execute the command.
/// </summary>
/// <param name="parameter"></param>
public void Execute(object parameter)
{
_execute();
}
/// <summary>
/// This method allow us to force the execution of CanExecute method to reevaluate execution.
/// </summary>
public void RaiseCanExecuteChanged()
{
var tmpHandle = CanExecuteChanged;
if (tmpHandle != null)
tmpHandle(this, new EventArgs());
}
/// <summary>
/// This event notify XAML controls using the command to reevaluate the CanExecute of it.
/// </summary>
public event EventHandler CanExecuteChanged;
}
/// <summary>
/// This class allows us to delegate command execution to viewmodels using a T type as parameter.
/// </summary>
public class DelegateCommand<T> : ICommand
{
private readonly Action<T> _execute;
private readonly Func<T, bool> _canExecute;
/// <summary>
/// Constructor not using canExecute.
/// </summary>
/// <param name="execute"></param>
public DelegateCommand(Action<T> execute) : this(execute, null) { }
/// <summary>
/// Constructor using both execute and canExecute.
/// </summary>
/// <param name="execute"></param>
/// <param name="canExecute"></param>
public DelegateCommand(Action<T> execute, Func<T, bool> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
/// <summary>
/// This method is called from XAML to evaluate if the command can be executed.
/// </summary>
/// <param name="parameter"></param>
/// <returns></returns>
public bool CanExecute(object parameter)
{
if (_canExecute != null)
return _canExecute((T)parameter);
return true;
}
/// <summary>
/// This method is called from XAML to execute the command.
/// </summary>
/// <param name="parameter"></param>
public void Execute(object parameter)
{
_execute((T)parameter);
}
/// <summary>
/// This method allow us to force the execution of CanExecute method to reevaluate execution.
/// </summary>
public void RaiseCanExecuteChanged()
{
var tmpHandle = CanExecuteChanged;
if (tmpHandle != null)
tmpHandle(this, new EventArgs());
}
/// <summary>
/// This event notify XAML controls using the command to reevaluate the CanExecute of it.
/// </summary>
public event EventHandler CanExecuteChanged;
}
}

Просмотреть файл

@ -0,0 +1,137 @@
namespace Advertising.ViewModels.Base
{
using System;
using System.Threading.Tasks;
using System.Windows.Input;
/// <summary>
/// This class allows us to delegate command execution to viewmodels.
/// This version of the command allow to use async/await.
/// </summary>
public class DelegateCommandAsync : ICommand
{
private readonly Func<Task<bool>> _canExecute;
private readonly Func<Task> _execute;
/// <summary>
/// Constructor not using canExecute.
/// </summary>
/// <param name="execute"></param>
public DelegateCommandAsync(Func<Task> execute) : this(execute, null)
{
}
/// <summary>
/// Constructor using both execute and canExecute.
/// </summary>
/// <param name="execute"></param>
/// <param name="canExecute"></param>
public DelegateCommandAsync(Func<Task> execute, Func<Task<bool>> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
/// <summary>
/// This method is called from XAML to evaluate if the command can be executed.
/// </summary>
/// <param name="parameter"></param>
/// <returns></returns>
public bool CanExecute(object parameter)
{
if (_canExecute != null)
return _canExecute().Result;
return true;
}
/// <summary>
/// This method is called from XAML to execute the command.
/// </summary>
/// <param name="parameter"></param>
public void Execute(object parameter)
{
_execute();
}
/// <summary>
/// This event notify XAML controls using the command to reevaluate the CanExecute of it.
/// </summary>
public event EventHandler CanExecuteChanged;
/// <summary>
/// This method allow us to force the execution of CanExecute method to reevaluate execution.
/// </summary>
public void RaiseCanExecuteChanged()
{
EventHandler tmpHandle = CanExecuteChanged;
if (tmpHandle != null)
tmpHandle(this, new EventArgs());
}
}
/// <summary>
/// This class allows us to delegate command execution to viewmodels using a T type as parameter.
/// </summary>
public class DelegateCommandAsync<T> : ICommand
{
private readonly Func<T, Task<bool>> _canExecute;
private readonly Func<T, Task> _execute;
/// <summary>
/// Constructor not using canExecute.
/// </summary>
/// <param name="execute"></param>
public DelegateCommandAsync(Func<T, Task> execute) : this(execute, null)
{
}
/// <summary>
/// Constructor using both execute and canExecute.
/// </summary>
/// <param name="execute"></param>
/// <param name="canExecute"></param>
public DelegateCommandAsync(Func<T, Task> execute, Func<T, Task<bool>> canExecute)
{
_execute = execute;
_canExecute = canExecute;
}
/// <summary>
/// This method is called from XAML to evaluate if the command can be executed.
/// </summary>
/// <param name="parameter"></param>
/// <returns></returns>
public bool CanExecute(object parameter)
{
if (_canExecute != null)
return _canExecute((T) parameter).Result;
return true;
}
/// <summary>
/// This method is called from XAML to execute the command.
/// </summary>
/// <param name="parameter"></param>
public void Execute(object parameter)
{
_execute((T) parameter);
}
/// <summary>
/// This event notify XAML controls using the command to reevaluate the CanExecute of it.
/// </summary>
public event EventHandler CanExecuteChanged;
/// <summary>
/// This method allow us to force the execution of CanExecute method to reevaluate execution.
/// </summary>
public void RaiseCanExecuteChanged()
{
EventHandler tmpHandle = CanExecuteChanged;
if (tmpHandle != null)
tmpHandle(this, new EventArgs());
}
}
}

Просмотреть файл

@ -0,0 +1,36 @@
namespace Advertising.ViewModels.Base
{
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
public abstract class ViewModelBase : INotifyPropertyChanged
{
private Frame appFrame;
public Frame AppFrame
{
get { return appFrame; }
}
public event PropertyChangedEventHandler PropertyChanged;
public abstract Task OnNavigatedFrom(NavigationEventArgs args);
public abstract Task OnNavigatedTo(NavigationEventArgs args);
public void RaisePropertyChanged([CallerMemberName]string propertyName = "")
{
var Handler = PropertyChanged;
if (Handler != null)
Handler(this, new PropertyChangedEventArgs(propertyName));
}
internal void SetAppFrame(Frame viewFrame)
{
appFrame = viewFrame;
}
}
}

Просмотреть файл

@ -0,0 +1,25 @@
namespace Advertising.ViewModels.Base
{
using Microsoft.Practices.Unity;
using Services.Dialog;
public class ViewModelLocator
{
readonly IUnityContainer _container;
public ViewModelLocator()
{
_container = new UnityContainer();
// ViewModels
_container.RegisterType<MainViewModel>();
// Services
_container.RegisterType<IDialogService, DialogService>(new ContainerControlledLifetimeManager());
}
public MainViewModel MainViewModel
{
get { return _container.Resolve<MainViewModel>(); }
}
}
}

Просмотреть файл

@ -0,0 +1,104 @@
using System.Threading.Tasks;
using Advertising.ViewModels.Base;
using Windows.UI.Xaml.Navigation;
using System.Windows.Input;
using Microsoft.Advertising.WinRT.UI;
using Advertising.Services.Dialog;
namespace Advertising.ViewModels
{
public class MainViewModel : ViewModelBase
{
private string _applicationId;
private string _videoIntersticialId;
private InterstitialAd _interstitialAd;
private ICommand _videoIntersticialCommand;
private IDialogService _dialogService;
public MainViewModel(IDialogService dialogService)
{
_dialogService = dialogService;
// Instantiate the interstitial video ad
_interstitialAd = new InterstitialAd();
// Attach event handlers
_interstitialAd.ErrorOccurred += OnAdError;
_interstitialAd.AdReady += OnAdReady;
_interstitialAd.Cancelled += OnAdCancelled;
_interstitialAd.Completed += OnAdCompleted;
}
public string ApplicationId
{
get { return _applicationId; }
set
{
_applicationId = value;
RaisePropertyChanged();
}
}
public string VideoIntersticialId
{
get { return _videoIntersticialId; }
set
{
_videoIntersticialId = value;
RaisePropertyChanged();
}
}
public ICommand VideoIntersticialCommand
{
get { return _videoIntersticialCommand = _videoIntersticialCommand ?? new DelegateCommand(VideoIntersticialCommandExecute); }
}
public override Task OnNavigatedFrom(NavigationEventArgs args)
{
return null;
}
public override Task OnNavigatedTo(NavigationEventArgs args)
{
SetAdsConf();
return null;
}
private void SetAdsConf()
{
ApplicationId = "d25517cb-12d4-4699-8bdc-52040c712cab";
VideoIntersticialId = "11389925";
}
private void VideoIntersticialCommandExecute()
{
_interstitialAd.RequestAd(AdType.Video,
ApplicationId,
VideoIntersticialId);
}
private void OnAdReady(object sender, object e)
{
_interstitialAd.Show();
}
private async void OnAdCancelled(object sender, object e)
{
await _dialogService.ShowAsync("Ad cancelled");
}
private async void OnAdCompleted(object sender, object e)
{
await _dialogService.ShowAsync("Ad completed");
}
private async void OnAdError(object sender, AdErrorEventArgs e)
{
await _dialogService.ShowAsync($"An error occurred. {e.ErrorCode}: {e.ErrorMessage}");
}
}
}

Просмотреть файл

@ -0,0 +1,26 @@
namespace Advertising.Views.Base
{
using ViewModels.Base;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
public class PageBase : Page
{
private ViewModelBase _vm;
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
_vm = (ViewModelBase)DataContext;
_vm.SetAppFrame(Frame);
_vm.OnNavigatedTo(e);
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
_vm.OnNavigatedFrom(e);
}
}
}

Просмотреть файл

@ -0,0 +1,27 @@
<base:PageBase
x:Class="Advertising.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Advertising.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:base="using:Advertising.Views.Base"
xmlns:ads="using:Microsoft.Advertising.WinRT.UI"
mc:Ignorable="d"
DataContext="{Binding MainViewModel, Source={StaticResource Locator}}">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button
Content="Video intersticial Ad"
Command="{Binding VideoIntersticialCommand}"
HorizontalAlignment="Center"
Margin="12"/>
<!--
Set the application id and ad unit id via markup.
More information at https://msdn.microsoft.com/en-us/library/windows/apps/mt170658.aspx
-->
<ads:AdControl
ApplicationId="d25517cb-12d4-4699-8bdc-52040c712cab"
AdUnitId="10043121"
Width="300" Height="250"/>
</StackPanel>
</base:PageBase>

Просмотреть файл

@ -0,0 +1,12 @@
using Advertising.Views.Base;
namespace Advertising.Views
{
public sealed partial class MainView : PageBase
{
public MainView()
{
this.InitializeComponent();
}
}
}

Просмотреть файл

@ -0,0 +1,17 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0",
"Unity": "4.0.1"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу