예제 #1
0
        public ActionResult MediaExportTest()
        {
            var files = System.IO.File.ReadAllLines(@"d:\temp\ocm-images\export.txt");

            var itemManager = new MediaItemManager();

            //for each file, download original, medium and thumnail, then upload s3
            foreach (var f in files)
            {
                var fields = f.Split('\t');

                var sourceURL = fields[1];

                System.Diagnostics.Debug.WriteLine(sourceURL);
                using (var client = new System.Net.WebClient())
                {
                    //https://ocm.blob.core.windows.net/images/IT/OCM85012/OCM-85012.orig.2017043019024667.jpg
                    var filename = sourceURL.Replace("https://ocm.blob.core.windows.net/images/", "");

                    var output = System.IO.Path.Combine(@"d:\temp\ocm-images-export\", filename);

                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(output));
                    client.DownloadFile(sourceURL, output);

                    var medURL = sourceURL.Replace(".orig.", ".medi.");
                    client.DownloadFile(medURL, output.Replace(".orig.", ".medi."));

                    var thmbURL = sourceURL.Replace(".orig.", ".thmb.");
                    client.DownloadFile(medURL, output.Replace(".orig.", ".thmb."));
                }
            }
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public bool ProcessMediaItemSubmission(HttpContext context, ref MediaItem mediaItem, int userId)
        {
            try
            {
                var    sr          = new System.IO.StreamReader(context.Request.InputStream);
                string jsonContent = sr.ReadToEnd();
                var    submission  = JsonConvert.DeserializeObject <Common.Model.Submissions.MediaItemSubmission>(jsonContent);
                if (submission.ImageDataBase64 == null)
                {
                    return(false);
                }
                string filePrefix = DateTime.UtcNow.Millisecond.ToString() + "_";

                var tempFiles = new List <string>();

                string tempFolder = context.Server.MapPath("~/temp/uploads/");

                string tmpFileName = tempFolder + filePrefix + submission.ChargePointID;
                if (submission.ImageDataBase64.StartsWith("data:image/jpeg"))
                {
                    tmpFileName += ".jpg";
                }
                if (submission.ImageDataBase64.StartsWith("data:image/png"))
                {
                    tmpFileName += ".png";
                }
                if (submission.ImageDataBase64.StartsWith("data:image/tiff"))
                {
                    tmpFileName += ".tiff";
                }

                var image = Base64ToImage(submission.ImageDataBase64);
                image.Save(tmpFileName);

                if (submission.ImageDataBase64.StartsWith("data:"))
                {
                    submission.ImageDataBase64 = submission.ImageDataBase64.Substring(submission.ImageDataBase64.IndexOf(',') + 1, submission.ImageDataBase64.Length - (submission.ImageDataBase64.IndexOf(',') + 1));
                }
                File.WriteAllBytes(tmpFileName, Convert.FromBase64String(submission.ImageDataBase64));

                tempFiles.Add(tmpFileName);

                var task = Task.Factory.StartNew(() =>
                {
                    var mediaManager = new MediaItemManager();

                    foreach (var tmpFile in tempFiles)
                    {
                        var photoAdded = mediaManager.AddPOIMediaItem(tempFolder, tmpFile, submission.ChargePointID, submission.Comment, false, userId);
                    }
                }, TaskCreationOptions.LongRunning);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #3
0
        public ActionResult MediaDelete(int id)
        {
            var itemManager = new MediaItemManager();
            var user        = new UserManager().GetUser((int)UserID);

            itemManager.DeleteMediaItem(user.ID, id);
            return(RedirectToAction("Details", "POI"));
        }
예제 #4
0
        public ActionResult MediaDelete(int id)
        {
            var itemManager = new MediaItemManager();
            var user        = new UserManager().GetUser(int.Parse(Session["UserID"].ToString()));

            itemManager.DeleteMediaItem(user.ID, id);
            return(RedirectToAction("Details", "POI"));
        }
예제 #5
0
        public ActionResult Media()
        {
            UserManager userManager = new UserManager();

            var user = userManager.GetUser((int)UserID);
            var list = new MediaItemManager().GetUserMediaItems(user.ID).OrderByDescending(m => m.DateCreated);

            return(View(list));
        }
예제 #6
0
        public ActionResult Media()
        {
            UserManager userManager = new UserManager();

            var user = userManager.GetUser(int.Parse(Session["UserID"].ToString()));
            var list = new MediaItemManager().GetUserMediaItems(user.ID).OrderByDescending(m => m.DateCreated);

            return(View(list));
        }
예제 #7
0
        public ActionResult Media()
        {
            UserManager userManager = new UserManager();

            var user = userManager.GetUser(int.Parse(Session["UserID"].ToString()));
            var list = new MediaItemManager().GetUserMediaItems(user.ID);

            return(View(list));
        }
예제 #8
0
        public ActionResult MediaDelete(int id)
        {
            var user        = new UserManager().GetUser((int)UserID);
            var itemManager = new MediaItemManager();
            var list        = itemManager.GetUserMediaItems(user.ID);

            //delete item if owned by this user
            if (list.Where(c => c.User.ID == user.ID && c.ID == id).Any())
            {
                itemManager.DeleteMediaItem(user.ID, id);
            }

            return(RedirectToAction("Media"));
        }
예제 #9
0
        public async Task <bool> ProcessMediaItemSubmission(string uploadPath, HttpContext context, MediaItem mediaItem, int userId)
        {
            if (context.Request.Form.Files.Count == 0)
            {
                return(false);
            }

            try
            {
                var    files         = context.Request.Form.Files;
                string filePrefix    = DateTime.UtcNow.Millisecond.ToString() + "_";
                int    chargePointId = int.Parse(context.Request.Form["id"]);
                string comment       = context.Request.Form["comment"];
                var    tempFiles     = new List <string>();

                foreach (var postedFile in context.Request.Form.Files)
                {
                    if (postedFile != null && postedFile.Length > 0)
                    {
                        string tmpFile = uploadPath + "\\" + filePrefix + postedFile.FileName;
                        using (var stream = new FileStream(tmpFile, FileMode.Create))
                        {
                            await postedFile.CopyToAsync(stream);
                        }
                        tempFiles.Add(tmpFile);
                    }
                }

                var task = Task.Factory.StartNew(() =>
                {
                    var mediaManager = new MediaItemManager();

                    foreach (var tmpFile in tempFiles)
                    {
                        var photoAdded = mediaManager.AddPOIMediaItem(uploadPath, tmpFile, chargePointId, comment, false, userId);
                    }
                }, TaskCreationOptions.LongRunning);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #10
0
        public bool ProcessMediaItemSubmission(HttpContext context, ref MediaItem mediaItem, int userId)
        {
            try
            {
                var    files         = context.Request.Files;
                string filePrefix    = DateTime.UtcNow.Millisecond.ToString() + "_";
                int    chargePointId = int.Parse(context.Request["id"]);
                string comment       = context.Request["comment"];
                var    tempFiles     = new List <string>();

                string tempFolder = context.Server.MapPath("~/temp/uploads/");
                foreach (string file in context.Request.Files)
                {
                    var postedFile = context.Request.Files[file];
                    if (postedFile != null && postedFile.ContentLength > 0)
                    {
                        string tmpFile = tempFolder + filePrefix + postedFile.FileName;
                        postedFile.SaveAs(tmpFile);
                        tempFiles.Add(tmpFile);
                    }
                }

                var task = Task.Factory.StartNew(() =>
                {
                    var mediaManager = new MediaItemManager();

                    foreach (var tmpFile in tempFiles)
                    {
                        var photoAdded = mediaManager.AddPOIMediaItem(tempFolder, tmpFile, chargePointId, comment, false, userId);
                    }
                }, TaskCreationOptions.LongRunning);

                return(true);
            }
            catch
            {
                return(false);
            }
        }