示例#1
0
        /// <summary>
        /// Gets the columns to be displayed from Bugzilla - colchange.cgi
        /// 
        /// </summary>
        /// <param name="BugzillaUrl">Url of the bugzilla system</param>
        /// <returns>Hashtable (key is column name, value is the index in the array of columns)</returns>
        public Hashtable GenerateColumnsToBeDisplayed( System.ComponentModel.BackgroundWorker backgroundWorker  )
        {
            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            HttpHelper httpRequest = new HttpHelper(_connectionId, connection.Charset);

            //GET HTML content for the page provided
            string htmlContent = httpRequest.GetFromUrl(String.Concat(connection.URL, DISPLAYED_COLUMNS_PAGE), false);

            ParseHtmlForColumnListValues(htmlContent);

            if (backgroundWorker != null)
            {
                backgroundWorker.ReportProgress(100);
            }

            return cols ;
        }
示例#2
0
        /// <summary>
        /// This method parses the buglist.cgi response html and retrives the bugs found
        /// </summary>
        /// <param name="BugzillaUrl">Url of the bugzilla system where the user is connected</param>
        /// <param name="Params">Hash containing  the columns that must be loaded and later on, displayed</param>
        /// <returns></returns>
        public List<MyZilla.BusinessEntities.Bug> SearchBugs(NameValueCollection Params)
        {
            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            string myZillaUrl = connection.URL;

            HttpHelper httpDialog = new HttpHelper(_connectionId, connection.Charset);

            myZillaUrl += SEARCH_BUGS_PAGE;// "buglist.cgi?";

            StringBuilder criterias = new StringBuilder();

            string paramFormat = "{0}={1}&";

            for (int i = 0; i < Params.Count; i++)
            {
                //compose QueryString based on the criteria selected in the interface
                for (int j = 0; j < Params.GetValues(i).Length; j++)
                {
                    criterias.Append(String.Format(paramFormat, Params.GetKey(i), Params.GetValues(i)[j]));
                }
            }

            myZillaUrl += criterias.ToString();

            string htmlContent = httpDialog.GetFromUrl(myZillaUrl + "ctype=csv", false);

            this.ParseCsvGettingBugs(htmlContent);

            return bugs;
        }
示例#3
0
        /// <summary>
        /// Get the LAST_UPDATED (delta_ts) of the specified bug.
        /// Used only for bugzilla 2.18
        /// </summary>
        /// <param name="bugzillaURL"></param>
        /// <param name="bugId"></param>
        /// <returns></returns>
        public string GetBugLastUpdated(int bugId)
        {
            string result = null;

            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            string myZillaUrl = connection.URL;

            string urlEnding = String.Format(BUG_LAST_UPDATED_URL, bugId);

            try
            {
                HttpHelper httpDialog = new HttpHelper(_connectionId, connection.Charset);

                string strContent = httpDialog.GetFromUrl(myZillaUrl + urlEnding, false);

                if (String.IsNullOrEmpty(strContent)) { }
                else {
                    result = GetStringBetween(strContent, "value=\"", "\"", strContent.IndexOf("delta_ts"), false);
                }
            }
            catch { }

            return result;
        }
示例#4
0
        private XmlNodeList GetBugsAsXML(string urlBase, string urlEnding, string charset)
        {
            XmlNodeList nodes = null;

            try
            {
                HttpHelper httpDialog = new HttpHelper(_connectionId, charset);

                string url = urlBase + urlEnding;

                httpDialog.BugzillaCharset = charset;

                string strContent = httpDialog.GetFromUrl(url, false);

                #region prevent error in loading the bugs xml

                string toFind = "urlbase=\"";

                int startIndex = strContent.IndexOf(toFind);

                int endIndex = strContent.IndexOf('"', startIndex + toFind.Length);

                string[] list = strContent.Substring(startIndex + toFind.Length, endIndex - startIndex - toFind.Length).Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries);

                if (list != null && list.GetLength(0) > 0)
                    strContent = strContent.Replace(list[0], urlBase);
                else
                    strContent = strContent.Replace(toFind + "\"", toFind + urlBase + "\"");

                startIndex = strContent.IndexOf("<!DOCTYPE");
                if (startIndex>=0){
                    endIndex = strContent.IndexOf(">", startIndex);

                    string xmlType = strContent.Substring(startIndex, endIndex-startIndex + 1);

                    strContent = strContent.Replace(xmlType, string.Empty);
                }

                #endregion

                XmlDocument doc = new XmlDocument();

                doc.LoadXml(CleanInvalidXmlChars(strContent));

                nodes = doc.GetElementsByTagName("bug");
            }
            catch (Exception ex)
            {
                MyLogger.Write(ex, "GetBugsAsXML", LoggingCategory.Exception);

                //result.ErrorMessage = ex.Message;
            }

            return nodes;
        }
示例#5
0
        /// <summary>
        /// Get the details of a bug, reading a xml structure.
        /// </summary>
        /// <param name="htmlContent"></param>
        /// <returns></returns>
        private MyZilla.BusinessEntities.Bug GetBugDetailsFromXml(string urlBase,  string urlEnding, string charset)
        {
            MyZilla.BusinessEntities.Bug result = new MyZilla.BusinessEntities.Bug();

            try
            {

                HttpHelper httpDialog = new HttpHelper(_connectionId, charset);

                string strContent =  httpDialog.GetFromUrl(urlBase + urlEnding, false);

            #if DEBUG
                //string bugDetailsFile = @"C:\Documents and Settings\Marius Zavoi\Desktop\LogFiles\show_bug.xml";
                //if (File.Exists(bugDetailsFile)){
                //    TextReader reader = new StreamReader(bugDetailsFile);
                //    using (reader) {
                //        strContent = reader.ReadToEnd();
                //    }
                //}
            #endif

                XmlDocument doc = new XmlDocument();

                string toFind = "urlbase=\"";

                int startIndex = strContent.IndexOf(toFind);

                int endIndex = strContent.IndexOf('"', startIndex + toFind.Length);

                string[] list = strContent.Substring(startIndex + toFind.Length, endIndex - startIndex - toFind.Length).Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries);

                if (list != null && list.GetLength(0)>0)
                    strContent = strContent.Replace(list[0], urlBase);
                else
                    strContent = strContent.Replace(toFind + "\"", toFind + urlBase + "\"");

                startIndex = strContent.IndexOf("<!DOCTYPE");
                if (startIndex >= 0)
                {
                    endIndex = strContent.IndexOf(">", startIndex);

                    string xmlType = strContent.Substring(startIndex, endIndex - startIndex + 1);

                    strContent = strContent.Replace(xmlType, string.Empty);
                }

                doc.LoadXml(CleanInvalidXmlChars(strContent));

                XmlNodeList bugDetail = doc.GetElementsByTagName("bug");

                result = GetBug(bugDetail[0]);

            }
            catch (Exception ex)
            {
                MyLogger.Write(ex, "GetBugDetailsFromXml", LoggingCategory.Exception);

                result.ErrorMessage = ex.Message;
            }

            return result;
        }
示例#6
0
        public string GetAttachment(int attID, bool isPicture, out Bitmap bitmap, out string errorMessage)
        {
            bitmap = null;

            string result = string.Empty  ;

            errorMessage = string.Empty;

            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            string url = String.Concat(connection.URL, ATTACHMENT_PAGE, attID);

            MyZilla.BL.Utils.HttpHelper httpDialog = new HttpHelper(_connectionId, connection.Charset);

            if (isPicture)
            {
                bitmap = httpDialog.GetPictureFromUrl(url, false);
            }
            else
            {

                string getResult = httpDialog.GetFromUrl(url, false);

                if (result.ToLower().IndexOf("error") >= 0)
                {
                    errorMessage = getResult;
                }
                else
                {
                    result = getResult;
                }

            }

            return result;
        }
示例#7
0
        public ArrayList GetValuesForProductDependentCatalogues(int classificationsCount, NameValueCollection products)
        {
            ArrayList result = new ArrayList();

            NameValueCollection resCPTS = new NameValueCollection();

            NameValueCollection resVERS = new NameValueCollection();

            // get the content of the page
            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            string myZillaUrl = connection.URL;

            HttpHelper httpDialog = new HttpHelper(_connectionId, connection.Charset);

            myZillaUrl += ADVANCED_SEARCH_BUGS_PAGE;

            string htmlContent = httpDialog.GetFromUrl(myZillaUrl, false);

            if (classificationsCount == 0)
            {
                for (int i = 0; i < products.Count; i++)
                {
                    string catalogItemName = products.GetKey(i);

                    Dictionary<string, string> res = GetSubstringForCriteria(htmlContent, "cpts[" + i.ToString() + "] = ", "];", catalogItemName);

                    foreach (KeyValuePair<string, string> entry in res)
                    {
                        resCPTS.Add(entry.Key, entry.Value);
                    }

                    res = GetSubstringForCriteria(htmlContent, "vers[" + i.ToString() + "] = ", "];", catalogItemName);

                    foreach (KeyValuePair<string, string> entry in res)
                    {
                        resVERS.Add(entry.Key, entry.Value);
                    }

                }

                result.Add(resCPTS);

                result.Add(resVERS);
            }

            return result;
        }
示例#8
0
        public bool TestConnectionToUrl(string url, string connectionType)
        {
            System.Net.CookieCollection cookies = HttpHelper.colCookies;

            bool result = true;

            try
            {
                // because the cookie collection is modified during the request, save it.

                HttpHelper httpRequest = new HttpHelper(_connectionId, this.bugzillaCharset);

                //GET HTML content for the page provided
                string htmlContent = httpRequest.GetFromUrl(url, true);

                // search in the htmlContent the string that represent the connection type
                if (htmlContent.IndexOf(connectionType) == -1)
                {
                    result = false;
                }

            }
            catch (Exception ex )
            {
                MyLogger.Write(ex, "TestConnectionToUrl", LoggingCategory.Exception);

                result = false;
            }
            finally
            {
                HttpHelper.colCookies = cookies;

            }

            return result ;
        }
示例#9
0
        public ArrayList GetSpecificCataloguesWhenManageBug(string productName, NameValueCollection Components)
        {
            MyLogger.Write("Start getting bug specific catalogs!", "GetSpecificCataloguesWhenManageBug", LoggingCategory.General);

            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            string myZillaUrl = connection.URL;

            HttpHelper httpHelper = new HttpHelper(_connectionId, connection.Charset);

            myZillaUrl = myZillaUrl + String.Format(ADD_BUG_PAGE, productName);

            //get html content
            string htmlContent = httpHelper.GetFromUrl(myZillaUrl, false);

            ParseHtmlForDependentCatalogues(new DataContainer(productName, htmlContent, Components));

            MyLogger.Write("Complete getting bug specific catalogs!", "GetSpecificCataloguesWhenManageBug", LoggingCategory.General);

            return resultSpecificCatalogues;
        }
示例#10
0
        public string GetPublishedMyZillaVersion(string url, string currentVersion)
        {
            string result = null;

            try
            {
                HttpHelper httpRequest = new HttpHelper(_connectionId, this.bugzillaCharset);

                //GET HTML content for the page provided
                string htmlContent = httpRequest.GetFromUrl(url, true);

                string[] versionGroups = htmlContent.Split('-');

                if ((versionGroups != null) && (versionGroups.GetLength(0))>=2) {

                    if (versionGroups != null && versionGroups.GetLength(0) >= 2)
                    {
                        result = versionGroups[1];
                    }
                }

            }
            catch (Exception ex)
            {
                MyLogger.Write(ex, "GetPublishedMyZillaVersion", LoggingCategory.Exception);

                result = null;
            }
            finally
            {

            }

            return result;
        }
示例#11
0
        public ArrayList GetCatalogues( string[] catalogIdList)
        {
            int pos = 0;
            int posBegin = 0;
            int posEnd = 0;

            List<string> lstOptions = null;

            string strSelect = string.Empty;

            ArrayList lstCatalogues = new ArrayList ();

            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            HttpHelper httpDialog = new HttpHelper(_connectionId, connection.Charset);

            string myZillaUrl = connection.URL;

            // get the content of the page
            myZillaUrl += ADVANCED_SEARCH_BUGS_PAGE;

            MyLogger.Write("Start getting main catalogs! Url = " + myZillaUrl, "GetCatalogues", LoggingCategory.General);

            string htmlContent = httpDialog.GetFromUrl(myZillaUrl, false);

            #if DEBUG
            MyZilla.BL.Interfaces.Utils.htmlContents = htmlContent;
            #endif

            // find the select TAG in html content.

            for (int catalogNumber = 0; catalogNumber < catalogIdList.Length; catalogNumber ++ )
            {

                pos = 0;

                lstOptions = new List<string>();

                while (pos < htmlContent.Length)
                {
                    posBegin = htmlContent.IndexOf("<select", pos);

                    if (posBegin == -1)
                    {
                        break;
                    }
                    else
                    {
                        posEnd = htmlContent.IndexOf("</select>", posBegin);

                        strSelect = htmlContent.Substring(posBegin, posEnd - posBegin);

                        if (strSelect.IndexOf("name=\"" + catalogIdList [catalogNumber ]) >= 0)
                        {
                            // the catalogue was found

                            lstOptions = HttpHelper.GetOptionsFormSelection(strSelect);

                            break;

                        }
                        else
                        {
                            pos = posEnd + 1;
                        }

                    }
                }

                lstCatalogues.Add(lstOptions);

            }

            MyLogger.Write("Complete getting main catalogs!", "GetCatalogues", LoggingCategory.General);

            return lstCatalogues;
        }
示例#12
0
        public string GetBugzillaVersion(string url)
        {
            string version = String.Empty;

            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            string urlBase = connection.URL;

            HttpHelper httpDialog = new HttpHelper(_connectionId, connection.Charset);

            string httpContent = httpDialog.GetFromUrl(String.Concat(urlBase, String.Format(BUG_DETAILS_URL, -1)), false);

            this.bugzillaCharset = httpDialog.BugzillaCharset;

            XmlDocument doc = new XmlDocument();

            string toFind = "urlbase=\"";

            int startIndex = httpContent.IndexOf(toFind);

            if (startIndex >= 0)
            {
                int endIndex = httpContent.IndexOf('"', startIndex + toFind.Length);

                if (endIndex > startIndex)
                {
                    string[] list = httpContent.Substring(startIndex + toFind.Length, endIndex - startIndex - toFind.Length).Split(new char[] { '"' }, StringSplitOptions.RemoveEmptyEntries);

                    httpContent = httpContent.Replace(list[0], urlBase);
                }
            }

            //WARNING
            //if login cookies are not generated
            //, xml is not returned and getting bugzilla version fails
            try
            {
                doc.LoadXml(httpContent);

                XmlNodeList bugVersion = doc.GetElementsByTagName("bugzilla");
                XmlNode versionNode = bugVersion[0];
                XmlElement versionElement = (XmlElement)versionNode;
                if (versionElement.HasAttributes)
                {
                    version = versionElement.Attributes["version"].InnerText;
                }
            }
            catch {
                //generic version number for cases when getting bugzilla version fails
                version = "2.0";
            }

            return version;
        }
示例#13
0
        public string GetBugzillaCharset(string url)
        {
            string version = String.Empty;

            TDSettings.ConnectionRow connection = MyZillaSettingsDataSet.GetInstance().GetConnectionById(_connectionId);

            string urlBase = connection.URL;

            HttpHelper httpDialog = new HttpHelper(_connectionId, connection.Charset);

            string httpContent = httpDialog.GetFromUrl(urlBase, false);

            this.bugzillaCharset = httpDialog.BugzillaCharset;

            return this.bugzillaCharset;
        }