partial void OnSave(NSObject sender)
{
if (!String.IsNullOrEmpty(PasswordText.StringValue))
{
// Try to find the CMIS server and Check credentials
var credentials = new ServerCredentials()
{
UserName = UserText.StringValue,
Password = PasswordText.StringValue,
Address = new Uri(AddressText.StringValue)
};
PasswordText.Enabled = false;
CancelButton.Enabled = false;
SaveButton.Enabled = false;
Thread check = new Thread(() => {
var fuzzyResult = CmisUtils.GetRepositoriesFuzzy(credentials);
var cmisServer = fuzzyResult.Item1;
Controller.repositories = (cmisServer != null)? cmisServer.Repositories: null;
InvokeOnMainThread(() => {
if (Controller.repositories == null)
{
string warning = "";
string message = fuzzyResult.Item2.Message;
Exception e = fuzzyResult.Item2;
if (e is PermissionDeniedException)
{
warning = Properties_Resources.LoginFailedForbidden;
}
else if (e is ServerNotFoundException)
{
warning = Properties_Resources.ConnectFailure;
}
else if (e.Message == "SendFailure" && cmisServer.Url.Scheme.StartsWith("https"))
{
warning = Properties_Resources.SendFailureHttps;
}
else if (e.Message == "TrustFailure")
{
warning = Properties_Resources.TrustFailure;
}
else if (e.Message == "Unauthorized")
{
message = Properties_Resources.LoginFailedForbidden;
}
else
{
warning = Properties_Resources.Sorry;
}
NSAlert alert = NSAlert.WithMessage(message, "OK", null, null, warning);
alert.Icon = new NSImage(System.IO.Path.Combine(NSBundle.MainBundle.ResourcePath, "Pixmaps", "process-syncing-error.icns"));
alert.Window.OrderFrontRegardless();
alert.RunModal();
PasswordText.Enabled = true;
CancelButton.Enabled = true;
SaveButton.Enabled = true;
}
else
{
RemoveEvent();
Controller.SettingsPageCompleted(PasswordText.StringValue, SliderIndexToPollingInterval(Slider.IntValue), (StartupCheckbox.State == NSCellStateValue.On));
}
});
});
check.Start();
}
else
{
Controller.SettingsPageCompleted(null, SliderIndexToPollingInterval(Slider.IntValue), (StartupCheckbox.State == NSCellStateValue.On));
}
}