Ejemplo n.º 1
0
 private void UpdateCommentFile(string file, string text)
 {
     file = file.Replace("_____", ".");
     TextFile.DeleteFile(file);
     TextFile.CreateFile(file);
     TextFile.AppendToFile(file, text);
 }
Ejemplo n.º 2
0
        public async Task CanSaveAs()
        {
            using (var manager = new PluginManager())
            {
                await manager.LoadCore(new TestCoreMod());

                var testFile = new TextFile();
                testFile.CreateFile("Test");

                var testFileViewModel = new FileViewModel(testFile, manager);
                Assert.AreEqual(true, testFileViewModel.CanSaveAs(manager));
            }
        }
Ejemplo n.º 3
0
        public void Create(string comment, string from, string day, string category)
        {
            var text = comment.Replace(Environment.NewLine, "<br />");

            text += "<br />Från: " + from;

            var time     = DateTime.Now.ToShortTimeString();
            var date     = DateTime.Now.ToShortDateString();
            var fileName = "comment_" + date + " " + time.Replace(":", ".") + ".txt";
            var sPath    = AppDomain.CurrentDomain.BaseDirectory + "Upload\\" + category + "\\" + day;
            var fileUrl  = sPath + "\\" + fileName;

            TextFile.CreateFile(fileUrl);
            TextFile.AppendToFile(fileUrl, text);
        }
Ejemplo n.º 4
0
        public async Task SaveAs()
        {
            using (var manager = new PluginManager())
            {
                await manager.LoadCore(new TestCoreMod());

                var testFile = new TextFile();
                testFile.CreateFile("Test");
                testFile.Contents = "saved";

                var testFileViewModel = new FileViewModel(testFile, manager);
                await testFileViewModel.Save("/test.txt", manager);

                Assert.AreEqual("saved", manager.CurrentFileSystem.ReadAllText("/test.txt"));
            }
        }
Ejemplo n.º 5
0
        public static void Save(DayStory d)
        {
            if (d.Category.Length == 0)
            {
                d.Category = "main";
            }

            var sPath = ConfigurationManager.AppSettings["UploadUrl"] + d.Category + "\\" + d.Day;

            Directory.CreateDirectory(sPath);
            Directory.CreateDirectory(sPath + "\\thumbnails");

            TextFile.CreateFile(sPath + "\\main.txt");
            TextFile.AppendToFile(sPath + "\\main.txt", d.Text);

            TextFile.CreateFile(sPath + "\\header.txt");
            TextFile.AppendToFile(sPath + "\\header.txt", d.Header);

            TextFile.CreateFile(sPath + "\\category.txt");
            TextFile.AppendToFile(sPath + "\\category.txt", d.Category);
        }
Ejemplo n.º 6
0
        public void UploadFile()
        {
            Image        thumbnailImage = null;
            Image        originalImage  = null;
            Bitmap       finalImage     = null;
            Graphics     graphic        = null;
            MemoryStream ms             = null;

            var c  = Request["category"];
            var id = Request["day"];

            if (id.Length == 0)
            {
                //Redirect("/Home/Day/"+ DateTime.Now.ToShortDateString());
            }

            try
            {
                // Get the data
                var jpegImageUpload = Request.Files["Filedata"];
                var newFolder       = id;

                var newPath = Path.Combine(_imageRoot, c, newFolder);
                Directory.CreateDirectory(newPath);

                var newPathThumbs = Path.Combine(newPath, c, "thumbnails");
                Directory.CreateDirectory(newPathThumbs);

                newPath       = string.Format("{0}\\", newPath);
                newPathThumbs = string.Format("{0}thumbnails\\", newPath);

                var imgName      = jpegImageUpload.FileName;
                var imgPath      = newPath + imgName;
                var imgPathThumb = newPathThumbs + imgName;

                // Retrieve the uploaded image
                originalImage = Image.FromStream(jpegImageUpload.InputStream);

                // Calculate the new width and height
                var       width = originalImage.Width;
                var       height = originalImage.Height;
                const int targetWidth = 100;
                const int targetHeight = 100;
                int       newWidth, newHeight;

                const float targetRatio = targetWidth / (float)targetHeight;
                var         imageRatio  = width / (float)height;

                if (targetRatio > imageRatio)
                {
                    newHeight = targetHeight;
                    newWidth  = (int)Math.Floor(imageRatio * targetHeight);
                }
                else
                {
                    newHeight = (int)Math.Floor(targetWidth / imageRatio);
                    newWidth  = targetWidth;
                }

                newWidth  = newWidth > targetWidth ? targetWidth : newWidth;
                newHeight = newHeight > targetHeight ? targetHeight : newHeight;


                // Create the thumbnail

                thumbnailImage = new Bitmap(targetWidth, targetHeight);
                graphic        = Graphics.FromImage(thumbnailImage);
                graphic.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, targetWidth, targetHeight));
                var pasteX = (targetWidth - newWidth) / 2;
                var pasteY = (targetHeight - newHeight) / 2;
                graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; /* new way */
                graphic.DrawImage(originalImage, pasteX, pasteY, newWidth, newHeight);

                // Store the data in my custom Thumbnail object
                ms = new MemoryStream();
                string thumbnail_id = DateTime.Now.ToString("yyyyMMddHHmmssfff");

                thumbnailImage.Save(imgPathThumb, ImageFormat.Jpeg);
                thumbnailImage.Save(ms, ImageFormat.Jpeg);
                var thumb = new Thumbnail(thumbnail_id, ms.GetBuffer());
                List <Thumbnail> thumbnails = Session["file_info"] as List <Thumbnail>;
                if (thumbnails == null)
                {
                    thumbnails           = new List <Thumbnail>();
                    Session["file_info"] = thumbnails;
                }
                thumbnails.Add(thumb);


                if (width > height)
                {
                    newWidth  = 600;
                    newHeight = 400;
                }
                else
                {
                    newWidth  = 400;
                    newHeight = 600;
                }

                finalImage = new Bitmap(newWidth, newHeight);
                graphic    = Graphics.FromImage(finalImage);
                graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; /* new way */
                graphic.DrawImage(originalImage, 0, 0, newWidth, newHeight);
                finalImage.Save(imgPath, ImageFormat.Jpeg);
                TextFile.CreateFile(imgPath + ".txt");

                Response.StatusCode = 200;
                Response.Write(thumbnail_id);
            }
            catch (Exception ex)
            {
                // If any kind of error occurs return a 500 Internal Server error
                Response.StatusCode = 500;
                Response.Write("An error occured");
                Response.End();
                //throw ex;
            }
            finally
            {
                //Clean up
                if (finalImage != null)
                {
                    finalImage.Dispose();
                }
                if (graphic != null)
                {
                    graphic.Dispose();
                }
                if (originalImage != null)
                {
                    originalImage.Dispose();
                }
                if (thumbnailImage != null)
                {
                    thumbnailImage.Dispose();
                }
                if (ms != null)
                {
                    ms.Close();
                }
                Response.End();
            }

            //return Redirect("/Home/Upload/"+c+"/"+id);
        }