public ComicSourceInfo(ComicSnapshot snapshot, ComicSource source, IComicSourceCondition condition) { Snapshot = snapshot; Source = source; Condition = condition; CanParse = !(condition is null); WatchCommand = new RelayCommand(Watch); CopyCommand = new RelayCommand(Copy); OpenCommand = new AsyncRelayCommand(OpenAsync); }
private void comic_update(object sender, EventArgs e, Comic comic, ComicSource source) { currentcomic = new CurrentComicInfo(comic, source); date.ResetBindings(); date.Checked = true; //i keep getting argumentoutofrangeexceptions. lets try this date.MaxDate = DateTimePicker.MaximumDateTime; date.MinDate = DateTimePicker.MinimumDateTime; //reset mindate and maxdate values then set it again date.MaxDate = source.getMaxDate(comic); date.MinDate = source.getMinDate(comic); date.Value = date.Value; statuscomic.Text = String.Format("({0}) {1}", currentcomic.source.name, currentcomic.comic.name); strip_update(null, null); }
public StorableComicSourceInfo(ComicSnapshot snapshot, ComicSource source, IComicSourceCondition condition, TStoreBox storeBox) : base(snapshot, source, condition) { StoreBox = storeBox; HasBox = storeBox != null; CanStore = condition != null; ToggleSuperFavoriteCommand = new RelayCommand(ToggleSuperFavorite); AddCommand = new AsyncRelayCommand(AddAsync); RemoveCommand = new RelayCommand(Remove); ToggleCommand = new AsyncRelayCommand(ToggleAsync); StoreService = AppEngine.GetRequiredService <ComicStoreService <TStoreBox> >(); }
// never heard of this approach // this is interesting // https://stackoverflow.com/questions/194863/random-date-in-c-sharp private void strip_rando(object sender, EventArgs e) { try { ComicSource comsrc = currentcomic.source; Comic com = currentcomic.comic; int r = (comsrc.getMaxDate(com) - comsrc.getMinDate(com)).Days; DateTime rd = comsrc.getMinDate(com).AddDays(new Random().Next(r)); if (currentcomic.comic.weekinfo.dayofweek is int butt) { date.Value = rd.AddDays(7 - ((int)rd.DayOfWeek - butt % 7)); } else { date.Value = rd; } } catch (ArgumentOutOfRangeException suck) { //Out of range? reroll again strip_rando(sender, e); //we dun care if argumentoutofrangeexception } }
public Garfield() { try { string json = File.ReadAllText(@"strips.json"); comics = JsonConvert.DeserializeObject <List <Comic> >(json); } catch (Exception suck) { MessageBox.Show(String.Format("Your strips.json is wrong.\n\n{0}\n\n...but I'll let you pass this time.", suck.ToString()), "UH OH IO!", MessageBoxButtons.OK, MessageBoxIcon.Error); comics = JsonConvert.DeserializeObject <List <Comic> >(@"[ { 'name': 'Garfield', 'numPanels': 3, 'minDate': '1978-06-19', 'fileName': '{0:yyyy-MM-dd}.gif', 'sources': [ // These are ComicSources. It contains information of the name of the source, the URL format, whether or not it's an HTML and regex for the data. // maxDate and minDate will override the top-layer date settings { 'name': 'GoComics', 'urlFormat': 'https://www.gocomics.com/garfield/{0:yyyy}/{0:MM}/{0:dd}', 'isHtml': true, // This is a RegexInfo. It simply contains the expression and group to tell the program how to pull the comic image URL from the HTML data. 'regex': { 'expression': 'item-comic-image.*data-srcset=\""(.*?) (.*?)(,|\\"")', 'group': 1 } }, { 'name': 'the-eye', 'urlFormat': 'https://the-eye.eu/public/Comics/Garfield/{0:yyyy-MM-dd}.gif', 'maxDate': '2020-07-21' }, { 'name': 'Uclick', 'minDate': '1978-06-19', 'urlFormat': 'http://images.ucomics.com/comics/ga/{0:yyyy}/ga{0:yyMMdd}.gif' }, { 'name': 'archive.org', 'urlFormat': 'https://web.archive.org/web/2019id_/https://d1ejxu6vysztl5.cloudfront.net/comics/garfield/{0:yyyy}/{0:yyyy-MM-dd}.gif', 'maxDate': '2020-07-21' } ] } ]" ); } file = new ToolStripMenuItem("&File"); comic = new ToolStripMenuItem("&Comic"); gimmick = new ToolStripMenuItem("&Gimmicks"); gimmicks = new Gimmicks(); foreach (Gimmick gimmick in gimmicks.gimmicks) { ToolStripMenuItem temp = new ToolStripMenuItem(gimmick.contentlabel, null); temp.Click += (sender, e) => strip_gimmick(sender, e, gimmick); // Not using the EventHandler in constructor this time lol gimmickMenus.Add(temp); } change = new ToolStripMenuItem("&Change comic"); save = new ToolStripMenuItem("&Save strip", null, new EventHandler(strip_save), (Keys.Control | Keys.S)); copy = new ToolStripMenuItem("&Copy strip image to clipboard", null, new EventHandler(strip_copy), (Keys.Control | Keys.C)); copyURL = new ToolStripMenuItem("Copy strip &URL to clipboard", null, new EventHandler(strip_copyURL), (Keys.Control | Keys.Shift | Keys.C)); nextstrip = new ToolStripMenuItem("&Next strip", null, new EventHandler(strip_next)); previousstrip = new ToolStripMenuItem("&Previous strip", null, new EventHandler(strip_previous)); gorando = new ToolStripMenuItem("&Go rando", null, new EventHandler(strip_rando)); exit = new ToolStripMenuItem("E&xit", null, new EventHandler(delegate(object sender, EventArgs e) { this.Close(); }), (Keys.Alt | Keys.F4)); currentcomic = new CurrentComicInfo(comics[0], comics[0].sources[0]); this.AutoSize = true; this.MinimumSize = new Size(661, 480); this.Text = @"Garfield strip picker - " + taglines[new Random().Next(0, taglines.Length)]; stripretriever = new HttpClient(); System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13; stripretriever.DefaultRequestHeaders.UserAgent.TryParseAdd("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); // f**k you msdn you lied to me /*stripretriever.DownloadProgressChanged += new DownloadProgressChangedEventHandler(delegate (object sender, DownloadProgressChangedEventArgs e) { * statusprogress.Value = e.ProgressPercentage; * });*/ panel = new TableLayoutPanel(); panel.ColumnCount = 0; panel.RowCount = 2; panel.Dock = DockStyle.Fill; panel.RowStyles.Clear(); panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 32)); panel.RowStyles.Add(new RowStyle(SizeType.Percent, 90)); this.Controls.Add(panel); picker = new TableLayoutPanel(); picker.ColumnCount = 3; picker.RowCount = 0; picker.Dock = DockStyle.Fill; picker.AutoSize = true; picker.ColumnStyles.Clear(); picker.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 64)); picker.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 90)); picker.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 64)); panel.Controls.Add(picker); stripmenu = new ContextMenuStrip(); stripmenu.Opening += new System.ComponentModel.CancelEventHandler(delegate(object sender, CancelEventArgs e) { stripmenu.Items.Clear(); stripmenu.Items.AddRange(new ToolStripMenuItem[] { save, copy, copyURL, nextstrip, previousstrip, gorando }); }); previous = new Button(); previous.Dock = DockStyle.Fill; previous.Text = "Previous"; previous.Click += new EventHandler(strip_previous); previous.Anchor = AnchorStyles.Left; picker.Controls.Add(previous); date = new DateTimePicker(); date.MinDate = currentcomic.source.getMinDate(currentcomic.comic); date.MaxDate = currentcomic.source.getMaxDate(currentcomic.comic); date.CustomFormat = "yyyy-MM-dd"; date.Format = DateTimePickerFormat.Custom; date.Dock = DockStyle.Fill; date.Anchor = AnchorStyles.None; date.ValueChanged += new EventHandler(strip_update); picker.Controls.Add(date); next = new Button(); next.Dock = DockStyle.Fill; next.Text = "Next"; next.Click += new EventHandler(strip_next); next.Anchor = AnchorStyles.Right; picker.Controls.Add(next); strip = new PictureBox(); strip.SizeMode = PictureBoxSizeMode.Zoom; strip.Dock = DockStyle.Fill; strip.ContextMenuStrip = stripmenu; strip.MinimumSize = new Size(640, 0); panel.Controls.Add(strip); status = new StatusStrip(); statuscomic = new ToolStripStatusLabel(String.Format("({0}) {1}", currentcomic.source.name, currentcomic.comic.name)); statusdate = new ToolStripStatusLabel(); statusprogress = new ToolStripProgressBar(); statusprogress.Alignment = ToolStripItemAlignment.Right; statusprogress.Visible = false; status.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { statuscomic, statusdate, statusprogress }); this.Controls.Add(status); menu = new MenuStrip(); file.DropDownOpening += new EventHandler(delegate(object sender, EventArgs e) { file.DropDownItems.Clear(); file.DropDownItems.AddRange(new ToolStripMenuItem[] { save, copy, copyURL, exit }); }); comic.DropDownOpening += new EventHandler(delegate(object sender, EventArgs e) { comic.DropDownItems.Clear(); comic.DropDownItems.AddRange(new ToolStripMenuItem[] { change, nextstrip, previousstrip, gorando }); }); gimmick.DropDownOpening += new EventHandler(delegate(object sender, EventArgs e) { gimmick.DropDownItems.Clear(); gimmick.DropDownItems.AddRange(gimmickMenus.ToArray()); }); for (int x = 0; x < comics.Count; x++) { // im so f****d up Comic item = comics[x]; ToolStripMenuItem f**k = new ToolStripMenuItem(item.name, null); //, new EventHandler((sender, e) => comic_update(sender, e))); for (int y = 0; y < item.sources.Count; y++) { ComicSource source = item.sources[y]; ToolStripMenuItem sourcemenu = new ToolStripMenuItem(source.name, null); sourcemenu.Click += (sender, e) => comic_update(sender, e, item, source); f**k.DropDownItems.Add(sourcemenu); } change.DropDownItems.Add(f**k); } menu.Items.AddRange(new ToolStripItem[] { file, comic, gimmick }); this.Controls.Add(menu); strip_rando(null, null); strip_update(null, null); }
public async Task <SearchComicResult> SearchAsync(string keywork, int skip, int take) { var page = 1; if (skip != 0 && skip > take) { page = take / skip; } var targetUrl = string.Format(SeachUrl, page, take, keywork); string str = string.Empty; using (var rep = await networkAdapter.GetStreamAsync(new RequestSettings { Address = targetUrl })) using (var sr = new StreamReader(rep)) { str = sr.ReadToEnd(); } var visitor = JsonVisitor.FromString(str); try { var total = int.Parse(visitor["Total"].ToString()); var items = visitor["Items"].ToArray(); var snaps = new List <ComicSnapshot>(); foreach (var item in items) { var comic = item["Comics"].ToArray(); if (!comic.Any()) { continue; } var sn = new ComicSnapshot(); var sources = new List <ComicSource>(); foreach (var c in comic) { var host = c["Host"]; var part = c["Url"]; var name = c["Source"]; var source = new ComicSource { Name = name.ToString(), TargetUrl = host.ToString() + part.ToString() }; sources.Add(source); } var first = comic.First(); sn.Name = first["SomanId"].ToString(); sn.ImageUri = first["PicUrl"].ToString(); sn.Author = first["Author"].ToString(); sn.Descript = first["Content"].ToString(); sn.TargetUrl = targetUrl; sn.Sources = sources.ToArray(); snaps.Add(sn); } return(new SearchComicResult { Snapshots = snaps.ToArray(), Support = true, Total = total }); } finally { visitor.Dispose(); } }
public CurrentComicInfo(Comic comic, ComicSource source) { this.comic = comic; this.source = source; }
protected override WithImageStorableComicSourceInfo <TResource, TImage> CreateSourceInfo(ComicSnapshot snapshot, ComicSource source, ComicEngine engine) { var store = AppEngine.GetRequiredService <WithImageComicStoreService <TResource, TImage> >(); var box = store.GetStoreBox(source.TargetUrl); return(new WithImageStorableComicSourceInfo <TResource, TImage>(snapshot, source, engine.GetComicSourceProviderType(source.TargetUrl), box)); }
protected override ComicSourceInfo CreateSourceInfo(ComicSnapshot snapshot, ComicSource source, ComicEngine engine) { return(new ComicSourceInfo(snapshot, source, engine.GetComicSourceProviderType(source.TargetUrl))); }
public WithImageStorableComicSourceInfo(ComicSnapshot snapshot, ComicSource source, IComicSourceCondition condition, WithImageComicStoreBox <TResource, TImage> storeBox) : base(snapshot, source, condition, storeBox) { }