/// <summary> /// Do the Download /// </summary> /// <returns> /// Return if Downloaded or not /// </returns> protected override bool DoDownload() { var strImgURL = this.ImageLinkURL; if (this.EventTable.ContainsKey(strImgURL)) { return(true); } var strFilePath = string.Empty; try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; return(false); } var ccObj = new CacheObject { IsDownloaded = false, FilePath = strFilePath, Url = strImgURL }; try { this.EventTable.Add(strImgURL, ccObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (this.EventTable.ContainsKey(strImgURL)) { return(false); } this.EventTable.Add(strImgURL, ccObj); } var strNewURL = strImgURL.Replace("/image/", @"/out.php/i"); strFilePath = strNewURL.Substring(strNewURL.IndexOf("_") + 1); strFilePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(strFilePath)); ////////////////////////////////////////////////////////////////////////// var newAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != newAlteredPath) { strFilePath = newAlteredPath; ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; } try { var client = new WebClient(); client.Headers.Add($"Referer: {strImgURL}"); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(false); } ((CacheObject)this.EventTable[this.ImageLinkURL]).IsDownloaded = true; CacheController.Instance().LastPic = ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; return(true); }
protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } string strFilePath = string.Empty; CacheObject CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } else { EventTable.Add(strImgURL, CCObj); } } string strIVPage = GetImageHostPage(ref strImgURL); if (strIVPage.Length < 10) { return(false); } string strNewURL = strImgURL.Substring(0, strImgURL.IndexOf("/", 8) + 1); int iStartSRC = 0; int iEndSRC = 0; iStartSRC = strIVPage.IndexOf("<img id=pic src=\""); if (iStartSRC < 0) { return(false); } iStartSRC += 17; iEndSRC = strIVPage.IndexOf("\" onclick=\"scaleImg('pic');\"", iStartSRC); if (iEndSRC < 0) { return(false); } strNewURL = "http://www.pussyupload.com/" + strIVPage.Substring(iStartSRC, iEndSRC - iStartSRC); strFilePath = strNewURL.Substring(strNewURL.LastIndexOf("gallery/") + 19); strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); ////////////////////////////////////////////////////////////////////////// string NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; } try { WebClient client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; //CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
public override void Configure(Funq.Container container) { JsConfig.EmitCamelCaseNames = true; JsConfig.IncludeNullValues = true; JsConfig.DateHandler = JsonDateHandler.ISO8601; LogManager.LogFactory = new ConsoleLogFactory(); SetConfig(new EndpointHostConfig { WsdlServiceNamespace = "", AllowJsonpRequests = true, DebugMode = true, EnableFeatures = Feature.All.Remove(GetDisabledFeatures()), CustomHttpHandlers = { // Use the CmsRazorHandler to add theming capabilities { HttpStatusCode.NotFound, new CmsRazorHandler("/notfound") } } }); //Authentication (see: https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.Endpoints.Tests/AuthTests.cs) Plugins.Add(new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { new BasicAuthProvider(), //Sign-in with Basic Auth }) { HtmlRedirect = null /* prevent redirect to login page, make the user login using basic auth prompt */ }); userRepository = new InMemoryAuthRepository(); container.Register <IUserAuthRepository>(userRepository); CreateUser(userRepository, 1, UserName, "DisplayName", null, Password); //Enable the validation feature and scan the service assembly for validators Plugins.Add(new ValidationFeature()); container.RegisterValidators(typeof(Services.CategoryService).Assembly); //Razor (use CmsRazorFormat to add theming capabilities) Plugins.Add(new CmsRazorFormat()); //Caching container.Register <ICacheClient>(new MemoryCacheClient()); //Entity Repositories container.RegisterAs <CategoryServiceRepository, ICategoryServiceRepository>(); container.RegisterAs <CustomerServiceRepository, ICustomerServiceRepository>(); container.RegisterAs <CustomerCustomerDemoServiceRepository, ICustomerCustomerDemoServiceRepository>(); container.RegisterAs <CustomerDemographicServiceRepository, ICustomerDemographicServiceRepository>(); container.RegisterAs <EmployeeServiceRepository, IEmployeeServiceRepository>(); container.RegisterAs <EmployeeTerritoryServiceRepository, IEmployeeTerritoryServiceRepository>(); container.RegisterAs <OrderServiceRepository, IOrderServiceRepository>(); container.RegisterAs <OrderDetailServiceRepository, IOrderDetailServiceRepository>(); container.RegisterAs <ProductServiceRepository, IProductServiceRepository>(); container.RegisterAs <RegionServiceRepository, IRegionServiceRepository>(); container.RegisterAs <ShipperServiceRepository, IShipperServiceRepository>(); container.RegisterAs <SupplierServiceRepository, ISupplierServiceRepository>(); container.RegisterAs <TerritoryServiceRepository, ITerritoryServiceRepository>(); //TypedList Repositories container.RegisterAs <TLSR.EmployeesByRegionAndTerritoryTypedListServiceRepository, TLSI.IEmployeesByRegionAndTerritoryTypedListServiceRepository>(); //TypedView Repositories container.RegisterAs <TVSR.AlphabeticalListOfProductsTypedViewServiceRepository, TVSI.IAlphabeticalListOfProductsTypedViewServiceRepository>(); container.RegisterAs <TVSR.CategorySalesFor1997TypedViewServiceRepository, TVSI.ICategorySalesFor1997TypedViewServiceRepository>(); container.RegisterAs <TVSR.CurrentProductListTypedViewServiceRepository, TVSI.ICurrentProductListTypedViewServiceRepository>(); container.RegisterAs <TVSR.CustomerAndSuppliersByCityTypedViewServiceRepository, TVSI.ICustomerAndSuppliersByCityTypedViewServiceRepository>(); container.RegisterAs <TVSR.InvoicesTypedViewServiceRepository, TVSI.IInvoicesTypedViewServiceRepository>(); container.RegisterAs <TVSR.OrderDetailsExtendedTypedViewServiceRepository, TVSI.IOrderDetailsExtendedTypedViewServiceRepository>(); container.RegisterAs <TVSR.OrdersQryTypedViewServiceRepository, TVSI.IOrdersQryTypedViewServiceRepository>(); container.RegisterAs <TVSR.OrderSubtotalTypedViewServiceRepository, TVSI.IOrderSubtotalTypedViewServiceRepository>(); container.RegisterAs <TVSR.ProductsAboveAveragePriceTypedViewServiceRepository, TVSI.IProductsAboveAveragePriceTypedViewServiceRepository>(); container.RegisterAs <TVSR.ProductSalesFor1997TypedViewServiceRepository, TVSI.IProductSalesFor1997TypedViewServiceRepository>(); container.RegisterAs <TVSR.ProductsByCategoryTypedViewServiceRepository, TVSI.IProductsByCategoryTypedViewServiceRepository>(); container.RegisterAs <TVSR.QuarterlyOrderTypedViewServiceRepository, TVSI.IQuarterlyOrderTypedViewServiceRepository>(); container.RegisterAs <TVSR.SalesByCategoryTypedViewServiceRepository, TVSI.ISalesByCategoryTypedViewServiceRepository>(); container.RegisterAs <TVSR.SalesTotalsByAmountTypedViewServiceRepository, TVSI.ISalesTotalsByAmountTypedViewServiceRepository>(); container.RegisterAs <TVSR.SummaryOfSalesByQuarterTypedViewServiceRepository, TVSI.ISummaryOfSalesByQuarterTypedViewServiceRepository>(); container.RegisterAs <TVSR.SummaryOfSalesByYearTypedViewServiceRepository, TVSI.ISummaryOfSalesByYearTypedViewServiceRepository>(); //DataAccess / OrmLite var connectionString = ConfigurationManager.ConnectionStrings["ApiDbConnectionString"].ConnectionString; container.Register <IDataAccessAdapterFactory>(c => new DataAccessAdapterFactory(connectionString)); container.Register <IDbConnectionFactory>(c => new OrmLiteConnectionFactory(connectionString, true, new SqlServerOrmLiteDialectProvider())); //DataAccess Caching CacheController.RegisterCache(string.Empty /* connectionString */, new ResultsetCache(5 * 60 /* will purge the cache every 5 minutes */)); }
public static void Run(string[] args) { bool autoExit = false; if (args.Length > 0) { autoExit = args[0] == "/a"; } OriginalController.InitConnectionString(); CacheController.RegisterCache(ConnectionString, new ResultsetCache()); RegisteredBenchers.Add(new LINQ2DBCompiledBencher(ConnectionString)); RegisteredBenchers.Add(new HandCodedBencher() { CommandText = SqlSelectCommandText, ConnectionStringToUse = ConnectionString }); RegisteredBenchers.Add(new HandCodedBencherUsingBoxing() { CommandText = SqlSelectCommandText, ConnectionStringToUse = ConnectionString }); RegisteredBenchers.Add(new LLBLGenProNoChangeTrackingRawSQLPocoBencher() { CommandText = SqlSelectCommandText }); RegisteredBenchers.Add(new RawDbDataReaderBencher() { CommandText = SqlSelectCommandText, ConnectionStringToUse = ConnectionString }); RegisteredBenchers.Add(new DapperBencher() { CommandText = SqlSelectCommandText, ConnectionStringToUse = ConnectionString }); RegisteredBenchers.Add(new EntityFramework7NoChangeTrackingBencher() { ConnectionStringToUse = ConnectionString }); RegisteredBenchers.Add(new LinqToSqlNoChangeTrackingBencher()); RegisteredBenchers.Add(new LLBLGenProNoChangeTrackingQuerySpecPocoBencher()); RegisteredBenchers.Add(new LLBLGenProNoChangeTrackingLinqPocoBencher()); RegisteredBenchers.Add(new LLBLGenProNoChangeTrackingBencher()); RegisteredBenchers.Add(new EntityFrameworkNoChangeTrackingBencher()); RegisteredBenchers.Add(new PetaPocoBencher() { CommandText = SqlSelectCommandText, ConnectionStringToUse = ConnectionString }); RegisteredBenchers.Add(new PetaPocoFastBencher() { CommandText = SqlSelectCommandText, ConnectionStringToUse = ConnectionString }); RegisteredBenchers.Add(new LINQ2DBNormalBencher(ConnectionString)); RegisteredBenchers.Add(new OrmLiteBencher() { CommandText = SqlSelectCommandText, ConnectionStringToUse = ConnectionString }); RegisteredBenchers.Add(new LLBLGenProNormalBencher()); RegisteredBenchers.Add(new LinqToSqlNormalBencher()); RegisteredBenchers.Add(new EntityFrameworkNormalBencher()); RegisteredBenchers.Add(new EntityFramework7NormalBencher() { ConnectionStringToUse = ConnectionString }); RegisteredBenchers.Add(new OakDynamicDbDtoBencher()); RegisteredBenchers.Add(new OakDynamicDbNormalBencher()); RegisteredBenchers.Add(new LLBLGenProResultsetCachingBencher()); RegisteredBenchers.Add(new NHibernateNormalBencher()); RegisteredBenchers.Add(new DataTableBencher() { CommandText = SqlSelectCommandText, ConnectionStringToUse = ConnectionString }); RegisteredBenchers.Add(new MassiveBencher()); OriginalController.DisplayHeader(); OriginalController.WarmupDB(); OriginalController.FetchKeysForIndividualFetches(); // Uncomment the line below if you want to profile a bencher. Specify the bencher instance and follow the guides on the screen. //ProfileBenchers(RegisteredBenchers.FirstOrDefault(b => b.GetType() == typeof(LLBLGenProNoChangeTrackingQuerySpecPocoBencher))); OriginalController.RunRegisteredBenchers(); OriginalController.ReportResultStatistics(autoExit); }
/// <summary> /// Do the Download /// </summary> /// <returns> /// Returns if the Image was downloaded /// </returns> protected override bool DoDownload() { var imageURL = ImageLinkURL; var filePath = string.Empty; if (EventTable.ContainsKey(imageURL)) { return(true); } try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } var cacheObject = new CacheObject { IsDownloaded = false, FilePath = filePath, Url = imageURL }; try { EventTable.Add(imageURL, cacheObject); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(imageURL)) { return(false); } EventTable.Add(imageURL, cacheObject); } var page = GetImageHostPage(ref imageURL); if (page.Length < 10) { return(false); } string imageDownloadURL; var m = Regex.Match(page, @"img src=\""(?<inner>[^\""]*)\"" class=\""pic\"" alt=\""(?<title>[^\""]*)\""", RegexOptions.Compiled); if (m.Success) { imageDownloadURL = m.Groups["inner"].Value; filePath = m.Groups["title"].Value; } else { return(false); } filePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(filePath)); if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } ////////////////////////////////////////////////////////////////////////// string newAlteredPath = Utility.GetSuitableName(filePath); if (filePath != newAlteredPath) { filePath = newAlteredPath; ((CacheObject)EventTable[this.ImageLinkURL]).FilePath = filePath; } try { var webClient = new WebClient(); webClient.Headers.Add(string.Format("Referer: {0}", imageURL)); webClient.DownloadFile(imageDownloadURL, filePath); webClient.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[imageURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[imageURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[imageURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(false); } ((CacheObject)EventTable[this.ImageLinkURL]).IsDownloaded = true; CacheController.Instance().LastPic = ((CacheObject)EventTable[this.ImageLinkURL]).FilePath = filePath; return(true); }
protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } string strFilePath = string.Empty; strFilePath = strImgURL.Substring(strImgURL.IndexOf("images/") + 7); strFilePath = strFilePath.Remove(strFilePath.Length - 37, 37); strFilePath += ".jpg"; try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); CacheObject CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } else { EventTable.Add(strImgURL, CCObj); } } ////////////////////////////////////////////////////////////////////////// try { string NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; } WebClient client = new WebClient(); client.DownloadFile(strImgURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; //CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
// Use this for initialization void Start() { cacheController = GetComponent <CacheController>(); }
public void TearDown() { _controller.Cache.Clear(); _controller = null; }
protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } string strFilePath = string.Empty; try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); CacheObject CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } else { EventTable.Add(strImgURL, CCObj); } } string sPage = GetImageHostPage(ref strImgURL); if (sPage.Length < 10) { return(false); } string strNewURL = string.Empty; int iStartSRC = 0; int iEndSRC = 0; iStartSRC = sPage.IndexOf("<div class=\"image\">"); if (iStartSRC < 0) { return(false); } iStartSRC += 30; iEndSRC = sPage.IndexOf("\" /></div>", iStartSRC); if (iEndSRC < 0) { return(false); } strNewURL = "http://www.imageflea.com/" + sPage.Substring(iStartSRC, iEndSRC - iStartSRC); strFilePath += strNewURL.Substring(strNewURL.LastIndexOf("/") + 1); ////////////////////////////////////////////////////////////////////////// try { string NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; } WebClient client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; //CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
protected override bool DoDownload() { var strImgURL = this.ImageLinkURL; if (this.EventTable.ContainsKey(strImgURL)) { return(true); } try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; return(false); } var CCObj = new CacheObject(); CCObj.IsDownloaded = false; // CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { this.EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (this.EventTable.ContainsKey(strImgURL)) { return(false); } else { this.EventTable.Add(strImgURL, CCObj); } } var strIVPage = this.GetImageHostPage(ref strImgURL); if (strIVPage.Length < 10) { return(false); } var strNewURL = strImgURL.Substring(0, strImgURL.IndexOf("/", 8) + 1); var iStartSRC = 0; var iEndSRC = 0; iStartSRC = strIVPage.IndexOf("Note: Large images are scaled to fit. <a href=\""); if (iStartSRC < 0) { return(false); } iStartSRC += 48; iEndSRC = strIVPage.IndexOf("\" class=\"small\">Click Here to view full size.</a> </p>", iStartSRC); if (iEndSRC < 0) { return(false); } strNewURL = strIVPage.Substring(iStartSRC, iEndSRC - iStartSRC); var strFilePath = strNewURL.Substring(strNewURL.LastIndexOf("/") + 1); strFilePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(strFilePath)); CCObj.FilePath = strFilePath; ////////////////////////////////////////////////////////////////////////// var NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; } try { var client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add( "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(false); } ((CacheObject)this.EventTable[this.ImageLinkURL]).IsDownloaded = true; // CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; return(true); }
protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } string strFilePath = string.Empty; try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } CacheObject ccObj = new CacheObject { IsDownloaded = false, FilePath = strFilePath, Url = strImgURL }; try { EventTable.Add(strImgURL, ccObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } EventTable.Add(strImgURL, ccObj); } const string sStartTitle = "<title>Kemipic - Earn money by sharing pictures, images - "; string sPage = GetImageHostPage(ref strImgURL); if (sPage.Length < 10) { return(false); } int iStartSrc = sPage.IndexOf(sStartTitle); if (iStartSrc < 0) { return(false); } iStartSrc += sStartTitle.Length; int iEndSrc = sPage.IndexOf(" - </title>", iStartSrc); if (iEndSrc < 0) { return(false); } strFilePath = sPage.Substring(iStartSrc, iEndSrc - iStartSrc); string strNewURL = strImgURL.Replace("share", "image").Replace(".html", strFilePath.Substring(strFilePath.LastIndexOf("."))); strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); ////////////////////////////////////////////////////////////////////////// try { string sNewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != sNewAlteredPath) { strFilePath = sNewAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; } WebClient client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; //CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
/// <summary> /// Creates the cache controller to sync with the context. /// </summary> private void CreateCacheController() { _cacheController = new CacheController(_scopeUri, _scopeName, this); CacheControllerBehavior behavior = _cacheController.ControllerBehavior; foreach (EntityType t in _schema.Collections) { behavior.AddType(t); } }
Settings() : base() { FileShareFilter_GridViewColumn_Name_Width = 100; FileShareFilter_GridViewColumn_Category_Width = 100; FileShareFilter_GridViewColumn_ID_Width = 100; FileShareFilter_GridViewColumn_LimitSize_Width = 100; FileShareFilter_GridViewColumn_LowerSize_Width = 100; FileShareFilter_GridViewColumn_Hash_Width = 100; FileShareTrigger_GridViewColumn_Name_Width = 100; FileShareTrigger_GridViewColumn_Category_Width = 100; FileShareTrigger_GridViewColumn_ID_Width = 100; FileShareTrigger_GridViewColumn_LimitSize_Width = 100; FileShareTrigger_GridViewColumn_LowerSize_Width = 100; FileShareTrigger_GridViewColumn_Hash_Width = 100; FileShareNode_GridViewColumn_CommunicationType_Width = 100; FileShareNode_GridViewColumn_Node_Width = 100; FileShareNode_GridViewColumn_Description_Width = 100; FileShareNode_GridViewColumn_ConnectionTime_Width = 100; GridViewColumn_Filename_Width = 100; GridViewColumn_ID_Width = 100; GridViewColumn_Size_Width = 100; GridViewColumn_Status_Width = 100; GridViewColumn_Hash_Width = 100; Grid_ColumnDefinitions_Width = new GridLength(207); DownloadDirectoryPath = ""; IsServiceStarted = false; Sign = ""; PrivateKey = ""; PublicKey = ""; Query_GridViewColumn_Filename_Width = 100; Query_GridViewColumn_CategoryList_Width = 100; Query_GridViewColumn_Sign_Width = 100; Query_GridViewColumn_ID_Width = 100; Query_GridViewColumn_Size_Width = 100; Query_GridViewColumn_Status_Width = 100; Query_GridViewColumn_CreationTime_Width = 100; Query_GridViewColumn_Hash_Width = 100; Query_GridViewColumn_Review_Width = 100; RefineSearchTreeViewItemSettingWindow_GridViewColumn_Include_Width = 100; RefineSearchTreeViewItemSettingWindow_GridViewColumn_Value_Width = 100; _cacheController = new CacheController(); _routeTable = new RouteTable(); _keyController = new KeyController(); TabRadioButton = false; TreeRadioButton = true; DisplaySize_1 = true; DisplaySize_2 = false; DisplaySize_3 = false; QueryTimerMaxCount = 2; StoreTimerMaxCount = 2; DownloadTimerMaxCount = 20; UploadTimerMaxCount = 2; SelectedIndexCategory = -1; _categoryDir = new Dictionary<string, string[]>(); _categoryList = new BindingList<string>(); _filterList = new BindingList<Profes.P2P.FileShare.FileShareControl.Filter>(); _triggerList = new BindingList<Profes.P2P.FileShare.FileShareControl.Trigger>(); _nodeShowList = new BindingList<NodeListViewItem>(); UploadDiffusionList = new List<UploadDiffusion>(); _downloadList = new BindingList<CacheListViewItem>(); _uploadList = new BindingList<CacheListViewItem>(); SearchTreeViewItem = new RefineSearchTreeViewItem { RefineSearchName = "Search", IsExpanded = true, }; QueryList = new string[] { "test" }; CommentsWindow_Height = 358; CommentsWindow_Width = 727; DownloadHistory = new List<CacheListViewItem>(); ConnectionType = ConnectionType.Direct; DirectConnectionInformation = new DirectConnectionInformation() { IPAddress = "", Port = new Random().Next(1024, 65536), }; UpnpConnectionInformation = new UpnpConnectionInformation() { GlobalIPAddress = "", MachineIPAddress = "", GatewayIPAddress = "", ExternalPort = new Random().Next(1024, 65536), InternalPort = new Random().Next(1024, 65536), }; OtherConnectionInformation = new OtherConnectionInformation() { IPAddress = "", Port = new Random().Next(1024, 65536), }; LogCheckBox_IsChecked = false; try { Load(); } catch { } }
protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } string strFilePath = string.Empty; strFilePath = strImgURL.Substring(strImgURL.LastIndexOf("/") + 1); try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); CacheObject CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } else { EventTable.Add(strImgURL, CCObj); } } string strNewURL = strImgURL; strNewURL = Regex.Replace(strNewURL, "view_image", "show_image"); ////////////////////////////////////////////////////////////////////////// try { string NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; } WebClient client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; //CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
/// <summary> /// Do the Download /// </summary> /// <returns> /// Returns if the Image was downloaded /// </returns> protected override bool DoDownload() { var strImgURL = this.ImageLinkURL; if (this.EventTable.ContainsKey(strImgURL)) { return(true); } var strFilePath = string.Empty; try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; return(false); } var ccObj = new CacheObject { IsDownloaded = false, FilePath = strFilePath, Url = strImgURL }; try { this.EventTable.Add(strImgURL, ccObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (this.EventTable.ContainsKey(strImgURL)) { return(false); } this.EventTable.Add(strImgURL, ccObj); } var sLargeUrl = $"{strImgURL}&pjk=l".Replace("view/?id", "view/index.php?id"); var sPage = this.GetImageHostsPage(ref sLargeUrl, strImgURL); if (sPage.Length < 10) { return(false); } string strNewURL; var m = Regex.Match(sPage, @"src=\""(?<inner>[^\""]*)\"" id=img1", RegexOptions.Singleline); if (m.Success) { strNewURL = m.Groups["inner"].Value; } else { return(false); } strFilePath = strNewURL.Substring(strNewURL.LastIndexOf("/") + 1); strFilePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(strFilePath)); ////////////////////////////////////////////////////////////////////////// try { var sNewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != sNewAlteredPath) { strFilePath = sNewAlteredPath; ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; } var client = new WebClient(); client.Headers.Add($"Referer: {sLargeUrl}"); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(false); } ((CacheObject)this.EventTable[this.ImageLinkURL]).IsDownloaded = true; CacheController.Instance().LastPic = ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; return(true); }
protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } string strFilePath = string.Empty; strFilePath = strImgURL.Substring(strImgURL.LastIndexOf("/") + 1); try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); CacheObject CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } else { EventTable.Add(strImgURL, CCObj); } } string strNewURL = "http://" + strImgURL.Substring(strImgURL.IndexOf("://") + 3, 4) + "letmehost.com/" + strImgURL.Substring(strImgURL.IndexOf("file=") + 5); ////////////////////////////////////////////////////////////////////////// HttpWebRequest lHttpWebRequest; HttpWebResponse lHttpWebResponse; Stream lHttpWebResponseStream; //FileStream lFileStream = null; //int bytesRead; try { lHttpWebRequest = (HttpWebRequest)WebRequest.Create(strNewURL); lHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"; lHttpWebRequest.Headers.Add("Accept-Language: en-us,en;q=0.5"); lHttpWebRequest.Headers.Add("Accept-Encoding: gzip,deflate"); lHttpWebRequest.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"); lHttpWebRequest.Referer = strImgURL; lHttpWebRequest.Accept = "image/png,*/*;q=0.5"; lHttpWebRequest.KeepAlive = true; lHttpWebResponse = (HttpWebResponse)lHttpWebRequest.GetResponse(); lHttpWebResponseStream = lHttpWebRequest.GetResponse().GetResponseStream(); if (lHttpWebResponse.ContentType.IndexOf("image") < 0) { //if (lFileStream != null) // lFileStream.Close(); return(false); } string NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; } WebClient client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; //CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
/// <summary> /// Tries to Login to the Forums /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void LoginBtnClick(object sender, EventArgs e) { if (this.ForumUrl.Text.StartsWith("http://")) { if (!this.ForumUrl.Text.EndsWith("/")) { this.ForumUrl.Text += "/"; } CacheController.Instance().UserSettings.CurrentForumUrl = this.ForumUrl.Text; } string welcomeString = this.rm.GetString("lblWelcome"), lblFailed = this.rm.GetString("lblFailed"); if (this.GuestLogin.Checked) { this.UserNameField.Text = "Guest"; this.PasswordField.Text = "Guest"; this.label3.Text = string.Format("{0}{1}", welcomeString, this.UserNameField.Text); this.label3.ForeColor = Color.Green; this.LoginButton.Enabled = false; if ( CacheController.Instance().UserSettings.ForumsAccount.Any( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl)) { CacheController.Instance().UserSettings.ForumsAccount.RemoveAll( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl); } var forumsAccount = new ForumAccount { ForumURL = CacheController.Instance().UserSettings.CurrentForumUrl, UserName = this.UserNameField.Text, UserPassWord = this.PasswordField.Text, GuestAccount = false }; CacheController.Instance().UserSettings.ForumsAccount.Add(forumsAccount); CacheController.Instance().UserSettings.CurrentUserName = this.UserNameField.Text; this.timer1.Enabled = true; } else { // Encrypt Password this.PasswordField.Text = Utility.EncodePassword(this.PasswordField.Text).Replace("-", string.Empty).ToLower(); var loginManager = new LoginManager(this.UserNameField.Text, this.PasswordField.Text); if (loginManager.DoLogin(CacheController.Instance().UserSettings.CurrentForumUrl)) { this.label3.Text = string.Format("{0}{1}", welcomeString, this.UserNameField.Text); this.label3.ForeColor = Color.Green; this.LoginButton.Enabled = false; if ( CacheController.Instance().UserSettings.ForumsAccount.Any( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl)) { CacheController.Instance().UserSettings.ForumsAccount.RemoveAll( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl); } var forumsAccount = new ForumAccount { ForumURL = CacheController.Instance().UserSettings.CurrentForumUrl, UserName = this.UserNameField.Text, UserPassWord = this.PasswordField.Text, GuestAccount = false }; CacheController.Instance().UserSettings.ForumsAccount.Add(forumsAccount); CacheController.Instance().UserSettings.CurrentUserName = this.UserNameField.Text; this.timer1.Enabled = true; } else { this.label3.Text = lblFailed; this.label3.ForeColor = Color.Red; } } }
protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } string strFilePath = string.Empty; strFilePath = strImgURL.Substring(strImgURL.IndexOf("?id=") + 4); try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); CacheObject CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } else { EventTable.Add(strImgURL, CCObj); } } string strIVPage = GetImageHostPage(ref strImgURL); if (strIVPage.Length < 10) { return(false); } string strNewURL = strImgURL.Substring(0, strImgURL.IndexOf("/", 8) + 1); int iStartIMG = 0; int iStartSRC = 0; int iEndSRC = 0; iStartIMG = strIVPage.IndexOf("<a href=\"random.php\"><img "); if (iStartIMG < 0) { return(false); } iStartSRC = strIVPage.IndexOf("src=\"", iStartIMG); if (iStartSRC < 0) { return(false); } iStartSRC += 5; iEndSRC = strIVPage.IndexOf("\" border=\"0\"", iStartSRC); if (iEndSRC < 0) { return(false); } strNewURL = strIVPage.Substring(iStartSRC, iEndSRC - iStartSRC); ////////////////////////////////////////////////////////////////////////// HttpWebRequest lHttpWebRequest; HttpWebResponse lHttpWebResponse; Stream lHttpWebResponseStream; //FileStream lFileStream = new FileStream(strFilePath, FileMode.Create); //int bytesRead; try { lHttpWebRequest = (HttpWebRequest)WebRequest.Create(strNewURL); lHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"; lHttpWebRequest.Headers.Add("Accept-Language: en-us,en;q=0.5"); lHttpWebRequest.Headers.Add("Accept-Encoding: gzip,deflate"); lHttpWebRequest.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"); lHttpWebRequest.Referer = strImgURL; lHttpWebRequest.Accept = "image/png,*/*;q=0.5"; lHttpWebRequest.KeepAlive = true; lHttpWebResponse = (HttpWebResponse)lHttpWebRequest.GetResponse(); lHttpWebResponseStream = lHttpWebRequest.GetResponse().GetResponseStream(); if (lHttpWebResponse.ContentType.IndexOf("image") < 0) { //if (lFileStream != null) // lFileStream.Close(); return(false); } if (lHttpWebResponse.ContentType.ToLower() == "image/jpeg") { strFilePath += ".jpg"; } else if (lHttpWebResponse.ContentType.ToLower() == "image/gif") { strFilePath += ".gif"; } else if (lHttpWebResponse.ContentType.ToLower() == "image/png") { strFilePath += ".png"; } string NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; } lHttpWebResponseStream.Close(); WebClient client = new WebClient(); client.Headers.Add("Accept-Language: en-us,en;q=0.5"); client.Headers.Add("Accept-Encoding: gzip,deflate"); client.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; //CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
/// <summary> /// If Login successfully send user data to MainForm /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param> private void Timer1Elapsed(object sender, ElapsedEventArgs e) { this.timer1.Enabled = false; ((MainForm)this.Owner).cameThroughCorrectLogin = true; if (CacheController.Instance().UserSettings.ForumsAccount.Any(item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl)) { CacheController.Instance().UserSettings.ForumsAccount.RemoveAll( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl); } var forumsAccount = new ForumAccount { ForumURL = CacheController.Instance().UserSettings.CurrentForumUrl, UserName = this.UserNameField.Text, UserPassWord = this.PasswordField.Text, GuestAccount = this.GuestLogin.Checked }; CacheController.Instance().UserSettings.ForumsAccount.Add(forumsAccount); CacheController.Instance().UserSettings.CurrentUserName = this.UserNameField.Text; this.Close(); }
public HttpResponseMessage UpdateRegexSettings(UpdateRegexSettingsRequest request) { try { List <KeyValuePair <string, string> > validationErrors = new List <KeyValuePair <string, string> >(); if (!ValidateRegex(request.IgnoreRegex)) { validationErrors.Add(new KeyValuePair <string, string>("IgnoreRegex", Localization.GetString("ignoreRegExInvalidPattern", LocalResourcesFile))); } if (!ValidateRegex(request.DoNotRewriteRegex)) { validationErrors.Add(new KeyValuePair <string, string>("DoNotRewriteRegex", Localization.GetString("doNotRewriteRegExInvalidPattern", LocalResourcesFile))); } if (!ValidateRegex(request.UseSiteUrlsRegex)) { validationErrors.Add(new KeyValuePair <string, string>("UseSiteUrlsRegex", Localization.GetString("siteUrlsOnlyRegExInvalidPattern", LocalResourcesFile))); } if (!ValidateRegex(request.DoNotRedirectRegex)) { validationErrors.Add(new KeyValuePair <string, string>("DoNotRedirectRegex", Localization.GetString("doNotRedirectUrlRegExInvalidPattern", LocalResourcesFile))); } if (!ValidateRegex(request.DoNotRedirectSecureRegex)) { validationErrors.Add(new KeyValuePair <string, string>("DoNotRedirectSecureRegex", Localization.GetString("doNotRedirectHttpsUrlRegExInvalidPattern", LocalResourcesFile))); } if (!ValidateRegex(request.ForceLowerCaseRegex)) { validationErrors.Add(new KeyValuePair <string, string>("ForceLowerCaseRegex", Localization.GetString("preventLowerCaseUrlRegExInvalidPattern", LocalResourcesFile))); } if (!ValidateRegex(request.NoFriendlyUrlRegex)) { validationErrors.Add(new KeyValuePair <string, string>("NoFriendlyUrlRegex", Localization.GetString("doNotUseFriendlyUrlsRegExInvalidPattern", LocalResourcesFile))); } if (!ValidateRegex(request.DoNotIncludeInPathRegex)) { validationErrors.Add(new KeyValuePair <string, string>("DoNotIncludeInPathRegex", Localization.GetString("keepInQueryStringRegExInvalidPattern", LocalResourcesFile))); } if (!ValidateRegex(request.ValidExtensionlessUrlsRegex)) { validationErrors.Add(new KeyValuePair <string, string>("ValidExtensionlessUrlsRegex", Localization.GetString("urlsWithNoExtensionRegExInvalidPattern", LocalResourcesFile))); } if (!ValidateRegex(request.RegexMatch)) { validationErrors.Add(new KeyValuePair <string, string>("RegexMatch", Localization.GetString("validFriendlyUrlRegExInvalidPattern", LocalResourcesFile))); } if (validationErrors.Count > 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new { Success = false, Errors = validationErrors })); } else { // if no errors, update settings in db UpdateRegexSettingsInternal(request); DataCache.ClearHostCache(false); CacheController.FlushPageIndexFromCache(); CacheController.FlushFriendlyUrlSettingsFromCache(); return(Request.CreateResponse(HttpStatusCode.OK, new { Success = true })); } } catch (Exception exc) { Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
protected override bool DoDownload() { var strImgURL = this.ImageLinkURL; if (this.EventTable.ContainsKey(strImgURL)) { return(true); } var strFilePath = string.Empty; try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; return(false); } var ccObj = new CacheObject { IsDownloaded = false, FilePath = strFilePath, Url = strImgURL }; try { this.EventTable.Add(strImgURL, ccObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (this.EventTable.ContainsKey(strImgURL)) { return(false); } this.EventTable.Add(strImgURL, ccObj); } const string sStartSrc = "<img style='width:{szer}px;' src='"; var sPage = this.GetImageHostPage(ref strImgURL); if (sPage.Length < 10) { return(false); } var iStartSrc = sPage.IndexOf(sStartSrc); if (iStartSrc < 0) { return(false); } iStartSrc += sStartSrc.Length; var iEndSrc = sPage.IndexOf("\" /></a>", iStartSrc); if (iEndSrc < 0) { return(false); } var sFullUrl = sPage.Substring(iStartSrc, iEndSrc - iStartSrc); strFilePath = sFullUrl.Substring(sFullUrl.IndexOf("\"") + 1); var strNewURL = sFullUrl.Remove(sFullUrl.IndexOf("'")); strFilePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(strFilePath)); ////////////////////////////////////////////////////////////////////////// var newAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != newAlteredPath) { strFilePath = newAlteredPath; ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; } strFilePath = Utility.CheckPathLength(strFilePath); ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; try { var client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(false); } ((CacheObject)this.EventTable[this.ImageLinkURL]).IsDownloaded = true; CacheController.Instance().LastPic = ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; return(true); }
/// <summary> /// Do the image Download /// </summary> /// <returns> /// Returns if the Image was downloaded /// </returns> protected override bool DoDownload() { var imageHostURL = ImageLinkURL; var filePath = string.Empty; if (EventTable.ContainsKey(imageHostURL)) { return(true); } try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } var cacheObject = new CacheObject { IsDownloaded = false, FilePath = filePath, Url = imageHostURL }; try { EventTable.Add(imageHostURL, cacheObject); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(imageHostURL)) { return(false); } EventTable.Add(imageHostURL, cacheObject); } var imageDownloadURL = this.ThumbImageURL.Replace("/thumbs/", "/images/").Replace("http://t", "http://img"); filePath = imageDownloadURL.Substring(imageDownloadURL.IndexOf("_") + 1); filePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(filePath)); ////////////////////////////////////////////////////////////////////////// var newAlteredPath = Utility.GetSuitableName(filePath); if (filePath != newAlteredPath) { filePath = newAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = filePath; } try { var client = new WebClient(); client.Headers.Add(string.Format("Referer: {0}", imageHostURL)); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(imageDownloadURL, filePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[imageHostURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[imageHostURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[imageHostURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(false); } ((CacheObject)EventTable[this.ImageLinkURL]).IsDownloaded = true; CacheController.Instance().LastPic = ((CacheObject)EventTable[this.ImageLinkURL]).FilePath = filePath; return(true); }
/// <summary> /// Attempts to extract hot linked and thumb->FullScale images. /// </summary> /// <param name="htmlDump">The html Dump.</param> /// <param name="postId">The post identifier.</param> /// <returns> /// The extract attachment images html. /// </returns> public static List <ImageInfo> ExtractAttachmentImagesHtml(string htmlDump, string postId) { List <ImageInfo> rtnList = new List <ImageInfo>(); htmlDump = htmlDump.Replace("&", "&"); var start = "<div class=\"attachments\">"; var end = "<!-- / attachments -->"; // use only message content var iStart = htmlDump.IndexOf(start, System.StringComparison.Ordinal); if (iStart < 0) { // fix post id if (postId.Contains("#post")) { postId = postId.Substring(postId.IndexOf("#post", System.StringComparison.Ordinal) + 5); } start = string.Format("<div id=\"post_message_{0}\">", postId); end = "</blockquote>"; iStart = htmlDump.IndexOf(start, System.StringComparison.Ordinal); if (iStart < 0) { // Return Empty List return(rtnList); } iStart += start.Length; var startDump = htmlDump.Substring(iStart); var iEnd = startDump.IndexOf(end, System.StringComparison.Ordinal); if (iEnd > 0) { htmlDump = startDump.Remove(iEnd); } } else { iStart += start.Length; var iEnd = htmlDump.IndexOf(end, System.StringComparison.Ordinal); if (iEnd > 0) { htmlDump = htmlDump.Substring(iStart, iEnd - iStart); } } /////////////////////////////////////////////// rtnList.AddRange( LinkFinder.ListAllLinks(htmlDump) .Select( link => new ImageInfo { ImageUrl = link.Href.StartsWith("http://") ? link.Href : CacheController.Instance().UserSettings.CurrentForumUrl + Utility.ReplaceHexWithAscii(link.Href), ThumbnailUrl = string.Empty }) .Where(newPicPoolItem => !Utility.IsImageNoneSense(newPicPoolItem.ImageUrl))); return(rtnList); }
protected override bool DoDownload() { var strImgURL = this.ImageLinkURL; if (this.EventTable.ContainsKey(strImgURL)) { return(true); } var strFilePath = string.Empty; strFilePath = strImgURL.Substring(strImgURL.IndexOf("show.php/") + 9); strFilePath = Regex.Replace(strFilePath, @"(^\d{6})_", string.Empty); strFilePath = strFilePath.Remove(strFilePath.Length - 9, 9); try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; return(false); } strFilePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(strFilePath)); var CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { this.EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (this.EventTable.ContainsKey(strImgURL)) { return(false); } else { this.EventTable.Add(strImgURL, CCObj); } } var strNewURL = "http://www.picturesupload.com/out.php/i" + strImgURL.Substring(strImgURL.IndexOf("show.php/") + 9); ////////////////////////////////////////////////////////////////////////// HttpWebRequest lHttpWebRequest; HttpWebResponse lHttpWebResponse; Stream lHttpWebResponseStream; // FileStream lFileStream = null; // int bytesRead; try { lHttpWebRequest = (HttpWebRequest)WebRequest.Create(strNewURL); lHttpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"; lHttpWebRequest.Headers.Add("Accept-Language: en-us,en;q=0.5"); lHttpWebRequest.Headers.Add("Accept-Encoding: gzip,deflate"); lHttpWebRequest.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"); lHttpWebRequest.Referer = strImgURL; lHttpWebRequest.Accept = "image/png,*/*;q=0.5"; lHttpWebRequest.KeepAlive = true; lHttpWebResponse = (HttpWebResponse)lHttpWebRequest.GetResponse(); lHttpWebResponseStream = lHttpWebRequest.GetResponse().GetResponseStream(); if (lHttpWebResponse.ContentType.IndexOf("image") < 0) { // if (lFileStream != null) // lFileStream.Close(); return(false); } if (lHttpWebResponse.ContentType.ToLower() == "image/jpeg") { strFilePath += ".jpg"; } else if (lHttpWebResponse.ContentType.ToLower() == "image/gif") { strFilePath += ".gif"; } else if (lHttpWebResponse.ContentType.ToLower() == "image/png") { strFilePath += ".png"; } var NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; } // lFileStream = new FileStream(strFilePath, FileMode.Create); lHttpWebResponseStream.Close(); var client = new WebClient(); client.Headers.Add("Accept-Language: en-us,en;q=0.5"); client.Headers.Add("Accept-Encoding: gzip,deflate"); client.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add( "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); /*do * { * // Read up to 1000 bytes into the bytesRead array. * bytesRead = lHttpWebResponseStream.Read(byteBuffer, 0, 999); * lFileStream.Write(byteBuffer, 0, bytesRead); * }while(bytesRead > 0); * * lHttpWebResponseStream.Close();*/ } catch (ThreadAbortException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(false); } ((CacheObject)this.EventTable[this.ImageLinkURL]).IsDownloaded = true; // CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; return(true); }
/// <summary> /// Do the Download /// </summary> /// <returns> /// Return if Downloaded or not /// </returns> protected override bool DoDownload() { var strImgURL = this.ImageLinkURL; if (this.EventTable.ContainsKey(strImgURL)) { return(true); } var strFilePath = string.Empty; try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; return(false); } var ccObj = new CacheObject { IsDownloaded = false, FilePath = strFilePath, Url = strImgURL }; try { this.EventTable.Add(strImgURL, ccObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (this.EventTable.ContainsKey(strImgURL)) { return(false); } this.EventTable.Add(strImgURL, ccObj); } var cookieValue = this.GetCookieValue(strImgURL, @"writeCookie\('ads_pixhub', '(?<inner>[^']*)', '1'\)"); if (string.IsNullOrEmpty(cookieValue)) { return(false); } var sPage = this.GetImageHostPage(ref strImgURL, $"ads_pixhub={cookieValue};"); if (sPage.Length < 10) { return(false); } string strNewURL; var match = Regex.Match( sPage, @"<div class=\""image-show resize\"">\s+.+?<img.+?src=\""(?<inner>[^\""]*)\"" alt=\""(?<filename>[^\""]*)\""", RegexOptions.Multiline); if (match.Success) { strNewURL = match.Groups["inner"].Value; if (strNewURL.Contains("thumbnail")) { strNewURL = strNewURL.Replace("thumbnail/", string.Empty); } strFilePath = match.Groups["filename"].Value; } else { return(false); } strFilePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(strFilePath)); ////////////////////////////////////////////////////////////////////////// var newAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != newAlteredPath) { strFilePath = newAlteredPath; ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; } try { var client = new WebClient(); client.Headers.Add($"Referer: {strImgURL}"); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(false); } ((CacheObject)this.EventTable[this.ImageLinkURL]).IsDownloaded = true; CacheController.Instance().LastPic = ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; return(true); }
protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } string strFilePath = strImgURL.Substring(strImgURL.LastIndexOf("/") + 1); try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); CacheObject ccObj = new CacheObject { IsDownloaded = false, FilePath = strFilePath, Url = strImgURL }; try { EventTable.Add(strImgURL, ccObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } EventTable.Add(strImgURL, ccObj); } string sPage = GetImageHostPage(ref strImgURL); if (sPage.Length < 10) { return(false); } int iStartSrc = sPage.IndexOf("<img id=\"podImage\" src=\""); if (iStartSrc < 0) { return(false); } iStartSrc += 24; int iEndSrc = sPage.IndexOf("\"", iStartSrc); if (iEndSrc < 0) { return(false); } string strNewURL = sPage.Substring(iStartSrc, iEndSrc - iStartSrc); ////////////////////////////////////////////////////////////////////////// string newAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != newAlteredPath) { strFilePath = newAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; } try { WebClient client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
public static UrlRuleConfiguration GetConfig(int portalId) { var cc = new CacheController(portalId); return(cc.GetUrlRuleConfig()); }
/// <summary> /// Do the Download /// </summary> /// <returns> /// Return if Downloaded or not /// </returns> protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } string strFilePath = string.Empty; try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } CacheObject ccObj = new CacheObject { IsDownloaded = false, FilePath = strFilePath, Url = strImgURL }; try { EventTable.Add(strImgURL, ccObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } EventTable.Add(strImgURL, ccObj); } string sPage = this.GetImageHostsPage(ref strImgURL); if (sPage.Length < 10) { return(false); } string strNewURL; var m = Regex.Match(sPage, @"src=\""http://img(?<inner>[^\""]*)\""", RegexOptions.Singleline); if (m.Success) { strNewURL = string.Format("http://img{0}", m.Groups["inner"].Value); } else { return(false); } strFilePath = strImgURL.Substring(strImgURL.LastIndexOf("/", StringComparison.Ordinal) + 1).Replace(".html", string.Empty); strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); ////////////////////////////////////////////////////////////////////////// string newAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != newAlteredPath) { strFilePath = newAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; } try { WebClient client = new WebClient(); client.Headers.Add(string.Format("Referer: {0}", strImgURL)); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
protected override bool DoDownload() { var strImgURL = this.ImageLinkURL; if (this.EventTable.ContainsKey(strImgURL)) { return(true); } var strIVPage = this.GetImageHostPage(ref strImgURL); if (strIVPage.Length < 10) { return(false); } var strNewURL = strImgURL.Substring(0, strImgURL.IndexOf("/", 8) + 1); var iStartSRC = 0; var iEndSRC = 0; iStartSRC = strIVPage.IndexOf("toggleResize();'><img src='"); if (iStartSRC < 0) { return(false); } iStartSRC += 27; iEndSRC = strIVPage.IndexOf("' id='mainImage'", iStartSRC); if (iEndSRC < 0) { return(false); } strNewURL = "http://suprfile.com/" + strIVPage.Substring(iStartSRC, iEndSRC - iStartSRC); var strFilePath = strNewURL.Substring(strNewURL.LastIndexOf("/") + 1); try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; return(false); } strFilePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(strFilePath)); var CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { this.EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (this.EventTable.ContainsKey(strImgURL)) { return(false); } else { this.EventTable.Add(strImgURL, CCObj); } } ////////////////////////////////////////////////////////////////////////// var NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; } try { var client = new WebClient(); client.Headers.Add("Accept-Language: en-us,en;q=0.5"); client.Headers.Add("Accept-Encoding: gzip,deflate"); client.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add( "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); } catch (ThreadAbortException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(false); } ((CacheObject)this.EventTable[this.ImageLinkURL]).IsDownloaded = true; // CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; return(true); }
/// <summary> /// Do the Download /// </summary> /// <returns> /// Return if Downloaded or not /// </returns> protected override bool DoDownload() { var imageURL = ImageLinkURL; var thumbURL = ThumbImageURL; if (EventTable.ContainsKey(imageURL)) { return(true); } var filePath = string.Empty; try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } var cacheObject = new CacheObject { IsDownloaded = false, FilePath = filePath, Url = imageURL }; try { EventTable.Add(imageURL, cacheObject); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(imageURL)) { return(false); } EventTable.Add(imageURL, cacheObject); } // Set the download Path var imageDownloadURL = thumbURL.Replace(@"thumbs/", string.Empty); // Set Image Name instead of using random name filePath = this.GetImageName(this.PostTitle, imageDownloadURL, this.ImageNumber); filePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(filePath)); ////////////////////////////////////////////////////////////////////////// filePath = Utility.GetSuitableName(filePath, true); ((CacheObject)EventTable[imageURL]).FilePath = filePath; try { var client = new WebClient(); client.Headers.Add(string.Format("Referer: {0}", thumbURL)); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(imageDownloadURL, filePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[imageURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(imageURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[imageURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(imageURL); return(true); } catch (WebException) { ((CacheObject)EventTable[imageURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(imageURL); return(false); } ((CacheObject)EventTable[imageURL]).IsDownloaded = true; CacheController.Instance().LastPic = ((CacheObject)EventTable[imageURL]).FilePath = filePath; return(true); }
protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } string strFilePath = string.Empty; if (strImgURL.Contains("_")) { strFilePath = strImgURL.Substring(strImgURL.IndexOf("_") + 1); } else { strFilePath = strImgURL.Substring(strImgURL.LastIndexOf("?id=") + 13); } try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); CacheObject CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } else { EventTable.Add(strImgURL, CCObj); } } string strIVPage = string.Empty; try { strIVPage = GetRealLink(strImgURL); } catch (Exception) { return(false); } string strNewURL = string.Empty; int iStartSRC = 0; int iEndSRC = 0; iStartSRC = strIVPage.IndexOf("<img src='."); if (iStartSRC < 0) { return(false); } iStartSRC += 11; iEndSRC = strIVPage.IndexOf("' id=\"image\"", iStartSRC); if (iEndSRC < 0) { return(false); } string sAltUrl = strImgURL; sAltUrl = sAltUrl.Remove(strImgURL.IndexOf("/img.php")); strNewURL = string.Format("{0}{1}", sAltUrl, strIVPage.Substring(iStartSRC, iEndSRC - iStartSRC)); ////////////////////////////////////////////////////////////////////////// try { WebClient client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
protected override bool DoDownload() { var strImgURL = this.ImageLinkURL; if (this.EventTable.ContainsKey(strImgURL)) { return(true); } var strFilePath = string.Empty; strFilePath = strImgURL.Substring(strImgURL.LastIndexOf("/") + 6); try { if (!Directory.Exists(this.SavePath)) { Directory.CreateDirectory(this.SavePath); } } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; return(false); } strFilePath = Path.Combine(this.SavePath, Utility.RemoveIllegalCharecters(strFilePath)); var CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { this.EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (this.EventTable.ContainsKey(strImgURL)) { return(false); } else { this.EventTable.Add(strImgURL, CCObj); } } var strNewURL = strImgURL; ////////////////////////////////////////////////////////////////////////// try { var NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; } var client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (IOException ex) { // MainForm.DeleteMessage = ex.Message; // MainForm.Delete = true; ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)this.EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(this.ImageLinkURL); return(false); } ((CacheObject)this.EventTable[this.ImageLinkURL]).IsDownloaded = true; // CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)this.EventTable[this.ImageLinkURL]).FilePath = strFilePath; return(true); }
protected override bool DoDownload() { string strImgURL = ImageLinkURL; if (EventTable.ContainsKey(strImgURL)) { return(true); } string strImgURLNew = strImgURL; strImgURLNew = strImgURLNew.Replace("view.php?mode=gallery&g=", "photos/").Replace("&photo=", "_") + "-.html"; string strIVPage = GetImageHostPage(ref strImgURLNew); // Adult Warning int iStartConfirm = 0; int iEndConfirm = 0; iStartConfirm = strIVPage.IndexOf("<title>"); iStartConfirm += 7; if (iStartConfirm < 0) { return(false); } try { iEndConfirm = strIVPage.IndexOf("</title>", iStartConfirm); } catch (Exception) { return(false); } if (iEndConfirm < 0) { return(false); } string sConfirmURL = strIVPage.Substring(iStartConfirm, iEndConfirm - iStartConfirm); if (sConfirmURL == "ImageBeaver Warning") { iStartConfirm = 0; iEndConfirm = 0; iStartConfirm = strIVPage.IndexOf("<p class=\"enter\"><a href=\""); iStartConfirm += 26; iEndConfirm = strIVPage.IndexOf("\">", iStartConfirm); string strURL = "http://www.imagebeaver.com/" + strIVPage.Substring(iStartConfirm, iEndConfirm - iStartConfirm); strIVPage = GetImageHostsPage(ref strURL); } if (strIVPage.Length < 10) { return(false); } string strNewURL = string.Empty; int iStartSRC = 0; int iEndSRC = 0; iStartSRC = strIVPage.IndexOf("onLoad=\"scaleImg('thepic')\" src=\""); if (iStartSRC < 0) { return(false); } iStartSRC += 33; iEndSRC = strIVPage.IndexOf("\">", iStartSRC); if (iEndSRC < 0) { return(false); } strNewURL = strIVPage.Substring(iStartSRC, iEndSRC - iStartSRC); string strFilePath = string.Empty; if (strImgURL.Contains(@"view.php?")) { strFilePath = strNewURL.Substring(strNewURL.LastIndexOf("/") + 1); } else { strFilePath = strImgURL.Substring(strImgURL.LastIndexOf("/") + 1); strFilePath = strFilePath.Replace(".html", ".jpg"); } try { if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; return(false); } strFilePath = Path.Combine(SavePath, Utility.RemoveIllegalCharecters(strFilePath)); CacheObject CCObj = new CacheObject(); CCObj.IsDownloaded = false; CCObj.FilePath = strFilePath; CCObj.Url = strImgURL; try { EventTable.Add(strImgURL, CCObj); } catch (ThreadAbortException) { return(true); } catch (Exception) { if (EventTable.ContainsKey(strImgURL)) { return(false); } else { EventTable.Add(strImgURL, CCObj); } } ////////////////////////////////////////////////////////////////////////// string NewAlteredPath = Utility.GetSuitableName(strFilePath); if (strFilePath != NewAlteredPath) { strFilePath = NewAlteredPath; ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; } try { WebClient client = new WebClient(); client.Headers.Add("Referer: " + strImgURL); client.Headers.Add("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6"); client.DownloadFile(strNewURL, strFilePath); client.Dispose(); } catch (ThreadAbortException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (IOException ex) { //MainForm.DeleteMessage = ex.Message; //MainForm.Delete = true; ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(true); } catch (WebException) { ((CacheObject)EventTable[strImgURL]).IsDownloaded = false; ThreadManager.GetInstance().RemoveThreadbyId(ImageLinkURL); return(false); } ((CacheObject)EventTable[ImageLinkURL]).IsDownloaded = true; //CacheController.GetInstance().u_s_LastPic = ((CacheObject)eventTable[mstrURL]).FilePath; CacheController.Instance().LastPic = ((CacheObject)EventTable[ImageLinkURL]).FilePath = strFilePath; return(true); }
/// <summary> /// Creates the cache controller to sync. /// </summary> private void CreateCacheController() { cacheController = new CacheController(scopeUri, scopeName, this); CacheControllerBehavior behavior = cacheController.ControllerBehavior; // Because the AddType is AddType<T>, need to create a generic method // for each type in the isolatedStorageSchema. This will only be done once, so it's // not too expensive. Type behaviorType = behavior.GetType(); MethodInfo addType = behaviorType.GetTypeInfo().GetDeclaredMethod("AddType"); // Loop over each collection in the isolatedStorageSchema. foreach (Type t in schema.Collections) { // Create the generic method for the type. MethodInfo addTypeT = addType.MakeGenericMethod(t); // Invoke the created method. addTypeT.Invoke(behavior, new object[] { }); } }
public void SetUp() { _controller = new CacheController(VolatileCache.DefaultInstance); }