Пример #1
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";

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