public ImageInfoItem(ImageInfo imgInfo) { InitializeComponent(); _imgInfo = imgInfo; }
private void ImageGalleryForm_Shown(object sender, EventArgs e) { //get from database Utils.DBCon dbcon = initDatabase(); if (dbcon!=null) { DbDataReader dr = dbcon.ExecuteReader("select * from gallery"); while (dr.Read()) { ImageInfo ai = new ImageInfo(); ai.Description = dr["Description"] as string; ai.ImageGuid = dr["ImageGuid"] as string; ai.ImgFile = dr["ImgFile"] as string; ai.LogCacheCode = dr["LogCacheCode"] as string; ai.LogCode = dr["LogCode"] as string; ai.LogUrl = dr["LogUrl"] as string; ai.LogVisitDate = DateTime.Parse(dr["LogVisitDate"] as string); ai.MobileUrl = dr["MobileUrl"] as string; ai.Name = dr["Name"] as string; ai.ThumbFile = dr["ThumbFile"] as string; ai.ThumbUrl = dr["ThumbUrl"] as string; ai.Url = dr["Url"] as string; _imageInfoList.Add(ai); } dbcon.Dispose(); dbcon = null; } ShowImageThumbnails(); }
private void ShowImageThumbnails() { ImageInfo[] imgInfoList = null; this.Cursor = Cursors.WaitCursor; if (radioButtonAll.Checked) { imgInfoList = (from a in _imageInfoList orderby radioButtonDate.Checked? a.LogVisitDate.ToString("s"): a.Name ascending select a).ToArray(); } else if (radioButtonActive.Checked) { if (Core.ActiveGeocache != null) { imgInfoList = (from a in _imageInfoList where a.LogCacheCode == Core.ActiveGeocache.Code orderby radioButtonDate.Checked ? a.LogVisitDate.ToString("s") : a.Name ascending select a).ToArray(); } } else if (radioButtonText.Checked) { string s = textBoxFilter.Text; imgInfoList = (from a in _imageInfoList where a.Name.ToLower().IndexOf(s, StringComparison.OrdinalIgnoreCase)>=0 orderby radioButtonDate.Checked ? a.LogVisitDate.ToString("s") : a.Name ascending select a).ToArray(); } if (imgInfoList==null) { imgInfoList = new ImageInfo[0]; } flowLayoutPanel1.SuspendLayout(); while (flowLayoutPanel1.Controls.Count > imgInfoList.Length) { flowLayoutPanel1.Controls.RemoveAt(flowLayoutPanel1.Controls.Count -1); } while (flowLayoutPanel1.Controls.Count < imgInfoList.Length) { flowLayoutPanel1.Controls.Add(new ImageInfoItem(null)); } if (radioButtonDescending.Checked) { for (int i = 0; i < imgInfoList.Length; i++) { (flowLayoutPanel1.Controls[i] as ImageInfoItem).ImgInfo = imgInfoList[imgInfoList.Length-i-1]; } } else { for (int i = 0; i < imgInfoList.Length; i++) { (flowLayoutPanel1.Controls[i] as ImageInfoItem).ImgInfo = imgInfoList[i]; } } flowLayoutPanel1.ResumeLayout(true); this.Cursor = Cursors.Default; }
private void getImagesThreadMethod() { try { using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_IMPORTINGMYF, STR_IMPORTINGMYF, 1, 0)) { try { Utils.DBCon dbcon = initDatabase(); var logs = new List<Utils.API.LiveV6.GeocacheLog>(); using (System.Net.WebClient wc = new System.Net.WebClient()) using (var api = new Utils.API.GeocachingLiveV6(Core)) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_IMPORTINGMYF, STR_IMPORTINGLOGS, 100, 0, true)) { var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest(); req.AccessToken = api.Token; req.ExcludeArchived = false; req.MaxPerPage = 50; req.StartIndex = 0; req.LogTypes = (from a in Core.LogTypes select (long)a.ID).ToArray(); var resp = api.Client.GetUsersGeocacheLogs(req); while (resp.Status.StatusCode == 0) { logs.AddRange(resp.Logs); foreach (var log in resp.Logs) { if (log.Images != null && !log.IsArchived) { foreach (var li in log.Images) { string imgGuid = li.ImageGuid.ToString("N"); ImageInfo ii = (from a in _imageInfoList where a.ImageGuid==imgGuid select a).FirstOrDefault(); if (ii == null) { ii = new ImageInfo(); ii.Description = li.Description; ii.ImageGuid = imgGuid; ii.MobileUrl = li.MobileUrl ?? ""; ii.Name = li.Name ?? ""; ii.ThumbUrl = li.ThumbUrl; ii.Url = li.Url; ii.LogCacheCode = log.CacheCode; ii.LogCode = log.Code; ii.LogUrl = log.Url; ii.LogVisitDate = log.VisitDate; ii.ThumbFile = Path.Combine(_thumbFolder, Path.GetFileName(li.ThumbUrl)); ii.ImgFile = Path.Combine(_imgFolder, Path.GetFileName(li.Url)); _imageInfoList.Add(ii); dbcon.ExecuteNonQuery(string.Format("insert into gallery (ImageGuid, ThumbUrl, Description, Name, MobileUrl, Url, LogCacheCode, LogCode, LogUrl, LogVisitDate, ThumbFile, ImgFile) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", ii.ImageGuid.Replace("'", "''"), ii.ThumbUrl.Replace("'", "''"), ii.Description.Replace("'", "''"), ii.Name.Replace("'", "''"), ii.MobileUrl.Replace("'", "''"), ii.Url.Replace("'", "''"), ii.LogCacheCode.Replace("'", "''"), ii.LogCode.Replace("'", "''"), ii.LogUrl.Replace("'", "''"), ii.LogVisitDate.ToString("s").Replace("'", "''"), ii.ThumbFile.Replace("'", "''"), ii.ImgFile.Replace("'", "''"))); } //check if local file(s) exist(s) //not fail on img download! try { if (!File.Exists(ii.ThumbFile)) { wc.DownloadFile(li.ThumbUrl, ii.ThumbFile); } if (!File.Exists(ii.ImgFile)) { wc.DownloadFile(li.Url, ii.ImgFile); } } catch { } } } } if (resp.Logs.Count() >= req.MaxPerPage) { req.StartIndex = logs.Count; if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGLOGS, logs.Count + req.MaxPerPage, logs.Count)) { break; } Thread.Sleep(1500); resp = api.Client.GetUsersGeocacheLogs(req); } else { break; } } if (resp.Status.StatusCode != 0) { _errormessage = resp.Status.StatusMessage; } } } if (dbcon != null) { dbcon.Dispose(); dbcon = null; } } catch (Exception e) { _errormessage = e.Message; } } } catch { } _actionReady.Set(); }
private void getImagesThreadMethod() { try { using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_IMPORTINGMYF, STR_IMPORTINGMYF, 1, 0)) { try { Utils.DBCon dbcon = initDatabase(); var logs = new List <Utils.API.LiveV6.GeocacheLog>(); using (System.Net.WebClient wc = new System.Net.WebClient()) using (var api = new Utils.API.GeocachingLiveV6(Core)) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(OwnerPlugin as Utils.BasePlugin.Plugin, STR_IMPORTINGMYF, STR_IMPORTINGLOGS, 100, 0, true)) { var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest(); req.AccessToken = api.Token; req.ExcludeArchived = false; req.MaxPerPage = 50; req.StartIndex = 0; req.LogTypes = (from a in Core.LogTypes select(long) a.ID).ToArray(); var resp = api.Client.GetUsersGeocacheLogs(req); while (resp.Status.StatusCode == 0) { logs.AddRange(resp.Logs); foreach (var log in resp.Logs) { if (log.Images != null && !log.IsArchived) { foreach (var li in log.Images) { string imgGuid = li.ImageGuid.ToString("N"); ImageInfo ii = (from a in _imageInfoList where a.ImageGuid == imgGuid select a).FirstOrDefault(); if (ii == null) { ii = new ImageInfo(); ii.Description = li.Description; ii.ImageGuid = imgGuid; ii.MobileUrl = li.MobileUrl ?? ""; ii.Name = li.Name ?? ""; ii.ThumbUrl = li.ThumbUrl; ii.Url = li.Url; ii.LogCacheCode = log.CacheCode; ii.LogCode = log.Code; ii.LogUrl = log.Url; ii.LogVisitDate = log.VisitDate; ii.ThumbFile = Path.Combine(_thumbFolder, Path.GetFileName(li.ThumbUrl)); ii.ImgFile = Path.Combine(_imgFolder, Path.GetFileName(li.Url)); _imageInfoList.Add(ii); dbcon.ExecuteNonQuery(string.Format("insert into gallery (ImageGuid, ThumbUrl, Description, Name, MobileUrl, Url, LogCacheCode, LogCode, LogUrl, LogVisitDate, ThumbFile, ImgFile) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", ii.ImageGuid.Replace("'", "''"), ii.ThumbUrl.Replace("'", "''"), ii.Description.Replace("'", "''"), ii.Name.Replace("'", "''"), ii.MobileUrl.Replace("'", "''"), ii.Url.Replace("'", "''"), ii.LogCacheCode.Replace("'", "''"), ii.LogCode.Replace("'", "''"), ii.LogUrl.Replace("'", "''"), ii.LogVisitDate.ToString("s").Replace("'", "''"), ii.ThumbFile.Replace("'", "''"), ii.ImgFile.Replace("'", "''"))); } //check if local file(s) exist(s) //not fail on img download! try { if (!File.Exists(ii.ThumbFile)) { wc.DownloadFile(li.ThumbUrl, ii.ThumbFile); } if (!File.Exists(ii.ImgFile)) { wc.DownloadFile(li.Url, ii.ImgFile); } } catch { } } } } if (resp.Logs.Count() >= req.MaxPerPage) { req.StartIndex = logs.Count; if (!progress.UpdateProgress(STR_IMPORTINGMYF, STR_IMPORTINGLOGS, logs.Count + req.MaxPerPage, logs.Count)) { break; } Thread.Sleep(1500); resp = api.Client.GetUsersGeocacheLogs(req); } else { break; } } if (resp.Status.StatusCode != 0) { _errormessage = resp.Status.StatusMessage; } } } if (dbcon != null) { dbcon.Dispose(); dbcon = null; } } catch (Exception e) { _errormessage = e.Message; } } } catch { } _actionReady.Set(); }