コード例 #1
0
        public ServerRoleDTO GetServerRoles()
        {
            var srDto = new ServerRoleDTO();

            srDto.Identifier        = GetSettingValue(SettingStrings.ServerIdentifier);
            srDto.OperationMode     = GetSettingValue(SettingStrings.OperationMode);
            srDto.IsTftpServer      = TftpServerRole;
            srDto.IsMulticastServer = MulticastServerRole;
            return(srDto);
        }
コード例 #2
0
        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);
        }