Esempio n. 1
0
 //[HttpPost]
 //public ActionResult UploadFiles( int id,IEnumerable<HttpPostedFileBase> files)
 //{
 //    foreach (HttpPostedFileBase file in files)
 //    {
 //    }
 //    //// byte[] data;
 //    //Photo thePhoto = new Photo();
 //    //thePhoto.BookID = id;
 //    //using (Stream inputStream = file.InputStream)
 //    //{
 //    //    MemoryStream memoryStream = inputStream as MemoryStream;
 //    //    if (memoryStream == null)
 //    //    {
 //    //        memoryStream = new MemoryStream();
 //    //        inputStream.CopyTo(memoryStream);
 //    //    }
 //    //    thePhoto.FileData = memoryStream.ToArray();
 //    //}
 //    //// var buffer = Convert.ToBase64CharArray(file);
 //    //// model.FileData = file.ToArray();
 //    //work.PhotoRepository.Insert(thePhoto);
 //    //work.Save();
 //    //return RedirectToAction("Details", "Book", new { id = id });
 //    return RedirectToAction("Details", "Book");
 //}
 //
 // GET: /Photo/Create
 public ActionResult Create(int id)
 {
     Photo thePhoto = new Photo();
     thePhoto.ParticipantID = id;
     // return View();
     return View(thePhoto);
 }
 public override void GenerateAndInsertThumbnail(Photo photo, Size thumbSize)
 {
     using (this.client = new MyGalleryProviderClient())
     {
         this.client.GenerateAndInsertThumbnail(photo, thumbSize);
     }
 }
 public PreviewPhotoWidget(Photo photo) {
     Build();
     this.labelCaption.LabelProp =
         string.Format("<span color=\"white\" bgcolor=\"black\"><big><b>      {0}      </b></big></span>",
             photo.HtmlEncodedTitle);
     this.imagePreview.SetCachedImage(FileCache.FromUrl(photo.Medium500Url));
 }
Esempio n. 4
0
        public ActionResult Create(Photo model)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        public async Task<Photo> GetOriginalTagsTask(Photo photo) {
            var extraParams = new Dictionary<string, string> {
                {
                    ParameterNames.PhotoId, photo.Id
                }, {
                    ParameterNames.Secret, photo.Secret
                }
            };

            var photoResponse =
                (Dictionary<string, object>)
                    await this._oAuthManager.MakeAuthenticatedRequestAsync(Methods.PhotosGetInfo, extraParams);

            // Override the internal tags with the original ones
            photo.Tags = string.Join(", ", photoResponse.ExtractOriginalTags());

            return photo;
        }
Esempio n. 6
0
        async void cameraCapture_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult != TaskResult.OK) return;

            var capturedPhoto = new BitmapImage();
            capturedPhoto.SetSource(e.ChosenPhoto);
            image.Source = capturedPhoto;

            string fileName = Guid.NewGuid().ToString() + ".jpg"; // Create a random file name
            var photo = new Photo { Caption = captionTextBox.Text, ContainerName = "photos", ResourceName = fileName };

            // Save a new item, this will populate the SAS from the MobileService
            await App.MobileService.GetTable<Photo>().InsertAsync(photo);

            // Upload the image data to the Blob Storage
            using (var client = new HttpClient())
            {
                using (var memoryStream = new MemoryStream())
                {
                    // Get a stream of the captured photo
                    var writableBitmap = new WriteableBitmap(capturedPhoto);
                    writableBitmap.SaveJpeg(memoryStream, capturedPhoto.PixelWidth, capturedPhoto.PixelHeight, 0, 100);
                    memoryStream.Position = 0; // Rewind the stream

                    // Now upload on the SAS
                    var content = new StreamContent(memoryStream);

                    // Create blob url with the SAS, and use it to upload
                    var blobUrlWithSAS = photo.BlobUrl + "?" + photo.SAS;
                    using (var uploadResponse = await client.PutAsync(new Uri(blobUrlWithSAS), content))
                    {
                        uploadResponse.EnsureSuccessStatusCode();
                        var remoteUrl = photo.BlobUrl;
                        remoteImage.Source = new BitmapImage(new Uri(remoteUrl)); // Load the remote image
                    }
                }
            }
        }
        public override List<Photo> ShowPublicAlbum(int albumID)
        {
            List<Photo> result = new List<Photo>();
            String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["Sql"].ConnectionString;
            SqlCommand cmd = new SqlCommand("PublicAlbum");
            DataTable dt = new DataTable();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@albumID", albumID);

            SqlConnection cn = new SqlConnection(strConnString);
            cmd.Connection = cn;
            cn.Open();
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;
            sda.Fill(dt);
            sda.Dispose();
            cn.Close();
            using (dt)
            {
                foreach (DataRow row in dt.Rows)
                {
                    Photo photo = new Photo();
                    photo.AlbumID = (int)row["AlbumID"];
                    photo.Description = (string)row["Description"];
                    photo.Name = (string)row["Name"];
                    photo.PhotoID = (int)row["PhotoID"];

                    result.Add(photo);
                }
            }
            return result;
        }
        public override List<Photo> PhotosWithoutThumb()
        {
            var imagesToResize = new List<Photo>();
            string strConnString = ConfigurationManager.ConnectionStrings["Sql"].ConnectionString;
            SqlCommand cmd = new SqlCommand("GetPhotosWithoutThumb");
            DataTable dt = new DataTable();
            cmd.CommandType = CommandType.StoredProcedure;

            SqlConnection cn = new SqlConnection(strConnString);
            cmd.Connection = cn;
            cn.Open();
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = cmd;
            sda.Fill(dt);
            sda.Dispose();
            cn.Close();

            foreach (DataRow row in dt.Rows)
            {
                var photo = new Photo();
                photo.PhotoByte = (byte[])row["Photo"];
                photo.PhotoID = (int)row["PhotoID"];
                imagesToResize.Add(photo);
            }
            dt.Dispose();

            return imagesToResize;
        }
        public override void GenerateAndInsertThumbnail(Photo photo, Size thumbSize)
        {
            Byte[] bytes = photo.PhotoByte;

            SqlCommand cmd = new SqlCommand("InserThumbanil");
            cmd.CommandType = CommandType.StoredProcedure;

            byte[] thumbnail = null;
            var ms = new MemoryStream();
            ms.Write(bytes, 0, bytes.Length);
            Bitmap bmp = new Bitmap(ms);

            Image thumb = bmp.GetThumbnailImage(thumbSize.Width, thumbSize.Height, null, new System.IntPtr());
            bmp.Dispose();
            var thumMs = new MemoryStream();

            thumb.Save(thumMs, System.Drawing.Imaging.ImageFormat.Bmp);
            thumbnail = thumMs.ToArray();
            cmd.Parameters.Add("@Thumbnail", SqlDbType.VarBinary).Value = thumbnail;
            cmd.Parameters.AddWithValue("@PhotoID", photo.PhotoID);

            InsertUpdateData(cmd);
        }
Esempio n. 10
0
 public Boolean AddPhoto(Photo photo)
 {
     if (photo == null) return false;
     _photos.AddLast(photo);
     return true;
 }
 private void FindAndSelectPhoto(Photo photo) {
     Log.Debug("FindAndSelectPhoto");
     foreach (var box in this.photosGrid.AllItems) {
         var hbox = box as HBox;
         if (hbox == null) {
             continue;
         }
         foreach (var child in hbox.AllChildren) {
             var photoWidget = child as PhotoWidget;
             if (photoWidget != null && photoWidget.WidgetItem.Id == photo.Id) {
                 photoWidget.IsSelected = true;
                 return;
             }
         }
     }
 }
Esempio n. 12
0
        public string Upload(int id, HttpPostedFileBase file)
        {
            //var length = Request.ContentLength;
            //var bytes = new byte[length];
            //Request.InputStream.Read(bytes, 0, length);

            //var files = Request.Files[0];
            //byte[] fileContents = new byte[files.ContentLength];
            //file.InputStream.Read(fileContents, 0, file.ContentLength);

            //  byte[]  fileContents = new byte[Request.ContentLength];
            // fileContents.to
            //  Request.InputStream.Read(fileContents, 0, Request.ContentLength);

            //   var file = Request.Files[0];

            Photo thePhoto = new Photo();
            thePhoto.ParticipantID = id;

            //  UploadedFile file = RetrieveFileFromRequest();
            // string savePath = string.Empty;
            // string virtualPath = SaveFile(file);

            using (var stream = new MemoryStream())
            {
                Request.InputStream.CopyTo(stream);
                thePhoto.FileData = stream.ToArray();
                // var domainModel = new MyDomainModel
                // {
                //    AdImage = image,
                //  Description = model.Description
                //};

                // TODO: persist the domain model by passing it to a method
                // on your DAL layer
            }

            List<Photo> thePhotos = work.PhotoRepository.Get(a => a.ParticipantID == id).ToList();
            if (thePhotos.Count() > 0)
            {
                UnitOfWork work2 = new UnitOfWork();
                Photo theOldPhoto = thePhotos[0];
                work2.PhotoRepository.Delete(theOldPhoto);
                work2.Save();

            }

            work.PhotoRepository.Insert(thePhoto);
            work.Save();

            return null;
        }
Esempio n. 13
0
 public abstract void GenerateAndInsertThumbnail(Photo photo, Size thumbSize);
Esempio n. 14
0
 public void GenerateAndInsertThumbnail(Photo photo, System.Drawing.Size thumbSize)
 {
     DBGateway.MyGalleryProviderSqlManager.GenerateAndInsertThumbnail(photo, thumbSize);
 }
 private static void WriteMetaDataFile(Photo photo, string targetFileName, Preferences preferences) {
     var metadata = preferences.Metadata.ToDictionary(metadatum => metadatum,
         metadatum =>
             photo.GetType()
                  .GetProperty(metadatum)
                  .GetValue(photo, null)
                  .ToString());
     if (metadata.Count > 0) {
         File.WriteAllText(string.Format("{0}.json", targetFileName), metadata.ToJson(), Encoding.UTF8);
     }
 }
Esempio n. 16
0
 public static void GenerateAndInsertThumbnail(Photo photo, Size thumbSize)
 {
     _Provider.GenerateAndInsertThumbnail(photo, thumbSize);
 }