Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Added the URI parser framework or #42
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Sep 2, 2019
1 parent 1b80d77 commit 7057408
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Component_Tests/Classes/Misc/Test_UriUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.Foundation;
using XMPP_API.Classes;
using XMPP_API.Classes.XmppUri;

namespace Component_Tests.Classes.Misc
{
Expand Down
4 changes: 2 additions & 2 deletions Data_Manager2/Classes/Toast/ChatToastActivation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using Windows.Foundation;
using XMPP_API.Classes;
using XMPP_API.Classes.XmppUri;

namespace Data_Manager2.Classes.Toast
{
public class ChatToastActivation : AbstractToastActivation
public class ChatToastActivation: AbstractToastActivation
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--
Expand Down
4 changes: 2 additions & 2 deletions Data_Manager2/Classes/Toast/MarkChatAsReadToastActivation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using Windows.Foundation;
using XMPP_API.Classes;
using XMPP_API.Classes.XmppUri;

namespace Data_Manager2.Classes.Toast
{
public class MarkChatAsReadToastActivation : AbstractToastActivation
public class MarkChatAsReadToastActivation: AbstractToastActivation
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using Windows.Foundation;
using XMPP_API.Classes;
using XMPP_API.Classes.XmppUri;

namespace Data_Manager2.Classes.Toast
{
public class MarkMessageAsReadToastActivation : AbstractToastActivation
public class MarkMessageAsReadToastActivation: AbstractToastActivation
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--
Expand Down
4 changes: 2 additions & 2 deletions Data_Manager2/Classes/Toast/SendReplyToastActivation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using Windows.Foundation;
using XMPP_API.Classes;
using XMPP_API.Classes.XmppUri;

namespace Data_Manager2.Classes.Toast
{
public class SendReplyToastActivation : AbstractToastActivation
public class SendReplyToastActivation: AbstractToastActivation
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--
Expand Down
6 changes: 3 additions & 3 deletions Data_Manager2/Classes/Toast/ToastActivationArgumentParser.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Logging;
using System;
using System;
using System.Linq;
using Logging;
using Windows.Foundation;
using XMPP_API.Classes;
using XMPP_API.Classes.XmppUri;

namespace Data_Manager2.Classes.Toast
{
Expand Down
7 changes: 4 additions & 3 deletions UWPX_UI/Pages/ExtendedSplashScreenPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
using XMPP_API.Classes.XmppUri;
using BackgroundTaskHelper = UWPX_UI_Context.Classes.BackgroundTaskHelper;

namespace UWPX_UI.Pages
Expand Down Expand Up @@ -226,13 +227,13 @@ private void EvaluateActivationArgs()
{
Logger.Info("App activated by protocol activation with: " + protocolActivationArgs.Uri.ToString());

// If we're currently not on a page, navigate to the main page
ROOT_FRAME.Navigate(typeof(ChatPage), protocolActivationArgs); // ToDo add arguments
// If we're currently not on a page, navigate to the main page:
ROOT_FRAME.Navigate(typeof(ChatPage), UriUtils.parse(protocolActivationArgs.Uri));
}
else if (ACTIVATION_ARGS is ToastNotificationActivatedEventArgs toastActivationArgs)
{
Logger.Info("App activated by toast with: " + toastActivationArgs.Argument);
// If empty args, no specific action (just launch the app)
// If empty args, no specific action (just launch the app):
if (string.IsNullOrEmpty(toastActivationArgs.Argument))
{
Logger.Warn("Toast activation with no argument!");
Expand Down
41 changes: 41 additions & 0 deletions XMPP_API/Classes/XmppUri/AbstractUriAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace XMPP_API.Classes.XmppUri
{
public abstract class AbstractUriAction
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--


#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
#region --Constructors--


#endregion
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
#region --Set-, Get- Methods--


#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--


#endregion

#region --Misc Methods (Private)--


#endregion

#region --Misc Methods (Protected)--


#endregion
//--------------------------------------------------------Events:---------------------------------------------------------------------\\
#region --Events--


#endregion
}
}
41 changes: 41 additions & 0 deletions XMPP_API/Classes/XmppUri/SendMessageUriAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace XMPP_API.Classes.XmppUri
{
public class SendMessageUriAction: AbstractUriAction
{
//--------------------------------------------------------Attributes:-----------------------------------------------------------------\\
#region --Attributes--


#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
#region --Constructors--


#endregion
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
#region --Set-, Get- Methods--


#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--


#endregion

#region --Misc Methods (Private)--


#endregion

#region --Misc Methods (Protected)--


#endregion
//--------------------------------------------------------Events:---------------------------------------------------------------------\\
#region --Events--


#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using System.Linq;
using System.Net;
using System.Text;
using Logging;
using Windows.Foundation;

namespace XMPP_API.Classes
namespace XMPP_API.Classes.XmppUri
{
public static class UriUtils
{
Expand Down Expand Up @@ -85,6 +86,54 @@ public static WwwFormUrlDecoder parseUriQuery(Uri uri)
return new WwwFormUrlDecoder(uri.Query);
}

/// <summary>
/// TODO: Not done yet.
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
public static AbstractUriAction parse(Uri uri)
{
if (!string.IsNullOrEmpty(uri?.OriginalString))
{
string tmp = uri.OriginalString;

// 1. 'xmpp:'
if (tmp.StartsWith("xmpp:"))
{
tmp = tmp.Substring(5);

// 2. Authority
string authority = null;
if (tmp.StartsWith("//"))
{
tmp.Substring(2);
int authEnd = tmp.IndexOf('/');
if (authEnd < 0)
{
authEnd = tmp.IndexOf('?');
if (authEnd < 0)
{
authEnd = tmp.IndexOf('#');
if (authEnd < 0)
{
authEnd = tmp.Length <= 0 ? 0 : tmp.Length - 1;
}
}
authority = tmp.Substring(0, authEnd);
tmp = tmp.Substring(authEnd + 1);
}
}

// 3.
}
else
{
Logger.Warn("Unable to parse XMPP URI - 'xmpp:' missing.");
}
}
return null;
}

#endregion

#region --Misc Methods (Private)--
Expand Down
4 changes: 3 additions & 1 deletion XMPP_API/XMPP_API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@
<Compile Include="Classes\OmemoCommandHelper.cs" />
<Compile Include="Classes\Presence.cs" />
<Compile Include="Classes\PubSubCommandHelper.cs" />
<Compile Include="Classes\UriUtils.cs" />
<Compile Include="Classes\XmppUri\UriUtils.cs" />
<Compile Include="Classes\XmppUri\AbstractUriAction.cs" />
<Compile Include="Classes\XmppUri\SendMessageUriAction.cs" />
<Compile Include="Classes\Utils.cs" />
<Compile Include="Classes\XMPPClient.cs" />
<Compile Include="Classes\XMPPUser.cs" />
Expand Down

0 comments on commit 7057408

Please sign in to comment.