1 | using System; |
---|
2 | using System.Windows.Forms; |
---|
3 | |
---|
4 | using Com.Piwigo.Lib.IService; |
---|
5 | using Com.Piwigo.Lib.DTO; |
---|
6 | using System.Collections.Generic; |
---|
7 | using System.IO; |
---|
8 | |
---|
9 | |
---|
10 | namespace TestPiwigoLib |
---|
11 | { |
---|
12 | public partial class Form1 : Form |
---|
13 | { |
---|
14 | public Form1() |
---|
15 | { |
---|
16 | InitializeComponent(); |
---|
17 | } |
---|
18 | |
---|
19 | private void Form1_Load(object sender, EventArgs e) |
---|
20 | { |
---|
21 | } |
---|
22 | |
---|
23 | private void button1_Click(object sender, EventArgs e) |
---|
24 | { |
---|
25 | UriBuilder urib = new UriBuilder(); |
---|
26 | urib.Host = tbServer.Text; |
---|
27 | urib.Path = "/ws.php"; |
---|
28 | urib.Scheme = "http://"; |
---|
29 | |
---|
30 | PwgServiceProvider.Instance.PwgSetupService.Setup("TestPiwigoLib", null, urib.Uri); |
---|
31 | |
---|
32 | |
---|
33 | Console.WriteLine(urib.Uri.AbsoluteUri); |
---|
34 | |
---|
35 | try |
---|
36 | { |
---|
37 | PwgSession sess = null; |
---|
38 | sess = PwgServiceProvider.Instance.PwgSessionService.GetPwgSession(); |
---|
39 | Console.WriteLine("user : " + sess.UserName + " " + sess.Status); |
---|
40 | |
---|
41 | sess = PwgServiceProvider.Instance.PwgSessionService.Login(tbUser.Text, tbPassword.Text); |
---|
42 | Console.WriteLine("user : " + sess.UserName + " " + sess.Status); |
---|
43 | |
---|
44 | //Boolean rc = PwgServiceProvider.Instance.PwgTagsService.AddTag("Loic"); |
---|
45 | |
---|
46 | //List<PwgTag> lstTag = PwgServiceProvider.Instance.PwgTagsService.GetAdminListOfTag(); |
---|
47 | |
---|
48 | //Int32 Page = 0; |
---|
49 | //Int32 PerPage = 0; |
---|
50 | //Int32 Count = 0; |
---|
51 | |
---|
52 | //List<PwgImage> lstImgTag = PwgServiceProvider.Instance.PwgTagsService.GetListOfImagesFormTags(new List<Int32>() { 1, 7 }, |
---|
53 | // null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, |
---|
54 | // ref Page, ref PerPage, ref Count); |
---|
55 | |
---|
56 | //List<PwgImage> lstImgCat = PwgServiceProvider.Instance.PwgAlbumsService.GetListOfImagesFormAlbum(1, |
---|
57 | // null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, |
---|
58 | // ref Page, ref PerPage, ref Count); |
---|
59 | |
---|
60 | //Console.WriteLine("lstImg : Page " + Page.ToString() + " PerPage " + PerPage); |
---|
61 | |
---|
62 | List<PwgAlbum> lstadmCat = PwgServiceProvider.Instance.PwgAlbumsService.GetAdminListOfAlbum(); |
---|
63 | |
---|
64 | List<PwgAlbum> lstCat = PwgServiceProvider.Instance.PwgAlbumsService.GetListOfAlbum(0, true, false); |
---|
65 | |
---|
66 | Int32 newid = 0; |
---|
67 | String msg = String.Empty; |
---|
68 | Boolean rc; |
---|
69 | // rc = PwgServiceProvider.Instance.PwgAlbumsService.AddAlbum("test_cat", 1, ref newid, ref msg); |
---|
70 | //List<PwgAlbum> lstCat = PwgServiceProvider.Instance.PwgAlbumsService.GetAdminListOfAlbum(); |
---|
71 | //Console.WriteLine(String.Format("newid : {0} message : {1}", newid,msg)); |
---|
72 | //rc = PwgServiceProvider.Instance.PwgAlbumsService.UpdateAlbumInfo(newid, "test2", "rename cat"); |
---|
73 | //Boolean rc = PwgServiceProvider.Instance.PwgAlbumsService.DeleteAlbum(newid, sess.SecurityToken, PwgAlbumPhotoDeletionModeEnum.None); |
---|
74 | //rc = PwgServiceProvider.Instance.PwgAlbumsService.MoveAlbum(new List<Int32>() { newid }, PwgAlbum.RootAlbumId, sess.SecurityToken); |
---|
75 | |
---|
76 | //lstCat = PwgServiceProvider.Instance.PwgAlbumsService.GetAdminListOfAlbum(); |
---|
77 | |
---|
78 | //FileInfo fiBig = new FileInfo("C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n.jpg"); |
---|
79 | //FileInfo fiThumb = new FileInfo(MakeThumb(fiBig, "C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n_thum.jpg", 64)); |
---|
80 | //FileInfo fiLow = new FileInfo(MakeThumb(fiBig, "C:\\Users\\bayral\\Downloads\\49133_1636405570_2648232_n_low.jpg", 256)); |
---|
81 | |
---|
82 | //FileInfo fiBig = new FileInfo("C:\\temp\\Oryx.jpg"); |
---|
83 | //FileInfo fiThumb = new FileInfo(MakeThumb(fiBig, "C:\\temp\\Oryx_thumb.jpg", 64)); |
---|
84 | //FileInfo fiLow = new FileInfo(MakeThumb(fiBig, "C:\\temp\\Oryx_low.jpg", 256)); |
---|
85 | |
---|
86 | //PwgImageAdded imgAdd = PwgServiceProvider.Instance.PwgImagesService.addImageByMultiPartForm(fiBig, null, 1, "benoit", "byarl", "test upload", 0, new List<PwgTag>() { new PwgTag() { Name = "Benoit" }, new PwgTag() { Name = "Noé" } }); |
---|
87 | //rc = PwgServiceProvider.Instance.PwgImagesService.addImage(fiBig, fiLow, fiThumb, "Benoit", "bayral", DateTime.Now, "demo", new List<string>() { "1" }, new List<string>() { "Benoit" }, PwgConfidentLevelEnum.All); |
---|
88 | //rc = PwgServiceProvider.Instance.PwgImagesService.DeleteImage(319, sess.SecurityToken); |
---|
89 | |
---|
90 | //PwgImageInfo info = PwgServiceProvider.Instance.PwgImagesService.getImageInfo(imgAdd.Id, null, null); |
---|
91 | |
---|
92 | //PwgImageRate imgRate = PwgServiceProvider.Instance.PwgImagesService.RateImage(1, 5); |
---|
93 | |
---|
94 | sess = PwgServiceProvider.Instance.PwgSessionService.Logout(); |
---|
95 | Console.WriteLine("user : " + sess.UserName + " " + sess.Status); |
---|
96 | } |
---|
97 | catch (PwgServiceException ex) |
---|
98 | { |
---|
99 | Console.WriteLine("Erreur " + ex.NumeroErr + " " + ex.MessageErr); |
---|
100 | Console.WriteLine(ex.Message); |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | private string MakeThumb(FileInfo fi, String ext, int size) |
---|
105 | { |
---|
106 | // create an image object, using the filename we just retrieved |
---|
107 | System.Drawing.Image image = System.Drawing.Image.FromFile(fi.FullName); |
---|
108 | |
---|
109 | // create the actual thumbnail image |
---|
110 | System.Drawing.Image thumbnailImage = image.GetThumbnailImage(size, size, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); |
---|
111 | |
---|
112 | // make a memory stream to work with the image bytes |
---|
113 | FileStream imageStream = new FileStream(ext, FileMode.OpenOrCreate); |
---|
114 | |
---|
115 | // put the image into the memory stream |
---|
116 | thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); |
---|
117 | |
---|
118 | imageStream.Close(); |
---|
119 | return ext; |
---|
120 | } |
---|
121 | |
---|
122 | /// <summary> |
---|
123 | /// Required, but not used |
---|
124 | /// </summary> |
---|
125 | /// <returns>true</returns> |
---|
126 | public bool ThumbnailCallback() |
---|
127 | { |
---|
128 | return true; |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | private void Form1_FormClosing(object sender, FormClosingEventArgs e) |
---|
133 | { |
---|
134 | global::TestPiwigoLib.Properties.Settings.Default.Save(); |
---|
135 | } |
---|
136 | } |
---|
137 | } |
---|