using System; using System.Collections.Generic; using Com.Piwigo.Lib.IService; using Com.Piwigo.Wpf.DTO; using Com.Piwigo.Lib.DTO; using Com.Piwigo.Wpf.DTO.Helper; using Com.Piwigo.Wpf.Helper; using Com.Piwigo.Wpf.Service; namespace Com.Piwigo.Wpf.Command { public sealed class PwgCmdConnect : AsyncCommand { public override string Text { get { return "Connect to server"; } } protected override void OnExecute(object parameter) { try { Uri uriServer = new Uri(PwgModelManager.Instance.Session.ServeurName); SendUiInfo("Setting up server..."); PwgServiceProvider.Instance.PwgSetupService.Setup(null, null, uriServer); PwgSessionWPF sesWPF = PwgModelManager.Instance.Session; SendUiInfo("Connecting to server..."); PwgSession sess = null; if (String.IsNullOrWhiteSpace(sesWPF.UserName) && String.IsNullOrWhiteSpace(sesWPF.Password)) { sess = PwgServiceProvider.Instance.PwgSessionService.GetPwgSession(); } else { sess = PwgServiceProvider.Instance.PwgSessionService.Login(PwgModelManager.Instance.Session.UserName, PwgModelManager.Instance.Session.Password); } SendUiInfo("Retriving list of Category from server..."); PwgSessionWPFHelper.AddPwgSessionInfoToPwgSessionWPF(sess, ref sesWPF); PwgCategoryListWPFHelper.InitRootCategory(); List lstCat = PwgServiceProvider.Instance.PwgCategoriesService.GetListOfCategory(null, null, null); //(PwgModelManager.Instance.Session.Status == PwgSessionStatusEnum.Guest) PwgRootCategoryWPF aRootCatWPF = PwgModelManager.Instance.RootCategoryList; PwgCategoryListWPFHelper.ConvertPwgCategoryListToPwgRootCategoryWPF(lstCat, ref aRootCatWPF); aRootCatWPF.IsExpanded = true; SendUiInfo("Setting up cache data ..."); ImageCacheManager.Instance.SetCurrentServer(uriServer.AbsoluteUri); SendUiInfo("Retriving list of Tags from server..."); List lstTag = PwgServiceProvider.Instance.PwgTagsService.GetListOfTag(true); PwgTagListWPF aTagListWPF = PwgModelManager.Instance.TagsList; PwgTagListWPFHelper.ConvertPwgTagListToPwgTagListWPF(lstTag, ref aTagListWPF); } catch (PwgServiceException ex) { SendUiInfo("Error " + ex.NumeroErr + " " + ex.MessageErr); } } } }