Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Screen Shot 2020-01-05 at 11.20.17 PM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screen Shot 2020-01-05 at 11.21.41 PM.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override Task ProcessHttpRequestAsync(HttpRequestMessage request, Cancell
{
if (request == null)
{
throw new ArgumentNullException("request");
throw new ArgumentNullException(nameof(request));
}
request.Headers.Add("Ocp-Apim-Subscription-Key", this.apiKey);
return base.ProcessHttpRequestAsync(request, cancellationToken);
Expand Down
3 changes: 1 addition & 2 deletions src/Functions/SantaTalk.Functions/SantaTalk.Functions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions src/Functions/SantaTalk.Functions/SantaTalk.Functions.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SantaTalk.Functions", "SantaTalk.Functions.csproj", "{8B1596A8-6091-4F56-8CC1-181879196AF1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SantaTalk.Models", "..\SantaTalk.Models\SantaTalk.Models.csproj", "{4F60AC05-3995-43B7-827F-A47DC2764D6A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8B1596A8-6091-4F56-8CC1-181879196AF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B1596A8-6091-4F56-8CC1-181879196AF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B1596A8-6091-4F56-8CC1-181879196AF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B1596A8-6091-4F56-8CC1-181879196AF1}.Release|Any CPU.Build.0 = Release|Any CPU
{4F60AC05-3995-43B7-827F-A47DC2764D6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F60AC05-3995-43B7-827F-A47DC2764D6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F60AC05-3995-43B7-827F-A47DC2764D6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F60AC05-3995-43B7-827F-A47DC2764D6A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
8 changes: 3 additions & 5 deletions src/Functions/SantaTalk.Functions/WriteSanta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ namespace SantaTalk.Functions
{
public static class WriteSanta
{
static TextAnalyticsClient textClient;

static readonly TextAnalyticsClient textClient;
static WriteSanta()
{
var keys = new ApiKeyServiceClientCredentials(Environment.GetEnvironmentVariable("APIKey"));

textClient = new TextAnalyticsClient(keys) { Endpoint = Environment.GetEnvironmentVariable("APIEndpoint") };
var credentials = new ApiKeyServiceClientCredentials(Environment.GetEnvironmentVariable("APIKey"));
textClient = new TextAnalyticsClient(credentials) { Endpoint = Environment.GetEnvironmentVariable("APIEndpoint") };
}

[FunctionName("WriteSanta")]
Expand Down
10 changes: 10 additions & 0 deletions src/Functions/SantaTalk.Functions/local.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"IsEncrypted": false,
"Values": {
"API_HOST": "https://configuredOnAzure.azurewebsites.net",
"END_POINT": "registers",
"APIKey": "6cf27ec5e0604d5b967fdb997f476443",
"APIEndpoint": "https://westcentralus.api.cognitive.microsoft.com/",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
4 changes: 2 additions & 2 deletions src/SantaTalk.Android/SantaTalk.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991265" />
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991477" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
<PackageReference Include="Xamarin.FFImageLoading.Forms">
<Version>2.4.11.982</Version>
Expand All @@ -64,7 +64,7 @@
<Version>1.1.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms.PancakeView">
<Version>1.3.6</Version>
<Version>1.3.7</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
Expand Down
4 changes: 2 additions & 2 deletions src/SantaTalk.iOS/SantaTalk.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991265" />
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991477" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
<PackageReference Include="Xamarin.FFImageLoading.Forms">
<Version>2.4.11.982</Version>
Expand All @@ -131,7 +131,7 @@
<Version>1.3.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms.PancakeView">
<Version>1.3.6</Version>
<Version>1.3.7</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms.StateSquid">
<Version>1.1.3</Version>
Expand Down
2 changes: 1 addition & 1 deletion src/SantaTalk/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<Color x:Key="entry_background">#190336</Color>
<Color x:Key="normal_text">#ffffff</Color>
<Color x:Key="white">#ffffff</Color>

<Color x:Key="shell_background">#301536</Color>
<!-- Controls -->
<Style TargetType="{x:Type StackLayout}">
<Setter Property="Spacing" Value="0" />
Expand Down
10 changes: 1 addition & 9 deletions src/SantaTalk/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace SantaTalk
{
Expand All @@ -9,14 +8,7 @@ public partial class App : Application
public App()
{
InitializeComponent();

var navPage = new NavigationPage(new MainPage())
{
BarBackgroundColor = Color.FromHex("#301536"),
BarTextColor = Color.Wheat
};

MainPage = navPage;
MainPage = new AppShell();
}

protected override void OnStart()
Expand Down
14 changes: 14 additions & 0 deletions src/SantaTalk/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:SantaTalk.Views"
Shell.FlyoutBehavior="Disabled"
Shell.TitleColor="Wheat"
Shell.BackgroundColor="{StaticResource shell_background}"
x:Class="SantaTalk.AppShell">

<ShellContent Route="home"
Title="Home"
ContentTemplate="{DataTemplate views:MainPage}">
</ShellContent>
</Shell>
14 changes: 14 additions & 0 deletions src/SantaTalk/AppShell.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;

namespace SantaTalk
{
public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
}
5 changes: 3 additions & 2 deletions src/SantaTalk/SantaTalk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991265" />
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991477" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
<PackageReference Include="Xamarin.FFImageLoading.Forms" Version="2.4.11.982" />
<PackageReference Include="Refractored.MvvmHelpers" Version="1.3.0" />
<PackageReference Include="Xamarin.Forms.PancakeView" Version="1.3.6" />
<PackageReference Include="Xamarin.Forms.PancakeView" Version="1.3.7" />
<PackageReference Include="Xamarin.Forms.StateSquid" Version="1.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
Expand All @@ -25,5 +25,6 @@
<ItemGroup>
<Folder Include="Services\" />
<Folder Include="ViewModels\" />
<Folder Include="Views\" />
</ItemGroup>
</Project>
9 changes: 4 additions & 5 deletions src/SantaTalk/Services/LetterDeliveryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ namespace SantaTalk
{
public class LetterDeliveryService
{
//string santaUrl = "{REPLACE WITH YOUR FUNCTION URL}/api/WriteSanta";

string santaUrl = "http://localhost:7071/api/WriteSanta";
static HttpClient httpClient = new HttpClient();
string santaUrl = "https://xamarinazureSantaTalk-kumar.azurewebsites.net/api/WriteSanta?code=xxxxxxxxxxx";
//string santaUrl = "http://localhost:7071/api/WriteSanta";

static readonly HttpClient httpClient = new HttpClient();
public async Task<SantaResults> WriteLetterToSanta(SantaLetter letter)
{
// if we're on the Android emulator, running functions locally, need to swap out the function url
Expand All @@ -22,7 +21,7 @@ public async Task<SantaResults> WriteLetterToSanta(SantaLetter letter)
santaUrl = "http://10.0.2.2:7071/api/WriteSanta";
}

SantaResults results = null;
SantaResults results;
try
{
var letterJson = JsonConvert.SerializeObject(letter);
Expand Down
36 changes: 31 additions & 5 deletions src/SantaTalk/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
using System;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using MvvmHelpers;
using SantaTalk.Views;
using Xamarin.Forms;

namespace SantaTalk
{
public class MainPageViewModel : BaseViewModel
{
public ICommand SendLetterCommand { get; private set; }

public MainPageViewModel()
{
SendLetterCommand = new Command(async () =>
{
await Application.Current.MainPage.Navigation.PushAsync(new ResultsPage(KidsName, LetterText));
});
SendLetterCommand = new Command(() =>
NavigateToResultPage().ConfigureAwait(false));
}

string kidsName;
Expand All @@ -29,6 +32,29 @@ public string LetterText
set => SetProperty(ref letterText, value);
}

public ICommand SendLetterCommand { get; }
async Task NavigateToResultPage()
{
var areFieldsValid = await AreFieldsValid(KidsName, LetterText);
if (!areFieldsValid)
return;

await Shell.Current.Navigation.PushAsync(new ResultsPage(KidsName, LetterText), true);
}

async Task<bool> AreFieldsValid(string name, string inputText)
{
var builder = new StringBuilder();

if (string.IsNullOrWhiteSpace(name))
builder.AppendLine("Please enter your name.");

else if (inputText.EndsWith("Dear Santa...", StringComparison.InvariantCultureIgnoreCase))
builder.AppendLine("Please write something...");

if (builder.Length != 0)
await Application.Current.MainPage.DisplayAlert("Invalid Field(s)", builder.ToString(), "Ok");

return builder.Length == 0;
}
}
}
34 changes: 21 additions & 13 deletions src/SantaTalk/ViewModels/ResultsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,31 @@ public async Task SendLetterToSanta()
LetterText = LetterText
};

var letterService = new LetterDeliveryService();
var results = await letterService.WriteLetterToSanta(letter);

if (results.SentimentScore == -1)
try
{
CurrentState = State.Error;
return;
}
var letterService = new LetterDeliveryService();
var results = await letterService.WriteLetterToSanta(letter);

if (results.SentimentScore.Equals(-1))
{
CurrentState = State.Error;
return;
}

var commentsService = new SantasCommentsService();
var comments = commentsService.MakeGiftDecision(results);
var commentsService = new SantasCommentsService();
var comments = commentsService.MakeGiftDecision(results);

SantasComment = comments.SentimentInterpretation;
GiftDecision = comments.GiftPrediction;
DetectedLanguage = results.DetectedLanguage;
SantasComment = comments.SentimentInterpretation;
GiftDecision = comments.GiftPrediction;
DetectedLanguage = results.DetectedLanguage;

CurrentState = State.Success;
CurrentState = State.Success;
}
catch(Exception ex)
{
currentState = State.Error;
Console.WriteLine(ex.Message);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
xmlns:controls="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
xmlns:viewmodels="clr-namespace:SantaTalk"
mc:Ignorable="d"
NavigationPage.HasNavigationBar="False"
NavigationPage.BackButtonTitle=""
mc:Ignorable="d"
ios:Page.UseSafeArea="True"
BackgroundColor="{StaticResource dark_gradient}"
x:Class="SantaTalk.MainPage">
BackgroundColor="{StaticResource dark_gradient}"
x:Class="SantaTalk.Views.MainPage">

<ContentPage.BindingContext>
<viewmodels:MainPageViewModel />
Expand Down
Loading