示例#1
0
        public Task <IActionResult> PutAsync(string id, [FromBody] SessionCreateRequest request)
        {
            if (!_interpManager.Interpreters.Any())
            {
                return(Task.FromResult <IActionResult>(new ApiErrorResult(BrokerApiError.NoRInterpreters)));
            }

            Interpreter interp;

            if (!string.IsNullOrEmpty(request.InterpreterId))
            {
                interp = _interpManager.Interpreters.FirstOrDefault(ip => ip.Id == request.InterpreterId);
                if (interp == null)
                {
                    return(Task.FromResult <IActionResult>(new ApiErrorResult(BrokerApiError.InterpreterNotFound)));
                }
            }
            else
            {
                interp = _interpManager.Interpreters.First();
            }

            try {
                var session = _sessionManager.CreateSession(User, id, interp, request.CommandLineArguments, request.IsInteractive);
                return(Task.FromResult <IActionResult>(new ObjectResult(session.Info)));
            } catch (Exception ex) {
                return(Task.FromResult <IActionResult>(new ApiErrorResult(BrokerApiError.UnableToStartRHost, ex.Message)));
            }
        }
示例#2
0
        public Task <IActionResult> PutAsync(string id, [FromBody] SessionCreateRequest request)
        {
            if (!_interpManager.Interpreters.Any())
            {
                return(Task.FromResult <IActionResult>(new ApiErrorResult(BrokerApiError.NoRInterpreters)));
            }

            string profilePath = User.FindFirst(Claims.RUserProfileDir)?.Value;
            var    password    = User.FindFirst(Claims.Password)?.Value.ToSecureString();

            Interpreter interp;

            if (!string.IsNullOrEmpty(request.InterpreterId))
            {
                interp = _interpManager.Interpreters.FirstOrDefault(ip => ip.Id == request.InterpreterId);
                if (interp == null)
                {
                    return(Task.FromResult <IActionResult>(new ApiErrorResult(BrokerApiError.InterpreterNotFound)));
                }
            }
            else
            {
                interp = _interpManager.Interpreters.First();
            }

            try {
                var session = _sessionManager.CreateSession(User.Identity, id, interp, password, profilePath, request.CommandLineArguments);
                return(Task.FromResult <IActionResult>(new ObjectResult(session.Info)));
            } catch (BrokerMaxedUsersException ex) {
                return(Task.FromResult <IActionResult>(new ApiErrorResult(BrokerApiError.BrokerMaxUsers, ex.Message)));
            } catch (Exception ex) {
                return(Task.FromResult <IActionResult>(new ApiErrorResult(BrokerApiError.UnableToStartRHost, ex.Message)));
            }
        }
 public Task <IActionResult> PutAsync(string id, [FromBody] SessionCreateRequest request)
 {
     try {
         var session = _sessionManager.CreateSession(id, request.InterpreterPath, request.InterpreterArchitecture, request.CommandLineArguments, request.IsInteractive);
         return(Task.FromResult <IActionResult>(new ObjectResult(session.Info)));
     } catch (Exception ex) {
         return(Task.FromResult <IActionResult>(new ApiErrorResult(BrokerApiError.UnableToStartRHost, ex.Message)));
     }
 }
示例#4
0
        public Task <SessionInfo> PutAsync(string id, [FromBody] SessionCreateRequest request)
        {
            SecureString securePassword = null;
            string       password       = User.FindFirst(Claims.Password)?.Value;

            if (password != null)
            {
                securePassword = new SecureString();
                foreach (var ch in password)
                {
                    securePassword.AppendChar(ch);
                }
            }

            var interp  = _interpManager.Interpreters.First(ip => ip.Info.Id == request.InterpreterId);
            var session = _sessionManager.CreateSession(User.Identity, id, interp, securePassword, request.CommandLineArguments);

            return(Task.FromResult(session.Info));
        }
示例#5
0
        public Session Create(Merchant merchant, SessionCreateRequest request)
        {
            try
            {
                if (_dbContext.Session.Any(x => x.MerchantId == merchant.Id && x.OrderId == request.OrderId))
                {
                    throw new OuterException(InnerError.SessionAlreadyExists);
                }

                var session = new Session
                {
                    Amount           = request.Amount,
                    Currency         = request.Currency,
                    FormKey          = request.FormKey,
                    FormLanguage     = request.FormLanguage,
                    MerchantId       = merchant.Id,
                    OrderDescription = request.OrderDescription,
                    OrderId          = request.OrderId,
                    ExternalId       = IdHelper.GetSessionId(),
                    ExpireTime       = DateTime.UtcNow.AddMinutes(SessionMinutesToExpire),
                    SessionType      = request.SessionType,
                    TryCount         = 0
                };

                _dbContext.Session.Add(session);
                _dbContext.SaveChanges();
                return(session);
            }
            catch (DbUpdateException)
            {
                throw new OuterException(InnerError.SessionAlreadyExists);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong Merchant-[{merchant.Id}] OrderId[{request.OrderId}]");
                _logger.LogError(ex.Message);
                throw;
            }
        }
示例#6
0
 public Task <SessionInfo> PutAsync(string id, SessionCreateRequest request) =>
 HttpPutAsync <SessionCreateRequest, SessionInfo>(putUri, request, id);
示例#7
0
 public Task <SessionInfo> PutAsync(string id, SessionCreateRequest request, CancellationToken cancellationToken = default) =>
 HttpPutAsync <SessionCreateRequest, SessionInfo>(GetSessionUri(id), request, cancellationToken);
示例#8
0
 public Task <SessionInfo> PutAsync(string id, SessionCreateRequest request, CancellationToken cancellationToken = default(CancellationToken)) =>
 HttpPutAsync <SessionCreateRequest, SessionInfo>(SessionUri, request, cancellationToken, id);