void connection(string connection, string error)
 {
     processingRequest  = false;
     syncServiceUri     = null;
     webBody            = null;
     isUpdatingSettings = MBSyncSettingsSections.none;
     changeButtonsState(true);
     // if the connect button is disable we can re-enable it here
     if (isConnecting)
     {
         isConnecting        = false;
         btConnect.IsEnabled = true;
         UpdateStatusToDisconnected();
     }
     MessageBox.Show("Can't connect to the Sync Server", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
 }
 void connection()
 {
     processingRequest  = false;
     syncServiceUri     = null;
     webBody            = null;
     isUpdatingSettings = MBSyncSettingsSections.none;
     changeButtonsState(true);
     if (isConnecting)
     {
         isConnecting        = false;
         btConnect.IsEnabled = true;
         UpdateStatusToDisconnected();
     }
     else
     {
         MessageBox.Show("Can't connect to the Sync Server", "Access is denied!", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        private async Task onConnect()
        {
            changeButtonsState(false);
            if (isConnected && request != null)
            {
                request             = null;
                isConnected         = false;
                btConnect.IsEnabled = true;
            }
            else if (!processingRequest && SyncServerURL.Text.Length > 6 && SyncServerUserName.Text.Length > 0 && SyncServerPassword.Text.Length > 0)
            {
                //request authentication
                processingRequest   = true;
                isConnecting        = true;
                btConnect.IsEnabled = false;

                // disable connect button, or change value to cancel
                syncServiceUri = new Uri(SyncServerURL.Text);
                if (syncServiceUri != null)
                {
                    Uri tempUri = new Uri("api/Authentication");
                    Uri authUrl = new Uri(tempUri, syncServiceUri);
                    if (authUrl != null)
                    {
                        var credentials       = SyncServerUserName.Text + ":" + SyncServerPassword.Text;
                        var plainTextBytes    = System.Text.Encoding.UTF8.GetBytes(credentials);
                        var base64credentials = System.Convert.ToBase64String(plainTextBytes);

                        using (HttpClient httpClient = new HttpClient())
                        {
                            httpClient.Timeout = new TimeSpan(0, 1, 0);
                            using (request = new HttpRequestMessage(HttpMethod.Post, authUrl))
                            {
                                request.Content    = new StringContent(credentials, System.Text.Encoding.UTF8);
                                isUpdatingSettings = MBSyncSettingsSections.authorization;
                                request.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
                                request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                                request.Content.Headers.ContentLength = plainTextBytes.Length;

                                using (HttpResponseMessage response = await httpClient.SendAsync(request))
                                {
                                    var _lastResponseCode = response.StatusCode;
                                    response.EnsureSuccessStatusCode();
                                    string responseContent = await response.Content.ReadAsStringAsync();

                                    List <Dictionary <string, object> > respDictList = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(responseContent);
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect service URL!", "Can't connect to the Sync Server",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("The Url, the user name and password are required to connect!", "Can't connect to the Sync Server",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        void connectionDidFinishLoading(string connection)
        {
            processingRequest = false;
            if (webBody != null)
            {
                var jsonStatus = JsonConvert.DeserializeObject <Dictionary <string, object> >(webBody);
                if (isConnecting)
                {
                    if (isUpdatingSettings == MBSyncSettingsSections.authorization)
                    {
                        isUpdatingSettings = MBSyncSettingsSections.none;
                        token = jsonStatus["token"] is String? jsonStatus["token"].ToString() : string.Empty;
                        if (token.Length == 0)
                        {
                            isConnecting        = false;
                            btConnect.IsEnabled = true;
                            UpdateStatusToDisconnected();
                            MessageBox.Show("Can't connect to the Sync Server", "Access is denied!", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                        getSyncServerStatus();
                        return;
                    }
                    isConnected       = true;
                    btConnect.Content = "Disconnect";
                    //ConnectProgress.stopAnimation(self)
                    // process response
                    UpdateStatus(jsonStatus);
                    //print(jsonStatus)
                    isConnecting        = false; // if was connecting we now finish and is connected or not
                    btConnect.IsEnabled = true;
                }
                else
                {
                    switch (isUpdatingSettings)
                    {
                    case MBSyncSettingsSections.blob:
                        //updateBlobSettings(jsonStatus! as AnyObject)
                        break;

                    case MBSyncSettingsSections.log:
                        //updateLogSettings(jsonStatus! as AnyObject)
                        break;

                    case MBSyncSettingsSections.security:
                        //self.updateSecuritySettings(jsonStatus! as AnyObject)
                        break;

                    case MBSyncSettingsSections.connectionStrings:
                        //updateConnetionStrings(jsonStatus! as AnyObject)
                        break;

                    case MBSyncSettingsSections.connector:
                        //updateConnectorSettings(jsonStatus! as AnyObject)
                        break;

                    case MBSyncSettingsSections.all:
                        //UpdateStatus(jsonStatus as AnyObject)
                        //window!.sheetParent!.endSheet(self.window!, returnCode: NSModalResponseOK)
                        break;

                    default:
                        break;
                    }
                }
            }

            isUpdatingSettings = MBSyncSettingsSections.none;
            webBody            = null;// at the end of process the request we clean up the response

            calculateGeneralStatus();
            changeButtonsState(true);
            _isDirty = false;
        }