/// <summary>
        /// 6/21/2012
        /// Links to Parts Registry pages and parses source code in order to obtain general information for a 
        /// particular part
        /// @ Nicole Francisco & Veronica Lin
        /// </summary>
        /// <param name="link">Particular extension of URL specific to this page</param>

        public RegDataSheet(string link)
        {
            _name = "";
            _type = "";
            _none = true;
            _terminator = new Terminators();
            _promoter = new Promoter();
            _rbs = new RBS();
            _gene = new Gene();
            _basicInfo = new BasicInfo();
            _description = new Description();
            //_protocol = new Protocol();
            _reference = new Reference();

            bool linkValid = true;

            #region HTML Web Request
            //the first link was set to -1 if no results showed up
            if (link.Equals("http://partsregistry.org/-1"))
            {
                linkValid = false;
            }

            if (linkValid)
            {
                try
                {

                    //Open a connection to PubMed publication page to get the information
                    Uri uri = new Uri(link);
                    // used to build entire input
                    StringBuilder sb = new StringBuilder();

                    // used on each read operation
                    byte[] buf = new byte[8192];

                    // prepare the web page we will be asking for
                    HttpWebRequest request =
                        (HttpWebRequest)WebRequest.Create(uri);

                    // execute the request
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    // we will read data via the response stream
                    Stream resStream = response.GetResponseStream();
                    string tempString = null;
                    int count = 0;

                    do
                    {
                        // fill the buffer with data
                        count = resStream.Read(buf, 0, buf.Length);

                        // make sure we read some data
                        if (count != 0)
                        {
                            // translate from bytes to ASCII text
                            tempString = Encoding.ASCII.GetString(buf, 0, count);

                            // continue building the string
                            sb.Append(tempString);
                        }
                    }
                    while (count > 0); // any more data to read?

            #endregion

                    String htmlText = sb.ToString(); //keep original to have objects parse through and find
                    //specific information
                    String tempText = sb.ToString(); //will be parsed through in this top-level method to find name and type of part
                    String sourceText = sb.ToString(); //will be parsed for sections of source code each class needs
                    int index = 0;
    

                    //find name of page
                    string pageTitle = "<h1 class='firstHeading'>"; //length: 25
                    string typeImg = "<img style='padding-top:0px' src='http://partsregistry.org/images/partbypart/icon_";
                    string partLead = "Part:";

                    //strings needed for each big class
                    string descriptionText = "";
                    string referenceText = "";

                    string categoriesBox = "";
                    string parametersBox = "";

                    if (sourceText.Contains("Designed by"))
                    {
                        index = sourceText.IndexOf("Designed by ");
                        sourceText = sourceText.Substring(index);
                        referenceText = sourceText.Substring(0, sourceText.IndexOf("</div>"));
                    }

                    if (sourceText.Contains("Assembly Compatibility:<UL>"))
                    {
                        index = sourceText.IndexOf("Assembly Compatibility:<UL>");
                        sourceText = sourceText.Substring(index);
                        descriptionText = sourceText.Substring(0, sourceText.IndexOf("<DIV id='reviews'>"));
                    }

                    if (sourceText.Contains("<div style='border:1px solid #aaa;'>"))
                    {
                        index = sourceText.IndexOf("<div style='border:1px solid #aaa;'>");
                        sourceText = sourceText.Substring(index);
                        categoriesBox = sourceText.Substring(0, sourceText.IndexOf("</div>"));
                    }

                    if (sourceText.Contains("<div id='parameters'>"))
                    {
                        index = sourceText.IndexOf("<div id='parameters'>");
                        sourceText = sourceText.Substring(index);
                        parametersBox = sourceText.Substring(0, sourceText.IndexOf("<!--"));
                    }

                    if (tempText.Contains(typeImg)) //checks if this page is a parts page
                    {
                        //Find type of the part
                        index = tempText.IndexOf(typeImg) + typeImg.Length;
                        tempText = tempText.Substring(index);
                        string temp = tempText.Substring(0, tempText.IndexOf("'>"));


                        //first case, where the type of the part is RBS
                        if (htmlText.Contains("rbs"))
                        {
                            //if (temp == "rbs.png" || htmlText.Contains("//rbs/prokaryote/regulated/issacs"))
                            //{
                                _type = "rbs";
                                _rbs = new RBS(categoriesBox);
                            //}
                            //Console.WriteLine("RBS!");
                        }
                        //second case, where the type of the part is promoter (different images for
                        //different types of promoters)
                        else if (htmlText.Contains("//promoter"))
                        {
                                _type = "promoter";
                                _promoter = new Promoter(categoriesBox + " " + parametersBox);
                                //Console.WriteLine("PROMOTER!");
                        
                        //if (temp == "regulatory.png" || temp == "reporter.png" ||
                        //    temp == "generator.png" || temp == "signalling.png" ||
                        //    temp == "intermediate.png" || temp == "composite.png")
                        //{
                            

                        }
                        //third case, where the type of the part is terminator
                        else if (temp == "terminator.png")
                        {
                            _type = "terminator";
                            _terminator = new Terminators(parametersBox);
                            //Console.WriteLine("TERMINATOR!");
                        }
                        //fourth case, where the type of the part is gene or protein coding sequence
                        else if (temp == "coding.png")
                        {
                            _type = "gene";
                            _gene = new Gene(categoriesBox);
                            //Console.WriteLine("GENE!");
                        }
                    }
                    //last case, where type of part is none of the 4 classified parts above
                    else
                    {
                        _none = false;
                    }

                    //Finding page title

                    //case where page is not a parts page
                    if (_none == false)
                    {
                        index = tempText.IndexOf("<h1 class=\"firstHeading\">") + "<h1 class=\"firstHeading\">".Length;
                        tempText = tempText.Substring(index);
                        _name = tempText.Substring(0, tempText.IndexOf("</h1>"));
                    }
                    //case where page is a parts page
                    else
                    {
                        index = tempText.IndexOf(pageTitle) + pageTitle.Length + partLead.Length;
                        tempText = tempText.Substring(index);
                        _name = tempText.Substring(0, tempText.IndexOf("</h1>"));
                    }

                    //string protocolLink = "http://partsregistry.org/cgi/partsdb/related.cgi?part=" + _name;

                    //if the page is a parts page
                    if (_none)
                    {
                        _basicInfo = new BasicInfo(htmlText, _type, _name);
                        //Console.WriteLine(_basicInfo); 
                        _description = new Description(descriptionText);
                        //Console.WriteLine(_description); 
                        //_protocol = new Protocol(protocolLink);
                        //Console.WriteLine(_protocol); 
                        _reference = new Reference(referenceText);
                        //Console.WriteLine(_reference); 
                    }

                    resStream.Close();
                    response.Close();
                }
                catch (Exception ex)
                {
                    Console.Write("Exception : " + ex.Message);
                }
            }
        }
 public RegDataSheet()
 {
     _name = "test";
     _type = "test";
     _none = true;
     _terminator = new Terminators();
     _promoter = new Promoter();
     _rbs = new RBS();
     _gene = new Gene();
     _basicInfo = new BasicInfo();
     _description = new Description();
     //_protocol = new Protocol();
     _reference = new Reference();
 }
        /// <summary>
        /// 6/21/2012
        /// Links to Parts Registry pages and parses source code in order to obtain general information for a
        /// particular part
        /// @ Nicole Francisco & Veronica Lin
        /// </summary>
        /// <param name="link">Particular extension of URL specific to this page</param>

        public RegDataSheet(string link)
        {
            _name        = "";
            _type        = "";
            _none        = true;
            _terminator  = new Terminators();
            _promoter    = new Promoter();
            _rbs         = new RBS();
            _gene        = new Gene();
            _basicInfo   = new BasicInfo();
            _description = new Description();
            //_protocol = new Protocol();
            _reference = new Reference();

            bool linkValid = true;

            #region HTML Web Request
            //the first link was set to -1 if no results showed up
            if (link.Equals("http://partsregistry.org/-1"))
            {
                linkValid = false;
            }

            if (linkValid)
            {
                try
                {
                    //Open a connection to PubMed publication page to get the information
                    Uri uri = new Uri(link);
                    // used to build entire input
                    StringBuilder sb = new StringBuilder();

                    // used on each read operation
                    byte[] buf = new byte[8192];

                    // prepare the web page we will be asking for
                    HttpWebRequest request =
                        (HttpWebRequest)WebRequest.Create(uri);

                    // execute the request
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    // we will read data via the response stream
                    Stream resStream  = response.GetResponseStream();
                    string tempString = null;
                    int    count      = 0;

                    do
                    {
                        // fill the buffer with data
                        count = resStream.Read(buf, 0, buf.Length);

                        // make sure we read some data
                        if (count != 0)
                        {
                            // translate from bytes to ASCII text
                            tempString = Encoding.ASCII.GetString(buf, 0, count);

                            // continue building the string
                            sb.Append(tempString);
                        }
                    }while (count > 0); // any more data to read?

                    #endregion

                    String htmlText = sb.ToString();   //keep original to have objects parse through and find
                    //specific information
                    String tempText   = sb.ToString(); //will be parsed through in this top-level method to find name and type of part
                    String sourceText = sb.ToString(); //will be parsed for sections of source code each class needs
                    int    index      = 0;


                    //find name of page
                    string pageTitle = "<h1 class='firstHeading'>"; //length: 25
                    string typeImg   = "<img style='padding-top:0px' src='http://partsregistry.org/images/partbypart/icon_";
                    string partLead  = "Part:";

                    //strings needed for each big class
                    string descriptionText = "";
                    string referenceText   = "";

                    string categoriesBox = "";
                    string parametersBox = "";

                    if (sourceText.Contains("Designed by"))
                    {
                        index         = sourceText.IndexOf("Designed by ");
                        sourceText    = sourceText.Substring(index);
                        referenceText = sourceText.Substring(0, sourceText.IndexOf("</div>"));
                    }

                    if (sourceText.Contains("Assembly Compatibility:<UL>"))
                    {
                        index           = sourceText.IndexOf("Assembly Compatibility:<UL>");
                        sourceText      = sourceText.Substring(index);
                        descriptionText = sourceText.Substring(0, sourceText.IndexOf("<DIV id='reviews'>"));
                    }

                    if (sourceText.Contains("<div style='border:1px solid #aaa;'>"))
                    {
                        index         = sourceText.IndexOf("<div style='border:1px solid #aaa;'>");
                        sourceText    = sourceText.Substring(index);
                        categoriesBox = sourceText.Substring(0, sourceText.IndexOf("</div>"));
                    }

                    if (sourceText.Contains("<div id='parameters'>"))
                    {
                        index         = sourceText.IndexOf("<div id='parameters'>");
                        sourceText    = sourceText.Substring(index);
                        parametersBox = sourceText.Substring(0, sourceText.IndexOf("<!--"));
                    }

                    if (tempText.Contains(typeImg)) //checks if this page is a parts page
                    {
                        //Find type of the part
                        index    = tempText.IndexOf(typeImg) + typeImg.Length;
                        tempText = tempText.Substring(index);
                        string temp = tempText.Substring(0, tempText.IndexOf("'>"));


                        //first case, where the type of the part is RBS
                        if (htmlText.Contains("rbs"))
                        {
                            //if (temp == "rbs.png" || htmlText.Contains("//rbs/prokaryote/regulated/issacs"))
                            //{
                            _type = "rbs";
                            _rbs  = new RBS(categoriesBox);
                            //}
                            //Console.WriteLine("RBS!");
                        }
                        //second case, where the type of the part is promoter (different images for
                        //different types of promoters)
                        else if (htmlText.Contains("//promoter"))
                        {
                            _type     = "promoter";
                            _promoter = new Promoter(categoriesBox + " " + parametersBox);
                            //Console.WriteLine("PROMOTER!");

                            //if (temp == "regulatory.png" || temp == "reporter.png" ||
                            //    temp == "generator.png" || temp == "signalling.png" ||
                            //    temp == "intermediate.png" || temp == "composite.png")
                            //{
                        }
                        //third case, where the type of the part is terminator
                        else if (temp == "terminator.png")
                        {
                            _type       = "terminator";
                            _terminator = new Terminators(parametersBox);
                            //Console.WriteLine("TERMINATOR!");
                        }
                        //fourth case, where the type of the part is gene or protein coding sequence
                        else if (temp == "coding.png")
                        {
                            _type = "gene";
                            _gene = new Gene(categoriesBox);
                            //Console.WriteLine("GENE!");
                        }
                    }
                    //last case, where type of part is none of the 4 classified parts above
                    else
                    {
                        _none = false;
                    }

                    //Finding page title

                    //case where page is not a parts page
                    if (_none == false)
                    {
                        index    = tempText.IndexOf("<h1 class=\"firstHeading\">") + "<h1 class=\"firstHeading\">".Length;
                        tempText = tempText.Substring(index);
                        _name    = tempText.Substring(0, tempText.IndexOf("</h1>"));
                    }
                    //case where page is a parts page
                    else
                    {
                        index    = tempText.IndexOf(pageTitle) + pageTitle.Length + partLead.Length;
                        tempText = tempText.Substring(index);
                        _name    = tempText.Substring(0, tempText.IndexOf("</h1>"));
                    }

                    //string protocolLink = "http://partsregistry.org/cgi/partsdb/related.cgi?part=" + _name;

                    //if the page is a parts page
                    if (_none)
                    {
                        _basicInfo = new BasicInfo(htmlText, _type, _name);
                        //Console.WriteLine(_basicInfo);
                        _description = new Description(descriptionText);
                        //Console.WriteLine(_description);
                        //_protocol = new Protocol(protocolLink);
                        //Console.WriteLine(_protocol);
                        _reference = new Reference(referenceText);
                        //Console.WriteLine(_reference);
                    }

                    resStream.Close();
                    response.Close();
                }
                catch (Exception ex)
                {
                    Console.Write("Exception : " + ex.Message);
                }
            }
        }