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

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

root category handled

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 : 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 Category from server...");
36                PwgSessionWPFHelper.AddPwgSessionInfoToPwgSessionWPF(sess, ref sesWPF);
37
38                PwgCategoryListWPFHelper.InitRootCategory();
39
40                List<PwgCategory> lstCat = PwgServiceProvider.Instance.PwgCategoriesService.GetListOfCategory(null, null, null); //(PwgModelManager.Instance.Session.Status == PwgSessionStatusEnum.Guest)
41                PwgRootCategoryWPF aRootCatWPF = PwgModelManager.Instance.RootCategoryList;
42
43                PwgCategoryListWPFHelper.ConvertPwgCategoryListToPwgRootCategoryWPF(lstCat, ref aRootCatWPF);
44                aRootCatWPF.IsExpanded = true;
45
46                SendUiInfo("Setting up cache data ...");
47                ImageCacheManager.Instance.SetCurrentServer(uriServer.AbsoluteUri);
48           
49
50            }
51            catch (PwgServiceException ex)
52            {
53                SendUiInfo("Error " + ex.NumeroErr + " " + ex.MessageErr);
54            }
55           
56        }
57    }
58}
Note: See TracBrowser for help on using the repository browser.