private bool CheckAvailability()
 {
     if (ServiceHelper.IsServerOnline())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #2
0
        private async Task <bool> CheckServiceAvailability()
        {
            string error  = string.Empty;
            bool   result = false;

            Action <bool> onFinally = (ok) =>
            {
                if (ok)
                {
                    result = true;
                    ServiceAvailability     = true;
                    IsReportSettingsEnabled = true;
                }
                else
                {
                    _window.ShowDialogError(error);
                    result = false;
                    ServiceAvailability = false;
                }
            };

            try
            {
                bool serverAvailability = ServiceHelper.IsServerOnline();
                if (serverAvailability)
                {
                    ServerAvailability = true;

                    // проверка наличия доступа
                    bool hasRights = await ServiceHelper.LoginAsync(true);

                    string answer = ServiceHelper.ErrorMessage;
                    // если доступ не получен и не авторизованы
                    if (hasRights == false)
                    {
                        if (String.IsNullOrEmpty(answer))
                        {
                            error = Strings.IncorrectService;
                            onFinally(false);
                        }
                        hasRights = await ServiceHelper.LoginAsync();

                        // авторизация не успешна
                        if (hasRights == false)
                        {
                            error = Strings.AuthorizationFailed;
                            onFinally(false);
                        }
                        else
                        {
                            onFinally(true);
                        }
                    }
                    else
                    {
                        if (answer == "result=0&user=")
                        {
                            hasRights = await ServiceHelper.LoginAsync();

                            if (hasRights)
                            {
                                onFinally(true);
                            }
                            else
                            {
                                onFinally(false);
                            }
                        }
                        else
                        {
                            onFinally(true);
                        }
                    }
                }
                else
                {
                    ServerAvailability = false;
                    onFinally(false);
                }
            }
            catch (Exception ex)
            {
                string message = String.Format(Strings.Error, ex.Message);
                error = message;
                onFinally(false);
                return(false);
            }
            return(result);
        }