From ca3283077685ae7431d8468f79cfa6d1b12a6127 Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 16 Aug 2019 14:52:52 -0700 Subject: [PATCH 01/24] Create App.xaml --- Samples/WeatherStationPowerBI/CS/App.xaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Samples/WeatherStationPowerBI/CS/App.xaml diff --git a/Samples/WeatherStationPowerBI/CS/App.xaml b/Samples/WeatherStationPowerBI/CS/App.xaml new file mode 100644 index 000000000..5019d9c91 --- /dev/null +++ b/Samples/WeatherStationPowerBI/CS/App.xaml @@ -0,0 +1,8 @@ + + + From c3c6bcb6b9bbe89ef4eb53c134078b2632b7c473 Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 16 Aug 2019 14:53:27 -0700 Subject: [PATCH 02/24] Create App.xaml.cs --- Samples/WeatherStationPowerBI/CS/App.xaml.cs | 99 ++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Samples/WeatherStationPowerBI/CS/App.xaml.cs diff --git a/Samples/WeatherStationPowerBI/CS/App.xaml.cs b/Samples/WeatherStationPowerBI/CS/App.xaml.cs new file mode 100644 index 000000000..0899811de --- /dev/null +++ b/Samples/WeatherStationPowerBI/CS/App.xaml.cs @@ -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 +{ + /// + /// Provides application-specific behavior to supplement the default Application class. + /// + sealed partial class App : Application + { + /// + /// 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(). + /// + public App() + { + this.InitializeComponent(); + this.Suspending += OnSuspending; + } + + /// + /// 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. + /// + /// Details about the launch request and process. + 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(); + } + + /// + /// Invoked when Navigation to a certain page fails + /// + /// The Frame which failed navigation + /// Details about the navigation failure + void OnNavigationFailed(object sender, NavigationFailedEventArgs e) + { + throw new Exception("Failed to load Page " + e.SourcePageType.FullName); + } + + /// + /// 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. + /// + /// The source of the suspend request. + /// Details about the suspend request. + private void OnSuspending(object sender, SuspendingEventArgs e) + { + var deferral = e.SuspendingOperation.GetDeferral(); + //TODO: Save application state and stop any background activity + deferral.Complete(); + } + } +} From 2fc7670f34d5a13e65260f84dc20dca444e4568b Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 16 Aug 2019 14:53:43 -0700 Subject: [PATCH 03/24] Create IPBIClient.cs --- .../WeatherStationPowerBI/CS/IPBIClient.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Samples/WeatherStationPowerBI/CS/IPBIClient.cs diff --git a/Samples/WeatherStationPowerBI/CS/IPBIClient.cs b/Samples/WeatherStationPowerBI/CS/IPBIClient.cs new file mode 100644 index 000000000..29cacba1e --- /dev/null +++ b/Samples/WeatherStationPowerBI/CS/IPBIClient.cs @@ -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 AcquireDeviceCodeAsync(); + Task CompleteAuthentication(); + Task ClearRowsAsync(string datasetName, string tableName); + Task ConnectAsync(); + Task CreateDatasetAsync(string datasetName); + Task GetAllDatasetsAsync(); + Task> GetDatasetsWithNameAsync(string name); + Task PushDataToTableAsync(Dataset dataset, string tableName, T data); + } +} From 687ed375fc5ea2996c76c48ca4809539f8199e59 Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 16 Aug 2019 14:53:57 -0700 Subject: [PATCH 04/24] Create IWeatherDataProvider.cs --- .../CS/IWeatherDataProvider.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Samples/WeatherStationPowerBI/CS/IWeatherDataProvider.cs diff --git a/Samples/WeatherStationPowerBI/CS/IWeatherDataProvider.cs b/Samples/WeatherStationPowerBI/CS/IWeatherDataProvider.cs new file mode 100644 index 000000000..30f80582f --- /dev/null +++ b/Samples/WeatherStationPowerBI/CS/IWeatherDataProvider.cs @@ -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(); + } +} From 6268ea221a4601061c58b7bf9e96ed32d272f77a Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 16 Aug 2019 14:54:10 -0700 Subject: [PATCH 05/24] Create JSONBuilder.cs --- .../WeatherStationPowerBI/CS/JSONBuilder.cs | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Samples/WeatherStationPowerBI/CS/JSONBuilder.cs diff --git a/Samples/WeatherStationPowerBI/CS/JSONBuilder.cs b/Samples/WeatherStationPowerBI/CS/JSONBuilder.cs new file mode 100644 index 000000000..4600c8a6d --- /dev/null +++ b/Samples/WeatherStationPowerBI/CS/JSONBuilder.cs @@ -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(); + } + } +} From d7c22529ab692d6d24d3435e19e727c73ae9c6d7 Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 16 Aug 2019 14:54:50 -0700 Subject: [PATCH 06/24] Create MainPage.xaml --- .../WeatherStationPowerBI/CS/MainPage.xaml | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Samples/WeatherStationPowerBI/CS/MainPage.xaml diff --git a/Samples/WeatherStationPowerBI/CS/MainPage.xaml b/Samples/WeatherStationPowerBI/CS/MainPage.xaml new file mode 100644 index 000000000..b78e98248 --- /dev/null +++ b/Samples/WeatherStationPowerBI/CS/MainPage.xaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +