public ActionResult GetView(string URL) { WebFetch wFetch = new WebFetch(); GenericViewModel Model = new GenericViewModel(); Model.DisplayString = wFetch.GetView(URL); return PartialView("RefreshView",Model); }
public ActionResult GetView(string URL) { WebFetch wFetch = new WebFetch(); GenericViewModel Model = new GenericViewModel(); Model.DisplayString = wFetch.GetView(URL); return(PartialView("RefreshView", Model)); }
/// <summary> /// Search for and download the specified gitignore, fails if not found /// </summary> /// <param name="ignore"></param> /// <returns>The downloaded .gitignore contents as a string</returns> /// <exception cref="FileNotFoundException">File was not found in the repository</exception> /// <Example> /// Input: "Visual Studio Code" -- Downloads visualstudiocode.gitignore and returns contents /// </Example> public string download(string ignore) { if (cache.Data.ContainsKey(ignore)) { if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Downloading .gitignore for {ignore}"); } return(WebFetch.fetch(cache.Data[ignore])); } else { Console.WriteLine($"Exact match to {ignore} not found. "); IList <String> searchResults = search(ignore); if (searchResults.Count > 1) { int choice = UserInputReader.EnumerateChoices( $"There are {searchResults.Count} .gitignore files similar to your choice.", "Enter a selection:", searchResults ); if (choice > -1) { // In the case that search adds extra lines for information, clean it up string choiceName = new StringReader(searchResults[choice]).ReadLine(); if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Downloading .gitignore for {choiceName}"); } return(WebFetch.fetch(cache.Data[choiceName])); } } else if (searchResults.Count == 1) { if (UserInputReader.GetConfirmation($".gitignore {ignore} not found. Did you mean {searchResults[0]}?", false)) { string choiceName = new StringReader(searchResults[0]).ReadLine(); if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Downloading .gitignore for {choiceName}"); } return(WebFetch.fetch(cache.Data[choiceName])); } } } throw new System.IO.FileNotFoundException("Specified .gitignore was not found in the Repository."); }
private void LoadWebImage() { Dialogs.LoadWebImage dialog = new Dialogs.LoadWebImage(); if (dialog.Run() == ResponseType.Ok && dialog.Url != null) { WebFetch webFetch = new WebFetch(dialog.Url); string fileName = null; try { if (dialog.Save == true) { string name = dialog.Url.Substring(dialog.Url.LastIndexOf('/') + 1); fileName = System.IO.Path.Combine(Paths.WebImagesDirectory, name); } else { fileName = System.IO.Path.GetTempFileName(); } webFetch.Save(fileName); } catch (Exception e) { MessageErrorDialog("Save Web Image", e.Message); } try { LoadImage(fileName, dialog.Save); } catch (Exception e) { MessageErrorDialog("Load Web Image", e.Message); // Delete Saved File if (dialog.Save == true) { File.Delete(fileName); } } // Delete Temp File if (dialog.Save == false) { File.Delete(fileName); } } dialog.Destroy(); }
/// <summary> /// Call before using the cache dictionary to ensure it is up to date /// </summary> /// <returns></returns> public ListingCache getCache() { ListingCache cache; DirectoryInfo pathInfo = new DirectoryInfo(cachePath); Action <ListingCache> cacheUpdate = (c) => { // Gets the latest cache from github if (flags.HasFlag(Options.Verbose)) { Console.WriteLine("Updating cache in memory from Github..."); } c.Update( Listing.FromJson( WebFetch.fetch(apiURL) ) ); if (flags.HasFlag(Options.Verbose)) { Console.WriteLine("Cache updated!"); } }; if (File.Exists(pathInfo.FullName)) { // Load cache from file cache = JsonConvert.DeserializeObject <ListingCache>(File.ReadAllText(pathInfo.FullName)); cache.flags = flags; // Get info branch info from Github Branch master = Branch.FromJson(WebFetch.fetch(branchURL)); if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Cache successfully loaded from {pathInfo.FullName}"); } // Get the latest commits timestamp DateTimeOffset lastCommitDate = master.Commit.Commit.Author.Date; // Check the timestamp // Could probably get by just checking the last changed time on the file instead of from cache timestamp? if (DateTimeOffset.Compare(lastCommitDate, cache.TimeStamp) <= 0) { if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Cache is outdated."); } cacheUpdate(cache); saveCache(pathInfo.FullName, cache); } else if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Cache up to date with Github, no updates needed."); } } else { // Cache file doesn't exist, so create it and (if we're allowed) save it // and (if we're allowed) save it to ~/.getignore.cache if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"No cache found, creating in memory..."); } cache = new ListingCache(flags); cacheUpdate(cache); saveCache(pathInfo.FullName, cache); } return(cache); }
public override string Fetch(DataRow dr) { Initialize(dr, true); string lic_no = dr["lic_no"].ToString().Replace(".", "").Replace("-", "").Replace("_", "").Replace("/", "").Replace("\\", "").Replace(" ", "").Trim().ToUpper(); string firstName = dr["dr_fname"].ToString().Trim(); string lastName = dr["dr_lname"].ToString().Trim(); string org = dr["orgName"].ToString().Trim(); if (String.IsNullOrEmpty(org)) { return(ErrorMsg.Custom("Invalid organization name")); } if (String.IsNullOrEmpty(lic_no)) { return(ErrorMsg.InvalidLicense); } else if (String.IsNullOrEmpty(firstName) || String.IsNullOrEmpty(lastName)) { return(ErrorMsg.InvalidFirstLastName); } ArrayList profsToQuery = GetProfsToQuery(dr["drtitle"].ToString().ToUpper()); if (profsToQuery.Count == 0) { if (org == "Georgia State Board of Optometry") { profsToQuery = GetProfsToQuery("OPT"); } else if (org == "Georgia Board of Nursing") { profsToQuery = GetProfsToQuery("RN"); } else if (org == "Georgia State Board of Examiners of Psychologists") { profsToQuery = GetProfsToQuery("PSY"); } else if (org == "Georgia Board of Chiropractic Examiners") { profsToQuery = GetProfsToQuery("CHIR"); } else if (org == "Georgia Board of Marriage and Family Therapists") { profsToQuery = GetProfsToQuery("MFT"); } else if (org == "Georgia Board of Professional Counselors") { profsToQuery = GetProfsToQuery("LPC"); } else if (org == "Georgia State Board of Podiatry") { profsToQuery = GetProfsToQuery("POD"); } else if (org == "Georgia State Board of Physical Therapy") { profsToQuery = GetProfsToQuery("PT"); } //else if (org == "Georgia Secretary of State") { profsToQuery = GetProfsToQuery(""); } else { Match match = Regex.Match(lic_no, "[a-zA-Z]+", RegexOptions.IgnoreCase); if (match.Success) { profsToQuery = GetProfsToQuery(match.Value); if (profsToQuery.Count == 0) { return(ErrorMsg.InvalidTitle); } } else { return(ErrorMsg.InvalidTitle); } } } HttpWebResponse objResponse = null; HttpWebRequest objRequest = null; //http://sos.ga.gov/myverification/; string basehref = "http://verify.sos.ga.gov/verification/"; string url = basehref; string url2 = basehref; string result = String.Empty; //MT 04/23/2008 Hit the login page to get the cookies info if (WebFetch.IsError(result = WebFetch.ProcessGetRequest2(ref objRequest, ref objResponse, url, "", null, null))) { return(ErrorMsg.CannotAccessSite); } result += "\n\r-----------------------------------\n\r"; foreach (Cookie c in objResponse.Cookies) { result += c.Name + ":::" + c.Value + ":::" + c.Expires + "\n\r"; } //Use the cookieColl to hold every cookie from every objResponse that comes back string pattern = string.Empty; string searchStatus = string.Empty; CookieCollection cookieColl = new CookieCollection(); //Add response cookies to cookieCollection cookieColl.Add(objResponse.Cookies); string theViewState = getFieldVal("__VIEWSTATE", result); string eventTarget = getFieldVal("__EVENTTARGET", result); string eventArgument = getFieldVal("__EVENTARGUMENT", result); // Since some of these potentially need to query against multiple providers, loop through the list and try each // For each of them, check whether there were 0, 1 or n results. If 1 result, then abort loop, otherwise continue through profs foreach (string s in profsToQuery) { string[] profTypeSplit = s.Split('|'); string professionName = profTypeSplit[0].Replace(" ", "+"); string licenseTypeName = profTypeSplit[1].Replace(" ", "+"); string post = "__EVENTTARGET=" + eventTarget + "&__EVENTARGUMENT=" + eventArgument + "&__VIEWSTATE=" + theViewState + "&t_web_lookup__profession_name=" + professionName + "&t_web_lookup__license_type_name=" + licenseTypeName + "&t_web_lookup__first_name=" //+ firstName + "&t_web_lookup__last_name=" //+ lastName + "&t_web_lookup__license_no=" + lic_no + "&t_web_lookup__addr_county=" + "&sch_button=Search"; //url = "http://secure.sos.state.ga.us/myverification/Search.aspx"; url = "http://verify.sos.ga.gov/verification/"; if (!WebFetch.IsError(result = WebFetch.ProcessPostRequest(ref objRequest, ref objResponse, url, post, "", null, cookieColl))) { result = WebFetch.ProcessPostResponse(ref objResponse, ref objRequest); } else { return(ErrorMsg.CannotAccessSearchResultsPage); } result += "\n\r-----------------------------------\n\r"; foreach (Cookie c in objResponse.Cookies) { result += c.Name + ":::" + c.Value + ":::" + c.Expires + "\n\r"; } // var cookiessss = cookieColl.ToString().Split('/'); //Add response cookies to cookieCollection cookieColl.Add(objResponse.Cookies); pattern = "(?<LINK>Details\\.aspx[^\"]*)\""; MatchCollection mc = Regex.Matches(result, pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase); if (mc.Count < 1) { searchStatus = "no matches found"; } else if (mc.Count > 1) { searchStatus = "multiple matches found"; break; } else { string theLink = mc[0].Groups["LINK"].ToString().Trim(); theLink = Regex.Replace(theLink, "&", "&"); url = httpPrefix(theLink, basehref); searchStatus = "found"; break; } } if (searchStatus == "no matches found") { //return "no matches found"; return(PlugIn4_5.ErrorMsg.NoResultsFound); } else if (searchStatus == "multiple matches found") { //return "multiple matches found"; return(ErrorMsg.MultipleProvidersFound); } if (!WebFetch.IsError(result = WebFetch.ProcessGetRequest2(ref objRequest, ref objResponse, url, "", null, cookieColl))) { pdf.Html = "<img id='banner_image' height='121' width='717' src='http://verify.sos.ga.gov/verification/images/banner.png' border='0' /><tr>" + Regex.Match(result, "<td class=\"pagetitle\".*?</div>.*?</tr>", RegexOptions.IgnoreCase | RegexOptions.Singleline).ToString(); pdf.Html = Regex.Replace(pdf.Html, "<td class=\".*?colspan=.*?\">", "<td>", RegexOptions.IgnoreCase | RegexOptions.Singleline); pdf.Html = Regex.Replace(pdf.Html, "Licensee Details", ""); pdf.Html += "This website is to be used as a primary source verification for licenses issued by the Professional Licensing Boards. Paper verifications are available for a fee. Please contact the Professional Licensing Boards at 478-207-2440."; pdf.ConvertToABCImage(new ImageParameters() { BaseUrl = url }); } else { return(ErrorMsg.CannotAccessDetailsPage); } result = cleanAllTags(result); result = (getLicenseeInfo(result) + "\n" + getLicenseInfo(result) + "\n" + getAssocLics(result) + "\n" + getDiscipInfo(result)); result = replaceStartTags(result, "br", "\n"); result = replaceEndTags(result, "br", ""); result = replaceStartTags(result, "p", "\n"); result = replaceEndTags(result, "p", ""); result = replaceStartTags(result, "b", ""); result = replaceEndTags(result, "b", ""); Match m = Regex.Match(result, "(No\\s+Discipline\\s+Info)|(No\\s+Other\\s+Documents)", RegexOptions.Singleline | RegexOptions.IgnoreCase); setSanction(!m.Success); if (this.expirable) { handleExpirable(result, dr["lic_exp"].ToString().Trim(), @"Expires\s*(:)*\s*</td>\s*<td>\s*(?<EXP>\d{1,2}(/|-)\d{1,2}(/|-)\d{2,4})\s*</td>", "EXP"); } return(result); }
/// <summary> /// Takes in the root listing of the gitignore, and "recursively" caches all files into a Dictionary /// </summary> /// <param name="listings"></param> public void Update(Listing[] listings) { if (flags.HasFlag(Options.Verbose)) { Console.WriteLine("Writing cache..."); } // Queue of listings to check next Queue <Listing> listingsQueue = new Queue <Listing>(listings); // Dirs to throw back into the queue when it's empty Stack <Listing> dirs = new Stack <Listing>(); String ignorePattern = @"(.*)\.gitignore"; // Note that it's not actually recurisve // I find recursion difficult to maintain/debug // Do-While because Count check at this point is redundant do { while (listingsQueue.Count > 0) { Listing list = listingsQueue.Dequeue(); if (flags.HasFlag(Options.Verbose)) { Console.WriteLine(list.Path); } if (list.Type == TypeEnum.Dir) { dirs.Push(list); } else { // Only find .gitignore files while also stripping it from the name Match match = Regex.Match(list.Name, ignorePattern); if (match.Success) { Data.Add(match.Groups[1].Value, list.DownloadUrl); if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Added {match.Groups[1].Value}."); } } } } while (dirs.Count > 0) { // Fetch contents from dir if (flags.HasFlag(Options.Verbose)) { Console.WriteLine($"Expanding directory {dirs.Peek().Name}."); } string dirJSON = WebFetch.fetch(dirs.Pop().Url); listings = Listing.FromJson(dirJSON); foreach (Listing l in listings) { listingsQueue.Enqueue(l); } } } while(listingsQueue.Count > 0); }