Ejemplo n.º 1
0
        public static UpdateInfo ParseHtmlRow(List <string> rowHTML, int rowIndex)
        {
            int indexOffset = (rowIndex * 7);

            string id     = (rowHTML[0 + indexOffset].Split('"', '"')[1]).Trim();//id [0]
            int    pFrom1 = rowHTML[0 + indexOffset].IndexOf(";\">") + ";\">".Length;
            int    pTo1   = rowHTML[0 + indexOffset].LastIndexOf("</A>");

            string   title          = (rowHTML[0 + indexOffset].Substring(pFrom1, pTo1 - pFrom1)).Trim(); //title [1]
            string   product        = (rowHTML[1 + indexOffset]).Trim();                                  //product [2]
            string   classification = (rowHTML[2 + indexOffset]).Trim();                                  //classification [3]
            DateTime lastUpdated    = Convert.ToDateTime(rowHTML[3 + indexOffset]);                       //lastUpdated [4]
            string   version        = (rowHTML[4 + indexOffset]).Trim();                                  //version [5]
            int      pFrom2         = rowHTML[5 + indexOffset].IndexOf("_size>") + "_size>".Length;
            int      pTo2           = rowHTML[5 + indexOffset].LastIndexOf("</SPAN> <SPAN");

            string size = (rowHTML[5 + indexOffset].Substring(pFrom2, pTo2 - pFrom2)).Trim(); //size [6]

            string            downloadDialogSiteHTML = WebController.MakePost(id, Configuration.Download_dialog_url);
            OrderedDictionary downloadUrls           = WebController.GetDownloadURLs(downloadDialogSiteHTML); //downloadUrls [7]

            UpdateInfo update = new UpdateInfo(id, title, product, classification, lastUpdated, version, size, downloadUrls);

            return(update);
        }
Ejemplo n.º 2
0
        private List <UpdateInfo> CollectUpdateDataForTable(List <string> updateTitles, DataTable table)
        {
            Console.WriteLine("Attempting to collect data for " + updateTitles.Count + " updates...");
            int x = 0;
            List <UpdateInfo> updates = new List <UpdateInfo>();

            foreach (string updateTitle in updateTitles) //For each update
            {
                Console.WriteLine("\nCollecting data for update " + (x + 1) + " of " + updateTitles.Count + ".");

                Console.WriteLine("Title is: " + updateTitle);

                //If data exists in CSV file
                if (QueryController.DoesUpdateTitleExistInTable(table, updateTitle) == true)
                {
                    Console.WriteLine("Update data already exists in table. Skipping...");
                    DataRow[]         rows       = QueryController.GetUpdateInfoFromTable(table, updateTitle);
                    OrderedDictionary dictionary = new OrderedDictionary
                    {
                        { rows[0]["downloadUrls"].ToString(), rows[0]["languages"].ToString() }
                    };
                    UpdateInfo update = new UpdateInfo(
                        rows[0]["id"].ToString(),
                        rows[0]["title"].ToString(),
                        rows[0]["product"].ToString(),
                        rows[0]["classification"].ToString(),
                        Convert.ToDateTime(rows[0]["lastUpdated"]),
                        rows[0]["version"].ToString(),
                        rows[0]["size"].ToString(),
                        dictionary
                        );
                    updates.Add(update);
                }
                else //Data doesn't exist in CSV file, collect it and populate the table
                {
                    string kb = Parser.GetKbFromTitle(updateTitle);

                    if (kb.Length > 0)
                    {
                        HtmlDocument      siteAsHtml = WebController.GetSiteAsHTML(Configuration.CATALOG_URL + kb);
                        List <UpdateInfo> kbUpdates  = Parser.GetUpdateInfoFromHTML(table, siteAsHtml);
                        if (kbUpdates.Count == 0)
                        {
                            Console.WriteLine("Update not found in Update Catalog. Skipping...");
                        }
                        else
                        {
                            table.AddUpdatesToTable(kbUpdates, Configuration.TableFolderPath, Configuration.TableName);
                            updates.AddRange(kbUpdates);
                        }
                    }
                }
                x++;
            }
            return(updates);
        }