Skip to content

Commit

Permalink
feat(pr: issue-291): include signalr for smalltalk mobile app
Browse files Browse the repository at this point in the history
Merge pull request #292 from live-dev999/live-dev999/issue291
  • Loading branch information
live-dev999 committed Apr 10, 2022
2 parents db7fda1 + 45ec648 commit 15a1906
Show file tree
Hide file tree
Showing 40 changed files with 645 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;


using Android.App;
using Android.Content.PM;
using Android.Runtime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties XamarinHotReloadDebuggerTimeoutExceptionO2NextGenSmallTalkAndroidHideInfoBar="True" />
</VisualStudio>
</ProjectExtensions>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
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;

namespace O2NextGen.SmallTalk.UWP
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
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;

namespace O2NextGen.SmallTalk.UWP
namespace O2NextGen.SmallTalk.UWP
{
public sealed partial class MainPage
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand All @@ -26,4 +25,4 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]
[assembly: ComVisible(false)]
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;


using Foundation;
using UIKit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using UIKit;
using UIKit;

namespace O2NextGen.SmallTalk.iOS
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private void InitApp()
{
//_settingsService = ViewModelLocator.Resolve<ISettingsService>();
//if (!_settingsService.UseMocks)
ViewModelLocator.UpdateDependencies(true);
ViewModelLocator.UpdateDependencies(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Xamarin.Forms;

namespace O2NextGen.SmallTalk.Core.Converters
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace O2NextGen.SmallTalk.Core.Exceptions
{
public class ServiceAuthenticationException : Exception
{
public string Content { get; }

public ServiceAuthenticationException()
{
}

public ServiceAuthenticationException(string content)
{
Content = content;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace O2NextGen.SmallTalk.Core.Extensions
{
public static class ObservableExtension
{
public static ObservableCollection<T> ToObservableCollection<T>(this IEnumerable<T> source)
{
ObservableCollection<T> collection = new ObservableCollection<T>();

foreach (T item in source)
{
collection.Add(item);
}

return collection;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace O2NextGen.SmallTalk.Core
{
public class GlobalSetting
{
public string GatewayChatEndpoint { get; set; } = "https://api-smalltalk.o2bus.com";
public static GlobalSetting Instance { get; } = new GlobalSetting();
public string HubConnectionURL { get; set; } = "http://localhost:5000/chathub";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Linq;

namespace O2NextGen.SmallTalk.Core.Helpers
{
public static class UriHelper
{
public static string CombineUri(params string[] uriParts)
{
string uri = string.Empty;
if (uriParts != null && uriParts.Count() > 0)
{
char[] trims = new char[] { '\\', '/' };
uri = (uriParts[0] ?? string.Empty).TrimEnd(trims);
for (int i = 1; i < uriParts.Count(); i++)
{
uri = string.Format("{0}/{1}", uri.TrimEnd(trims), (uriParts[i] ?? string.Empty).TrimStart(trims));
}
}
return uri;
}

internal static object CombineUri(object gatewayChatEndpoint, string v)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.0-preview.2.22153.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2401" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,71 @@
using O2NextGen.Sdk.NetCore.Models.smalltalk;
using O2NextGen.SmallTalk.Core.Extensions;
using O2NextGen.SmallTalk.Core.Helpers;
using O2NextGen.SmallTalk.Core.Services.RequestProvider;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;

namespace O2NextGen.SmallTalk.Core.Services.Chat
{
public class ChatService : IChatService
{
public Task AddMessageToSessionAsync(string message)
public ChatService(IRequestProvider requestProvider)
{
throw new NotImplementedException();
this._requestProvider = requestProvider;
}
private const string _apiUrlBase = "/api/chat";
private readonly IRequestProvider _requestProvider;

public async Task<ChatMessage> AddMessageToSessionAsync(string message)
{
var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayChatEndpoint, $"{_apiUrlBase}/session/1/messages");

var addMessage = await _requestProvider.PostAsync(uri, new ChatMessage()
{
Id = 0,
Message = message,
RecipientId = 1,
SenderId = 2
});

return addMessage;
}

public void GetByIdMessage(long sessionId, long id)
{
throw new NotImplementedException();
}

public Task<ObservableCollection<ChatMessage>> GetMessageAsync()
public async Task<ObservableCollection<ChatMessage>> GetMessageAsync()
{
throw new NotImplementedException();
var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayChatEndpoint, $"{_apiUrlBase}/session/1/messages");

var messages = await _requestProvider.GetAsync<IEnumerable<ChatMessage>>(uri);

if (messages != null)
return messages?.ToObservableCollection();
else
return new ObservableCollection<ChatMessage>();
}

public void GetMessages(long sessionId)
public async Task GetMessagesAsync(long sessionId)
{
throw new NotImplementedException();
}

public Task<ChatSession> GetSessionAsync()
public async Task<ChatSession> GetSessionAsync()
{
throw new NotImplementedException();
var uri = UriHelper.CombineUri(GlobalSetting.Instance.GatewayChatEndpoint, $"{_apiUrlBase}/session/1");

var chatSession = await _requestProvider.GetAsync<ChatSession>(uri);

if (chatSession != null)
return chatSession;
else
return new ChatSession();
//throw new NotImplementedException();
}

public Task<ObservableCollection<ChatSession>> GetSessionsAsync()
Expand All @@ -41,5 +77,10 @@ public void Sessions(long sessionId)
{
throw new NotImplementedException();
}

void IChatService.GetMessagesAsync(long sessionId)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public void GetByIdMessage(long sessionId, long id)
throw new NotImplementedException();
}

public void GetMessages(long sessionId)
public void GetMessagesAsync(long sessionId)
{
throw new NotImplementedException();
}

private ObservableCollection<ChatSession> MockSessions = new ObservableCollection<ChatSession>
private ObservableCollection<ChatSession> _mockSessions = new ObservableCollection<ChatSession>
{
new ChatSession() {
Id = 1,
Expand All @@ -35,7 +35,6 @@ public void GetMessages(long sessionId)
{
Id = 2,
Message = "Tests 2",
SenderId = 1,
RecipientId = 2
},
new ChatMessage()
Expand Down Expand Up @@ -80,7 +79,7 @@ public async Task<ObservableCollection<ChatSession>> GetSessionsAsync()
{
await Task.Delay(10);

return MockSessions;
return _mockSessions;
}

public void Sessions(long sessionId)
Expand All @@ -92,20 +91,22 @@ public async Task<ChatSession> GetSessionAsync()
{
await Task.Delay(10);

return MockSessions[0];
return _mockSessions[0];
}
public async Task<ObservableCollection<ChatMessage>> GetMessageAsync()
{
await Task.Delay(10);

return new ObservableCollection<ChatMessage>(MockSessions[0].Messages);
return new ObservableCollection<ChatMessage>(_mockSessions[0].Messages);
}

public async Task AddMessageToSessionAsync(string message)
public async Task<ChatMessage> AddMessageToSessionAsync(string message)
{
await Task.Delay(10);
long index = MockSessions.Count+1;
MockSessions[0].Messages.Add(new ChatMessage() { Id = index,Message=message,SenderId=1,RecipientId=2 });
long index = _mockSessions.Count + 1;
var addMessage = new ChatMessage() { Id = index, Message = message, SenderId = 1, RecipientId = 2 };
_mockSessions[0].Messages.Add(addMessage);
return addMessage;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace O2NextGen.SmallTalk.Core.Services.Chat
public interface IChatService
{
void GetByIdMessage(long sessionId, long id);
void GetMessages(long sessionId);
void GetMessagesAsync(long sessionId);
void Sessions(long sessionId);
Task<ObservableCollection<ChatSession>> GetSessionsAsync();
Task<ChatSession> GetSessionAsync();
Task<ObservableCollection<ChatMessage>> GetMessageAsync();
Task AddMessageToSessionAsync(string message);
Task<ChatMessage> AddMessageToSessionAsync(string message);
}
}
Loading

0 comments on commit 15a1906

Please sign in to comment.