/// <summary> /// Delete file or move it to recycle bin, navigate to next pic /// and display information /// </summary> /// <param name="Recyclebin"></param> internal static void DeleteFile(string file, bool Recyclebin) { if (TryDeleteFile(file, Recyclebin)) { var filename = Path.GetFileName(file); Pics.Remove(filename); filename = filename.Length >= 25 ? Shorten(filename, 21) : filename; ToolTipStyle(Recyclebin ? "Sent " + filename + " to the recyle bin" : "Deleted " + filename); PreloadCount = reverse ? PreloadCount - 1 : PreloadCount + 1; // Go to next image if (!reverse) { Pic(FolderIndex); } else if (FolderIndex - 2 >= 0) { Pic(FolderIndex - 2); } else { Unload(); } } else { ToolTipStyle("An error occured when deleting " + file); } }
public String POST() { int counts = 0; System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; string url = HttpContext.Current.Request.Url.AbsoluteUri; Pics prodimage = new Pics(); String Status = ""; for (int m = 0; m < files.Count; m++) { //get files(product pictures) System.Web.HttpPostedFile file = files[m]; string filename = new FileInfo(file.FileName).Name; if (file.ContentLength > 0) { Guid id = Guid.NewGuid(); string modifiedFileName = id.ToString() + "_" + filename; byte[] imageprod = new byte[file.ContentLength]; file.InputStream.Read(imageprod, 0, file.ContentLength); prodimage.Image = imageprod; db.Pics1.Add(prodimage); db.SaveChanges(); counts++; } } if (counts > 0) { return(Status); } return("Upload was unsuccesful"); }
/// <summary> /// Reset to default state /// </summary> internal static void Unload() { mainWindow.Bar.ToolTip = mainWindow.Bar.Text = NoImage; mainWindow.Title = NoImage + " - " + AppName; canNavigate = false; mainWindow.img.Source = null; freshStartup = true; if (Pics != null) { Pics.Clear(); } PreloadCount = 0; Preloader.Clear(); FolderIndex = 0; mainWindow.img.Width = mainWindow.Scroller.Width = mainWindow.Scroller.Height = mainWindow.img.Height = double.NaN; xWidth = xHeight = 0; prevPicResource = null; if (!string.IsNullOrWhiteSpace(TempZipPath)) { DeleteTempFiles(); TempZipPath = string.Empty; } NoProgress(); AnimationHelper.Fade(ajaxLoading, 0, TimeSpan.FromSeconds(.2)); }
/// <summary> /// Removes the key, after checking if it exists /// </summary> /// <param name="key"></param> internal static void Remove(string key) { if (key == null) { #if DEBUG Trace.WriteLine("Preloader.Remove key null, " + key); #endif return; } if (!Contains(key)) { #if DEBUG Trace.WriteLine("Preloader.Remove does not contain " + key); #endif return; } _ = Sources[key]; #if DEBUG if (!Sources.TryRemove(key, out _)) { Trace.WriteLine($"Failed to Remove {key} from Preloader, index {Pics.IndexOf(key)}"); } #else Sources.TryRemove(key, out _); #endif }
public async Task <string> Vote(BoringPic boring, bool isLike) { var b = Pics; var msg = await _api.Vote(boring.PicID, isLike); if (string.IsNullOrEmpty(msg)) { return(null); } else if (msg.Contains("THANK YOU")) { if (isLike) { b[Pics.IndexOf(boring)].VotePositive++; } else { b[Pics.IndexOf(boring)].VoteNegative++; } } Pics = b; return(msg); }
/// <summary> /// Deletes file or send it to recycle bin /// </summary> /// <param name="file"></param> /// <param name="Recycle"></param> /// <returns></returns> internal static bool TryDeleteFile(string file, bool Recycle) { /// Need to add function to remove from PicGallery if (!File.Exists(file)) { return(false); } try { var recycle = Recycle ? RecycleOption.SendToRecycleBin : RecycleOption.DeletePermanently; FileSystem.DeleteFile(file, UIOption.OnlyErrorDialogs, recycle); Pics.Remove(file); } #if DEBUG catch (Exception e) { Trace.WriteLine("Delete exception \n" + e.Message); return(false); } #else catch (Exception) { return(false); } #endif return(true); }
/// <summary> /// Removes the key, after checking if it exists /// </summary> /// <param name="key"></param> internal static void Remove(string key) { if (key == null) { return; } if (!Contains(key)) { return; } _ = Sources[key]; #if DEBUG if (Sources.TryRemove(key, out _)) { Trace.WriteLine("Removed = " + key + " from Preloader, index " + Pics.IndexOf(key)); } else { Trace.WriteLine("Failed to Remove = " + key + " from Preloader, index " + Pics.IndexOf(key)); } #else Sources.TryRemove(key, out _); #endif //GC.Collect(); // Need to force this, else too high memory usage? }
internal static void HandleRename() { if (FileFunctions.RenameFile(Pics[FolderIndex], ConfigureWindows.GetMainWindow.TitleText.Text)) { // Check if the file is not in the same folder if (Path.GetDirectoryName(ConfigureWindows.GetMainWindow.TitleText.Text) != Path.GetDirectoryName(Pics[FolderIndex])) { Pics.Remove(Pics[FolderIndex]); if (Pics.Count > 0) { Pic(); } else { Pic(ConfigureWindows.GetMainWindow.TitleText.Text); } } else { Pics[FolderIndex] = ConfigureWindows.GetMainWindow.TitleText.Text; ConfigureWindows.GetMainWindow.Title = ConfigureWindows.GetMainWindow.Title.Replace(Path.GetFileName(Pics[FolderIndex]), Pics[FolderIndex], System.StringComparison.InvariantCultureIgnoreCase); ConfigureWindows.GetMainWindow.TitleText.Text = ConfigureWindows.GetMainWindow.TitleText.Text.Replace(Path.GetFileName(Pics[FolderIndex]), Pics[FolderIndex], System.StringComparison.InvariantCultureIgnoreCase); ConfigureWindows.GetMainWindow.TitleText.ToolTip = ConfigureWindows.GetMainWindow.TitleText.ToolTip.ToString().Replace(Path.GetFileName(Pics[FolderIndex]), Pics[FolderIndex], System.StringComparison.InvariantCultureIgnoreCase); } Refocus(false); } else { Tooltip.ShowTooltipMessage(Application.Current.Resources["AnErrorOccuredMovingFile"]); Refocus(); } }
internal static void Add(BitmapSource bmp, string key) { if (string.IsNullOrWhiteSpace(key)) { return; } if (Contains(key)) { return; } if (bmp == null) { return; } if (!bmp.IsFrozen) { bmp.Freeze(); } #if DEBUG if (Sources.TryAdd(key, bmp)) { Trace.WriteLine("Manually added = " + key + " to Preloader, index " + Pics.IndexOf(key)); } else { Trace.WriteLine("Preloader failed to add = " + key + " , index " + Pics.IndexOf(key)); } #else Sources.TryAdd(key, bmp); #endif }
public void HandleRequest(HttpListenerContext context) { NameValueCollection query; using (StreamReader rdr = new StreamReader(context.Request.InputStream)) query = HttpUtility.ParseQueryString(rdr.ReadToEnd()); Pics pics = new Pics() { SearchOffset = Convert.ToInt32(query["offset"]), Pictures = new List<Pic>() { new Pic() { PicName = "Dark Fire", PictureId = "dark_fire", DataType = 2, Tags = new List<string>() { "test", "test2", "dark", "fire" } } } }; XmlSerializer serializer = new XmlSerializer(pics.GetType(), new XmlRootAttribute(pics.GetType().Name) { Namespace = "" }); XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Encoding = Encoding.UTF8; XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws); serializer.Serialize(xtw, pics, pics.Namespaces); }
protected override void HandleRequest() { Pics pics = new Pics() { SearchOffset = Convert.ToInt32(Query["offset"]), Pictures = new List<Pic>() { new Pic() { PicName = "Dark Fire", PictureId = "dark_fire", DataType = 2, Tags = new List<string>() { "test", "test2", "dark", "fire" } } } }; XmlSerializer serializer = new XmlSerializer(pics.GetType(), new XmlRootAttribute(pics.GetType().Name) { Namespace = "" }); XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Encoding = Encoding.UTF8; XmlWriter xtw = XmlWriter.Create(Context.Response.OutputStream, xws); serializer.Serialize(xtw, pics, pics.Namespaces); }
/// <summary> /// Add file to preloader from index /// </summary> /// <param name="i">Index of Pics</param> internal static void Add(int i) { if (i >= Pics.Count || i < 0) { return; } IsLoading = true; //#if DEBUG //System.Threading.Thread.Sleep(500); //#endif if (File.Exists(Pics[i])) { if (!Contains(Pics[i])) { Add(Pics[i]); } } else { Pics.Remove(Pics[i]); IsLoading = false; #if DEBUG Trace.WriteLine("Preloader removed = " + Pics[i] + " from Pics, index " + i); #endif } }
/// <summary> /// Reset to default state /// </summary> internal static void Unload() { ConfigureWindows.GetMainWindow.TitleText.ToolTip = ConfigureWindows.GetMainWindow.TitleText.Text = Application.Current.Resources["NoImage"] as string; ConfigureWindows.GetMainWindow.Title = Application.Current.Resources["NoImage"] as string + " - " + UILogic.SetTitle.AppName; CanNavigate = false; ConfigureWindows.GetMainWindow.MainImage.Source = null; FreshStartup = true; if (Pics != null) { Pics.Clear(); } Preloader.Clear(); GalleryFunctions.Clear(); ConfigureWindows.GetMainWindow.MainImage.Width = ConfigureWindows.GetMainWindow.Scroller.Width = ConfigureWindows.GetMainWindow.Scroller.Height = ConfigureWindows.GetMainWindow.MainImage.Height = double.NaN; ScaleImage.xWidth = ScaleImage.xHeight = 0; if (!string.IsNullOrWhiteSpace(ArchiveExtraction.TempZipPath)) { DeleteTempFiles(); ArchiveExtraction.TempZipPath = string.Empty; } SystemIntegration.Taskbar.NoProgress(); }
/// <summary> /// Add file to preloader from index /// </summary> /// <param name="i">Index of Pics</param> internal static void Add(int i) { if (i >= Pics.Count || i < 0) { return; } if (File.Exists(Pics[i])) { if (!Contains(Pics[i])) { Add(Pics[i]); } #if DEBUG else { Trace.WriteLine("Skipped at index " + i); } #endif } else { Pics.Remove(Pics[i]); #if DEBUG Trace.WriteLine($"Preloader removed: {Pics[i]} from Pics, index {i}"); #endif } }
//internal static int Count { get { return Sources.Count; } } /// <summary> /// Add file to prelader /// </summary> /// <param name="file">file path</param> internal static void Add(string file) { if (Contains(file)) { IsLoading = false; return; } IsLoading = true; var pic = ImageDecoder.RenderToBitmapSource(file); if (pic == null) { IsLoading = false; return; } if (!pic.IsFrozen) { pic.Freeze(); } Sources.TryAdd(file, pic); IsLoading = false; #if DEBUG Trace.WriteLine("Added = " + file + " to Preloader, index " + Pics.IndexOf(file)); #endif }
/// <summary> /// Delete file or move it to recycle bin, navigate to next pic /// and display information /// </summary> /// <param name="Recyclebin"></param> internal static void DeleteFile(bool Recyclebin) { if (!TryDeleteFile(Pics[FolderIndex], Recyclebin)) { ShowTooltipMessage(Application.Current.Resources["AnErrorOccuredWhenDeleting"] + Environment.NewLine + Pics[FolderIndex]); return; } // Sync with gallery if (UC.GetPicGallery != null) { UC.GetPicGallery.Container.Children.RemoveAt(Pics.IndexOf(Pics[FolderIndex])); } // Sync with preloader Preloader.Remove(Pics[FolderIndex]); Pics.Remove(Pics[FolderIndex]); if (Pics.Count <= 0) { Unload(); return; } Pic(false); ShowTooltipMessage(Recyclebin ? Application.Current.Resources["SentFileToRecycleBin"] : Application.Current.Resources["Deleted"]); }
public string Get(ProjectPrintPic request) { if (Pics.PrintPic()) { return(new OkResponse("print success").ToString()); } else { return(new FailResponse("print fail").ToString()); } }
public void AddPic(Picture picture) { var pic = new PictureVM { Id = picture.Id, MSource = PictureExtensions.ImagePath(picture.Id + picture.Extension, "m", picture.Created), SSource = PictureExtensions.ImagePath(picture.Id + picture.Extension, "s", picture.Created), }; Pics.Add(pic); }
public IHttpActionResult GetPics(int id) { Pics pics = db.Pics1.Find(id); if (pics == null) { return(NotFound()); } return(Ok(pics)); }
/// <summary> /// Add file to prelader /// </summary> /// <param name="file">file path</param> internal static Task Add(string file) { return(Task.Run(() => { var pic = ImageDecoder.RenderToBitmapSource(file); #if DEBUG Trace.WriteLine($"Added {file} to Preloader, index {Pics.IndexOf(file)}"); #endif Sources.TryAdd(file, pic); })); }
public void SavePicture(string Id) { if (!string.IsNullOrEmpty(Id)) { var pic = new PictureVM { Id = Guid.Parse(Id), MSource = PictureExtensions.ImagePath(Id + ".jpg", "m", DateTime.Now), SSource = PictureExtensions.ImagePath(Id + ".jpg", "s", DateTime.Now), }; Pics.Add(pic); } }
//public void RemovePic(Picture picture) //{ // var pic = Pics.FirstOrDefault(p => p.Id == picture.Id); // if(pic != null) // { // Pics.Remove(pic); // }; //} protected async Task DeletePicture(string picId) { var result = await PictureService.DeleteAsync(picId); if (!string.IsNullOrEmpty(result.Id.ToString())) { var pic = Article.Pictures.FirstOrDefault(p => p.Id == Guid.Parse(picId)); if (pic != null) { Article.Pictures.Remove(pic); } Pics.Remove(Pics.FirstOrDefault(p => p.Id == Guid.Parse(picId))); StateHasChanged(); } }
public async void Show(Article article) { Article = article; Pics.Clear(); if (Article.Pictures != null) { foreach (var pic in article.Pictures) { AddPic(pic); } } DialogTitle = article.Id == 0 ? $"{Translate.Keys["Add"]} {Translate.Keys["Article"]}" : $"{Translate.Keys["Update"]}: {article.Title}"; StateHasChanged(); await JsRuntime.InvokeAsync <object>("ShowModal", "articleModal"); }
public string Post(ProjectSavePic request) { using (StreamReader dat = new StreamReader(request.RequestStream)) { string str = dat.ReadToEnd(); if (Pics.SavePic(str)) { return(new OkResponse("save picture success").ToString()); } else { return(new FailResponse("save picture fail").ToString()); } } }
/// <summary> /// Clears data, to free objects no longer necessary to store in memory and allow changing folder without error. /// </summary> internal static void ChangeFolder(bool backup = false) { if (Pics.Count > 0 && backup) { // Make a backup of xPicPath and FolderIndex if (!string.IsNullOrWhiteSpace(Pics[FolderIndex])) { BackupPath = Pics[FolderIndex]; } } Pics.Clear(); GalleryFunctions.Clear(); Preloader.Clear(); FreshStartup = true; DeleteTempFiles(); }
/// <summary> /// Gets values and extracts archives /// </summary> /// <param name="path"></param> /// <returns></returns> internal static Task GetValues(string path) { return(Task.Run(() => { // Determine if archive to be extracted or not bool zipped = false; var extension = Path.GetExtension(path); extension = extension.ToLower(CultureInfo.CurrentCulture); switch (extension) { // Archives case ".zip": case ".7zip": case ".7z": case ".rar": case ".cbr": case ".cb7": case ".cbt": case ".cbz": case ".xz": case ".bzip2": case ".gzip": case ".tar": case ".wim": case ".iso": case ".cab": zipped = Extract(path); if (!zipped) { Pics = new List <string>(); FolderIndex = -1; } return; } // Set files to Pics and get index Pics = FileList(Path.GetDirectoryName(path)); if (Pics == null) { return; } FolderIndex = Pics.IndexOf(path); })); }
public ContentResult VoteDiaUpload() { int error = 1; string fileName = ""; Pic pic = Pics.UploadImg(CurrentUser, ref error, ref fileName); if (error > 0) { return(Content("<script type='text/javascript' language='javascript'>window.parent.App.votePicCallBack(1,\"" + pic.ID.ToString() + "\",\"" + fileName + "\");</script>")); } else if (error == -1) { return(Content("<script type='text/javascript' language='javascript'>window.parent.App.votePicCallBack(-1);</script>")); } else { return(Content("<script type='text/javascript' language='javascript'>window.parent.App.votePicCallBack(-2);</script>")); } }
public ContentResult ThemePicUpload() { int error = 1; string fileName = ""; Pic pic = Pics.UploadImg(CurrentUser, ref error, ref fileName, false); if (error > 0) { return(Content("<script type='text/javascript' language='javascript'>window.parent.App.skinManage.themePicCallBack(1,\"" + pic.ID.ToString() + "\",\"" + pic.OriginalPicUrl + "\");</script>")); } else if (error == -1) { return(Content("<script type='text/javascript' language='javascript'>window.parent.App.skinManage.themePicCallBack(-1);</script>")); } else { return(Content("<script type='text/javascript' language='javascript'>window.parent.App.skinManage.themePicCallBack(-2);</script>")); } }
public void HandleRequest(HttpListenerContext context) { NameValueCollection query; using (StreamReader rdr = new StreamReader(context.Request.InputStream)) query = HttpUtility.ParseQueryString(rdr.ReadToEnd()); Pics pics = new Pics() { SearchOffset = Convert.ToInt32(query["offset"]), Pictures = new List <Pic>() { new Pic() { PicName = "Dark Fire", PictureId = "dark_fire", DataType = 2, Tags = new List <string>() { "test", "test2", "dark", "fire" } } } }; XmlSerializer serializer = new XmlSerializer(pics.GetType(), new XmlRootAttribute(pics.GetType().Name) { Namespace = "" }); XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Encoding = Encoding.UTF8; XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws); serializer.Serialize(xtw, pics, pics.Namespaces); }
//protected override async Task OnInitializedAsync() //{ //} protected override async Task OnParametersSetAsync() { Id = Id ?? "1"; Article = await ArticleService.GetAsync(int.Parse(Id)); foreach (var picture in Article.Pictures) { var pic = new PictureVM { Id = picture.Id, MSource = PictureExtensions.ImagePath(picture.Id + picture.Extension, "m", picture.Created), NSource = PictureExtensions.ImagePath(picture.Id + picture.Extension, "n", picture.Created), Active = "" }; Pics.Add(pic); } if (Pics.Count > 0) { Pics.First().Active = "active"; } }
public static FileType GetFileType(string fullName) { var extn = Path.GetExtension(fullName); if (Pics.Contains(extn)) { return(FileType.Image); } if (Audio.Contains(extn)) { return(FileType.Audio); } if (Video.Contains(extn)) { return(FileType.Video); } if (Docs.Contains(extn)) { return(FileType.Document); } return(FileType.Custom); }
public ContentResult MyProfileUpload() { int error = 1; string fileName = ""; Pic pic = Pics.UploadImg(CurrentUser, ref error, ref fileName); if (error > 0) { return(Content("<script type='text/javascript' language='javascript'>window.parent.App.PicUploadCallBack(1,\"" + pic.SmallPicUrl + "\",\"" + fileName + "\",\"" + pic.ID.ToString() + "\");</script>")); } // Response.Write("<script type='text/javascript' type='language'>window.parent.App.PicUploadCallBack(1,\""+pic.SmallPicUrl+"\",\""+fileName+"\");</script>"); else if (error == -1) { return(Content("<script type='text/javascript' language='javascript'>window.parent.App.PicUploadCallBack(-1);</script>")); // Response.Write("<script type='text/javascript' type='language'>window.parent.App.PicUploadCallBack(-1);</script>"); } else { return(Content("<script type='text/javascript' language='javascript'>window.parent.App.PicUploadCallBack(-2);</script>")); // Response.Write("<script type='text/javascript' type='language'>window.parent.App.PicUploadCallBack(-2);</script>"); } }
public override void HandleRequest(HttpListenerContext context) { NameValueCollection query; using (var rdr = new StreamReader(context.Request.InputStream)) query = HttpUtility.ParseQueryString(rdr.ReadToEnd()); if (query.AllKeys.Length == 0) { string queryString = string.Empty; string currUrl = context.Request.RawUrl; int iqs = currUrl.IndexOf('?'); if (iqs >= 0) { query = HttpUtility.ParseQueryString((iqs < currUrl.Length - 1) ? currUrl.Substring(iqs + 1) : String.Empty); } } Pics pics = new Pics(); pics.Offset = query["offset"] != null ? Convert.ToInt32(query["offset"]) : 0; pics.Pictures = new List<Pic>(); int count = 0; using(var db = new Database(Program.Settings.GetValue("conn"))) { var cmd = db.CreateQuery(); cmd.CommandText = "SELECT COUNT(id) FROM sprites"; count = ((int) (long) cmd.ExecuteScalar()); cmd = db.CreateQuery(); cmd.CommandText = "SELECT * FROM sprites"; using (MySqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { int id = rdr.GetInt32("id"); string guid = rdr.GetString("guid"); string name = rdr.GetString("name"); int dataType = rdr.GetInt32("dataType"); string[] tags = rdr.GetString("tags").Split(','); if (query["tags"] != null) { List<string> tagList = new List<string>(tags); bool succeded = true; foreach (var i in query["tags"].Trim().Split(',')) { if (!tagList.Contains(i.Trim())) succeded = false; } if (!succeded) continue; } if (query["dataType"] != null && Convert.ToInt32(query["dataType"]) != dataType) continue; if (query["guid"] != null) { //if (query["guid"] == "Admin") // continue; if (query["guid"] != guid) continue; } var pic = new Pic { Id = id, DataType = dataType, PicName = name, Tags = string.Join(",", tags) }; if (query["myGUID"] == guid) { pic.Mine = ""; } pics.Pictures.Add(pic); } } } int num = 0; if (query["offset"] != null) pics.Pictures.RemoveRange(0, (Convert.ToInt32(query["offset"]) > count) ? count : Convert.ToInt32(query["offset"])); if (query["num"] != null) if ((num = Convert.ToInt32(query["num"])) < count) pics.Pictures.RemoveRange(num, count - num); var ms = new MemoryStream(); var serializer = new XmlSerializer(pics.GetType(), new XmlRootAttribute(pics.GetType().Name) { Namespace = "" }); var xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Encoding = Encoding.UTF8; xws.Indent = true; XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws); serializer.Serialize(xtw, pics, pics.Namespaces); }