Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge #18

Merged
merged 24 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
connect to graph
  • Loading branch information
tajbender committed Mar 15, 2023
commit 14ff2ee2070b3734718139f1f884534bf79daa89
11 changes: 6 additions & 5 deletions src/electrifier/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public App()
ConfigureServices((context, services) =>
{
// Default Activation Handler
Debug.Assert(services != null, nameof(services) + " != null");
_ = services.AddTransient<ActivationHandler<LaunchActivatedEventArgs>, DefaultActivationHandler>();

// Other Activation Handlers
Expand Down Expand Up @@ -113,7 +114,7 @@ public App()
GetService<IAppNotificationService>()?
.Initialize();

UnhandledException += App_UnhandledException;
// UnhandledException += App_UnhandledException;
}

//private void App_StartAppCenter()
Expand All @@ -122,10 +123,10 @@ public App()
//}


private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs args)
{
App_UnhandledException(sender, args, false);
}
// private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs args)
// {
// App_UnhandledException(sender, args, false);
// }

/// <summary>
/// Log and handle exceptions as appropriate.
Expand Down
1 change: 1 addition & 0 deletions src/electrifier/Views/ShellPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
Header="{x:Bind ((ContentControl)ViewModel.Selected).Content, Mode=OneWay}"
IsBackButtonVisible="Visible"
IsBackEnabled="{x:Bind ViewModel.IsBackEnabled, Mode=OneWay}"
IsPaneOpen="False"
IsSettingsVisible="True"
PaneTitle="{x:Bind ViewModel.NavigationService.PaneDisplayTitle, Mode=OneWay}"
SelectedItem="{x:Bind ViewModel.Selected, Mode=OneWay}"
Expand Down
2 changes: 1 addition & 1 deletion src/electrifier/Views/ShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ShellPage(ShellViewModel viewModel)
App.MainWindow.Activated += MainWindow_Activated;

AppTitleBarText.Text = ResourceExtensions.GetLocalized("AppDisplayName");
ThisComputerName = StringExtensions.GetLocalized($"This PC: {GetThisComputerName()}"); // TODO: i18n
ThisComputerName = $"This PC: {GetThisComputerName()}"; // TODO: i18n
}

private void OnLoaded(object sender, RoutedEventArgs e)
Expand Down
45 changes: 32 additions & 13 deletions src/electrifier/Views/WorkbenchPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,42 @@
Width="Auto" />
<ColumnDefinition
Width="*" />
<ColumnDefinition
Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>

<StackPanel
Grid.Column="0">
<Button>tajbender@hotmail.de</Button>
<Button>taj@electrifier.org</Button>
<Button>MSFT</Button>
</StackPanel>
<TextBlock
Grid.Column="1">
tajbender
</TextBlock>
<PersonPicture
x:Name="PersonPicture"
Grid.Column="2" />
Grid.Column="0"
Grid.Row="0" />
<TextBlock
Grid.Column="0"
Grid.Row="1">
Not Connected
</TextBlock>

<StackPanel
Grid.Column="1"
Grid.Row="0"
Grid.RowSpan="2"
Orientation="Vertical">
<Button
Click="ButtonTajbenderHotmail_OnClickAsync">
Login tajbender@hotmail.de
</Button>
<Button
Click="ButtonTajElectrifier_OnClick">
Login taj@electrifier.org
</Button>
<Button
Click="ButtonMSFTDummy_OnClick">
Login MSFT Dummy
</Button>
</StackPanel>
</Grid>
</StackPanel>
</Grid>
Expand Down
114 changes: 113 additions & 1 deletion src/electrifier/Views/WorkbenchPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
using electrifier.ViewModels;
using System.Reflection.Metadata;
using electrifier.ViewModels;
using Microsoft.UI.Xaml.Controls;
using System.Text;
using Windows.ApplicationModel.Resources;
using Microsoft.UI.Xaml;
using Microsoft.Identity.Client;
using CommunityToolkit.Authentication;
using Microsoft.Graph;
using Azure.Identity;

namespace electrifier.Views;

Expand Down Expand Up @@ -32,4 +39,109 @@ public WorkbenchPage()
//var manager = await graphClient.Me.Manager.GetAsync();

}

private void ButtonTajbenderHotmail_OnClickAsync(object sender, RoutedEventArgs args)
{
var scopes = new[] { "User.Read" };

// Multi-tenant apps can use "common", single-tenant apps must use the tenant ID from the Azure portal
var tenantId = "common";

// Value from app registration
var clientId = "67501219-8281-4e6f-8348-aad08088c13b";

var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};

var userName = "tajbender@hotmail.de";
var password = string.Empty;

// https://learn.microsoft.com/dotnet/api/azure.identity.usernamepasswordcredential
var userNamePasswordCredential = new UsernamePasswordCredential(
userName, password, tenantId, clientId, options);




var graphClient = new GraphServiceClient(userNamePasswordCredential, scopes);

Console.WriteLine($@"Got Graph Client: {graphClient.ToString()}");


var result = graphClient.Me.Messages["{message-id}"].GetAsync();
var result2 = graphClient.Me.Messages["{message-id}"].SingleValueExtendedProperties;



//var strings = result?.BodyPreview;


//try
//{
// var graphClient = new GraphServiceClient(requestAdapter);

// var result = await graphClient.Me.Messages["{message-id}"].GetAsync();
//}
//catch (Exception e)
//{
// Console.WriteLine(e);
// throw;
//}



//// Load OAuth settings
//try
//{
// //var oauthSettings = ResourceLoader.GetForCurrentView("OAuth");

// //var appId = oauthSettings.GetString("AppId");
// //var scopes = oauthSettings.GetString("Scopes");

// var appId = "";
// var scopes = "";

// if (string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(scopes))
// {
// // TODO: Notification.Show("Could not load OAuth Settings from resource file.");
// }
// else
// {
// // Configure MSAL provider
// var msalClient = PublicClientApplicationBuilder.Create(appId)
// .WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
// .Build();

// ProviderManager.Instance.GlobalProvider = new MsalProvider(msalClient, scopes.Split(' '));

// // Handle auth state change
// ProviderManager.Instance.ProviderStateChanged += GraphProviderUpdated;

// //// Navigate to HomePage.xaml
// //RootFrame.Navigate(typeof(HomePage));
// }


//}
//catch (Exception e)
//{
// throw;
//}


}

private void GraphProviderUpdated(object? sender, ProviderStateChangedEventArgs e)
{

}

private void ButtonTajElectrifier_OnClick(object sender, RoutedEventArgs e)
{
}
private void ButtonMSFTDummy_OnClick(object sender, RoutedEventArgs e)
{
}
}
14 changes: 10 additions & 4 deletions src/electrifier/electrifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="CommunityToolkit.Authentication.Msal" Version="7.1.3" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0-preview1" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Animations" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.1" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0-preview.2.23128.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Graph" Version="5.1.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230228005-preview1" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.50.0" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="2.26.0" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1587.40">
<Aliases>webview2</Aliases>
</PackageReference>
<PackageReference Include="Microsoft.Web.WebView2.DevToolsProtocolExtension" Version="1.0.824" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.2.230217.4" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="WinUIEx" Version="2.1.0" />
Expand Down
7 changes: 3 additions & 4 deletions src/electrifier/electrifier.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeEditing/SuppressNullableWarningFix/Enabled/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Hotmail/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=shemas/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tajbender/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>