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

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

retrieve tags list and image for a tag.

File size: 2.8 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                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}
Note: See TracBrowser for help on using the repository browser.