public CustomApiCallDTO GetToken(string serverName)
        {
            var secondaryServer = GetSecondaryServerByName(serverName);
            var customApiCall   = new CustomApiCallDTO();

            customApiCall.BaseUrl = new Uri(secondaryServer.ApiURL);
            customApiCall.Token   = secondaryServer.LastToken;
            if (new APICall(customApiCall).ServiceAccountApi.Test())
            {
                return(customApiCall);
            }
            var token = new APICall(customApiCall).TokenApi.Get(secondaryServer.ServiceAccountName,
                                                                new EncryptionServices().DecryptText(secondaryServer.ServiceAccountPassword));

            if (token != null)
            {
                if (!string.IsNullOrEmpty(token.error_description))
                {
                    return(null);
                }
                customApiCall.Token       = token.access_token;
                secondaryServer.LastToken = token.access_token;
                _uow.SecondaryServerRepository.Update(secondaryServer, secondaryServer.Id);
                _uow.Save();
            }
            return(customApiCall);
        }
Beispiel #2
0
 public SettingAPI(string resource, CustomApiCallDTO cApiDto) : base(resource)
 {
     _apiRequest = new ApiRequest(cApiDto.Token, cApiDto.BaseUrl);
 }
Beispiel #3
0
 public APICall(CustomApiCallDTO cApi)
 {
     _cApiDto = cApi;
 }
        public ActionResultDTO AddSecondaryServer(SecondaryServerEntity secondaryServer)
        {
            var actionResult = new ActionResultDTO();

            //Verify connection to secondary server
            //Get token
            var customApiCall = new CustomApiCallDTO();

            customApiCall.BaseUrl = new Uri(secondaryServer.ApiURL);
            var token = new APICall(customApiCall).TokenApi.Get(secondaryServer.ServiceAccountName,
                                                                secondaryServer.ServiceAccountPassword);
            var serverRoles = new ServerRoleDTO();

            if (token != null)
            {
                if (!string.IsNullOrEmpty(token.error_description))
                {
                    actionResult.ErrorMessage = token.error_description;
                    return(actionResult);
                }
                customApiCall.Token = token.access_token;
                serverRoles         = new APICall(customApiCall).ServiceAccountApi.GetServerRoles();
                if (serverRoles.OperationMode != "Cluster Secondary")
                {
                    actionResult.ErrorMessage =
                        "Could Not Add Secondary Server.  It's Operation Mode Must First Be Changed To Cluster Secondary.";
                    return(actionResult);
                }
                if (!serverRoles.IsImageServer && !serverRoles.IsTftpServer && !serverRoles.IsMulticastServer)
                {
                    actionResult.ErrorMessage =
                        "Could Not Add Secondary Server.  You Must First Assign Roles To The Server";
                    return(actionResult);
                }
                if (serverRoles.Identifier == SettingServices.GetSettingValue(SettingStrings.ServerIdentifier))
                {
                    actionResult.ErrorMessage =
                        "Could Not Add Secondary Server.  Server Identifiers Must Be Different";
                    return(actionResult);
                }
            }
            else
            {
                actionResult.ErrorMessage = "Unknown Error While Attempting To Contact Secondary Server";
                return(actionResult);
            }

            secondaryServer.Name = serverRoles.Identifier;

            secondaryServer.TftpRole               = Convert.ToInt16(serverRoles.IsTftpServer);
            secondaryServer.MulticastRole          = Convert.ToInt16(serverRoles.IsMulticastServer);
            secondaryServer.ServiceAccountPassword =
                new EncryptionServices().EncryptText(secondaryServer.ServiceAccountPassword);

            var validationResult = ValidateSecondaryServer(secondaryServer, true);

            if (validationResult.Success)
            {
                _uow.SecondaryServerRepository.Insert(secondaryServer);
                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = secondaryServer.Id;
            }

            else
            {
                actionResult.ErrorMessage = validationResult.ErrorMessage;
            }

            return(actionResult);
        }