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

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

Async image thumbail retriving

File size: 2.3 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                List<PwgCategory> lstCat = PwgServiceProvider.Instance.PwgCategoriesService.GetListOfCategory(null, false, null); //(PwgModelManager.Instance.Session.Status == PwgSessionStatusEnum.Guest)
39                PwgCategoryListWPF lstCatWPF = PwgModelManager.Instance.CategoryList;
40
41                PwgCategoryListWPFHelper.ConvertPwgCategoryListToPwgCategoryListWPF(lstCat, ref lstCatWPF);
42
43                SendUiInfo("Setting up cache data ...");
44                ImageCacheManager.Instance.SetCurrentServer(uriServer.AbsoluteUri);
45           
46
47            }
48            catch (PwgServiceException ex)
49            {
50                SendUiInfo("Error " + ex.NumeroErr + " " + ex.MessageErr);
51            }
52           
53        }
54    }
55}
Note: See TracBrowser for help on using the repository browser.