/// <summary>
        /// Set task as completed
        /// </summary>
        public BaseResponse LogEndTaskExecution(SchedulerTaskType type)
        {
            SchedulerQueue schedulerQueue = Uow.SchedulerQueues.GetLastByType(type, SchedulerDestination);

            if (schedulerQueue != null)
            {
                Uow.SchedulerQueues.FinishAndChangeStatus(schedulerQueue, SchedulerExecutionStatus.Success);

                if (schedulerQueue.Dependencies != null)
                {
                    foreach (SchedulerTaskType schedulerTaskType in schedulerQueue.Dependencies)
                    {
                        SchedulerQueue item = Uow.SchedulerQueues.GetLastByType(schedulerTaskType, SchedulerDestination);
                        if (item != null)
                        {
                            long changedLockerMask = item.LockerMask & (~schedulerQueue.TaskType.GetLockerMask());
                            Uow.SchedulerQueues.ChangeLockerMask(item, changedLockerMask);
                        }
                    }
                }

                return(BaseResponse.Success());
            }

            return(BaseResponse.Error(ErrorCode.SchedulerQueueItemNotFound));
        }
        /// <summary>
        /// Set task as executing
        /// </summary>
        public BaseResponse LogStartTaskExecution(SchedulerTaskType type)
        {
            SchedulerQueue schedulerQueue = Uow.SchedulerQueues.GetLastByType(type, SchedulerDestination);

            if (schedulerQueue != null)
            {
                Uow.SchedulerQueues.StartAndChangeStatus(schedulerQueue, SchedulerExecutionStatus.Executing);

                return(BaseResponse.Success());
            }

            return(BaseResponse.Error(ErrorCode.SchedulerQueueItemNotFound));
        }
        public IResponse Follow(int userID, int userFollowedID)
        {
            try
            {
                twitterDataService.Follow(userID, userFollowedID);

                return(BaseResponse.Success());
            }
            catch (Exception)
            {
                return(BaseResponse.Error());
            }
        }
        public IResponse AddTweet(int userID, string content)
        {
            try
            {
                var tweet = twitterDataService.AddTweet(userID, content);

                return(BaseResponse.Success());
            }
            catch (Exception)
            {
                return(BaseResponse.Error());
            }
        }
        /// <summary>
        /// Set task as completed with exception
        /// </summary>
        public BaseResponse LogTaskException(SchedulerTaskType type, Exception exception)
        {
            SchedulerQueue schedulerQueue = Uow.SchedulerQueues.GetLastByType(type, SchedulerDestination);

            if (schedulerQueue != null)
            {
                Uow.SchedulerQueues.FinishAndChangeStatus(schedulerQueue, SchedulerExecutionStatus.Failed);
                schedulerQueue.Description = string.Format("InnerException: {0}; StackTrace: {1}", exception.InnerException, exception.StackTrace);

                return(BaseResponse.Success());
            }

            return(BaseResponse.Error(ErrorCode.SchedulerQueueItemNotFound));
        }
        public IResponse GetUsers(int userID, string firstName)
        {
            try
            {
                var users = twitterDataService.GetUsers(userID, firstName);

                var convertedUsers = ConversionHelper.ConvertUsers(users);

                return(UsersResponse.Success(convertedUsers));
            }
            catch (Exception)
            {
                return(BaseResponse.Error());
            }
        }
        public IResponse GetOwnTweets(int userID)
        {
            try
            {
                var tweets = twitterDataService.GetOwnTweets(userID);

                var convertedTweets = ConversionHelper.ConvertTweets(tweets).OrderByDescending(x => x.DateAdded).ToArray();

                return(TweetsResponse.Success(convertedTweets));
            }
            catch (Exception)
            {
                return(BaseResponse.Error());
            }
        }
示例#8
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (context.ModelState.IsValid)
            {
                await next();
            }

            var errors = context.ModelState.Values.SelectMany(x => x.Errors)
                         .Select(x => x.ErrorMessage)
                         .Where(x => !string.IsNullOrEmpty(x))
                         .ToList();
            string message = "The input parameters are invalid.";

            context.Result = new BadRequestObjectResult(BaseResponse.Error(message, errors));
        }
        public BaseResponse <OperationResult> Calculate(MathRequest request)
        {
            var operation = _factory.Create(request.OperationId, request.Operands);

            try
            {
                operation.Validate();
            }
            catch (OperandException e)
            {
                return(BaseResponse.Error <OperationResult>(e.ErrorCode, e.Message));
            }

            var result = operation.Execute();

            return(BaseResponse.Ok(FormatResult(result, Request.Headers.Where(x => x.Key.Contains("math-")))));
        }
        public IResponse EditAccount(int userID, string firstName, string lastName, string password)
        {
            try
            {
                var user = twitterDataService.EditUser(userID, firstName, lastName, password);
                if (user == null)
                {
                    return(BaseResponse.Error());
                }

                var convertedUser = ConversionHelper.ConvertUser(user);
                return(AccountResponse.Success(convertedUser));
            }
            catch (Exception)
            {
                return(BaseResponse.Error());
            }
        }
        public IResponse Login(string email, string password)
        {
            try
            {
                var user = twitterDataService.GetUser(email, password);
                if (user == null)
                {
                    return(BaseResponse.Error());
                }

                var convertedUser = ConversionHelper.ConvertUser(user);
                return(AccountResponse.Success(convertedUser));
            }
            catch (Exception)
            {
                return(BaseResponse.Error());
            }
        }
示例#12
0
        public BaseResponse ChangePassword(string customerCode, PasswordUseScope useScope, string oldPassword, string newPassword)
        {
            List <SZKingdomArgument> arguments = new List <SZKingdomArgument>();

            arguments.Add(SZKingdomArgument.UserCode(customerCode));
            arguments.Add(SZKingdomArgument.PasswordUseScpose(useScope));
            arguments.Add(SZKingdomArgument.OldAuthenticationData(_marketDataLibrary.EncryptPassword(customerCode, oldPassword)));
            arguments.Add(SZKingdomArgument.NewAuthenticationData(_marketDataLibrary.EncryptPassword(customerCode, newPassword)));
            arguments.Add(SZKingdomArgument.EncryptionKey(customerCode));
            arguments.Add(SZKingdomArgument.EncryptionType(EncryptionType.WinEncryption));
            arguments.Add(SZKingdomArgument.AuthenticationType(AuthenticationType.Password));

            EntityResponse <DataTable> result = _marketDataLibrary.ExecuteCommand(SZKingdomRequest.ChangePassword, arguments);

            if (result.IsSuccess)
            {
                return(BaseResponse.Success());
            }

            return(BaseResponse.Error(result.ErrorCode, result.FormattedMessage));
        }
        /// <summary>
        /// Create Task(if not exists) in Queue
        /// </summary>
        public BaseResponse CreateQueueTask(SchedulerQueue schedulerQueue, bool terminatePrevious = false)
        {
            SchedulerQueue existsSchedulerQueue = Uow.SchedulerQueues.GetLastByType(schedulerQueue.TaskType, SchedulerDestination);

            if (existsSchedulerQueue == null || existsSchedulerQueue.Status != SchedulerExecutionStatus.InQueue)
            {
                if (terminatePrevious)
                {
                    Uow.SchedulerQueues
                    .ChangeStatus(schedulerQueue.TaskType,
                                  SchedulerExecutionStatus.Pending,
                                  SchedulerExecutionStatus.Terminated,
                                  SchedulerDestination,
                                  true);
                    existsSchedulerQueue = null;
                }

                if (existsSchedulerQueue == null)
                {
                    existsSchedulerQueue = new SchedulerQueue
                    {
                        Status       = SchedulerExecutionStatus.Pending,
                        TaskType     = schedulerQueue.TaskType,
                        PlannedDate  = schedulerQueue.PlannedDate,
                        Destination  = SchedulerDestination,
                        LockerMask   = schedulerQueue.LockerMask,
                        Dependencies = schedulerQueue.Dependencies
                    };

                    Uow.SchedulerQueues.Add(existsSchedulerQueue);

                    return(BaseResponse.Success());
                }
            }

            return(BaseResponse.Error(ErrorCode.SchedulerQueueItemAlreadyExists));
        }