Esempio n. 1
0
    private static void getLanes_ModalX(ref SharedRail.ModalX_Lane mXlane, ref SharedRail.ModalX_Date mXdate, ref string doc)
    {
        string   tmp;
        int      ind;
        DateTime today = DateTime.Today;
        DateTime availDate;
        long     jsDateStamp;

        ind = doc.IndexOf("rateRequestId");
        doc = doc.Substring(ind);
        ind = doc.IndexOf(":");
        doc = doc.Substring(ind + 1);
        ind = doc.IndexOf(",");
        mXlane.rateRequestId = doc.Remove(ind).Replace("\"", "");

        while (doc.IndexOf("laneId") != -1)
        {
            ind       = doc.IndexOf("laneId");
            doc       = doc.Substring(ind);
            ind       = doc.IndexOf(":");
            doc       = doc.Substring(ind + 1);
            ind       = doc.IndexOf(",");
            mXlane.id = doc.Remove(ind);

            // Only scrape the "bestLane"
            ind = doc.IndexOf("bestLane");
            tmp = doc.Substring(ind);
            ind = tmp.IndexOf(":");

            tmp = tmp.Substring(ind + 1);
            ind = tmp.IndexOf(",");
            tmp = tmp.Remove(ind);

            if (tmp.Equals("true")) // If best lane
            {
                ind = doc.IndexOf("origAreaId");
                doc = doc.Remove(ind + 20);

                ind = doc.IndexOf("origArea");
                doc = doc.Substring(ind);
                ind = doc.IndexOf("id");
                doc = doc.Substring(ind);
                ind = doc.IndexOf(":");
                doc = doc.Substring(ind + 1);
                ind = doc.IndexOf(",");
                mXlane.origAreaId = doc.Remove(ind);

                ind = doc.IndexOf("zip");
                doc = doc.Substring(ind);
                ind = doc.IndexOf(":");
                doc = doc.Substring(ind + 1);
                ind = doc.IndexOf(",");
                mXlane.origAreaZip = doc.Remove(ind).Replace("\"", "");

                ind = doc.IndexOf("destArea");
                doc = doc.Substring(ind);
                ind = doc.IndexOf("id");
                doc = doc.Substring(ind);
                ind = doc.IndexOf(":");
                doc = doc.Substring(ind + 1);
                ind = doc.IndexOf(",");
                mXlane.destAreaId = doc.Remove(ind);

                ind = doc.IndexOf("zip");
                doc = doc.Substring(ind);
                ind = doc.IndexOf(":");
                doc = doc.Substring(ind + 1);
                ind = doc.IndexOf(",");
                mXlane.destAreaZip = doc.Remove(ind).Replace("\"", "");

                while (doc.IndexOf("status\":\"AVAILABLE") != -1)
                {
                    ind         = doc.IndexOf("status\":\"AVAILABLE");
                    doc         = doc.Substring(ind);
                    ind         = doc.IndexOf("date");
                    doc         = doc.Substring(ind);
                    ind         = doc.IndexOf(":");
                    doc         = doc.Substring(ind + 1);
                    ind         = doc.IndexOf(",");
                    mXdate.date = doc.Remove(ind);

                    if (!long.TryParse(mXdate.date, out jsDateStamp))
                    {
                        throw new Exception("ModalX Date not parsed");
                    }
                    availDate = SharedRail.getDateFromJsGetTimeValue(jsDateStamp);

                    // Make the time of the dates equal for the comparison
                    TimeSpan ts = new TimeSpan(13, 30, 0);
                    today     = today.Date + ts;
                    availDate = availDate.Date + ts;

                    int result = DateTime.Compare(today, availDate);
                    if (result >= 0) // Today's date or earlier is too early, get at least tomorrow pickup date
                    {
                        continue;
                    }

                    ind = doc.IndexOf("LaneProvider");
                    doc = doc.Substring(ind);
                    ind = doc.IndexOf(",");
                    doc = doc.Substring(ind + 1);
                    ind = doc.IndexOf("]");
                    mXdate.laneProvider = doc.Remove(ind).Replace("\"", "");
                    mXlane.modalX_Date  = mXdate;

                    if (result < 0)
                    {
                        break;
                    }
                }

                #region Not used
                //ind = doc.IndexOf("\"lane\"");
                //doc = doc.Substring(ind);
                //ind = doc.IndexOf(":");
                //doc = doc.Substring(ind + 1);
                //ind = doc.IndexOf(",");
                //mXlane.lane = doc.Remove(ind).Replace("\"", "");

                //while (doc.IndexOf("status\":\"AVAILABLE") != -1)
                //{
                //    ind = doc.IndexOf("status\":\"AVAILABLE");
                //    doc = doc.Substring(ind);
                //}
                #endregion
            }
            else
            {
                continue;
            }
        }
    }
Esempio n. 2
0
    private void tryDate_ModalX(ref SharedRail.RailResult railResult, ref DateTime date, ref Int64 dateStamp, ref string referrer,
                                ref Int64 timeStampNow, ref DateTime now, ref SharedRail.ModalX_PurchasedBy purchasedBy,
                                ref HelperFuncs.ModalX_Result res)
    {
        string url = "", contentType, accept, method = "POST", doc = "", data = "";

        // This request throws an exception, but.. this is correct. Only there are no rates for these zip codes (on the weekend)
        url         = "https://www.modal-x.com/tw-services/modalx/v1.0.0/TDIS/rates/search";
        contentType = "application/json";
        data        = "{\"origZip\":\"" + origZip + "\",\"destZip\":\"" + destZip + "\",\"pickupDate\":" + dateStamp.ToString() +
                      ",\"origCountry\":\"USA\",\"destCountry\":\"USA\"}";
        accept = "*/*";
        doc    = (string)HelperFuncs.generic_http_request_3("string", container, url, referrer, contentType, accept, method, data, false, false, "", "");

        SharedRail.ModalX_Lane mXlane = new SharedRail.ModalX_Lane();
        SharedRail.ModalX_Date mXdate = new SharedRail.ModalX_Date();
        getLanes_ModalX(ref mXlane, ref mXdate, ref doc);
        //--------------------------------------------------------------------------------------------------------------------

        timeStampNow = SharedRail.GetTime(ref now);

        url         = "https://www.modal-x.com/tw-services/modalx/v1.0.0/TDIS/accessorials?_dc=" + timeStampNow.ToString();
        contentType = "";
        method      = "GET";
        doc         = (string)HelperFuncs.generic_http_request_3("string", container, url, referrer, contentType, accept, method, "", false, false, "", "");

        //--------------------------------------------------------------------------------------------------------------------

        url         = "https://www.modal-x.com/tw-services/modalx/v1.0.0/TDIS/requests/rates/deliverydate";
        contentType = "application/json";
        method      = "POST";
        data        = "{\"pickupDate\":" + dateStamp.ToString() + ",\"laneIndex\":{\"laneId\":" + mXlane.id +
                      ",\"origAreaId\":" + mXlane.origAreaId + ",\"destAreaId\":" + mXlane.destAreaId + "}}";
        doc = (string)HelperFuncs.generic_http_request_3("string", container, url, referrer, contentType, accept, method, data, false, false, "", "");

        // Scrape delivery date
        #region delivery date

        string[] tokens = new string[3];
        tokens[0] = "payload";
        tokens[1] = "[";
        tokens[2] = "]";

        string deliveryDateStr = HelperFuncs.scrapeFromPage(tokens, doc);

        #endregion


        //--------------------------------------------------------------------------------------------------------------------

        url = "https://www.modal-x.com/tw-services/modalx/v1.0.0/TDIS/requests/rates";

        DateTime scrapedPuDate      = SharedRail.getDateFromJsGetTimeValue(Convert.ToInt64(mXlane.modalX_Date.date));
        Int64    scrapedPuDateStamp = SharedRail.GetTime(ref scrapedPuDate);

        data = string.Concat("{\"baseRate\":null,\"preMarkkupTotal\":null,\"totalCharge\":null,\"fscPercent\":0,\"markupFee\":",
                             "{\"percent\":null,\"minAmount\":\"\",\"markupAmount\":null,\"percentAdminOverridden\":false,\"amountAdminOverridden\":false},",
                             "\"miscChargeNote\":\"\",\"railFuelSurcharge\":null,\"appliedLineHaul\":null,\"contractor\":null,\"priceAuthority\":null,",
                             "\"discountPercentage\":null,\"accessorials\":[{\"charge\":null,\"qualifier\":\"FUEL\"}],\"pickupDate\":", mXlane.modalX_Date.date,
                             ",",
                             "\"deliveryDate\":", deliveryDateStr, ",\"laneIndex\":{\"laneId\":\"", mXlane.id, "\",\"origAreaId\":\"", mXlane.origAreaId,
                             "\",\"destAreaId\":\"",
                             mXlane.destAreaId, "\"},",
                             "\"equipTypeXref\":\"U53DH\",\"locations\":[{\"order\":1,\"type\":\"ORIG\",\"postalCode\":\"", origZip, "\",\"country\":\"USA\",",
                             "\"city\":\"\",\"state\":\"\",\"county\":\"\",\"netTime\":", scrapedPuDateStamp, ",\"nltTime\":", scrapedPuDateStamp, "},",
                             "{\"order\":2,\"type\":\"ORIG\",\"postalCode\":\"\",\"country\":\"USA\",\"city\":\"\",\"state\":\"\",\"county\":\"\",",
                             "\"netTime\":", scrapedPuDateStamp, ",\"nltTime\":", scrapedPuDateStamp, "},{\"order\":3,\"type\":\"ORIG\",\"postalCode\":\"\",\"country\":\"USA\",",
                             "\"city\":\"\",\"state\":\"\",\"county\":\"\",\"netTime\":", scrapedPuDateStamp, ",\"nltTime\":", scrapedPuDateStamp, "},",
                             "{\"order\":1,\"type\":\"DEST\",\"postalCode\":\"\",\"country\":\"USA\",\"city\":\"\",\"state\":\"\",",
                             "\"county\":\"\",\"netTime\":null,\"nltTime\":null},{\"order\":2,\"type\":\"DEST\",\"postalCode\":\"\",\"country\":\"USA\",",
                             "\"city\":\"\",\"state\":\"\",\"county\":\"\",\"netTime\":null,\"nltTime\":null},{\"order\":3,\"type\":\"DEST\",",
                             "\"postalCode\":\"", destZip, "\",\"country\":\"USA\",\"city\":\"\",\"state\":\"\",\"county\":\"\",\"netTime\":null,\"nltTime\":null}],",
                             "\"hazmat\":false,\"scaleLightHeavy\":false,\"status\":null,\"numOfLoads\":1,\"note\":\"\",\"beneficialOwner\":\"\",",
                             "\"capRequestId\":null,\"lineHaul\":null,\"reqStatus\":null,\"rateRequestId\":", mXlane.rateRequestId, ",\"customer\":\"\",\"thirdParty\":\"\",",
                             "\"remainingLoads\":\"\",\"confirmationNumber\":\"\",\"requestDate\":\"\",\"lane\":\"", mXlane.lane, "\",\"purchasedBy\":",
                             "\"", purchasedBy.email, "\",\"purchasedByPhone\":\"", purchasedBy.phone, "\",\"purchasedByName\":\"", purchasedBy.name, "\",",
                             "\"purchasedByCompany\":\"", purchasedBy.company, "\"}");
        //HelperFuncs.writeToSiteErrors("ModalX data", data);
        doc = (string)HelperFuncs.generic_http_request_3("string", container, url, referrer, contentType, accept, method, data, false, false, "", "");
        //HelperFuncs.writeToSiteErrors("ModalX doc", doc);
        getResult_ModalX(ref doc, ref res);
    }