1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using Com.Piwigo.Lib.IService; |
---|
4 | using Com.Piwigo.Wpf.DTO; |
---|
5 | using Com.Piwigo.Lib.DTO; |
---|
6 | using Com.Piwigo.Wpf.DTO.Helper; |
---|
7 | using Com.Piwigo.Wpf.Helper; |
---|
8 | using Com.Piwigo.Wpf.Service; |
---|
9 | |
---|
10 | namespace Com.Piwigo.Wpf.Command |
---|
11 | { |
---|
12 | public sealed class PwgCmdConnect : AsyncCommand |
---|
13 | { |
---|
14 | public override string Text { get { return "Connect to server"; } } |
---|
15 | |
---|
16 | protected override void OnExecute(object parameter) |
---|
17 | { |
---|
18 | try { |
---|
19 | Uri uriServer = new Uri(PwgModelManager.Instance.Session.ServeurName); |
---|
20 | SendUiInfo("Setting up server..."); |
---|
21 | PwgServiceProvider.Instance.PwgSetupService.Setup(null, null, uriServer); |
---|
22 | PwgSessionWPF sesWPF = PwgModelManager.Instance.Session; |
---|
23 | SendUiInfo("Connecting to server..."); |
---|
24 | PwgSession sess = null; |
---|
25 | if (String.IsNullOrWhiteSpace(sesWPF.UserName) && String.IsNullOrWhiteSpace(sesWPF.Password)) |
---|
26 | { |
---|
27 | sess = PwgServiceProvider.Instance.PwgSessionService.GetPwgSession(); |
---|
28 | } |
---|
29 | else |
---|
30 | { |
---|
31 | sess = PwgServiceProvider.Instance.PwgSessionService.Login(PwgModelManager.Instance.Session.UserName, |
---|
32 | PwgModelManager.Instance.Session.Password); |
---|
33 | } |
---|
34 | |
---|
35 | SendUiInfo("Retriving list of Album from server..."); |
---|
36 | PwgSessionWPFHelper.AddPwgSessionInfoToPwgSessionWPF(sess, ref sesWPF); |
---|
37 | |
---|
38 | PwgAlbumListWPFHelper.InitRootAlbum(); |
---|
39 | |
---|
40 | List<PwgAlbum> lstCat = PwgServiceProvider.Instance.PwgAlbumsService.GetListOfAlbum(null, null, null); //(PwgModelManager.Instance.Session.Status == PwgSessionStatusEnum.Guest) |
---|
41 | PwgRootAlbumWPF aRootCatWPF = PwgModelManager.Instance.RootAlbumList; |
---|
42 | |
---|
43 | PwgAlbumListWPFHelper.ConvertPwgAlbumListToPwgRootAlbumWPF(lstCat, ref aRootCatWPF); |
---|
44 | aRootCatWPF.IsExpanded = true; |
---|
45 | |
---|
46 | SendUiInfo("Setting up cache data ..."); |
---|
47 | ImageCacheManager.Instance.SetCurrentServer(uriServer.AbsoluteUri); |
---|
48 | |
---|
49 | SendUiInfo("Retriving list of Tags from server..."); |
---|
50 | List<PwgTag> lstTag = PwgServiceProvider.Instance.PwgTagsService.GetListOfTag(true); |
---|
51 | PwgTagListWPF aTagListWPF = PwgModelManager.Instance.TagsList; |
---|
52 | PwgTagListWPFHelper.ConvertPwgTagListToPwgTagListWPF(lstTag, ref aTagListWPF); |
---|
53 | } |
---|
54 | catch (PwgServiceException ex) |
---|
55 | { |
---|
56 | SendUiInfo("Error " + ex.NumeroErr + " " + ex.MessageErr); |
---|
57 | } |
---|
58 | |
---|
59 | } |
---|
60 | } |
---|
61 | } |
---|