Skip to content

Commit

Permalink
Update depencencies
Browse files Browse the repository at this point in the history
  • Loading branch information
gus33000 committed Dec 9, 2023
1 parent 0b73250 commit 823cdac
Show file tree
Hide file tree
Showing 31 changed files with 469 additions and 452 deletions.
33 changes: 18 additions & 15 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
using Chat.ContentDialogs;
using System;
using System.Globalization;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using System;
using System.Globalization;

namespace Chat
{
sealed partial class App : Application
public sealed partial class App : Application
{
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
this.UnhandledException += App_UnhandledException;
InitializeComponent();
Suspending += OnSuspending;
UnhandledException += App_UnhandledException;
}

private async void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)
{
e.Handled = true;
string ExceptionDesc = e.Exception.Message + "\nHRESULT: 0x" + e.Exception.HResult.ToString("X4", new CultureInfo("en-US")) + "\n" + e.Exception.StackTrace + "\n" + e.Exception.Source;
if (e.Exception.InnerException != null)
{
ExceptionDesc += "\n\n" + e.Exception.InnerException.Message + "\nHRESULT: 0x" + e.Exception.InnerException.HResult.ToString("X4", new CultureInfo("en-US")) + "\n" + e.Exception.InnerException.StackTrace + "\n" + e.Exception.InnerException.Source;
else
}
else
{
ExceptionDesc += "\n\nNo inner exception was thrown";
}

await new UnhandledExceptionContentDialog(ExceptionDesc).ShowAsync();
_ = await new UnhandledExceptionContentDialog(ExceptionDesc).ShowAsync();
}

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Shell rootShell = Window.Current.Content as Shell;

if (rootShell == null)
if (Window.Current.Content is not Shell rootShell)
{
rootShell = new Shell();

Expand All @@ -42,7 +44,9 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
}

if (e != null)
{
rootShell.HandleArguments(e);
}

Window.Current.Content = rootShell;
}
Expand All @@ -56,10 +60,9 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)

protected override void OnActivated(IActivatedEventArgs e)
{
if (e != null && e.Kind == ActivationKind.Protocol || e != null && e.Kind == ActivationKind.ToastNotification)
if ((e != null && e.Kind == ActivationKind.Protocol) || (e != null && e.Kind == ActivationKind.ToastNotification))
{
Shell rootShell = Window.Current.Content as Shell;
if (rootShell == null)
if (Window.Current.Content is not Shell rootShell)
{
rootShell = new Shell();

Expand All @@ -79,7 +82,7 @@ protected override void OnActivated(IActivatedEventArgs e)

private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
SuspendingDeferral deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
Expand Down
13 changes: 7 additions & 6 deletions Chat.BackgroundTasks/BackgroundTaskUtils.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Windows.ApplicationModel.Background;
using Windows.ApplicationModel.Chat;
using Windows.Devices.Sms;
using System;

namespace Chat.BackgroundTasks
{
Expand Down Expand Up @@ -107,7 +106,7 @@ internal static void UnRegisterBackgroundTask<T>()

if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(taskName)))
{
var task = BackgroundTaskRegistration.AllTasks.First(i => i.Value.Name.Equals(taskName));
KeyValuePair<Guid, IBackgroundTaskRegistration> task = BackgroundTaskRegistration.AllTasks.First(i => i.Value.Name.Equals(taskName));
task.Value.Unregister(true);
}
}
Expand All @@ -117,16 +116,18 @@ internal static void RegisterBackgroundTask<T>(IBackgroundTrigger trigger)
string taskName = typeof(T).Name;

if (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(taskName)))
{
return;
}

var builder = new BackgroundTaskBuilder()
BackgroundTaskBuilder builder = new BackgroundTaskBuilder()
{
Name = taskName,
TaskEntryPoint = typeof(T).FullName
};

builder.SetTrigger(trigger);
builder.Register();
_ = builder.Register();
}
}
}
6 changes: 3 additions & 3 deletions Chat.BackgroundTasks/Chat.BackgroundTasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>Chat.BackgroundTasks</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.19041.0</TargetPlatformVersion>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.22621.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
Expand Down Expand Up @@ -130,10 +130,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.13</Version>
<Version>6.2.14</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
<Version>7.1.0</Version>
<Version>7.1.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
28 changes: 13 additions & 15 deletions Chat.BackgroundTasks/ChatMessageNotificationBackgroundTask.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Chat.Common;
using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.ApplicationModel.Background;
using Windows.ApplicationModel.Chat;
Expand Down Expand Up @@ -43,37 +41,37 @@ private async Task<string> SaveFile(IRandomAccessStreamReference stream, string

StorageFile file = await storageFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);

using (var srcStream = await stream.OpenReadAsync())
using (var targetStream = await file.OpenAsync(FileAccessMode.ReadWrite))
using (var reader = new DataReader(srcStream.GetInputStreamAt(0)))
using (IRandomAccessStreamWithContentType srcStream = await stream.OpenReadAsync())
using (IRandomAccessStream targetStream = await file.OpenAsync(FileAccessMode.ReadWrite))
using (DataReader reader = new DataReader(srcStream.GetInputStreamAt(0)))
{
var output = targetStream.GetOutputStreamAt(0);
await reader.LoadAsync((uint)srcStream.Size);
IOutputStream output = targetStream.GetOutputStreamAt(0);
_ = await reader.LoadAsync((uint)srcStream.Size);
while (reader.UnconsumedBufferLength > 0)
{
uint dataToRead = reader.UnconsumedBufferLength > 64
? 64
: reader.UnconsumedBufferLength;

IBuffer buffer = reader.ReadBuffer(dataToRead);
await output.WriteAsync(buffer);
_ = await output.WriteAsync(buffer);
}

await output.FlushAsync();
_ = await output.FlushAsync();

return file.Path;
}
}

private async Task DisplayToast(ChatMessage message)
{
var information = await ContactUtils.FindContactInformationFromSender(message.From);
ContactUtils.ContactInformation information = await ContactUtils.FindContactInformationFromSender(message.From);
string thumbnailpath = "";
string text = "";

string deviceid = SmsDevice2.GetDefault().DeviceId;

foreach (var attachment in message.Attachments)
foreach (ChatMessageAttachment attachment in message.Attachments)
{
try
{
Expand All @@ -92,14 +90,14 @@ private async Task DisplayToast(ChatMessage message)
if (attachment.MimeType.StartsWith("image/"))
{
text += "Image content in this message. ";
var imageextension = attachment.MimeType.Split('/').Last();
string imageextension = attachment.MimeType.Split('/').Last();
thumbnailpath = await SaveFile(attachment.DataStreamReference, "messagepicture." + DateTimeOffset.Now.ToUnixTimeMilliseconds() + "." + imageextension);
}

if (attachment.MimeType.StartsWith("audio/"))
{
text += "Audio content in this message. ";
var audioextension = attachment.MimeType.Split('/').Last();
string audioextension = attachment.MimeType.Split('/').Last();
}
}
catch
Expand All @@ -108,7 +106,7 @@ private async Task DisplayToast(ChatMessage message)
}
}

var toastContent = new ToastContent()
ToastContent toastContent = new ToastContent()
{
Visual = new ToastVisual()
{
Expand Down Expand Up @@ -167,7 +165,7 @@ private async Task DisplayToast(ChatMessage message)
}
};

var toastNotif = new ToastNotification(toastContent.GetXml());
ToastNotification toastNotif = new ToastNotification(toastContent.GetXml());
ToastNotificationManager.CreateToastNotifier().Show(toastNotif);
}
}
Expand Down
8 changes: 2 additions & 6 deletions Chat.BackgroundTasks/SmsBackgroundTask.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using Chat.Common;
using Microsoft.Toolkit.Uwp.Notifications;
using System;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.ApplicationModel.Background;
using Windows.Devices.Sms;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Notifications;

namespace Chat.BackgroundTasks
Expand Down Expand Up @@ -72,7 +68,7 @@ private async Task DisplayToast(IBackgroundTaskInstance taskInstance)
return;
}

var toastContent = new ToastContent()
ToastContent toastContent = new ToastContent()
{
Visual = new ToastVisual()
{
Expand Down Expand Up @@ -127,7 +123,7 @@ private async Task DisplayToast(IBackgroundTaskInstance taskInstance)
}
};

var toastNotif = new ToastNotification(toastContent.GetXml());
ToastNotification toastNotif = new ToastNotification(toastContent.GetXml());
ToastNotificationManager.CreateToastNotifier().Show(toastNotif);

try
Expand Down
4 changes: 2 additions & 2 deletions Chat.BackgroundTasks/SmsReplyBackgroundTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private async Task HandleTaskActions(IBackgroundTaskInstance taskInstance)

}

var details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;
ToastNotificationActionTriggerDetail details = taskInstance.TriggerDetails as ToastNotificationActionTriggerDetail;

string arguments = details.Argument;

Expand All @@ -45,7 +45,7 @@ private async Task HandleTaskActions(IBackgroundTaskInstance taskInstance)
{
string messagetosend = (string)details.UserInput["textBox"];
SmsDevice2 smsDevice = SmsDevice2.FromId(deviceid);
await SmsUtils.SendTextMessageAsync(smsDevice, from, messagetosend);
_ = await SmsUtils.SendTextMessageAsync(smsDevice, from, messagetosend);
}
catch
{
Expand Down
4 changes: 2 additions & 2 deletions Chat.BackgroundTasks/UpdateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void Run(IBackgroundTaskInstance taskInstance)
BackgroundTaskUtils.UnRegisterToastNotificationBackgroundTasks();
BackgroundTaskUtils.RegisterToastNotificationBackgroundTasks();

var toastContent = new ToastContent()
ToastContent toastContent = new ToastContent()
{
Visual = new ToastVisual()
{
Expand All @@ -40,7 +40,7 @@ public void Run(IBackgroundTaskInstance taskInstance)
};

// Create the toast notification
var toastNotif = new ToastNotification(toastContent.GetXml());
ToastNotification toastNotif = new ToastNotification(toastContent.GetXml());

// And send the notification
ToastNotificationManager.CreateToastNotifier().Show(toastNotif);
Expand Down
6 changes: 1 addition & 5 deletions Chat.Common/BadgeHandler.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using Windows.Data.Xml.Dom;
using Windows.Storage;
using Windows.UI.Notifications;

namespace Chat.Common
namespace Chat.Common
{
public class BadgeHandler
{
Expand Down
4 changes: 2 additions & 2 deletions Chat.Common/Chat.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>Chat.Common</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.19041.0</TargetPlatformVersion>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.22621.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
Expand Down Expand Up @@ -128,7 +128,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.13</Version>
<Version>6.2.14</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
Expand Down
Loading

0 comments on commit 823cdac

Please sign in to comment.