diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j.iOS/Info.plist b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j.iOS/Info.plist
index 31c765e..472017e 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j.iOS/Info.plist
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j.iOS/Info.plist
@@ -27,7 +27,7 @@
CFBundleIdentifier
nl.resoftware.pocketgraph
CFBundleVersion
- 1.0.2
+ 1.0.3
UILaunchStoryboardName
LaunchScreen
CFBundleName
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Managers/ConnectionStringManager.cs b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Managers/ConnectionStringManager.cs
index 8e4939a..1c3ddf2 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Managers/ConnectionStringManager.cs
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Managers/ConnectionStringManager.cs
@@ -59,5 +59,22 @@ namespace Xamarin.Neo4j.Managers
await SaveConnectionStrings(connectionStrings);
}
+
+ public static async Task UpdateConnectionString(Guid id, Neo4jConnectionString connectionString)
+ {
+ var connectionStrings = await GetConnectionStrings();
+
+ var connectionStringToUpdate = connectionStrings.FirstOrDefault(cs => cs.Id == id);
+
+ if (connectionStringToUpdate == null)
+ return;
+
+ connectionStringToUpdate.Scheme = connectionString.Scheme;
+ connectionStringToUpdate.Host = connectionString.Host;
+ connectionStringToUpdate.Username = connectionString.Username;
+ connectionStringToUpdate.Password = connectionString.Password;
+
+ await SaveConnectionStrings(connectionStrings);
+ }
}
}
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Models/Neo4jConnectionString.cs b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Models/Neo4jConnectionString.cs
index 3c79839..76fb48d 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Models/Neo4jConnectionString.cs
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Models/Neo4jConnectionString.cs
@@ -21,23 +21,27 @@ namespace Xamarin.Neo4j.Models
public string Host { get; set; }
+ public string Scheme { get; set; }
+
public string Username { get; set; }
public string Password { get; set; }
public Tuple ParseHost()
{
- if (Host.StartsWith("neo4j://"))
- return new Tuple(Host, false, false);
+ var fullHost = Scheme + Host;
+
+ if (fullHost.StartsWith("neo4j://"))
+ return new Tuple(fullHost, false, false);
- if (Host.StartsWith("bolt://"))
- return new Tuple(Host.Replace("bolt://", "neo4j://"), false, false);
+ if (fullHost.StartsWith("bolt://"))
+ return new Tuple(fullHost.Replace("bolt://", "neo4j://"), false, false);
- if (Host.StartsWith("neo4j+s://"))
- return new Tuple(Host.Replace("neo4j+s://", "neo4j://"), true, false);
+ if (fullHost.StartsWith("neo4j+s://"))
+ return new Tuple(fullHost.Replace("neo4j+s://", "neo4j://"), true, false);
- if (Host.StartsWith("neo4j+ssc://"))
- return new Tuple(Host.Replace("neo4j+ssc://", "neo4j://"), true, true);
+ if (fullHost.StartsWith("neo4j+ssc://"))
+ return new Tuple(fullHost.Replace("neo4j+ssc://", "neo4j://"), true, true);
throw new NotSupportedException("Unknown protocol.");
}
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/AddConnectionPage.xaml b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/AddConnectionPage.xaml
index 563b8e7..0a2e7c1 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/AddConnectionPage.xaml
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/AddConnectionPage.xaml
@@ -7,6 +7,22 @@
+
+
+
+
+
+ neo4j://
+ neo4j+s://
+ neo4j+ssc://
+ bolt://
+ bolt+s://
+ bolt+ssc://
+
+
+
+
+
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/AddConnectionPage.xaml.cs b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/AddConnectionPage.xaml.cs
index e2a0c51..9ad4be7 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/AddConnectionPage.xaml.cs
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/AddConnectionPage.xaml.cs
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
+using Xamarin.Neo4j.Models;
using Xamarin.Neo4j.ViewModels;
namespace Xamarin.Neo4j.Pages
@@ -13,11 +14,11 @@ namespace Xamarin.Neo4j.Pages
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class AddConnectionPage : ContentPage
{
- public AddConnectionPage()
+ public AddConnectionPage(Neo4jConnectionString neo4JConnectionString = null)
{
InitializeComponent();
- BindingContext = new AddConnectionViewModel(Navigation);
+ BindingContext = new AddConnectionViewModel(Navigation, neo4JConnectionString);
}
}
}
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/ConnectionsPage.xaml b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/ConnectionsPage.xaml
index 10d2859..f2626aa 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/ConnectionsPage.xaml
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Pages/ConnectionsPage.xaml
@@ -45,7 +45,8 @@
-
+
+
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Services/Neo4jService.cs b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Services/Neo4jService.cs
index 56e369b..1c5bd2d 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Services/Neo4jService.cs
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/Services/Neo4jService.cs
@@ -34,7 +34,7 @@ namespace Xamarin.Neo4j.Services
private BoltGraphClient GraphClient { get; set; }
- public async Task EstablishConnection(Neo4jConnectionString connectionString)
+ public async Task> EstablishConnection(Neo4jConnectionString connectionString)
{
try
{
@@ -54,22 +54,32 @@ namespace Xamarin.Neo4j.Services
await GraphClient.ConnectAsync();
}
- catch (ServiceUnavailableException)
+ catch (ServiceUnavailableException e)
{
- return false;
+ return new Tuple(false, e.Message);
}
- catch (AuthenticationException)
+ catch (AuthenticationException e)
{
- return false;
+ return new Tuple(false, e.Message);
}
- catch (UriFormatException)
+ catch (SecurityException e)
{
- return false;
+ return new Tuple(false, e.Message);
}
- return true;
+ catch (UriFormatException e)
+ {
+ return new Tuple(false, e.Message);
+ }
+
+ catch (NotSupportedException e)
+ {
+ return new Tuple(false, e.Message);
+ }
+
+ return new Tuple(true, "Connection was successful!");
}
public async Task> LoadDatabases()
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/AddConnectionViewModel.cs b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/AddConnectionViewModel.cs
index debb531..7ba0bf3 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/AddConnectionViewModel.cs
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/AddConnectionViewModel.cs
@@ -25,15 +25,21 @@ namespace Xamarin.Neo4j.ViewModels
{
public class AddConnectionViewModel : ViewModelBase, INotifyPropertyChanged
{
- private string _host, _username, _password;
+ private Guid? _id;
+
+ private string _scheme, _host, _username, _password;
private readonly Neo4jService _neo4jService;
public event PropertyChangedEventHandler PropertyChanged;
- public AddConnectionViewModel(INavigation navigation) : base(navigation)
+ public AddConnectionViewModel(INavigation navigation, Neo4jConnectionString neo4JConnectionString = null) : base(navigation)
{
- InitializeDefaultValues();
+ if (neo4JConnectionString == null)
+ InitializeDefaultValues();
+
+ else
+ InitializeValues(neo4JConnectionString);
_neo4jService = DependencyService.Resolve();
@@ -41,23 +47,29 @@ namespace Xamarin.Neo4j.ViewModels
{
var connectionString = BuildConnectionString();
- var couldConnect = await _neo4jService.EstablishConnection(connectionString);
+ var (_, message) = await _neo4jService.EstablishConnection(connectionString);
- await UserDialogs.Instance.AlertAsync(couldConnect ? "Connection successful." : "Connection failed.");
+ await UserDialogs.Instance.AlertAsync(message);
}));
Commands.Add("Save", new Command(async () =>
{
var connectionString = BuildConnectionString();
- var namePromptResult = await UserDialogs.Instance.PromptAsync("How do you want to name this connection?", "Save Connection", "Save", "Cancel");
+ if (_id.HasValue)
+ await ConnectionStringManager.UpdateConnectionString(_id.Value, connectionString);
+
+ else
+ {
+ var namePromptResult = await UserDialogs.Instance.PromptAsync("How do you want to name this connection?", "Save Connection", "Save", "Cancel");
- if (!namePromptResult.Ok || string.IsNullOrWhiteSpace(namePromptResult.Value))
- return;
+ if (!namePromptResult.Ok || string.IsNullOrWhiteSpace(namePromptResult.Value))
+ return;
- connectionString.Name = namePromptResult.Value;
-
- await ConnectionStringManager.AddConnectionString(connectionString);
+ connectionString.Name = namePromptResult.Value;
+
+ await ConnectionStringManager.AddConnectionString(connectionString);
+ }
await Navigation.PopAsync();
}));
@@ -66,19 +78,30 @@ namespace Xamarin.Neo4j.ViewModels
{
var connectionString = BuildConnectionString();
- var couldConnect = await _neo4jService.EstablishConnection(connectionString);
+ var (couldConnect, message) = await _neo4jService.EstablishConnection(connectionString);
if (couldConnect)
await Navigation.PushAsync(new SessionPage(connectionString));
else
- await UserDialogs.Instance.AlertAsync( "Connection failed.");
+ await UserDialogs.Instance.AlertAsync(message);
}));
}
+ private void InitializeValues(Neo4jConnectionString neo4JConnectionString)
+ {
+ _id = neo4JConnectionString.Id;
+
+ Scheme = neo4JConnectionString.Scheme;
+ Host = neo4JConnectionString.Host;
+ Username = neo4JConnectionString.Username;
+ Password = neo4JConnectionString.Password;
+ }
+
private void InitializeDefaultValues()
{
Username = "neo4j";
+ Scheme = "neo4j://";
}
[NotifyPropertyChangedInvocator]
@@ -92,6 +115,7 @@ namespace Xamarin.Neo4j.ViewModels
return new Neo4jConnectionString
{
Id = Guid.NewGuid(),
+ Scheme = Scheme,
Host = Host,
Username = Username,
Password = Password
@@ -100,6 +124,18 @@ namespace Xamarin.Neo4j.ViewModels
#region Bindable Properties
+ public string Scheme
+ {
+ get => _scheme;
+
+ set
+ {
+ _scheme = value;
+
+ OnPropertyChanged(nameof(Scheme));
+ }
+ }
+
public string Host
{
get => _host;
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/ConnectionsViewModel.cs b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/ConnectionsViewModel.cs
index 6afc114..3df525a 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/ConnectionsViewModel.cs
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/ConnectionsViewModel.cs
@@ -32,6 +32,14 @@ namespace Xamarin.Neo4j.ViewModels
Navigation.PushAsync(new AddConnectionPage());
}));
+ Commands.Add("EditConnectionString", new Command(async (o) =>
+ {
+ if (!(o is Neo4jConnectionString neo4jConnectionString))
+ return;
+
+ await Navigation.PushAsync(new AddConnectionPage(neo4jConnectionString));
+ }));
+
Commands.Add("DeleteConnectionString", new Command(async (o) =>
{
if (!(o is Neo4jConnectionString neo4jConnectionString))
diff --git a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/SessionViewModel.cs b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/SessionViewModel.cs
index 1493235..667a06a 100644
--- a/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/SessionViewModel.cs
+++ b/Xamarin.Neo4j/Xamarin.Neo4j/Xamarin.Neo4j/ViewModels/SessionViewModel.cs
@@ -7,6 +7,7 @@
// © Xamarin.Neo4j
//
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
@@ -78,8 +79,15 @@ namespace Xamarin.Neo4j.ViewModels
private async void InitializeConnection(Neo4jConnectionString connectionString)
{
- await _neo4jService.EstablishConnection(connectionString);
+ var (isConnected, message) = await _neo4jService.EstablishConnection(connectionString);
+ if (!isConnected)
+ {
+ await UserDialogs.Instance.AlertAsync(message);
+
+ return;
+ }
+
AvailableDatabases = await _neo4jService.LoadDatabases();
if (!string.IsNullOrWhiteSpace(connectionString.Database))