Exemplo n.º 1
0
        public void Book_request_vs_BookingKey(ref string error_response, ref LTLBookRequest ltl_book_request,
                                               ref AES_API_info api_info)
        {
            Json_helper json_helper = new Json_helper();

            try
            {
                if (ltl_book_request.items.Count == api_info.m_lPiece.Length)
                {
                    // Do nothing
                    DB.LogGenera(iam, "Book_request_vs_BookingKey, number of items MATCHING", ltl_book_request.bookingKey);
                }
                else
                {
                    DB.LogGenera(iam, "Book_request_vs_BookingKey, number of items NOT matching",
                                 string.Concat("ltl_book_request.items.Count: ", ltl_book_request.items.Count,
                                               " api_info.m_lPiece.Length: ",
                                               api_info.m_lPiece.Length,
                                               " ltl_book_request.bookingKey: ", ltl_book_request.bookingKey
                                               )
                                 );

                    //error_response = json_helper.Build_error_response("400", "");
                }
                //int units = 0;

                //for (byte i = 0; i < ltl_book_request.items.Count; i++)
                //{
                //    //units += ltl_book_request.items[i].units;
                //}
            }
            catch (Exception e)
            {
                DB.LogGenera(iam, "Validate_book_request_info_matches_BookingKey_info", e.ToString());
                //error_response = json_helper.Build_error_response("400", "");
            }
        }
Exemplo n.º 2
0
        public void Validate_booking_request_json(ref string data, ref string error_response,
                                                  ref string request_format, ref LTLBookRequest ltl_book_request)
        {
            Models.Public.LTL.Helper public_helper = new Models.Public.LTL.Helper();
            Parser parser = new Parser();

            bool is_request_valid_json = false;

            //Xml_helper xml_helper = new Xml_helper();
            Json_helper json_helper = new Json_helper();

            StringBuilder logger = new StringBuilder();

            if ((data.StartsWith("{") && data.EndsWith("}")) || // For object
                (data.StartsWith("[") && data.EndsWith("]")))   // For array
            {
                #region JSON


                request_format = "JSON";
                DB.LogGenera(iam, "Public API request_format", request_format);

                is_request_valid_json = json_helper.Is_request_valid_json(ref data);
                if (is_request_valid_json == true)
                {
                    try
                    {
                        ltl_book_request = new JavaScriptSerializer().Deserialize <LTLBookRequest>(data);
                        if (string.IsNullOrEmpty(ltl_book_request.bookingKey))
                        {
                            error_response = json_helper.Build_error_response("401", "Please give bookingKey");
                            return;
                        }

                        int units = 0;

                        for (byte i = 0; i < ltl_book_request.items.Count; i++)
                        {
                            //units += ltl_book_request.items[i].units;
                        }

                        #region Log info

                        #region Not used

                        /*
                         * DB.LogGenera(iam, "ltl_book_request.bookingKey", ltl_book_request.bookingKey);
                         * DB.LogGenera(iam,"ltl_book_request.originZip", ltl_book_request.originZip);
                         * DB.LogGenera(iam,"ltl_book_request.originCity", ltl_book_request.originCity);
                         * DB.LogGenera(iam,"ltl_book_request.originState", ltl_book_request.originState);
                         *
                         * DB.LogGenera(iam,"ltl_book_request.destinationZip", ltl_book_request.destinationZip);
                         * DB.LogGenera(iam,"ltl_book_request.destinationCity", ltl_book_request.destinationCity);
                         * DB.LogGenera(iam,"ltl_book_request.destinationState", ltl_book_request.destinationState);
                         *
                         * DB.LogGenera(iam,"ltl_book_request.pickupDate", ltl_book_request.pickupDate.ToShortDateString());
                         *
                         * DB.LogGenera(iam,"ltl_book_request.originAddress1", ltl_book_request.originAddress1);
                         * DB.LogGenera(iam,"ltl_book_request.originAddress2", ltl_book_request.originAddress2);
                         * DB.LogGenera(iam,"ltl_book_request.originState", ltl_book_request.originState);
                         * //DB.LogGenera(iam,"additionalServices.TSD", ltl_book_request.additionalServices.TSD.ToString());
                         *
                         * //DB.LogGenera(iam,"ltl_book_request.linealFeet", ltl_book_request.linealFeet.ToString());
                         *
                         * //DB.LogGenera(iam,"ltl_book_request.totalCube", ltl_book_request.totalCube.ToString());
                         */
                        #endregion

                        logger.Append(
                            string.Concat(
                                "bookingKey: ", ltl_book_request.bookingKey,
                                "linealFeet: ", ltl_book_request.linealFeet.ToString(),
                                "totalCube: ", ltl_book_request.totalCube.ToString(),
                                "originZip: ", ltl_book_request.originZip,
                                "originCity: ", ltl_book_request.originCity,
                                "originState: ", ltl_book_request.originState,
                                "destinationZip: ", ltl_book_request.destinationZip,
                                "destinationCity: ", ltl_book_request.destinationCity,
                                "destinationState: ", ltl_book_request.destinationState,
                                "pickupDate: ", ltl_book_request.pickupDate.ToShortDateString(),
                                "originAddress1: ", ltl_book_request.originAddress1,
                                "originAddress2: ", ltl_book_request.originAddress2,
                                "originState: ", ltl_book_request.originState

                                )
                            );

                        #region Add freight items to logger

                        for (byte i = 0; i < ltl_book_request.items.Count; i++)
                        {
                            logger.Append(
                                string.Concat(
                                    "items[", i, "].freightClass ",
                                    ltl_book_request.items[i].freightClass, ", ",
                                    "items[", i, "].weight",
                                    ltl_book_request.items[i].weight, ", ",

                                    "items[", i, "].commodity ",
                                    ltl_book_request.items[i].commodity, ", ",
                                    "items[", i, "].type ",
                                    ltl_book_request.items[i].type, ", ",
                                    "items[", i, "].description ",
                                    ltl_book_request.items[i].description, ", ",

                                    "items[", i, "].hazmat ",
                                    ltl_book_request.items[i].hazmat, ", ",
                                    "items[", i, "].length ",
                                    ltl_book_request.items[i].length, ", ",
                                    "items[", i, "].width ",
                                    ltl_book_request.items[i].width, ", ",
                                    "items[", i, "].height ",
                                    ltl_book_request.items[i].height, ", ",
                                    "items[", i, "].units ",
                                    ltl_book_request.items[i].units, ", ",
                                    "items[", i, "].pieces ",
                                    ltl_book_request.items[i].pieces, ", ",

                                    "items[", i, "].tag ",
                                    ltl_book_request.items[i].tag
                                    )
                                );

                            #region Not used

                            /*
                             * DB.LogGenera(iam,"Item",
                             *  string.Concat(
                             *      "items[", i, "].freightClass ",
                             *  ltl_book_request.items[i].freightClass, ", ",
                             *  "items[", i, "].weight",
                             *  ltl_book_request.items[i].weight, ", ",
                             *
                             *  "items[", i, "].commodity ",
                             *  ltl_book_request.items[i].commodity, ", ",
                             *  "items[", i, "].type ",
                             *  ltl_book_request.items[i].type, ", ",
                             *  "items[", i, "].description ",
                             *  ltl_book_request.items[i].description, ", ",
                             *
                             *   "items[", i, "].hazmat ",
                             *  ltl_book_request.items[i].hazmat, ", ",
                             *   "items[", i, "].length ",
                             *  ltl_book_request.items[i].length, ", ",
                             *   "items[", i, "].width ",
                             *  ltl_book_request.items[i].width, ", ",
                             *   "items[", i, "].height ",
                             *  ltl_book_request.items[i].height, ", ",
                             *   "items[", i, "].units ",
                             *  ltl_book_request.items[i].units, ", ",
                             *   "items[", i, "].pieces ",
                             *  ltl_book_request.items[i].pieces, ", ",
                             *
                             *  "items[", i, "].tag ",
                             *  ltl_book_request.items[i].tag
                             *
                             *  )
                             *
                             *
                             *  );
                             */
                            #endregion

                            #endregion
                        }

                        DB.LogGenera(iam, "Logger", logger.ToString());

                        #endregion
                    }
                    catch (Exception e)
                    {
                        DB.LogGenera(iam, "Deserialize", e.ToString());
                        error_response = json_helper.Build_error_response("400", "");
                    }
                }
                else
                {
                    error_response = json_helper.Build_booking_error_response("400", "JSON Request was not properly formatted");
                }

                #endregion
            }
            else
            {
                #region Request format was not valid

                DB.LogGenera(iam, "WS Request was not valid JSON", data);
                //Xml_helper xml_helper = new Xml_helper();
                //error_response = xml_helper.Build_error_response("400", "Request was not properly formatted",
                //    ref request_format);

                error_response = json_helper.Build_error_response("400", "Request was not properly formatted");


                #endregion
            }
        }