Пример #1
0
        public async Task <IProject> GetProjectWithLabelAsync(int id)
        {
            IProject project = await projectController.GetByIdAsync(id);

            if (!project.LabeledPath.IsNullOrEmpty())
            {
                project.LabeledPath = await System.IO.File.ReadAllTextAsync(project.LabeledPath);
            }
            return(project);
        }
Пример #2
0
        public static async Task <IImage> ImageUploadAsync(IData data)
        {
            try
            {
                data = GetBase64OutOfXML(data);
                var      bytes   = data.Base64.Base64ToByte();
                IProject project = await projectController.GetByIdAsync(data.ProjectId);

                Image image = new Image();
                image.Width  = data.Width;
                image.Height = data.Height;

                //Queries whether the directory (for images) of the respective project exists and creates it if not.
                string dir_path = $"./Ressources/Images/{project.Id}_{project.Name}";
                if (!System.IO.Directory.Exists(dir_path))
                {
                    System.IO.Directory.CreateDirectory(dir_path);
                }

                //Queries whether the image exists
                //  -if so, it will only be updated
                //  -if no, a database entry is made with the respective path
                string img_path = $"./Ressources/Images/{project.Id}_{project.Name}/{data.Name}";
                if (!System.IO.File.Exists(img_path))
                {
                    image.ImagePath = img_path;
                    image.ProjectId = data.ProjectId;
                }

                //the image is saved
                await System.IO.File.WriteAllBytesAsync(img_path, bytes);

                await imageController.InsertAsync(image);

                await imageController.SaveChangesAsync();

                return(image);
            }
            catch (Exception er)
            {
                Console.WriteLine(er.ToString());
                return(null);
            }
        }
Пример #3
0
        public static async Task <IData> GetPictureByIdAsync(int id)
        {
            IImage image = await imageController.GetByIdAsync(id);

            byte[] bytes  = System.IO.File.ReadAllBytes(image.ImagePath);
            string base64 = bytes.ImageToBase64();

            string[] pathParts = image.ImagePath.Split('/');
            IData    data      = new Data
            {
                Id        = id,
                Base64    = base64,
                Name      = pathParts[^ 1],