source: extensions/PiwigoLib/PiwigoWpf/Command/PwgCmdConnect.cs @ 11904

Last change on this file since 11904 was 11904, checked in by bayral, 13 years ago

PiwigoWPF

File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using Com.Piwigo.Lib.IService;
4using Com.Piwigo.Wpf.DTO;
5using Com.Piwigo.Lib.DTO;
6using Com.Piwigo.Wpf.DTO.Helper;
7using Com.Piwigo.Wpf.Helper;
8using Com.Piwigo.Wpf.Service;
9
10namespace Com.Piwigo.Wpf.Command
11{
12    public sealed class PwgCmdConnect : PwgCmdBase
13    {
14        public override bool CanExecute(object parameter)
15        {
16            Boolean retVal = false;
17            if ( AppHelper.IsInDesignModeStatic == true)
18            {
19                retVal = false;
20            }
21            else
22            {
23                if ((PwgModelManager.Instance.Session != null)
24                    & (PwgModelManager.Instance.Session.ServeurName != null))
25                {
26                    retVal = !String.IsNullOrWhiteSpace(PwgModelManager.Instance.Session.ServeurName);
27                }
28            }
29            return (retVal);
30        }
31
32        public override void Execute(object parameter)
33        {
34            try {
35                Uri uriServer = new Uri(PwgModelManager.Instance.Session.ServeurName);
36
37                PwgServiceProvider.Instance.PwgSetupService.Setup(null, null, uriServer);
38                PwgSession sess = PwgServiceProvider.Instance.PwgSessionService.GetPwgSession();
39                sess = PwgServiceProvider.Instance.PwgSessionService.Login( PwgModelManager.Instance.Session.UserName,
40                                                                            PwgModelManager.Instance.Session.Password);
41
42                PwgSessionWPF sesWPF = PwgModelManager.Instance.Session;
43                PwgSessionWPFHelper.AddPwgSessionInfoToPwgSessionWPF(sess, ref sesWPF);
44
45                List<PwgCategory> lstCat = PwgServiceProvider.Instance.PwgCategoriesService.GetListOfCategory(null, false, (PwgModelManager.Instance.Session.Status == PwgSessionStatusEnum.Guest));
46                PwgCategoryListWPF lstCatWPF = PwgModelManager.Instance.CategoryList;
47
48                PwgCategoryListWPFHelper.ConvertPwgCategoryListToPwgCategoryListWPF(lstCat, ref lstCatWPF);
49
50                ImageCacheManager.Instance.SetCurrentServer(uriServer.AbsoluteUri);
51            }
52            catch (PwgServiceException ex)
53            {
54                Console.WriteLine("Erreur " + ex.NumeroErr + " " + ex.MessageErr);
55                Console.WriteLine(ex.Message);
56            }
57
58        }
59    }
60}
Note: See TracBrowser for help on using the repository browser.