Пример #1
0
        public ConsumeResponse GetWordConsume(int count, string token, string fileName = "", string taskId = "")
        {
            ConsumeResponse result = null;

            try
            {
                string         apiName        = "consume";
                ConsumeRequest consumeRequest = new ConsumeRequest();
                consumeRequest.count    = count;
                consumeRequest.fileName = fileName;
                consumeRequest.taskId   = taskId;
                string          json       = JsonConvert.SerializeObject(consumeRequest);
                string          resultStr  = HttpHelper.HttpUrlSend(apiName, "POST", json, token);
                ConsumeResponse resultInfo = JsonConvert.DeserializeObject <ConsumeResponse>(resultStr);
                if (resultInfo != null)
                {
                    result = resultInfo;
                }
            }
            catch (Exception ex)
            {
                WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message);
            }
            return(result);
        }
Пример #2
0
        public JsonResult CreateConsume(ConsumeRequest request)
        {
            if (!request.CustomerID.HasValue)
            {
                return(JsonResult(new APIBaseResponse(false, "CM_005")));
            }

            var customer = customerService.GetCustomer(request.CustomerID.Value);

            if (customer == null)
            {
                return(JsonResult(new APIBaseResponse(false, "CM_002")));
            }

            request.DiscountRatio = RatioConfigHelper.GetRatioConfig("DiscountRatio").value;
            request.KickbackRatio = RatioConfigHelper.GetRatioConfig("KickbackRatio").value;

            var customerAmount = customer.CustomerAmount.FirstOrDefault();

            if (customerAmount == null || customerAmount.Amount < request.Amount * request.DiscountRatio)
            {
                return(JsonResult(new APIBaseResponse(false, "CM_004")));
            }


            string errorMessage = consumeRecordService.CreateCustomeConsume(request);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                return(Json(new APIBaseResponse(false, null, errorMessage)));
            }

            return(SuccessJsonResult());
        }
Пример #3
0
        public void Publish1000MessagesWithPropertiesAndHeaderTest()
        {
            var headers = new Dictionary <String, String>();

            headers.Add("MyHeader1", "MyHeaderValue1");
            headers.Add("MyHeader2", "MyHeaderValue2");
            headers.Add("MyHeader3", "MyHeaderValue3");
            headers.Add("MyHeader4", "MyHeaderValue4");
            headers.Add("MyHeader5", "MyHeaderValue5");
            var payload = "Publish1000MessagesWithPropertiesAndHeaderTest";

            for (int i = 0; i < 1000; i++)
            {
                var properties = new PublishProperties("appid", "correlationid", "messageid", userName, 2, headers);
                var body       = new PublishRequest(routingKey, payload + i, PublishRequest.PayloadEncodingEnum.String,
                                                    properties);
                var response = instance.PublishMessage(vhost, exchange, body);
                Assert.NotNull(response);
                Assert.True(response.Routed);
            }

            for (int i = 0; i < 1000; i++)
            {
                var request             = new ConsumeRequest(1, "ack_requeue_false", "auto", 50000000);
                var consumeResponseList = instance.ConsumeMessage(vhost, "shared.queue", request);
                var consumeResponse     = consumeResponseList[0];
                Assert.NotNull(consumeResponse);
                Assert.Equal(payload + i, consumeResponse.Payload);
                Assert.Equal(headers, consumeResponse.Properties.Headers);
            }
        }
Пример #4
0
        public void ConsumeMessageTest()
        {
            ConsoleRunnerLogger logger = new ConsoleRunnerLogger(true);

            logger.LogMessage("Testing");
            var body     = new ConsumeRequest(4, "ack_requeue_false", "auto", 50000);
            var response = instance.ConsumeMessage(vhost, queue, body);

            Assert.NotNull(response);
        }
Пример #5
0
        public void PublishMessageWithPropertiesTest()
        {
            var payload  = "PublishMessageWithPropertiesTest";
            var body     = new PublishRequest(routingKey, payload, PublishRequest.PayloadEncodingEnum.String, new PublishProperties("appid", "correlationid", "messageid", userName, 2));
            var response = instance.PublishMessage(vhost, exchange, body);

            Assert.NotNull(response);
            Assert.True(response.Routed);

            var request             = new ConsumeRequest(1, "ack_requeue_false", "auto", 50000000);
            var consumeResponseList = instance.ConsumeMessage(vhost, "shared.queue", request);
            var consumeResponse     = consumeResponseList[0];

            Assert.NotNull(consumeResponse);
            Assert.Equal(payload, consumeResponse.Payload);
        }
        public string CreateCustomeConsume(ConsumeRequest request)
        {
            var sqlScript = DBScriptManager.GetScript(this.GetType(), "CreateCustomeConsume");

            var paramErrorMsg = new SqlParameter("@ErrorMessage", SqlDbType.NVarChar, 1000);

            paramErrorMsg.Direction = ParameterDirection.Output;

            var paramCustomerID = new SqlParameter("@CustomerID", SqlDbType.Int);

            paramCustomerID.Value = request.CustomerID;

            var paramAmount = new SqlParameter("@Amount", SqlDbType.Decimal);

            paramAmount.Value = request.Amount;

            var paramDetail = new SqlParameter("@Detail", SqlDbType.NVarChar, 1000);

            paramDetail.Value = request.Detail ?? string.Empty;

            var paramUserID = new SqlParameter("@UserID", SqlDbType.VarChar, 25);

            paramUserID.Value = request.UserID;

            var paramDiscountRatio = new SqlParameter("@DiscountRatio", SqlDbType.Decimal);

            paramDiscountRatio.Value = request.DiscountRatio;

            var paramKickbackRatio = new SqlParameter("@KickbackRatio", SqlDbType.Decimal);

            paramKickbackRatio.Value = request.KickbackRatio;

            ExecuteSqlCommand(sqlScript,
                              new SqlParameter[]
            {
                paramCustomerID,
                paramAmount,
                paramDetail,
                paramUserID,
                paramDiscountRatio,
                paramKickbackRatio,
                paramErrorMsg
            });

            return(Convert.ToString(paramErrorMsg.Value));
        }
Пример #7
0
 public string CreateCustomeConsume(ConsumeRequest request)
 {
     return(consumeRecordRepository.CreateCustomeConsume(request));
 }
Пример #8
0
        public KeyValuePair <string, List <Consume> > GetConsumeRecord(string recordID, int page, int pageSize, ConsumeRequest model, string sort)
        {
            try
            {
                string rpt   = model.rpt;
                string agt   = model.agent;
                string air   = model.airline;
                string citem = model.citem;
                //  whereCondition = "";
                model = null;



                Consume        Consume    = new Consume();
                SqlParameter[] Parameters =
                {
                    new SqlParameter("@OwnerType", rpt),
                    new SqlParameter("@Agent",     agt),
                    new SqlParameter("@Airline",   air),
                    new  SqlParameter("@Usersno",  ((CargoFlash.Cargo.Model.UserLogin)(System.Web.HttpContext.Current.Session["UserDetail"])).UserSNo.ToString()),
                    new SqlParameter("@CItem",     citem)
                };
                DataSet ds          = SqlHelper.ExecuteDataset(DMLConnectionString.WebConfigConnectionString, CommandType.StoredProcedure, "GetConsumble", Parameters);
                var     ConsumeList = ds.Tables[0].AsEnumerable().Select(e => new Consume
                {
                    Owner     = Convert.ToString(e["Owner"].ToString()),
                    Item      = Convert.ToString(e["item"].ToString()),
                    City      = Convert.ToString(e["City"].ToString()),
                    Ownertype = Convert.ToString(e["OwnerType"].ToString()),
                    Consumble = Convert.ToString(e["Consumble"].ToString()),
                    ULDOut    = Convert.ToString(e["ULDOut"].ToString()),
                    ULDStack  = Convert.ToString(e["ULDStack"].ToString()),
                    BuildUp   = Convert.ToString(e["BuildUp"].ToString()),
                    Balance   = Convert.ToString(e["Balance"].ToString()),

                    Dt = Convert.ToString(e["Dt"].ToString())
                });
                return(new KeyValuePair <string, List <Consume> >(ds.Tables[1].Rows[0][0].ToString(), ConsumeList.AsQueryable().ToList()));
            }
            catch (Exception ex)// (Exception ex)
            {
                // do something for error
                DataSet dsError;
                System.Data.SqlClient.SqlParameter[] ParametersError =
                {
                    new System.Data.SqlClient.SqlParameter("@ErrorMessage", ex.Message),
                    new System.Data.SqlClient.SqlParameter("@ProcName",     "GetConsumble"),
                    new System.Data.SqlClient.SqlParameter("@UserSNo",      ((CargoFlash.Cargo.Model.UserLogin)(System.Web.HttpContext.Current.Session["UserDetail"])).UserSNo.ToString())
                };
                dsError = CargoFlash.SoftwareFactory.Data.SqlHelper.ExecuteDataset(CargoFlash.SoftwareFactory.Data.DMLConnectionString.WebConfigConnectionString, System.Data.CommandType.StoredProcedure, "ProcOfHandleErrors", ParametersError);
                throw ex;
            }
        }
Пример #9
0
        /// <summary>
        /// Consume Message
        /// </summary>
        /// <exception cref="Thinkcode.RabbitMQ.OpenAPI.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="vhost"></param>
        /// <param name="queue"></param>
        /// <param name="body"> (optional)</param>
        /// <returns>Task of ApiResponse (List&lt;ConsumeResponse&gt;)</returns>
        public async System.Threading.Tasks.Task <Thinkcode.RabbitMQ.OpenAPI.Client.ApiResponse <List <ConsumeResponse> > > ConsumeMessageAsyncWithHttpInfo(string vhost, string queue, ConsumeRequest body = null)
        {
            // verify the required parameter 'vhost' is set
            if (vhost == null)
            {
                throw new Thinkcode.RabbitMQ.OpenAPI.Client.ApiException(400, "Missing required parameter 'vhost' when calling PubSubApi->ConsumeMessage");
            }

            // verify the required parameter 'queue' is set
            if (queue == null)
            {
                throw new Thinkcode.RabbitMQ.OpenAPI.Client.ApiException(400, "Missing required parameter 'queue' when calling PubSubApi->ConsumeMessage");
            }


            Thinkcode.RabbitMQ.OpenAPI.Client.RequestOptions requestOptions = new Thinkcode.RabbitMQ.OpenAPI.Client.RequestOptions();

            String[] @contentTypes = new String[] {
                "application/json"
            };

            // to determine the Accept header
            String[] @accepts = new String[] {
                "application/json"
            };

            foreach (var contentType in @contentTypes)
            {
                requestOptions.HeaderParameters.Add("Content-Type", contentType);
            }

            foreach (var accept in @accepts)
            {
                requestOptions.HeaderParameters.Add("Accept", accept);
            }

            if (vhost != null)
            {
                requestOptions.PathParameters.Add("vhost", Thinkcode.RabbitMQ.OpenAPI.Client.ClientUtils.ParameterToString(vhost)); // path parameter
            }
            if (queue != null)
            {
                requestOptions.PathParameters.Add("queue", Thinkcode.RabbitMQ.OpenAPI.Client.ClientUtils.ParameterToString(queue)); // path parameter
            }
            requestOptions.Data = body;

            // authentication (basic_auth) required
            // http basic authentication required
            if (!String.IsNullOrEmpty(this.Configuration.Username) || !String.IsNullOrEmpty(this.Configuration.Password))
            {
                requestOptions.HeaderParameters.Add("Authorization", "Basic " + Thinkcode.RabbitMQ.OpenAPI.Client.ClientUtils.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password));
                requestOptions.HeaderParameters.Add("X-Auth-Fallback", "Basic " + Thinkcode.RabbitMQ.OpenAPI.Client.ClientUtils.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password));
            }

            // make the HTTP request

            var response = await this.AsynchronousClient.PostAsync <List <ConsumeResponse> >("/queues/{vhost}/{queue}/get", requestOptions, this.Configuration);

            if (this.ExceptionFactory != null)
            {
                Exception exception = this.ExceptionFactory("ConsumeMessage", response);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(response);
        }
Пример #10
0
        /// <summary>
        /// Consume Message
        /// </summary>
        /// <exception cref="Thinkcode.RabbitMQ.OpenAPI.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="vhost"></param>
        /// <param name="queue"></param>
        /// <param name="body"> (optional)</param>
        /// <returns>Task of List&lt;ConsumeResponse&gt;</returns>
        public async System.Threading.Tasks.Task <List <ConsumeResponse> > ConsumeMessageAsync(string vhost, string queue, ConsumeRequest body = null)
        {
            Thinkcode.RabbitMQ.OpenAPI.Client.ApiResponse <List <ConsumeResponse> > localVarResponse = await ConsumeMessageAsyncWithHttpInfo(vhost, queue, body);

            return(localVarResponse.Data);
        }
Пример #11
0
 /// <summary>
 /// Consume Message
 /// </summary>
 /// <exception cref="Thinkcode.RabbitMQ.OpenAPI.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="vhost"></param>
 /// <param name="queue"></param>
 /// <param name="body"> (optional)</param>
 /// <returns>List&lt;ConsumeResponse&gt;</returns>
 public List <ConsumeResponse> ConsumeMessage(string vhost, string queue, ConsumeRequest body = null)
 {
     Thinkcode.RabbitMQ.OpenAPI.Client.ApiResponse <List <ConsumeResponse> > localVarResponse = ConsumeMessageWithHttpInfo(vhost, queue, body);
     return(localVarResponse.Data);
 }