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";

            SearchTNsRequest  request  = null;
            SearchTNsResponse response = new SearchTNsResponse();

            // Build the request from the query string
            try
            {
                request =
                    new SearchTNsRequest(Request.QueryString);
            }
            catch (Exception ex)
            {
                response.SetJeop(
                    "Unable to build request from query string: " + ex.Message);
                Response.Write(response.ToXml());
                return;
            }

            // Debug, test write request.
            //Response.Write(request.ToXml());
            //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            // Neither ratecenter nor state?
            if (string.IsNullOrEmpty(request.rc) || string.IsNullOrEmpty(request.state))
            {
                response.Action  = "Error";
                response.Message =
                    "No parameters. " +
                    "Requires 'rc' and its 'state'." +
                    "Include 'quanitity' if a specific number of TNs is wanted.";
                Response.Write(response.ToXml());
                return;
            }

            // Declare a list of TNs.
            List <string> tnList = new List <string>();

            // Rate center and state?
            if (!string.IsNullOrEmpty(request.rc) && !string.IsNullOrEmpty(request.state))
            {
                // Check with BCom
                BComTnSearchResponse bcomResponse = null;
                try
                {
                    bcomResponse =
                        new HTTPS_Interface().SearchTnByRateCenter(
                            new BComTnByRateCenterRequest(
                                request.rc, request.state));
                }
                catch (Exception ex)
                {
                    response.SetJeop("Error during Tn By Ratecenter Search: " + ex.Message);
                    Response.Write(response.ToXml());
                    return;
                }

                // Debug, Print out response.
                //Response.Write(Serializer.SerializeObject(bcomResponse, typeof(BComTnSearchResponse)));
                //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

                // Success?
                if (bcomResponse.Status == "Success")
                {
                    // Check for an returned TNs.
                    if (bcomResponse.SearchResult != null &&
                        bcomResponse.SearchResult.TelephoneNumberList != null &&
                        bcomResponse.SearchResult.TelephoneNumberList.Count > 0 &&
                        HTTPS_Interface.LooseStringToInteger(
                            bcomResponse.SearchResult.ResultCount) > 0)
                    {
                        // Add to the list, if not already there.
                        foreach (string tn in bcomResponse.SearchResult.TelephoneNumberList)
                        {
                            if (!tnList.Contains(tn))
                            {
                                tnList.Add(tn);
                            }
                        }
                    }
                }
                else
                {
                    // Get error message
                    string errorMessage = string.Empty;
                    try
                    {
                        errorMessage =
                            bcomResponse.ErrorCode + " - " +
                            bcomResponse.ErrorMessage;
                    }
                    catch
                    {
                        errorMessage = "Error: Unable to parse error response.";
                    }

                    // Return error
                    response.SetJeop(errorMessage);
                    Response.Write(response.ToXml());
                    return;
                }
            }

            // Any TNs?
            if (tnList.Count < 1)
            {
                response.SetError("No TNs were returned.");
            }
            // Complete!
            else
            {
                response.SetComplete();
                // Add Tn list
                response.tns =
                    tnList.ToArray();
            }

            // Return result.
            Response.Write(response.ToXml());
            return;
        }
Example #2
0
        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";

            CheckServiceRequest  request  = null;
            CheckServiceResponse response = new CheckServiceResponse();

            // Build the request from the query string
            try
            {
                request =
                    new CheckServiceRequest(Request.QueryString);
            }
            catch (Exception ex)
            {
                response.SetJeop(
                    "Unable to build request from query string: " + ex.Message);
                Response.Write(response.ToXml());
                return;
            }

            // Debug, test write request.
            //Response.Write(request.ToXml());
            //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            // Neither tns or zip?
            if (string.IsNullOrEmpty(request.oppid) &&
                string.IsNullOrEmpty(Request.QueryString["tns"]) &&
                string.IsNullOrEmpty(request.zip))
            {
                response.Action  = "Error";
                response.Message =
                    "No parameters. " +
                    "'oppid' loads the parameters from the database. " +
                    "'tns' is a list of semicolon delimited porting tns. " +
                    "'zip' is a zipcode to check for available tns. " +
                    "Zipcode must be in the XXXXX or XXXXX-XXXX format.";
                Response.Write(response.ToXml());
                return;
            }

            // If the oppid is set, try to get the tns or zip from the database.
            DB db = new DB();

            if (!string.IsNullOrEmpty(request.oppid))
            {
                try
                {
                    request =
                        db.LoadCheckServiceRequest(request.oppid);
                }
                catch (Exception ex)
                {
                    response.SetJeop("Error loading request parameters from database: " + ex.Message);
                    Response.Write(response.ToXml());
                    return;
                }
            }

            // Still no tns or zip?
            if (request.tns == null && request.zip == null)
            {
                response.SetJeop("Error loading request parameters from database. No tns or zip returned.");
                Response.Write(response.ToXml());
                return;
            }

            // To allow both zip check and LNP check error messages, declare flag and jeop message.
            bool   jeopFlag    = false;
            string jeopMessage = string.Empty;

            // Any TNs? Do lnp check.
            if (request.tns != null && request.tns.Length > 0)
            {
                // Check with BCom
                BComLnpCheckResponse bcomResponse = null;
                try
                {
                    bcomResponse =
                        new HTTPS_Interface().LnpCheck(
                            new BComLnpCheckRequest(
                                request.tns));
                }
                catch (Exception ex)
                {
                    response.SetJeop("Error during LNP Check: " + ex.Message);
                    Response.Write(response.ToXml());
                    return;
                }

                // Debug, Print out response.
                //Response.Write(Serializer.SerializeObject(bcomResponse, typeof(BComLnpCheckResponse)));
                //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

                // Success?
                if (bcomResponse.Status == "Success")
                {
                    // Unsupported rate centers, aka LNP Check said no?
                    if (bcomResponse.NumberPortabilityResponse != null &&
                        bcomResponse.NumberPortabilityResponse.UnsupportedRateCenters != null &&
                        bcomResponse.NumberPortabilityResponse.UnsupportedRateCenters.Length > 0)
                    {
                        // Build a list of each unsupported TN
                        string tnList = string.Empty;
                        // For each Ratecenter Group
                        foreach (RateCenterGroup rcg in bcomResponse.NumberPortabilityResponse.UnsupportedRateCenters)
                        {
                            // If there's a tn list
                            if (rcg.TnList != null)
                            {
                                // Add each unsupported TN.
                                foreach (string tn in rcg.TnList)
                                {
                                    tnList += tn + " ";
                                }
                            }
                        }
                        // Trim the list
                        tnList = tnList.Trim();
                        // Set Jeop flag and message.
                        jeopFlag    = true;
                        jeopMessage = "The following TNs cannot be ported: " + tnList;
                    }
                }
                else
                {
                    // Get error message
                    string errorMessage = string.Empty;
                    try
                    {
                        errorMessage =
                            bcomResponse.ErrorCode + " - " +
                            bcomResponse.ErrorMessage;
                    }
                    catch
                    {
                        errorMessage = "Error: Unable to parse error response.";
                    }

                    // Return error
                    response.SetJeop(errorMessage);
                    Response.Write(response.ToXml());
                    return;
                }
            }

            // Zip code? Do a number check.
            if (!string.IsNullOrEmpty(request.zip))
            {
                // Check with BCom
                BComTnSearchResponse bcomResponse = null;
                try
                {
                    var bcomRequest = new BComTnByZipRequest(request.zip);
                    bcomRequest.Quantity = "1";

                    bcomResponse = new HTTPS_Interface().SearchTnByZip(
                        bcomRequest);
                }
                catch (Exception ex)
                {
                    response.SetJeop("Error during Zip Check: " + ex.Message);
                    Response.Write(response.ToXml());
                    return;
                }

                // Debug, Print out response.
                //Response.Write(Serializer.SerializeObject(bcomResponse, typeof(BComTnSearchResponse)));
                //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

                // Success?
                if (bcomResponse.Status == "Success")
                {
                    // No results? aka Zip check said no?
                    if (bcomResponse.SearchResult == null ||
                        bcomResponse.SearchResult.ResultCount == null ||
                        HTTPS_Interface.LooseStringToInteger(
                            bcomResponse.SearchResult.ResultCount) < 1)
                    {
                        // Set Jeop flag and message.
                        jeopFlag    = true;
                        jeopMessage = "No TNs available for " + request.zip + ".";
                    }
                }
                else
                {
                    // Get error message
                    string errorMessage = string.Empty;
                    try
                    {
                        errorMessage =
                            bcomResponse.ErrorCode + " - " +
                            bcomResponse.ErrorMessage;
                    }
                    catch
                    {
                        errorMessage = "Error: Unable to parse error response.";
                    }

                    // Return error
                    response.SetJeop(errorMessage);
                    Response.Write(response.ToXml());
                    return;
                }
            }

            // Jeop?
            if (jeopFlag)
            {
                response.SetJeop(jeopMessage);
            }
            // Complete!
            else
            {
                response.SetComplete();
            }

            // Return result.
            Response.Write(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";

            SearchTNsRequest  request  = null;
            SearchTNsResponse response = new SearchTNsResponse();

            // Build the request from the query string
            try
            {
                request =
                    new SearchTNsRequest(Request.QueryString);
            }
            catch (Exception ex)
            {
                response.SetJeop(
                    "Unable to build request from query string: " + ex.Message);
                Response.Write(response.ToXml());
                return;
            }

            // Debug, test write request.
            //Response.Write(request.ToXml());
            //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

            // Neither oppid, npanxx, ratecenter, nor zip?
            if (string.IsNullOrEmpty(request.oppid) &&
                string.IsNullOrEmpty(request.npanxx) &&
                (string.IsNullOrEmpty(request.rc) || string.IsNullOrEmpty(request.state)) &&
                string.IsNullOrEmpty(request.zip))
            {
                response.Action  = "Error";
                response.Message =
                    "No parameters. " +
                    "'oppid' loads the parameters from the database. " +
                    "Include a combination of: 'npanxx' or 'npa' and 'nxx', " +
                    "'rc' and its 'state', and 'zip'. " +
                    "Zipcode must be in the XXXXX or XXXXX-XXXX format.";
                Response.Write(response.ToXml());
                return;
            }

            // If the oppid is set, try to get the rc or zip from the database.
            DB db = new DB();

            if (!string.IsNullOrEmpty(request.oppid))
            {
                try
                {
                    request =
                        db.LoadSearchTNsRequest(request.oppid);
                }
                catch (Exception ex)
                {
                    response.SetJeop("Error loading request parameters from database: " + ex.Message);
                    Response.Write(response.ToXml());
                    return;
                }
            }

            // Still no rc or zip?
            if ((string.IsNullOrEmpty(request.rc) && string.IsNullOrEmpty(request.state)) ||
                string.IsNullOrEmpty(request.zip))
            {
                response.SetJeop("Error loading request parameters from database. No ratecenter or zip returned.");
                Response.Write(response.ToXml());
                return;
            }

            // Declare a list of TNs.
            List <string> tnList = new List <string>();

            // NPANXX?
            if (!string.IsNullOrEmpty(request.npanxx))
            {
                // Check with BCom
                BComTnSearchResponse bcomResponse = null;
                try
                {
                    bcomResponse =
                        new HTTPS_Interface().SearchTnByNpaNxx(
                            new BComTnByNpaNxxRequest(
                                request.npa, request.nxx));
                }
                catch (Exception ex)
                {
                    response.SetError("Error during Tn By NpaNxx Search: " + ex.Message);
                    Response.Write(response.ToXml());
                    return;
                }

                // Debug, Print out response.
                //Response.Write(Serializer.SerializeObject(bcomResponse, typeof(BComTnSearchResponse)));
                //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

                // Success?
                if (bcomResponse.Status == "Success")
                {
                    // Check for an returned TNs.
                    if (bcomResponse.SearchResult != null &&
                        bcomResponse.SearchResult.TelephoneNumberList != null &&
                        bcomResponse.SearchResult.TelephoneNumberList.Count > 0 &&
                        HTTPS_Interface.LooseStringToInteger(
                            bcomResponse.SearchResult.ResultCount) > 0)
                    {
                        // Add to the list, if not already there.
                        foreach (string tn in bcomResponse.SearchResult.TelephoneNumberList)
                        {
                            if (!tnList.Contains(tn))
                            {
                                tnList.Add(tn);
                            }
                        }
                    }
                }
                else
                {
                    // Get error message
                    string errorMessage = string.Empty;
                    try
                    {
                        errorMessage =
                            bcomResponse.ErrorCode + " - " +
                            bcomResponse.ErrorMessage;
                    }
                    catch
                    {
                        errorMessage = "Error: Unable to parse error response.";
                    }

                    // Return error
                    response.SetJeop(errorMessage);
                    Response.Write(response.ToXml());
                    return;
                }
            }

            // Rate center and state?
            if (!string.IsNullOrEmpty(request.rc) && !string.IsNullOrEmpty(request.state))
            {
                // Check with BCom
                BComTnSearchResponse bcomResponse = null;
                try
                {
                    bcomResponse =
                        new HTTPS_Interface().SearchTnByRateCenter(
                            new BComTnByRateCenterRequest(
                                request.rc, request.state));
                }
                catch (Exception ex)
                {
                    response.SetJeop("Error during Tn By Ratecenter Search: " + ex.Message);
                    Response.Write(response.ToXml());
                    return;
                }

                // Debug, Print out response.
                //Response.Write(Serializer.SerializeObject(bcomResponse, typeof(BComTnSearchResponse)));
                //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

                // Success?
                if (bcomResponse.Status == "Success")
                {
                    // Check for an returned TNs.
                    if (bcomResponse.SearchResult != null &&
                        bcomResponse.SearchResult.TelephoneNumberList != null &&
                        bcomResponse.SearchResult.TelephoneNumberList.Count > 0 &&
                        HTTPS_Interface.LooseStringToInteger(
                            bcomResponse.SearchResult.ResultCount) > 0)
                    {
                        // Add to the list, if not already there.
                        foreach (string tn in bcomResponse.SearchResult.TelephoneNumberList)
                        {
                            if (!tnList.Contains(tn))
                            {
                                tnList.Add(tn);
                            }
                        }
                    }
                }
                else
                {
                    // Get error message
                    string errorMessage = string.Empty;
                    try
                    {
                        errorMessage =
                            bcomResponse.ErrorCode + " - " +
                            bcomResponse.ErrorMessage;
                    }
                    catch
                    {
                        errorMessage = "Error: Unable to parse error response.";
                    }

                    // Return error
                    response.SetJeop(errorMessage);
                    Response.Write(response.ToXml());
                    return;
                }
            }

            // Zip?
            if (!string.IsNullOrEmpty(request.zip))
            {
                // Check with BCom
                BComTnSearchResponse bcomResponse = null;
                try
                {
                    bcomResponse =
                        new HTTPS_Interface().SearchTnByZip(
                            new BComTnByZipRequest(
                                request.zip));
                }
                catch (Exception ex)
                {
                    response.SetJeop("Error during Tn By Zip Search: " + ex.Message);
                    Response.Write(response.ToXml());
                    return;
                }

                // Debug, Print out response.
                //Response.Write(Serializer.SerializeObject(bcomResponse, typeof(BComTnSearchResponse)));
                //Response.Write(Environment.NewLine + Environment.NewLine + Environment.NewLine);

                // Success?
                if (bcomResponse.Status == "Success")
                {
                    // Check for an returned TNs.
                    if (bcomResponse.SearchResult != null &&
                        bcomResponse.SearchResult.TelephoneNumberList != null &&
                        bcomResponse.SearchResult.TelephoneNumberList.Count > 0 &&
                        HTTPS_Interface.LooseStringToInteger(
                            bcomResponse.SearchResult.ResultCount) > 0)
                    {
                        // Add to the list, if not already there.
                        foreach (string tn in bcomResponse.SearchResult.TelephoneNumberList)
                        {
                            if (!tnList.Contains(tn))
                            {
                                tnList.Add(tn);
                            }
                        }
                    }
                }
                else
                {
                    // Get error message
                    string errorMessage = string.Empty;
                    try
                    {
                        errorMessage =
                            bcomResponse.ErrorCode + " - " +
                            bcomResponse.ErrorMessage;
                    }
                    catch
                    {
                        errorMessage = "Error: Unable to parse error response.";
                    }

                    // Return error
                    response.SetJeop(errorMessage);
                    Response.Write(response.ToXml());
                    return;
                }
            }

            // Any TNs?
            if (tnList.Count < 1)
            {
                response.SetError("No TNs were returned.");
            }
            // Complete!
            else
            {
                response.SetComplete();
                // Add Tn list
                response.tns =
                    tnList.ToArray();
            }

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