Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #394 from microsoft/saraclay-patch-1
Browse files Browse the repository at this point in the history
Create App.xaml
  • Loading branch information
saraclay authored Aug 16, 2019
2 parents 5703a52 + 2268b02 commit abbf7ce
Show file tree
Hide file tree
Showing 28 changed files with 1,273 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Samples/WeatherStationPowerBI/CS/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application
x:Class="WeatherStation.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WeatherStation"
RequestedTheme="Light">

</Application>
99 changes: 99 additions & 0 deletions Samples/WeatherStationPowerBI/CS/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Microsoft.IdentityModel.Clients.ActiveDirectory;

namespace WeatherStation
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{

Frame rootFrame = Window.Current.Content as Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();

rootFrame.NavigationFailed += OnNavigationFailed;

if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}

// Place the frame in the current Window
Window.Current.Content = rootFrame;
}

if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}

/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Samples/WeatherStationPowerBI/CS/Assets/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

24 changes: 24 additions & 0 deletions Samples/WeatherStationPowerBI/CS/IPBIClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace WeatherStation
{
struct AuthData
{
public string VerificationUrl;
public string UserCode;
}

interface IPBIClient
{
Task<AuthData> AcquireDeviceCodeAsync();
Task CompleteAuthentication();
Task ClearRowsAsync(string datasetName, string tableName);
Task ConnectAsync();
Task CreateDatasetAsync(string datasetName);
Task<PBIDatasets> GetAllDatasetsAsync();
Task<IEnumerable<Dataset>> GetDatasetsWithNameAsync(string name);
Task<string> PushDataToTableAsync<T>(Dataset dataset, string tableName, T data);
}
}
14 changes: 14 additions & 0 deletions Samples/WeatherStationPowerBI/CS/IWeatherDataProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WeatherStation
{
interface IWeatherDataProvider
{
double GetTemperature();
double GetHumidity();
}
}
83 changes: 83 additions & 0 deletions Samples/WeatherStationPowerBI/CS/JSONBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright Microsoft 2015

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace WeatherStation
{
public static class JSONBuilder
{
public static string ToJson(object obj)
{
StringBuilder jsonBuilder = new StringBuilder();

jsonBuilder.Append("{\"rows\":");
var json_value = JsonConvert.SerializeObject(obj, new JsonSerializerSettings());
jsonBuilder.Append(json_value);
jsonBuilder.Append("}");

return jsonBuilder.ToString();
}

public static string ToJsonSchema(object obj, string name)
{
StringBuilder jsonSchemaBuilder = new StringBuilder();
string typeName = string.Empty;

jsonSchemaBuilder.Append(string.Format("{0}\"name\": \"{1}\",\"tables\": [", "{", name));
jsonSchemaBuilder.Append(String.Format("{0}\"name\": \"{1}\", ", "{", obj.GetType().Name));
jsonSchemaBuilder.Append("\"columns\": [");

PropertyInfo[] properties = obj.GetType().GetProperties();

foreach (PropertyInfo p in properties)
{
string sPropertyTypeName = p.PropertyType.Name;
if (sPropertyTypeName.StartsWith("Nullable") && p.PropertyType.GenericTypeArguments != null && p.PropertyType.GenericTypeArguments.Length == 1)
sPropertyTypeName = p.PropertyType.GenericTypeArguments[0].Name;
switch (sPropertyTypeName)
{
case "Int32":
case "Int64":
typeName = "Int64";
break;
case "Double":
typeName = "Double";
break;
case "Boolean":
typeName = "bool";
break;
case "DateTime":
typeName = "DateTime";
break;
case "DateTimeOffset":
typeName = "DateTimeOffset";
break;
case "String":
typeName = "string";
break;
default:
typeName = null;
break;
}

if (typeName == null)
throw new Exception("type not supported");

jsonSchemaBuilder.Append(string.Format("{0} \"name\": \"{1}\", \"dataType\": \"{2}\"{3},", "{", p.Name, typeName, "}"));
}

jsonSchemaBuilder.Remove(jsonSchemaBuilder.ToString().Length - 1, 1);
jsonSchemaBuilder.Append("]}]}");

return jsonSchemaBuilder.ToString();
}
}
}
37 changes: 37 additions & 0 deletions Samples/WeatherStationPowerBI/CS/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Page
x:Class="WeatherStation.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WeatherStation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="Black" RequestedTheme="Dark">
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="70" />
<RowDefinition Height="70" />
<RowDefinition Height="*" />
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="300" />
<ColumnDefinition Width="300" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="1" Grid.Row="1" FontFamily="Segoe UI" FontSize="48" Text="Temperature:" VerticalAlignment="Center" Height="70"/>
<TextBlock Grid.Column="1" Grid.Row="2" FontFamily="Segoe UI" FontSize="48" Text="Humidity:" VerticalAlignment="Center" Height="70"/>
<TextBlock Grid.Column="2" Grid.Row="1" x:Name="tempValue" FontFamily="Segoe UI" FontSize="48" Text="0" VerticalAlignment="Center" Height="70"/>
<TextBlock Grid.Column="2" Grid.Row="2" x:Name="humValue" FontFamily="Segoe UI" FontSize="48" Text="0" VerticalAlignment="Center" Height="70"/>

<TextBox Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="3" x:Name="passcode" FontFamily="Segoe UI" Text="" Height="35" IsReadOnly="True" FontSize="18.667"/>
<TextBlock Grid.Column="1" Grid.Row="4" Grid.ColumnSpan="2" x:Name="statusValue" FontFamily="Segoe UI" FontSize="18.667" Text="Started" Height="35" />
<TextBlock Grid.Column="3" Grid.Row="4" x:Name="ipAddress" FontFamily="Segoe UI" FontSize="18.667" Text="IP:" Height="35"/>
<Button Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="1" x:Name="resetButton" Content="Reset" HorizontalAlignment="Left" VerticalAlignment="Top" ToolTipService.ToolTip="Click to reset data" Height="35" Width="300" FontSize="18" Margin="0,10,0,0" Opacity="0.75" Click="resetButton_Click"/>

</Grid>
</Page>
Loading

0 comments on commit abbf7ce

Please sign in to comment.