private void CheckOrder(BComOrderResponse response)
        {
            // Are portions missing?
            if ((response.OrderResponse == null) ||
                (response.OrderResponse.CompletedQuantity == null) ||
                (response.OrderResponse.CompletedNumbers == null) ||
                (response.OrderResponse.OrderStatus == null))
            {
                this.response.SetJeop("Portions of the response are missing.");
            }

            // Is the OrderStatus COMPLETE?
            if (response.OrderResponse.OrderStatus.ToUpper() != "COMPLETE")
            {
                this.response.SetJeop(
                    "The Order status is not complete. Status: " + response.OrderResponse.OrderStatus.ToUpper());
            }

            bool success = false;

            // Is there at least one completed?
            int completedQuantity = -1;

            success = int.TryParse(response.OrderResponse.CompletedQuantity, out completedQuantity);
            if (success == false)
            {
                this.response.SetJeop(
                    "Unable to parse number of complete TN orders. Value: " + response.OrderResponse.CompletedQuantity);
            }
            else if (completedQuantity < 1)
            {
                this.response.SetJeop(
                    "Not enough TNs were ordered. Ordered: " + completedQuantity.ToString() + ", Required: 1");
            }

            // Same logic but on the list of TNs.
            if (response.OrderResponse.CompletedNumbers.Length < 1)
            {
                this.response.SetJeop(
                    "Not enough TNs were returned. Ordered: " +
                    response.OrderResponse.CompletedNumbers.Length + ", Required: 1");
            }

            // Finally, try to get the first TN on the list.
            string TN = string.Empty;

            if (!string.IsNullOrEmpty(response.OrderResponse.CompletedNumbers[0].FullNumber))
            {
                TN = response.OrderResponse.CompletedNumbers[0].FullNumber;
            }
            else
            {
                this.response.SetJeop(
                    "A blank TN was returned.");
            }
        }
        private BComOrderResponse OrderTN()
        {
            // Create an HTTPS_ Interface.
            HTTPS_Interface httpsInterface = new HTTPS_Interface();

            // Create Order Request
            BComOrderRequest request =
                new BComOrderRequest();

            request.Order = new Order();
            request.Order.ExistingTelephoneNumberOrderType =
                new ExistingTelephoneNumberOrderType();
            request.Order.ExistingTelephoneNumberOrderType.TelephoneNumberList =
                new TelephoneNumberList();

            // Generate a pseudo oppid from coid.
            this.oppid = PseudoOppid(coid);

            // Load the request.
            try
            {
                request.Order.CustomerOrderId = this.coid.ToString();
                request.Order.SiteId          = this.siteid.ToString();
                request.Order.PeerId          = this.peerid.ToString();
                request.Order.Name            = Settings.GenerateOrderName(this.oppid, "PCO");
                request.Order.ExistingTelephoneNumberOrderType.TelephoneNumberList.Add(TN);
                request.Order.PartialAllowed = "true"; // Set to true to allow error messages.
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failed creating order from details: " + ex.Message);
            }

            // Send the request and get the response.
            BComOrderResponse response =
                httpsInterface.OrderTNs(request);

            // Do not update NativeOrders here as the TN needs to be extracted.
            // Instead make a copy of the requests raw xml.
            this.requestXML = request.ToXml();

            // Return the response.
            return(response);
        }
        private BComOrderResponse OrderTN(DataTable aviatorData)
        {
            // Create an HTTPS_ Interface.
            HTTPS_Interface httpsInterface = new HTTPS_Interface();

            // Create SipPeer Request
            BComOrderRequest request =
                new BComOrderRequest();

            request.Order = new Order();
            request.Order.ExistingTelephoneNumberOrderType =
                new ExistingTelephoneNumberOrderType();

            // Load the request.
            try
            {
                request.Order.CustomerOrderId = this.coid.ToString();
                request.Order.SiteId          = this.siteid.ToString();
                request.Order.PeerId          = this.peerid.ToString();
                request.Order.Name            = Settings.GenerateOrderName(
                    aviatorData.Rows[0]["oppid"].SafeToString(), "OMNL");
                for (int i = 0; i < aviatorData.Rows.Count; i++)
                {
                    request.Order.ExistingTelephoneNumberOrderType.TelephoneNumberList.Add(aviatorData.Rows[i]["TN"].ToString());
                }
                request.Order.PartialAllowed = "true"; // Set to true to allow error messages.
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failed loading Aviator data into order: " + ex.Message);
            }

            // Send the request and get the response.
            BComOrderResponse response =
                httpsInterface.OrderTNs(request);

            // Do not update NativeOrders here as the TN needs to be extracted.
            // Instead make a copy of the requests raw xml.
            this.requestXML = request.ToXml();

            // Return the response.
            return(response);
        }
Exemple #4
0
        private BComOrderResponse OrderTN(DataRow aviatorData)
        {
            // Create an HTTPS_ Interface.
            HTTPS_Interface httpsInterface = new HTTPS_Interface();

            // Create SipPeer Request
            BComOrderRequest request =
                new BComOrderRequest();

            request.Order = new Order();
            request.Order.RateCenterSearchAndOrderType =
                new RateCenterSearchAndOrderType();

            // Load the request.
            try
            {
                request.Order.CustomerOrderId = this.coid.ToString();
                request.Order.SiteId          = this.siteid.ToString();
                request.Order.PeerId          = this.peerid.ToString();
                request.Order.Name            = Settings.GenerateOrderName(
                    aviatorData["oppid"].SafeToString(), "OSNL");
                request.Order.RateCenterSearchAndOrderType.EnableLCA  = "false";
                request.Order.RateCenterSearchAndOrderType.Quantity   = "1";
                request.Order.RateCenterSearchAndOrderType.RateCenter = this.rc;
                request.Order.RateCenterSearchAndOrderType.State      = this.rcState;
                request.Order.PartialAllowed = "true"; // Set to true to allow error messages.
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failed loading Aviator data into order: " + ex.Message);
            }

            // Send the request and get the response.
            BComOrderResponse response =
                httpsInterface.OrderTNs(request);

            // Do not update NativeOrders here as the TN needs to be extracted.
            // Instead make a copy of the requests raw xml.
            this.requestXML = request.ToXml();

            // Return the response.
            return(response);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Clear the page.
            Response.Clear();

            // Set the type to XML.
            Response.ContentType = "text/xml";
            //Response.ContentType = "text/plain"; // For debuggin purposes.

            // Declare a response.
            this.response = new OrderMultipleNativeLineResponse();

            // First make sure the parameters are there.
            SetParameters();

            // Failed? Then Jeop.
            if (this.response.Action != "PENDING")
            {
                Response.Write(this.response.ToXml());
                return;
            }

            // Debug, test write parameter.
            //Response.Write("Oppid: " + oppid);
            //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            // Create a database interface.
            try
            {
                this.db = new DB();
            }
            catch (Exception ex)
            {
                this.response.SetJeop(
                    "Unable to open a database connection: " + ex.Message);
                Response.Write(this.response.ToXml());
                this.db.Close();
                return;
            }

            // DataTable to load install information.
            //DataRow aviatorData = null;
            DataTable aviatorData = null;

            // Load the install data.
            try
            {
                aviatorData =
                    this.db.LoadAviatorInstallTableData(oppid);
            }
            catch (Exception ex)
            {
                string jeop = "Unable to load data from Aviator: " + ex.Message;
                this.response.SetJeop(jeop);
                Response.Write(this.response.ToXml());
                this.db.JeopStep(
                    this.oppid, this.wf_id, this.wf_step_id, this.jeopname, jeop);
                this.db.Close();
                return;
            }

            // Debug, test write data.
            //string data = string.Empty;
            //foreach(object item in aviatorData.ItemArray)
            //{
            //    data += " | " + item.ToString();
            //}
            //Response.Write("Data: " + data);
            //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            // Get the cpid (account_number) from the Aviator data.
            this.cpid = -1;
            bool success = false;

            success = long.TryParse(
                aviatorData.Rows[0]["cpid"].SafeToString(), out this.cpid);

            // Failed? Then Jeop.
            if (success == false)
            {
                string jeop =
                    "Unable to parse CPID for opp: Returned value of " + aviatorData.Rows[0]["cpid"].SafeToString();
                this.response.SetJeop(jeop);
                Response.Write(this.response.ToXml());
                this.db.JeopStep(
                    this.oppid, this.wf_id, this.wf_step_id, this.jeopname, jeop);
                this.db.Close();
                return;
            }

            // Loads the BCom account, creating parts as needed.
            LoadBComAccount(aviatorData);

            // Did it fail?
            if (this.response.Action != "PENDING")
            {
                // Write the error response and exit.
                Response.Write(this.response.ToXml());
                this.db.JeopStep(
                    this.oppid, this.wf_id, this.wf_step_id, this.jeopname, this.response.Message);
                this.db.Close();
                return;
            }

            // Get the ratecenter and its state.
            this.rc      = aviatorData.Rows[0]["RC"].SafeToString();
            this.rcState = aviatorData.Rows[0]["RCState"].SafeToString();

            // Fail if the ratecenter or state is missing.
            if ((string.IsNullOrEmpty(this.rc)) ||
                (string.IsNullOrEmpty(this.rcState)))
            {
                // Write the error response and exit.
                string jeop = "RateCenter/State is missing from the Aviator data.";
                this.response.SetJeop(jeop);
                Response.Write(this.response.ToXml());
                this.db.JeopStep(
                    this.oppid, this.wf_id, this.wf_step_id, this.jeopname, jeop);
                this.db.Close();
                return;
            }

            // Debug, test write data.
            //Response.Write("RateCenter: " + this.rc + ", " + this.rcState);
            //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            // One last id to get, the coid.
            try
            {
                this.coid =
                    this.db.GenerateNativeCOID();
            }
            catch (Exception ex)
            {
                string jeop = "Unable to generate Native COID: " + ex.Message;
                this.response.SetJeop(jeop);
                Response.Write(this.response.ToXml());
                this.db.JeopStep(
                    this.oppid, this.wf_id, this.wf_step_id, this.jeopname, jeop);
                this.db.Close();
                return;
            }

            // Debug, test write data.
            //Response.Write("COID: " + this.coid.ToString());
            //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            // Now, using the ratecenter, order a TN.
            BComOrderResponse orderResponse = null;

            try
            {
                orderResponse = OrderTN(aviatorData);
            }
            catch (Exception ex)
            {
                string jeop = "Unable to order a TN for opp: " + ex.Message;
                this.response.SetJeop(jeop);
                Response.Write(this.response.ToXml());
                this.db.JeopStep(
                    this.oppid, this.wf_id, this.wf_step_id, this.jeopname, jeop);
                this.db.Close();
                return;
            }

            // Did the request fail?
            if (orderResponse.Status != "Success")
            {
                // Immediately Jeop with the error message.
                string jeop = orderResponse.ErrorMessage;
                this.response.SetJeop(jeop);

                // Update NativeOrders information.
                try
                {
                    this.db.UpdateNativeOrdersTable(
                        orderResponse, this.coid, this.cpid, this.oppid,
                        this.wf_id, this.wf_step_id, this.jeopname, string.Empty,
                        this.requestXML, this.response.Action, this.response.Message);
                }
                catch
                {
                    // Ignore the error
                }

                // Return the response.
                this.db.JeopStep(
                    this.oppid, this.wf_id, this.wf_step_id, this.jeopname, jeop);
                this.db.Close();
                // Return result.
                Response.Write(this.response.ToXml());
                return;
            }
            CheckOrder(orderResponse);
            // Extract the TN and add to NativeOrders

            /*this.TN = string.Empty;
             * try
             * {
             *  this.TN = ExtractAndUpdateTN(orderResponse);
             * }
             * catch (Exception ex)
             * {
             *  this.TN = "";
             *  this.response.SetJeop(
             *      "Error extracting TN from BCom response: " + ex.Message);
             *  // Continue from here to update the failure and return the response.
             * }
             *
             * // Debug, test write data.
             * //Response.Write("TN: " + this.TN);
             * //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);
             *
             * // Make sure the retreived TN is set in Aviator if present.
             * if (!string.IsNullOrEmpty(this.TN))
             * {
             *  try
             *  {
             *      this.db.UpdateOrderPhone(this.oppid, this.TN);
             *  }
             *  catch (Exception ex)
             *  {
             *      this.response.SetJeop(
             *          "Failed to set successful TN in Aviator! TN: " + this.TN +
             *          "; Error: " + ex.Message);
             *      // Continue from here to update the failure and return the response.
             *  }
             * }*/

            // Complete if not failed.
            if (this.response.Action == "PENDING")
            {
                this.response.SetComplete();

                // Assign the extracted TN to the response.
                this.response.Message = this.TN;

                // Now complete.
                this.db.CompleteStep(this.oppid, this.wf_id, this.wf_step_id);
            }

            // Update NativeOrders information.
            try
            {
                this.db.UpdateNativeOrdersTable(
                    orderResponse, this.coid, this.cpid, this.oppid,
                    this.wf_id, this.wf_step_id, this.jeopname, this.TN,
                    this.requestXML, this.response.Action, this.response.Message);
            }
            catch
            {
                // Ignore the error.
            }

            // Close the db
            this.db.Close();

            // Return result.
            Response.Write(this.response.ToXml());
            return;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Clear the page.
            Response.Clear();

            // Set the type to XML.
            Response.ContentType = "text/xml";
            //Response.ContentType = "text/plain"; // For debuggin purposes.

            // Declare a response.
            this.response = new OrderBandwidthTNResponse();

            // No Tn?
            if (string.IsNullOrEmpty(Request.QueryString["tn"]))
            {
                response.Action  = "Error";
                response.Message =
                    "No parameters. " +
                    "'tn' must be a ten digit telephone number.";
                Response.Write(response.ToXml());
                return;
            }
            else if (Request.QueryString["tn"].Length != 10 ||
                     !System.Text.RegularExpressions.Regex.IsMatch(Request.QueryString["tn"], @"\d{10}"))
            {
                response.Action  = "Error";
                response.Message =
                    "Bad parameters. " +
                    "'tn' must be a ten digit telephone number. TN: " + Request.QueryString["tn"];
                Response.Write(response.ToXml());
                return;
            }
            else
            {
                // Valid TN!
                this.TN = Request.QueryString["tn"];
            }

            // No MetaSwitch?
            if (string.IsNullOrEmpty(Request.QueryString["metaswitch"]))
            {
                response.Action  = "Error";
                response.Message =
                    "Invalid parameters. " +
                    "Metaswitch should be assigned as Metaswitch0 for Core or Metaswitch1 for National.";
                Response.Write(response.ToXml());
                return;
            }
            else if (Request.QueryString["metaswitch"].ToUpper() != "METASWITCH0" &&
                     Request.QueryString["metaswitch"].ToUpper() != "METASWITCH1")
            {
                response.Action  = "Error";
                response.Message =
                    "Invalid parameters. " +
                    "Metaswitch should be assigned as Metaswitch0 or Metaswitch1. The requested type is " + Request.QueryString["metaswitch"];
                Response.Write(response.ToXml());
                return;
            }
            else
            {
                // Valid metaswitch!
                this.metaswitch = Request.QueryString["metaswitch"];
            }

            // Cpid (account number)?
            if (!string.IsNullOrEmpty(Request.QueryString["accountnumber"]))
            {
                bool success  = false;
                long testcpid = -1;
                success = long.TryParse(Request.QueryString["accountnumber"], out testcpid);
                if (success)
                {
                    cpid = testcpid;
                }
            }

            // Create a database interface.
            try
            {
                this.db = new DB();
            }
            catch (Exception ex)
            {
                this.response.SetJeop(
                    "Unable to open a database connection: " + ex.Message);
                Response.Write(this.response.ToXml());
                this.db.Close();
                return;
            }

            // Loads the BCom account, creating parts as needed.
            LoadBComAccount(metaswitch);

            // One last id to get, the coid.
            try
            {
                this.coid =
                    this.db.GenerateNativeCOID();
            }
            catch (Exception ex)
            {
                string jeop = "Unable to generate Native COID: " + ex.Message;
                this.response.SetJeop(jeop);
                Response.Write(this.response.ToXml());
                this.db.Close();
                return;
            }

            // Now, using the given TN, order it.
            BComOrderResponse orderResponse = null;

            try
            {
                orderResponse = OrderTN();
            }
            catch (Exception ex)
            {
                string jeop = "Unable to order the TN: " + ex.Message;
                this.response.SetJeop(jeop);
                Response.Write(this.response.ToXml());
                this.db.Close();
                return;
            }

            // Extract the id from the response.
            this.id = string.Empty;
            try
            {
                if ((orderResponse != null) &&
                    (orderResponse.OrderResponse != null) &&
                    (orderResponse.OrderResponse.Order != null))
                {
                    if (!string.IsNullOrEmpty(orderResponse.OrderResponse.Order.id))
                    {
                        id = orderResponse.OrderResponse.Order.id;
                    }
                    else
                    {
                        this.id = "";
                        this.response.SetJeop(
                            "Error extracting id from BCom response: not found or empty.");
                        // Continue from here to update the failure and return the response.
                    }
                }
            }
            catch (Exception ex)
            {
                this.id = "";
                this.response.SetJeop(
                    "Error extracting id from BCom response: " + ex.Message);
                // Continue from here to update the failure and return the response.
            }

            // Did the request fail?
            if (orderResponse.Status != "Success")
            {
                // Immediately Jeop with the error message.
                string jeop = orderResponse.ErrorMessage;
                this.response.SetJeop(jeop);

                // Update NativeOrders information.
                try
                {
                    this.db.UpdateNativeOrdersTable(
                        orderResponse, this.coid, this.cpid, this.oppid,
                        -1, -1, string.Empty, string.Empty,
                        this.requestXML, this.response.Action, this.response.Message);
                }
                catch
                {
                    // Ignore the error
                }

                this.db.Close();
                // Return result.
                Response.Write(this.response.ToXml());
                return;
            }

            // Complete if not failed.
            if (this.response.Action == "PENDING")
            {
                this.response.SetComplete();

                // Assign the extracted id to the response.
                this.response.Message = this.id;
            }

            // Update NativeOrders information.
            try
            {
                this.db.UpdateNativeOrdersTable(
                    orderResponse, this.coid, this.cpid, this.oppid,
                    -1, -1, string.Empty, this.TN,
                    this.requestXML, this.response.Action, this.response.Message);
            }
            catch
            {
                // Ignore the error.
            }

            // Close the db
            this.db.Close();

            // Return result.
            Response.Write(this.response.ToXml());
            return;
        }