Beispiel #1
0
        public ActionResult Create([Bind(Include = "UserName,Profession_Name,Description")] ProfessionalPending professionalPending, string[] selectedOptions, HttpPostedFileBase[] applyFiles)
        {
            if (ModelState.IsValid && selectedOptions != null && applyFiles != null)
            {
                for (int i = 0; i < selectedOptions.Length; i++)
                {//MtM relationship
                    //TODO: figure out if we need more adding (to the icollection)
                    db.PendingToCategories.Add(new PendingToCategory(professionalPending.UserName, selectedOptions[i]));
                }

                //formatting our files
                for (int i = 0; i < applyFiles.Length; i++)
                {//converting each file to a byte array
                    MemoryStream target = new MemoryStream();
                    applyFiles[i].InputStream.CopyTo(target);
                    byte[] content = target.ToArray();
                    //TODO: check if we need more manipulation before saving the byte array
                    PendingFile file = new PendingFile(db.PendingFiles.Count(), content, professionalPending.UserName);
                    db.PendingFiles.Add(file);
                }

                //sealing  and adding pending-professional to the DB
                db.ProfessionalPendings.Add(professionalPending);
                db.SaveChanges();

                return(RedirectToAction("../HomePage/Home"));
            }

            //  ViewBag.Profession_Name = new SelectList(db.Professions, "Profession_Name", "Profession_Name", professionalPending.Profession_Name);
            //ViewBag.UserName = new SelectList(db.Users, "UserName", "FirstName", professionalPending.UserName);
            return(View(professionalPending));
        }
Beispiel #2
0
        private void extractStillImage(PendingFile file)
        {
            var file_path = Path.Combine(MyFileFolder.Pending, file.saved_path);

            var thumb_path = Path.Combine(MyFileFolder.Thumbs, file.file_id.ToString() + ".medium.thumb");

            if (File.Exists(thumb_path))
            {
                File.Delete(thumb_path);
            }

            using (var process = new Process())
            {
                process.StartInfo = new ProcessStartInfo
                {
                    FileName       = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ffmpeg.exe"),
                    Arguments      = string.Format("-i \"{0}\" -r 1 -t 1 -s vga -f image2 \"{1}\"", file_path, thumb_path),
                    CreateNoWindow = true,
                    WindowStyle    = ProcessWindowStyle.Hidden
                };

                process.Start();
                if (!process.WaitForExit(30 * 1000))
                {
                    throw new Exception("ffmpeg does not exit in 30 secs: " + process.StartInfo.Arguments);
                }

                if (!File.Exists(thumb_path))
                {
                    throw new Exception("ffmpeg failed extract still image:" + process.StartInfo.Arguments);
                }
            }
        }
Beispiel #3
0
        private void deleteFile(PendingFile file)
        {
            try{
                var file_path = Path.Combine(MyFileFolder.Pending, file.saved_path);
                File.Delete(file_path);
            }
            catch (Exception err)
            {
                log4net.LogManager.GetLogger(GetType()).Warn("Unable to delete a file", err);
            }

            try
            {
                using (var conn = new SQLiteConnection(MyDbContext.ConnectionString))
                {
                    conn.Open();

                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "update PendingFiles set deleted = 1 where file_id = @file";
                        cmd.Prepare();
                        cmd.Parameters.Add(new SQLiteParameter("@file", file.file_id));
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception err)
            {
                log4net.LogManager.GetLogger(GetType()).Warn("Unable to mark pending file record deleted", err);
            }
        }
        private void showFile(Guid file_id, string file_name, FileAssetType type, string dev, string dev_id)
        {
            try
            {
                this.filename.Text = file_name;
                this.Text          = string.Format(Resources.ProgressTooltip, dev);
                this.currDeviceId  = dev_id;

                PendingFile file = null;
                using (var db = new MyDbContext())
                {
                    var q = from f in db.Object.PendingFiles
                            where f.file_id == file_id
                            select f;


                    file = q.FirstOrDefault();
                }

                if (file == null)
                {
                    return;
                }

                if (type == FileAssetType.image)
                {
                    pictureBox1.ImageLocation = Path.Combine(MyFileFolder.Photo, ".pending", file.saved_path);
                }
                else
                {
                    pictureBox1.Image = Resources.video;
                }

                Show();
            }
            catch (Exception err)
            {
                log4net.LogManager.GetLogger(GetType()).Warn(err.ToString());
            }
        }
Beispiel #5
0
        public void SaveFileRecord(Model.FileAsset file)
        {
            var pendingFile = new PendingFile
            {
                file_id     = file.file_id,
                file_name   = file.file_name,
                file_path   = file.file_path,
                file_size   = file.file_size,
                deleted     = file.deleted,
                device_id   = file.device_id,
                event_time  = file.event_time,
                saved_path  = file.saved_path,
                seq         = file.seq,
                thumb_ready = file.thumb_ready,
                type        = file.type
            };

            using (var db = new MyDbContext())
            {
                db.Object.PendingFiles.Add(pendingFile);
                db.Object.SaveChanges();
            }
        }
Beispiel #6
0
        private void generateThumbnail(PendingFile file, out int width, out int height)
        {
            var file_path = Path.Combine(MyFileFolder.Pending, file.saved_path);

            using (var m = readFilesToMemory(file_path))
                using (var fullImage = createBitmap(m))
                {
                    width  = fullImage.Width;
                    height = fullImage.Height;

                    var longSide = Math.Max(fullImage.Width, fullImage.Height);

                    if (longSide < 256)
                    {
                        return;
                    }

                    var orientation = ImageHelper.ImageOrientation(fullImage);
                    file.orientation = (int)orientation;

                    if (longSide > 2048)
                    {
                        using (var thum = ImageHelper.ScaleBasedOnLongSide(fullImage, 2048))
                        {
                            ImageHelper.CorrectOrientation(orientation, thum);
                            thum.Save(Path.Combine(thumbnailLocation, file.file_id.ToString() + ".large.thumb"), ImageFormat.Jpeg);
                        }
                    }
                    else
                    {
                        fullImage.Save(Path.Combine(thumbnailLocation, file.file_id.ToString() + ".large.thumb"), ImageFormat.Jpeg);
                    }

                    if (longSide > 1024)
                    {
                        using (var thum = ImageHelper.ScaleBasedOnLongSide(fullImage, 1024))
                        {
                            ImageHelper.CorrectOrientation(orientation, thum);
                            thum.Save(Path.Combine(thumbnailLocation, file.file_id.ToString() + ".medium.thumb"), ImageFormat.Jpeg);
                        }
                    }
                    else
                    {
                        fullImage.Save(Path.Combine(thumbnailLocation, file.file_id.ToString() + ".medium.thumb"), ImageFormat.Jpeg);
                    }

                    if (longSide > 512)
                    {
                        using (var thum = ImageHelper.ScaleBasedOnLongSide(fullImage, 512))
                        {
                            ImageHelper.CorrectOrientation(orientation, thum);
                            thum.Save(Path.Combine(thumbnailLocation, file.file_id.ToString() + ".small.thumb"), ImageFormat.Jpeg);
                        }
                    }
                    else
                    {
                        fullImage.Save(Path.Combine(thumbnailLocation, file.file_id.ToString() + ".small.thumb"), ImageFormat.Jpeg);
                    }

                    if (longSide > 256)
                    {
                        using (var thum = ImageHelper.ScaleBasedOnLongSide(fullImage, 256))
                        {
                            ImageHelper.CorrectOrientation(orientation, thum);
                            thum.Save(Path.Combine(thumbnailLocation, file.file_id.ToString() + ".tiny.thumb"), ImageFormat.Jpeg);
                        }
                    }
                    else
                    {
                        fullImage.Save(Path.Combine(thumbnailLocation, file.file_id.ToString() + ".tiny.thumb"), ImageFormat.Jpeg);
                    }
                }
        }