source: extensions/PiwigoLib/PiwigoUpload/Service/UploadToPiwigo.cs @ 13520

Last change on this file since 13520 was 13520, checked in by bayral, 12 years ago

new project for windows live publish plugin
Well advance single uploader

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
6using Com.Piwigo.Uploader.DTO;
7using Com.Piwigo.Lib.DTO;
8using Com.Piwigo.Lib.IService;
9
10namespace Com.Piwigo.Uploader.Service
11{
12    public class UploadToPiwigo : IService
13    {
14        public void runService()
15        {
16            foreach (LocalAlbum Alb in ModelManager.Instance.lstAlbumLocaux)
17            {
18                uploadAlbum(Alb, ModelManager.Instance.PwgAlbumIdSelected);
19            } 
20        }
21
22        internal void uploadAlbum(LocalAlbum aAlbum, Int32? catId)
23        {
24            Boolean rc;
25            Int32 IdNewAlbum = 0;
26            String strMsgInfo = String.Empty;
27            rc = PwgServiceProvider.Instance.PwgAlbumsService.AddAlbum(aAlbum.Name, catId, ref  IdNewAlbum, ref strMsgInfo);
28
29            if (rc == true)
30            {
31                aAlbum.Id = IdNewAlbum;
32
33                foreach (LocalImage Img in aAlbum.LocalImages)
34                {
35                    if (aAlbum.Id.HasValue)
36                    {
37                        Img.UpperCatId = aAlbum.Id.Value;
38                    }
39                    uploadImage(Img);
40                }
41
42                foreach (LocalAlbum Alb in aAlbum.SubAlbums)
43                {
44                    uploadAlbum(Alb, null);
45                }
46            }
47            else
48            {
49                throw new ApplicationException("uploadlabum error");
50            }
51        }
52
53        internal void uploadImage(LocalImage aImg)
54        {
55            FileInfo fi = new FileInfo(aImg.LocalFile);
56
57            List<PwgTag> lstTag = new List<PwgTag>();
58            if (aImg.LstTags != null)
59            {
60                lstTag.AddRange(aImg.LstTags);
61            }
62
63            PwgServiceProvider.Instance.PwgImagesService.addImageByMultiPartForm(fi, null, aImg.UpperCatId, aImg.Name, aImg.Author, aImg.AuthorComment, aImg.ConfidentialLevel, lstTag);
64        }
65    }
66}
Note: See TracBrowser for help on using the repository browser.