示例#1
0
        private static FSpot.Core.Tag [] ToTags(int [] ids)
        {
            if (null == ids)
            {
                return(null);
            }

            List <FSpot.Core.Tag> tags =
                new List <FSpot.Core.Tag> (ids.Length);

            foreach (int id in ids)
            {
                FSpot.Core.Tag tag = FSpot.App.Instance.Database.Tags
                                     .GetTagById(id);
                if (null != tag)
                {
                    tags.Add(tag);
                }
                else
                {
                    Log.Warning("No such tag ID in DB: "
                                + id);
                }
            }
            return(tags.ToArray());
        }
示例#2
0
        public string Upload(IPhoto photo, IFilter filter, bool is_public, bool is_family, bool is_friend)
        {
            if (token == null)
            {
                throw new Exception("Must Login First");
            }
            // FIXME flickr needs rotation
            string error_verbose;

            using (FilterRequest request = new FilterRequest(photo.DefaultVersion.Uri)) {
                try {
                    string tags = null;

                    filter.Convert(request);
                    string path = request.Current.LocalPath;

                    if (ExportTags && photo.Tags != null)
                    {
                        StringBuilder     taglist  = new StringBuilder();
                        FSpot.Core.Tag [] t        = photo.Tags;
                        FSpot.Core.Tag    tag_iter = null;

                        for (int i = 0; i < t.Length; i++)
                        {
                            if (i > 0)
                            {
                                taglist.Append(",");
                            }

                            taglist.Append(String.Format("\"{0}\"", t[i].Name));

                            // Go through the tag parents
                            if (ExportTagHierarchy)
                            {
                                tag_iter = t[i].Category;
                                while (tag_iter != App.Instance.Database.Tags.RootCategory && tag_iter != null)
                                {
                                    // Skip top level tags because they have no meaning in a linear tag database
                                    if (ExportIgnoreTopLevel && tag_iter.Category == App.Instance.Database.Tags.RootCategory)
                                    {
                                        break;
                                    }

                                    // FIXME Look if the tag is already there!
                                    taglist.Append(",");
                                    taglist.Append(String.Format("\"{0}\"", tag_iter.Name));
                                    tag_iter = tag_iter.Category;
                                }
                            }
                        }

                        tags = taglist.ToString();
                    }
                    try {
                        string photoid =
                            flickr.UploadPicture(path, photo.Name, photo.Description, tags, is_public, is_family, is_friend);
                        return(photoid);
                    } catch (FlickrNet.FlickrException ex) {
                        Log.Error("Problems uploading picture: " + ex.ToString());
                        error_verbose = ex.ToString();
                    }
                } catch (Exception e) {
                    // FIXME we need to distinguish between file IO errors and xml errors here
                    throw new System.Exception("Error while uploading", e);
                }
            }

            throw new System.Exception(error_verbose);
        }