コード例 #1
0
        public ActionResult EditAllImages(EditAllImagesViewModel model)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel.UploadedImages != null)
            {
                foreach (ImageModel img in sessionModel.UploadedImages)
                {
                    if (model.GlyphOutside != null)
                    {
                        img.GlyphOutside = (bool)model.GlyphOutside;
                    }

                    if (model.GlyphPosition != null)
                    {
                        img.GlyphPosition = (GlyphPositionChoises)model.GlyphPosition;
                    }

                    if (model.GlyphSize != null)
                    {
                        img.GlyphSize = (GlyphSizeChoises)model.GlyphSize;
                    }
                }
                this.AddToSession("ProjectInfo", sessionModel); //save in session
            }
            return(RedirectToAction("ImageList"));
        }
コード例 #2
0
        public ActionResult ImageUpload(List <IFormFile> files)
        {
            List <ImageModel> pathsForImages = new List <ImageModel>();

            if (files != null)
            {
                for (int i = 0; i < files.Count; i++)
                {
                    IFormFile file = files[i];
                    if (!UploadedFileIsImage.Check(file))
                    {
                        continue;
                    }

                    if (file.Length > 0)
                    {
                        string fileName            = Path.GetFileName(file.FileName);  // getting fileName
                        string fileNameWithoutType = Path.GetFileNameWithoutExtension(file.FileName);
                        string myUniqueFileName    = Convert.ToString(Guid.NewGuid()); // assigning Unique filename (Guid)
                        string fileExtension       = Path.GetExtension(fileName);      // getting file extension
                        string newFileName         = myUniqueFileName + fileExtension; // concatenating FileName + FileExtension

                        string filepath = UserDirectoryPath;
                        filepath += newFileName;
                        string pathToSaveInSession = $@"/{"TempFiles"}/~{this.SessionId()}/{newFileName}";

                        using (FileStream fs = System.IO.File.Create(filepath))
                        {
                            file.CopyTo(fs);
                            fs.Flush();

                            ImageModel newModel = new ImageModel()
                            {
                                Path          = pathToSaveInSession,
                                Name          = fileNameWithoutType,
                                GlyphSize     = GlyphSizeChoises.Medium,
                                GlyphOutside  = false,
                                GlyphPosition = GlyphPositionChoises.TopLeft
                            };

                            pathsForImages.Add(newModel); //add the image path to the list
                        }
                    }
                }
            }

            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel.UploadedImages != null) //Does the user have an image array in the session already? If that's the case just append the new image list to the old one
            {
                sessionModel.UploadedImages.AddRange(pathsForImages);
            }
            else
            {
                sessionModel.UploadedImages = pathsForImages;
            }

            this.AddToSession("ProjectInfo", sessionModel);
            return(View(sessionModel.UploadedImages));
        }
コード例 #3
0
        /// <summary>
        /// Get the image paths for the dropdown menu
        /// </summary>
        private IEnumerable <SelectListItem> getImagePaths()
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            SelectListItem[] items;
            if (sessionModel.UploadedImages != null)
            {                                                                      //there is at least 1 uploaded image
                items = new SelectListItem[sessionModel.UploadedImages.Count + 1]; //the first choice (index 0) is "no image attached", so list length + 1 is the new length
                for (int i = 1; i < sessionModel.UploadedImages.Count + 1; i++)
                {
                    items[i] = new SelectListItem()
                    {
                        Text = sessionModel.UploadedImages[i - 1].Name, Value = sessionModel.UploadedImages[i - 1].Path
                    };                                                                                                                                   //selection choice
                }
            }
            else
            {
                items = new SelectListItem[1]; //the "no image attached" is the only element
            }

            items[0] = new SelectListItem()
            {
                Text = "No image attached.", Value = "Null"
            };
            return(items);
        }
コード例 #4
0
        public ActionResult EditAuthor(int id, AuthorModel model)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            sessionModel.Authors[id] = model;
            this.AddToSession("ProjectInfo", sessionModel); //save in session
            return(RedirectToAction("AuthorList"));
        }
コード例 #5
0
        public ActionResult EditFigure(int id, FigureModel model)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            model.Image = searchImageByPath(model.ImagePath);
            sessionModel.Figures[id] = model;
            this.AddToSession("ProjectInfo", sessionModel); //save in session
            return(RedirectToAction("FigureList"));
        }
コード例 #6
0
        public ActionResult EditImage(int id, ImageModel model)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            model.Path = sessionModel.UploadedImages[id].Path; //don't change the path
            sessionModel.UploadedImages[id] = model;
            this.AddToSession("ProjectInfo", sessionModel);    //save in session
            return(RedirectToAction("ImageList"));
        }
コード例 #7
0
        /// <summary>
        /// Checks if the project has been already finished
        /// </summary>
        /// <param name="controller">The controller of the view</param>
        /// <returns>Is it finished?</returns>
        public static bool IsProjectFinished(this Controller controller)
        {
            SessionModelCollector sessionModel = SessionHelper.GetFromSession <SessionModelCollector>(controller, "ProjectInfo");

            if (sessionModel != null)
            {
                return(sessionModel.IsFinished);
            }

            return(false);
        }
コード例 #8
0
        public ActionResult RemoveFigure(int id)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel.Figures != null)
            {
                sessionModel.Figures.RemoveAt(id);
                this.AddToSession("ProjectInfo", sessionModel); //save in session
            }

            return(RedirectToAction("FigureList"));
        }
コード例 #9
0
        public ActionResult ProjectFile(ProjectFileModel model)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel != null)
            {
                sessionModel.ProjectFile = model;
                sessionModel.IsFinished  = true;
            }

            this.AddToSession("ProjectInfo", sessionModel);
            return(RedirectToAction("NewImages"));
        }
コード例 #10
0
        public ActionResult AddAuthor(AuthorModel model)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel.Authors == null)
            {
                sessionModel.Authors = new List <AuthorModel>();
            }

            sessionModel.Authors.Add(model);                //add the new model to the list

            this.AddToSession("ProjectInfo", sessionModel); //save in session
            return(RedirectToAction("AuthorList"));
        }
コード例 #11
0
        public ActionResult EditImage(int id)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel.UploadedImages != null)
            {
                if (sessionModel.UploadedImages[id] != null)
                {
                    ImageModel model = sessionModel.UploadedImages[id];
                    return(this.CheckViewFirst(model));
                }
            }

            return(View("AddModel"));
        }
コード例 #12
0
        public ActionResult EditAuthor(int id)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel.Authors != null)
            {
                if (sessionModel.Authors[id] != null)
                {
                    AuthorModel model = sessionModel.Authors[id];
                    return(View(model));
                }
            }

            return(this.CheckViewFirst("AddAuthor"));
        }
コード例 #13
0
        public ActionResult AddFigure(FigureModel model)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel.Figures == null)
            {
                sessionModel.Figures = new List <FigureModel>();
            }

            model.Image = searchImageByPath(model.ImagePath);
            sessionModel.Figures.Add(model);                //add the new model to the list

            this.AddToSession("ProjectInfo", sessionModel); //save in session
            return(RedirectToAction("FigureList"));
        }
コード例 #14
0
        public ActionResult EditFigure(int id)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel.Figures != null)
            {
                if (sessionModel.Figures[id] != null)
                {
                    FigureModel model = sessionModel.Figures[id];
                    model.ImagePaths = getImagePaths();
                    return(View(model));
                }
            }

            return(View("AddModel"));
        }
コード例 #15
0
        /// <summary>
        /// Search in the uploaded images for a specific path.
        /// </summary>
        /// <param name="path">The path for search</param>
        /// <returns>The uploaded ImageModel</returns>
        private ImageModel searchImageByPath(string path)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel.UploadedImages != null)
            {
                foreach (ImageModel img in sessionModel.UploadedImages)
                {
                    if (img.Path == path)
                    {
                        return(img);
                    }
                }
            }

            return(null);
        }
コード例 #16
0
        public ActionResult MetaData(MetaDataModel model)
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel == null) //if the sessionmodel is not exists
            {
                sessionModel = new SessionModelCollector
                {
                    MetaData  = model,
                    SessionId = this.SessionId()
                };
            }
            else //if exists just update (so the user edited the metadata)
            {
                sessionModel.MetaData = model;
            }

            this.AddToSession("ProjectInfo", sessionModel); //add metadata to the session
            return(RedirectToAction("AuthorList"));
        }
コード例 #17
0
        private void createUserDirectoryPathIfNotExists()
        {
            //handle temp files directory
            string tempDirectoryPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "TempFiles");

            if (!Directory.Exists(tempDirectoryPath))
            {
                Directory.CreateDirectory(tempDirectoryPath);
            }

            //handle the uploaded file path
            string filepath = new PhysicalFileProvider(tempDirectoryPath).Root + $@"\~{this.SessionId()}\";

            if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
                SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");
                sessionModel.SessionDirectoryPath = filepath;
                this.AddToSession("ProjectInfo", sessionModel);
            }

            deleteOldArticleDirectories();
        }
コード例 #18
0
        public ActionResult AuthorList()
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            return(this.CheckViewFirst((sessionModel.Authors != null) ? sessionModel.Authors : new List <AuthorModel>()));
        }
コード例 #19
0
        public ActionResult NewImages()
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            if (sessionModel == null || sessionModel.Figures == null)
            {
                return(View(sessionModel));
            }

            //create a directory in the user's session directory
            string pathToSaveNewImages = sessionModel.SessionDirectoryPath + @"\NewImages";

            if (!Directory.Exists(pathToSaveNewImages))
            {
                Directory.CreateDirectory(pathToSaveNewImages);
            }

            HashSet <string> imageNames = new HashSet <string>();

            for (int i = 0; i < sessionModel.Figures.Count; i++)
            {
                ImageModel img         = sessionModel.Figures[i].Image;
                int        glyphWidth  = 0;
                int        glyphHeight = 0;

                //set the sizes
                switch (img.GlyphSize)
                {
                case GlyphSizeChoises.Small:
                    glyphWidth  = Consts.GlyphWidthSmall;
                    glyphHeight = Consts.GlyphHeightSmall;
                    break;

                case GlyphSizeChoises.Medium:
                    glyphWidth  = Consts.GlyphWidthMedium;
                    glyphHeight = Consts.GlyphHeightMedium;
                    break;

                case GlyphSizeChoises.Big:
                    glyphWidth  = Consts.GlyphWidthBig;
                    glyphHeight = Consts.GlyphHeightBig;
                    break;
                }
                int qrSize = glyphWidth;

                string QRCode = $"{sessionModel.ProjectFile.URLToFile};{i}";                                          //the content of the qr code
                using (Image <Rgba32> img_glyph = Image.Load <Rgba32>(_env.ContentRootPath + @"\Glyphs\glyph_0.png")) // the glyph img
                    using (Image <Rgba32> img_base = Image.Load <Rgba32>(_env.WebRootPath + img.Path))                // the base image
                        using (Image <Rgba32> img_qrCode = Image.Load <Rgba32>(createQRCode(QRCode)))                 // qr code img
                        {
                            int outputWidth  = img_base.Width;
                            int outputHeight = img_base.Height;

                            //the glyph and the qr code bigger than the base img? (shouldn't be, but handle it)
                            if (outputWidth < glyphWidth + qrSize)
                            {
                                outputWidth = glyphWidth + qrSize;
                            }
                            if (outputHeight < glyphHeight + qrSize)
                            {
                                outputHeight = glyphHeight + qrSize;
                            }

                            //if the glyph is outside we need a bigger img
                            if (img.GlyphOutside)
                            {
                                outputWidth += glyphWidth;
                            }

                            using (Image <Rgba32> outputImage = new Image <Rgba32>(outputWidth, outputHeight)) // create output image of the correct dimensions
                            {
                                img_glyph.Mutate(o => o.Resize(new Size(glyphWidth, glyphHeight)));            //resize glyph
                                img_qrCode.Mutate(o => o.Resize(new Size(qrSize, qrSize)));                    //resize qrcode

                                int imgX           = 0;
                                int imgY           = 0;
                                int baseImgOffsetX = 0;
                                switch (img.GlyphPosition)
                                {
                                case GlyphPositionChoises.BottomLeft:
                                    imgX = 0;
                                    imgY = outputHeight - glyphHeight - qrSize;

                                    if (img.GlyphOutside)
                                    {
                                        baseImgOffsetX = glyphWidth;
                                    }
                                    break;

                                case GlyphPositionChoises.BottomRight:
                                    imgX = outputWidth - glyphWidth;
                                    imgY = outputHeight - glyphHeight - qrSize;
                                    break;

                                case GlyphPositionChoises.TopLeft:
                                    imgX = 0;
                                    imgY = 0;
                                    if (img.GlyphOutside)
                                    {
                                        baseImgOffsetX = glyphWidth;
                                    }
                                    break;

                                case GlyphPositionChoises.TopRight:
                                    imgX = outputWidth - glyphWidth;
                                    imgY = 0;
                                    break;
                                }

                                //create the new image
                                outputImage.Mutate(o => o
                                                   .DrawImage(img_base, new Point(baseImgOffsetX, 0), 1f)               // base img
                                                   .DrawImage(img_glyph, new Point(imgX, imgY), 1f)                     // glyph
                                                   .DrawImage(img_qrCode, new Point(imgX, imgY + img_glyph.Height), 1f) // qrCode under to the glyph
                                                   );

                                string imageName = $"{img.Name}";
                                Random rnd       = new Random();
                                while (imageNames.Contains(imageName) || !isFileNameOk(imageName))
                                {
                                    imageName = $"output{rnd.Next(0, 100000)}";
                                }
                                imageNames.Add(imageName);
                                outputImage.Save(@$ "{pathToSaveNewImages}\{imageName}.png"); //save to the newimages folder
コード例 #20
0
        public ActionResult ProjectFile()
        {
            ProjectFileModel model = new ProjectFileModel()
            {
                PathToFile = "ERROR"
            };

            try
            {
                SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");
                if (sessionModel.Figures.Count <= 0)
                {
                    return(RedirectToAction("Figure", "FigureList"));
                }

                var filepath = sessionModel.SessionDirectoryPath + @"\document.augp";
                using (FileStream fileStream = new FileStream(filepath, FileMode.Create)) //create the .augp file in the user's temp folder
                {
                    XmlWriterSettings settings = new XmlWriterSettings()
                    {
                        Indent = true
                    };
                    using (XmlWriter writer = XmlWriter.Create(fileStream, settings))
                    {
                        writer.WriteStartDocument(false);
                        //start file
                        writer.WriteStartElement("AugmentedPaper");

                        //METADATA
                        writer.WriteStartElement("MetaData");
                        writer.WriteAttributeString("ArticleName", sessionModel.MetaData.ProjectName);
                        writer.WriteAttributeString("DOI", sessionModel.MetaData.DOI);

                        writer.WriteStartElement("Authors");

                        if (sessionModel.Authors != null)
                        {
                            foreach (var item in sessionModel.Authors)
                            {
                                writer.WriteStartElement("Author");

                                writer.WriteAttributeString("Name", item.FullName);
                                writer.WriteAttributeString("Affiliation", item.Affiliation);

                                writer.WriteEndElement(); //</Figure>
                            }
                        }
                        else
                        {
                            writer.WriteComment("No authors found.");
                        }

                        writer.WriteEndElement(); //</Authors>

                        writer.WriteEndElement(); //</MetaData>
                        //METADATA ENDS

                        //FIGURES
                        writer.WriteStartElement("Figures");

                        //Figures
                        if (sessionModel.Figures != null && sessionModel.Figures.Count > 0)
                        {
                            for (int i = 0; i < sessionModel.Figures.Count; i++)
                            {
                                writer.WriteStartElement("Figure");

                                writer.WriteAttributeString("Id", i.ToString());
                                writer.WriteAttributeString("Title", sessionModel.Figures[i].Name);
                                writer.WriteAttributeString("ObjFile", sessionModel.Figures[i].ObjPath);
                                writer.WriteAttributeString("MtlFile", sessionModel.Figures[i].MtlPath);

                                writer.WriteEndElement(); //</Figure>
                            }
                        }
                        else
                        {
                            writer.WriteComment("No models found.");
                        }

                        writer.WriteEndElement(); //</Figures>
                        //FIGURES END

                        writer.WriteEndElement(); //</AugmentedPaper>
                        //end file

                        writer.Flush();
                    }
                    fileStream.Flush();
                }

                model.PathToFile         = filepath;
                sessionModel.ProjectFile = model;
                this.AddToSession("ProjectInfo", sessionModel);
            } catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
            }

            return(this.CheckViewFirst(model));
        }
コード例 #21
0
        public ActionResult FigureList()
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            return(this.CheckViewFirst((sessionModel.Figures != null) ? sessionModel.Figures : new List <FigureModel>()));
        }
コード例 #22
0
        public ActionResult ImageList()
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            return(this.CheckViewFirst((sessionModel.UploadedImages != null) ? sessionModel.UploadedImages : new List <ImageModel>()));
        }
コード例 #23
0
        public ActionResult ImageUpload()
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo");

            return(this.CheckViewFirst(sessionModel.UploadedImages));
        }
コード例 #24
0
        public ActionResult MetaData()
        {
            SessionModelCollector sessionModel = this.GetFromSession <SessionModelCollector>("ProjectInfo"); //use the given values as metadata if it's already exists in the session (so the user don't have to type it again)

            return(this.CheckViewFirst((sessionModel != null) ? sessionModel.MetaData : null));
        }