コード例 #1
0
        public  string creaFotos(string identificador, HttpFileCollectionBase FileCollection)
        {

            pictureManagerService pictureService = new pictureManagerService();
            Directorio dir = new Directorio();
            string nameFile = "electronia--" + identificador;
            string result = "";

            

            if (FileCollection.Count > 0)
            {
                
                dir = new Directorio();
                dir = pictureService.CreaDirectorio(identificador);


                for (int i = 0; i < FileCollection.Count; i++)
                {

                    if (FileCollection[i].FileName.Length > 0)
                    {
                        
                        pictureService = new pictureManagerService();
                        Foto new_photo = new Foto();
                        new_photo.item_id = identificador;
                        new_photo.url_general = dir.url + nameFile;
                        new_photo.path_general = dir.path + nameFile;

                        new_photo = pictureService.postFoto(identificador,  new_photo);

                        if (new_photo.num_photo > 0)
                        {
                            Picture pic = new Picture();
                            string nombre = nameFile + "_" + new_photo.num_photo + "_original.jpg";
                            FileCollection[i].SaveAs(dir.path + nombre);
                            string contenido = "";

                            try
                            {

                                pic = pictureService.CrearFoto(identificador, nombre, new_photo.num_photo, 640, 480, dir);
                                pictureService.CreaPaquetes(pic);

                                //string urlfotos = new_photo.url_general;
                                /*
                                contenidoGallery = "{\"icono\":\"" + urlfotos.Replace("_original.", "_50.") +
                                                          "\",\"individual\":\"" + urlfotos.Replace("_original.", "_300.") +
                                                          "\",\"zoom\":\"" + urlfotos.Replace("_original.", "_zoom.") + "\"}";
                                */
                                List<Foto> lista_photos = new List<Foto>();

                                lista_photos = pictureService.getFotos(identificador);

                                foreach (var photos in lista_photos)
                                {
                                    string urlfotos = photos.url_general;
                                    contenido = "{" +
                                                                     "\"name\":\"" + photos.item_id + "_" + photos.num_photo + "_50.jpg\"," +
                                                                     "\"size\":902604," +
                                                                     "\"url\":\"" + urlfotos.Replace("_original.", "_zoom.") + "\"," +
                                                                     "\"thumbnail_url\":\"" + urlfotos.Replace("_original.", "_60.") + "\"," +
                                                                     "\"delete_url\":\"/home/process_picture/" + photos.item_id + "/?option=delete&photo=" + photos.num_photo + "\"," +
                                                                     "\"delete_type\":\"GET\"" +
                                                                     "},";
                                }

                                if (contenido.Length > 0)
                                {
                                    contenido = "[" + contenido + "]";
                                    contenido = contenido.Replace(",]", "]");
                                }




                            }
                            catch
                            {
                                // cuando no subio la foto
                            }

                            result = contenido;
                        }
                    }
                }
                 
            }
            else
            {
                // obtenemos el get para generar el admin de fotos

                List<Foto> lista_photos = new List<Foto>();
                string contenido = "";

                lista_photos = pictureService.getFotos(identificador);

                foreach (var photos in lista_photos)
                {
                    string urlfotos = photos.url_general;
                    contenido = contenido + "{" +
                                                     "\"name\":\"" + photos.item_id + "_" + photos.num_photo + "_50.jpg\"," +
                                                     "\"size\":902604," +
                                                     "\"url\":\"" + urlfotos.Replace("_original.", "_zoom.") + "\"," +
                                                     "\"thumbnail_url\":\"" + urlfotos.Replace("_original.", "_60.") + "\"," +
                                                     "\"delete_url\":\"/home/process_picture/" + photos.item_id + "/?option=delete&photo=" + photos.num_photo + "\"," +
                                                     "\"delete_type\":\"GET\"" +
                                                     "},";
                }

                if (contenido.Length > 0)
                {
                    contenido = "[" + contenido + "]";
                    contenido = contenido.Replace(",]", "]");
                }

                /*
                Directorio dir = new Directorio();
                dir = pictureService.CreaDirectorio(identificador, anioRegistro, mesRegistro);
                string ruta = dir.path;
                
                Archivo archivoAdmin = new Archivo();
                archivoAdmin = pictureService.CrearArchivo(ruta, identificador + "_admin", "json");
                
                string fotos = pictureService.LeerArchivo(archivoAdmin);
                result = fotos;
                */
                result = contenido;
                
            }




            return result;
        }
コード例 #2
0
        public Foto postFoto(string item_id, Foto new_photo)
        {
            Foto foto = new Foto();
            // haces post
            HttpContent content = new ObjectContent<Foto>(new_photo, jsonFormatter);
            client = new HttpClient();
            client.BaseAddress = new Uri(urlApiBase);

            // Add an Accept header for JSON format.
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            // Send an HTTP GET request. Blocking!

            var resp = client.PostAsync("/Picture/" + item_id, content).Result;

            if (resp.IsSuccessStatusCode)
            {
               var result = resp.Content.ReadAsAsync<Foto>().Result;
               foto = new Foto
               {
                   id = result.id,
                   item_id = result.item_id,
                   num_photo = result.num_photo,
                   url_general = result.url_general
               };
            }

            return foto;

        }