Пример #1
0
        public JsonResult ProcessSingleUploads(App app, HttpPostedFileBase file, int galleryId,
                                               UploadProcessor uploadProcessorSepecific)
        {
            if (file != null && app.UploadGuid != null)
            {
                //look for cache if sequence exist before
                var fileName = app.UploadGuid.ToString();
                if (file.ContentLength > 0)
                {
                    // first save gallery and temp record.
                    //upload the image
                    uploadProcessorSepecific.UploadFile(file, fileName, 0, true, true);
                    //successfully uploaded now save a gallery info
                    var galleryCategory = db.GalleryCategories.Find(galleryId);
                    var gallery         =
                        db.Galleries.FirstOrDefault(
                            n =>
                            n.UploadGuid == app.UploadGuid &&
                            n.GalleryCategoryID == galleryCategory.GalleryCategoryID);
                    if (gallery == null)
                    {
                        gallery                   = new Gallery();
                        gallery.GalleryID         = Guid.NewGuid();
                        gallery.UploadGuid        = app.UploadGuid;
                        gallery.Title             = app.AppName;
                        gallery.Extension         = UploadProcessor.GetExtension(file);
                        gallery.GalleryCategoryID = galleryCategory.GalleryCategoryID;
                        gallery.Sequence          = 0;
                        db.Galleries.Add(gallery);
                        // try to add a temp record as well.
                        var tempUpload = new TempUpload();
                        tempUpload.TempUploadID = Guid.NewGuid();
                        tempUpload.UserID       = UserManager.GetLoggedUserId();
                        tempUpload.GalleryID    = gallery.GalleryID;
                        tempUpload.RelatingUploadGuidForDelete = app.UploadGuid;
                        db.TempUploads.Add(tempUpload);
                        db.SaveChanges();
                    }
                    // resize
                    //new Thread(() => {

                    uploadProcessorSepecific.ResizeImageAndProcessImage(gallery, galleryCategory);
                    uploadProcessorSepecific.RemoveTempImage(gallery);
                    //}).Start();
                }
                return(Json(new { isUploaded = true, message = "successfully done" }, "text/html"));
            }
            return(Json(new { isUploaded = false, message = "No file send." }, "text/html"));
        }
Пример #2
0
        public void UploadSongs()
        {
            string targetLocation  = "Natasha Kmeto";
            var    uploadProcessor = new UploadProcessor(containerName, Settings.Default.AzureAccountName, Settings.Default.AzureAccountKey);

            uploadProcessor.OnError  += (s) => { testContextInstance.WriteLine("Error: {0}", s); };
            uploadProcessor.OnStatus += (s) => { testContextInstance.WriteLine("{0}", s); };

            using (var dataContext = new MusicEntities1())
            {
                var songs = from song in dataContext.SONG
                            where song.LOCATION.IndexOf(targetLocation) > -1
                            select song;

                songs = from song in songs
                        where !song.UPLOADED
                        select song;

                foreach (var song in songs)
                {
                    // Change drive to C:
                    if (song.LOCATION.ToLower()[0] != 'c')
                    {
                        song.LOCATION = song.LOCATION.Substring(1);
                        song.LOCATION = "c" + song.LOCATION;
                    }

                    testContextInstance.WriteLine("{0}", song.LOCATION);
                    var fileinfo = new Tuple <string, string>(song.LOCATION, song.ID.ToString());
                    if (uploadProcessor.UploadFile(fileinfo))
                    {
                        song.UPLOADED = true;
                    }
                }
                dataContext.SaveChanges();
            }
        }