Esempio n. 1
0
        public void DownloadPhoto(Photo photo, string dest)
        {
/*            BinaryWriter writer = new BinaryWriter (File.Open (dest, FileMode.Create));
 *                      MemoryStream data = new MemoryStream ();
 *          try {
 *              long len;
 *              using (BinaryReader reader = new BinaryReader (StreamPhoto (photo, out len))) {
 *                  int count = 0;
 *                  byte [] buf = new byte [chunk_length];
 *
 *                                      // Skip the header
 *                                      //count = reader.Read (buf,0,89);
 *
 *                                      //if (count < 89)
 *                                      //	count+=reader.Read (buf,0,89-count);
 *
 *                                      while (true) {
 *                  buf = reader.ReadBytes (8192);
 *                  if (buf.Length == 0)
 *                      break;
 *
 *                  data.Write (buf, 0, buf.Length);
 *                                      //Console.Write (buf.);
 *                                      }
 *
 */
/*                    do {
 *                      count = reader.Read (buf, 0, chunk_length);
 *                      writer.Write (buf, 0, count);
 *                                              data.Write (buf, 0, count);
 *                  } while (count != 0);
 */
            /*data.Flush ();
             *
             * ContentNode node = ContentParser.Parse (client.Bag, data.GetBuffer ());
             * node.Dump ();
             * reader.Close ();
             *
             *  }
             * } finally {
             * data.Close ();
             *
             *  writer.Close ();
             * }*/
            // maybe use FetchResponse to get a stream and feed it to pixbuf?
            byte [] photos_data = client.Fetcher.Fetch(String.Format("/databases/{0}/items", id),
                                                       String.Format("meta=dpap.thumb,dpap.filedata&query=('dmap.itemid:{0}')", photo.Id));
            ContentNode node = ContentParser.Parse(client.Bag, photos_data);

            // DEBUG
            Console.WriteLine("About to dump the photo!");
            node.Dump();
            ContentNode filedata_node = node.GetChild("dpap.filedata");

            Console.WriteLine("Photo starts at index " + filedata_node.Value);
            BinaryWriter writer = new BinaryWriter(File.Open(dest, FileMode.Create));

            int count = 0;
            int off   = System.Int32.Parse(filedata_node.Value.ToString());

            byte []      photo_buf;
            MemoryStream data = new MemoryStream();

            writer.Write(photos_data, (int)off, (int)photos_data.Length - off);
            data.Position = 0;
            //	Gdk.Pixbuf pb = new Gdk.Pixbuf (data);
            data.Close();
            Console.Write("Written " + count + " out of " + (photos_data.Length - off));
        }
Esempio n. 2
0
        private void RefreshAlbums(string revquery)
        {
            byte [] albums_data;

            try {
                albums_data = client.Fetcher.Fetch(String.Format("/databases/{0}/containers", id), "meta=dpap.aspectratio,dmap.itemid,dmap.itemname,dpap.imagefilename,dpap.imagefilesize,dpap.creationdate,dpap.imagepixelwidth,dpap.imagepixelheight,dpap.imageformat,dpap.imagerating,dpap.imagecomments,dpap.imagelargefilesize&type=photo");
            } catch (WebException) {
                return;
            }

            ContentNode albums_node = ContentParser.Parse(client.Bag, albums_data);

            // DEBUG data
            albums_node.Dump();
            Console.WriteLine("after dump!");

            if (IsUpdateResponse(albums_node))
            {
                return;
            }

            // handle album additions/changes
            ArrayList plids = new ArrayList();

            if (albums_node.GetChild("dmap.listing") == null)
            {
                return;
            }

            foreach (ContentNode albumNode in (ContentNode [])albums_node.GetChild("dmap.listing").Value)
            {
                // DEBUG
                Console.WriteLine("foreach loop");
                Album pl = Album.FromNode(albumNode);
                if (pl != null)
                {
                    plids.Add(pl.Id);
                    Album existing = LookupAlbumById(pl.Id);

                    if (existing == null)
                    {
                        AddAlbum(pl);
                    }
                    else
                    {
                        existing.Update(pl);
                    }
                }
            }
            // DEBUG
            Console.WriteLine("delete albums that don't exist");
            // delete albums that no longer exist
            foreach (Album pl in new List <Album> (albums))
            {
                if (!plids.Contains(pl.Id))
                {
                    RemoveAlbum(pl);
                }
            }

            plids = null;
            // DEBUG
            Console.WriteLine("Add/remove photos in the albums");
            // add/remove photos in the albums
            foreach (Album pl in albums)
            {
                byte [] album_photos_data = client.Fetcher.Fetch(String.Format("/databases/{0}/containers/{1}/items",
                                                                               id, pl.Id), "meta=dpap.aspectratio,dmap.itemid,dmap.itemname,dpap.imagefilename,dpap.imagefilesize,dpap.creationdate,dpap.imagepixelwidth,dpap.imagepixelheight,dpap.imageformat,dpap.imagerating,dpap.imagecomments,dpap.imagelargefilesize&type=photo");
                ContentNode album_photos_node = ContentParser.Parse(client.Bag, album_photos_data);

                if (IsUpdateResponse(album_photos_node))
                {
                    return;
                }

                if ((byte)album_photos_node.GetChild("dmap.updatetype").Value == 1)
                {
                    // handle album photo deletions
                    ContentNode delete_list = album_photos_node.GetChild("dmap.deletedidlisting");

                    if (delete_list != null)
                    {
                        foreach (ContentNode deleted in (ContentNode [])delete_list.Value)
                        {
                            int index = pl.LookupIndexByContainerId((int)deleted.Value);

                            if (index < 0)
                            {
                                continue;
                            }

                            pl.RemoveAt(index);
                        }
                    }
                }

                // add new photos, or reorder existing ones

                int plindex = 0;
                foreach (ContentNode pl_photo_node in (ContentNode [])album_photos_node.GetChild("dmap.listing").Value)
                {
                    Photo plphoto      = null;
                    int   container_id = 0;
                    Photo.FromAlbumNode(this, pl_photo_node, out plphoto, out container_id);

                    if (pl [plindex] != null && pl.GetContainerId(plindex) != container_id)
                    {
                        pl.RemoveAt(plindex);
                        pl.InsertPhoto(plindex, plphoto, container_id);
                    }
                    else if (pl [plindex] == null)
                    {
                        pl.InsertPhoto(plindex, plphoto, container_id);
                    }

                    plindex++;
                }
            }
        }