Changeset 11922


Ignore:
Timestamp:
Aug 8, 2011, 6:57:56 PM (13 years ago)
Author:
bayral
Message:

Async image thumbail retriving

Location:
extensions/PiwigoLib
Files:
2 added
1 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • extensions/PiwigoLib/PiwigoLib/Service/PwgSessionService.cs

    r11911 r11922  
    4444                    {
    4545                        ConvertProxyResponseToDTO(response, ref PwgSession);
    46                         PwgSession.IsConnected = true;
    4746                    }
    4847                } catch (PwgProxyException ex)
     
    6463        {
    6564            PwgSession = null;
     65            Boolean isConnected = false;
    6666            try
    6767            {
    6868                PwgSessionProxyResponse response = PwgSessionProxy.pwg_session_login(UserName, Password);
    6969
    70                 if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok )
     70                if (response.Retour != PwgBaseProxyReponseRetourEnum.Ok)
    7171                {
     72
    7273                    if (response.Erreur != null)
    7374                    {
    74                         throw new PwgServiceException("Login, the server has return the error.", 
    75                             response.Erreur.Code, 
     75                        throw new PwgServiceException("Login, the server has return the error.",
     76                            response.Erreur.Code,
    7677                            response.Erreur.Message);
    7778                    }
     
    8182                    }
    8283                }
     84                else
     85                {
     86                    isConnected = true;
     87                }
    8388            }
    8489            catch (PwgProxyException ex)
     
    8792            }
    8893
    89             return GetPwgSession();
     94            PwgSession sess= GetPwgSession();
     95            sess.IsConnected = isConnected;
     96            return sess;
    9097        }
    9198
     
    93100        {
    94101            PwgSession = null;
     102            Boolean isConnected = false;
    95103            try
    96104            {
     
    116124            }
    117125
    118             return GetPwgSession();
     126            PwgSession sess = GetPwgSession();
     127            sess.IsConnected = isConnected;
     128            return sess;
    119129        }
    120130        /// <summary>
  • extensions/PiwigoLib/PiwigoWpf/App.xaml

    r11911 r11922  
    99        <ObjectDataProvider x:Name="SessionODP" x:Key="Session" ObjectType="{x:Type piwigo:PwgSessionWPF}" />
    1010        <ObjectDataProvider x:Name="CategoriesODP" x:Key="Categories" ObjectType="{x:Type piwigo:PwgCategoryListWPF}"/> <!--IsAsynchronous="True"-->
    11 
     11        <!--IsAsynchronous="True"-->
    1212        <ResourceDictionary  x:Key="VisualStyleApp" Source="VisualStyleApp.xaml"/>
    1313    </Application.Resources>
  • extensions/PiwigoLib/PiwigoWpf/Command/PwgCmdConnect.cs

    r11911 r11922  
    1010namespace Com.Piwigo.Wpf.Command
    1111{
    12     public sealed class PwgCmdConnect : PwgCmdBase
     12    public sealed class PwgCmdConnect : AsyncCommand
    1313    {
    14         public override void Execute(object parameter)
     14        public override string Text { get { return "Connect to server"; } }
     15
     16        protected override void OnExecute(object parameter)
    1517        {
    1618            try {
    17                 IsRunning = true;
    1819                Uri uriServer = new Uri(PwgModelManager.Instance.Session.ServeurName);
    19 
     20                SendUiInfo("Setting up server...");
    2021                PwgServiceProvider.Instance.PwgSetupService.Setup(null, null, uriServer);
    2122                PwgSessionWPF sesWPF = PwgModelManager.Instance.Session;
    22                
     23                SendUiInfo("Connecting to server...");
    2324                PwgSession sess = null;
    2425                if (String.IsNullOrWhiteSpace(sesWPF.UserName) && String.IsNullOrWhiteSpace(sesWPF.Password))
     
    3233                }
    3334
     35                SendUiInfo("Retriving list of Category from server...");
    3436                PwgSessionWPFHelper.AddPwgSessionInfoToPwgSessionWPF(sess, ref sesWPF);
    3537
     
    3941                PwgCategoryListWPFHelper.ConvertPwgCategoryListToPwgCategoryListWPF(lstCat, ref lstCatWPF);
    4042
     43                SendUiInfo("Setting up cache data ...");
    4144                ImageCacheManager.Instance.SetCurrentServer(uriServer.AbsoluteUri);
     45           
    4246
    43                 IsRunning = false;
    4447            }
    4548            catch (PwgServiceException ex)
    4649            {
    47                 Console.WriteLine("Erreur " + ex.NumeroErr + " " + ex.MessageErr);
    48                 Console.WriteLine(ex.Message);
     50                SendUiInfo("Error " + ex.NumeroErr + " " + ex.MessageErr);
    4951            }
    50 
     52           
    5153        }
    5254    }
  • extensions/PiwigoLib/PiwigoWpf/Command/PwgCmdDisconnect.cs

    r11911 r11922  
    1010namespace Com.Piwigo.Wpf.Command
    1111{
    12     public sealed class PwgCmdDisconnect : PwgCmdBase
     12    public sealed class PwgCmdDisconnect : AsyncCommand
    1313    {
    14         public override void Execute(object parameter)
     14        public override string Text { get { return "Disconnect from server"; } }
     15
     16        protected override void OnExecute(object parameter)
    1517        {
    1618            try {
    17                 IsRunning = true;
    1819                PwgSessionWPF sesWPF = PwgModelManager.Instance.Session;
    1920               
     21                SendUiInfo("Logging out ...");
     22
    2023                PwgSession sess = null;
    2124                sess = PwgServiceProvider.Instance.PwgSessionService.Logout();
    2225
    2326                PwgSessionWPFHelper.AddPwgSessionInfoToPwgSessionWPF(sess, ref sesWPF);
    24                
     27
     28                SendUiInfo("Removing Image and Category ...");
     29                if (PwgModelManager.Instance.ImageList != null)
     30                {
     31                    PwgModelManager.Instance.ImageList.Clear();
     32                }
     33
    2534                if (PwgModelManager.Instance.CategoryList != null)
    2635                {
     
    2837                }
    2938
     39                SendUiInfo("Unset cache data ...");
    3040                ImageCacheManager.Instance.UnsetCurrentServer();
    31 
    32                 IsRunning = false;
    3341            }
    3442            catch (PwgServiceException ex)
    3543            {
    36                 Console.WriteLine("Erreur " + ex.NumeroErr + " " + ex.MessageErr);
    37                 Console.WriteLine(ex.Message);
     44                SendUiInfo("Error " + ex.NumeroErr + " " + ex.MessageErr);
    3845            }
    39 
    4046        }
    4147    }
  • extensions/PiwigoLib/PiwigoWpf/Command/PwgCmdGetImageforCategory.cs

    r11911 r11922  
    1010namespace Com.Piwigo.Wpf.Command
    1111{
    12     public sealed class PwgCmdGetImageforCategory : PwgCmdBase
     12    public sealed class PwgCmdGetImageforCategory : AsyncCommand
    1313    {
    14         public override void Execute(object parameter)
     14        public override string Text { get { return "Get images for a category"; } }
     15
     16        protected override void OnExecute(object parameter)
    1517        {
    1618            PwgCategoryWPF catParam;
     
    1921            Int32 acount = 0;
    2022
    21             try {
     23            try
     24            {
    2225                Uri uriServer = new Uri(PwgModelManager.Instance.Session.ServeurName);
    2326                if (parameter is PwgCategoryWPF)
    2427                {
     28                    PwgImageListWPF lstImgWPF = PwgModelManager.Instance.ImageList;
     29                    SendUiInfo("Removing image...");
     30                    if (lstImgWPF != null)
     31                    {
     32                        lstImgWPF.Clear();
     33                    }
     34
    2535                    catParam = (PwgCategoryWPF)parameter;
     36                    SendUiInfo("Setting up cache data...");
    2637                    ImageCacheManager.Instance.SetCurrentCategory(catParam.Id.ToString());
    2738
     39                    SendUiInfo("Retriving images list from server...");
    2840                    List<PwgImage> lstImg = PwgServiceProvider.Instance.PwgCategoriesService.GetListOfImagesFormCategory(catParam.Id, false, null, null, null, null, null, null, null, null, null, null, null, null, null, true, ref aPage, ref aPerPage, ref  acount);
    29                     PwgImageListWPF lstImgWPF = PwgModelManager.Instance.ImageList;
    30 
     41                   
    3142                    PwgImageListWPFHelper.ConvertPwgImageListToPwgImageListWPF(lstImg, ref lstImgWPF);
    3243                }
    33              
    3444            }
    3545            catch (PwgServiceException ex)
    3646            {
    37                 Console.WriteLine("Erreur " + ex.NumeroErr + " " + ex.MessageErr);
    38                 Console.WriteLine(ex.Message);
     47                SendUiInfo("Error " + ex.NumeroErr + " " + ex.MessageErr);
    3948            }
    40 
    4149        }
    4250    }
  • extensions/PiwigoLib/PiwigoWpf/Command/PwgCmdProvider.cs

    r11911 r11922  
    99    public static class PwgCmdProvider
    1010    {
    11         public static PwgCmdBase GetByType<T>()
     11        public static AsyncCommand GetByType<T>()
    1212        {
    13             PwgCmdBase objICom;
     13            AsyncCommand objICom;
    1414
    1515            switch (typeof(T).Name)
     
    3232        }
    3333
    34         public static PwgCmdBase _pwgCmdConnect;
    35         public static PwgCmdBase PwgCmdConnect
     34        public static AsyncCommand _pwgCmdConnect;
     35        public static AsyncCommand PwgCmdConnect
    3636        {
    3737            get
     
    4545        }
    4646
    47         public static PwgCmdBase _pwgCmdDisconnect;
    48         public static PwgCmdBase PwgCmdDisconnect
     47        public static AsyncCommand _pwgCmdDisconnect;
     48        public static AsyncCommand PwgCmdDisconnect
    4949        {
    5050            get
     
    5858        }
    5959
    60         public static PwgCmdBase _pwgCmdGetImageforCategory;
    61         public static PwgCmdBase PwgCmdGetImageforCategory
     60        public static AsyncCommand _pwgCmdGetImageforCategory;
     61        public static AsyncCommand PwgCmdGetImageforCategory
    6262        {
    6363            get
  • extensions/PiwigoLib/PiwigoWpf/DTO/PwgImageWPF.cs

    r7150 r11922  
    1212    public class PwgImageWPF : INotifyPropertyChanged
    1313    {
     14        private String _imgSource;
     15        public String ImgSource
     16        {
     17            set { _imgSource = value; OnPropertyChanged("ImgSource"); }
     18            get
     19            {
     20                if (_imgSource == null)
     21                {
     22                    _imgSource = Com.Piwigo.Wpf.Service.ImageCacheManager.Instance.GetImageFilename(this);
     23                }
     24                return _imgSource;
     25            }
     26        }
     27       
     28
    1429        private Int32 _id;
    1530        public  Int32 Id
  • extensions/PiwigoLib/PiwigoWpf/DTO/PwgModelManager.cs

    r11905 r11922  
    2727        public class PwgModelManagerBase
    2828        {
     29            private AsyncObservableCollection<String> _lstMsgInfo = new AsyncObservableCollection<String>();
     30            public AsyncObservableCollection<String> lstMsgInfo
     31            {
     32                set { _lstMsgInfo = value; OnPropertyChanged("lstMsgInfo"); }
     33                get { return _lstMsgInfo; }
     34            }
     35
     36            private Boolean _booCmdRunning = false;
     37            public Boolean booCmdRunning
     38            {
     39                set { _booCmdRunning = value; OnPropertyChanged("booCmdRunning"); }
     40                get { return _booCmdRunning; }
     41            }
     42
    2943            private PwgImageListWPF _imageList;
    3044            public PwgImageListWPF ImageList
     
    4963
    5064            public event PropertyChangedEventHandler PropertyChanged;
    51             private void OnPropertyChanged(String info)
     65            internal void OnPropertyChanged(String info)
    5266            {
    5367                if (PropertyChanged != null)
  • extensions/PiwigoLib/PiwigoWpf/Helper/AppHelper.cs

    r11911 r11922  
    5252        }
    5353
    54         static public void ExecuteCommand<T>(object parameter) where T:  PwgCmdBase
     54        static public void ExecuteCommand<T>(object parameter) where T : AsyncCommand
    5555        {
    56             PwgCmdBase cmd = PwgCmdProvider.GetByType<T>();
     56            AsyncCommand cmd = PwgCmdProvider.GetByType<T>();
    5757            if (cmd.CanExecute(parameter))
    5858            {
  • extensions/PiwigoLib/PiwigoWpf/Helper/ImageUrlCachedConverter.cs

    r11904 r11922  
    2121         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    2222        {
    23             String src;
     23            String src = string.Empty;
    2424            if (value == null) return null;
    2525            PwgImageWPF someObj = value as PwgImageWPF;
    2626
    27             src = ImageCacheManager.Instance.GetImageFilename(someObj);
     27            //src = ImageCacheManager.Instance.GetImageFilename(someObj);
    2828
    2929            return src;
  • extensions/PiwigoLib/PiwigoWpf/MainWindow.xaml

    r11911 r11922  
    77        xmlns:pwgcmd="clr-namespace:Com.Piwigo.Wpf.Command"
    88        xmlns:pwgsrv="clr-namespace:Com.Piwigo.Wpf.Service"
     9        xmlns:pwghlp="clr-namespace:Com.Piwigo.Wpf.Helper"
    910        Title="PiwigoWpf"
    1011        WindowState="Maximized"
    1112        MinHeight="600" MinWidth="800">
    1213    <Window.Resources>
    13         <ObjectDataProvider x:Key="listCat" IsAsynchronous="True" />
    14         <ObjectDataProvider x:Key="listImg" IsAsynchronous="True" />
    15 
    16               <!-- DATA TEMPLATES -->
     14        <pwghlp:AdvBooltoVisibilityConverter x:Key="AdvBooltoVisibilityConverter"  Collapse="False" Reverse="False" />
     15        <pwghlp:AdvBooltoVisibilityConverter x:Key="AdvBooltoVisibilityConverterReversal"  Collapse="False" Reverse="True" />
     16               <!-- DATA TEMPLATES -->
    1717
    1818        <DataTemplate DataType="{x:Type pwgdto:PwgImageWPF}">
     
    2121                <Image ToolTip="{Binding File}" >
    2222                    <Image.Source>
    23                         <PriorityBinding>
    24                             <Binding IsAsync="True" Converter="{x:Static pwgsrv:ImageCacheManager.ImageUrlCachedConverter}"/>
    25                             <Binding Source="pack://application:,,,/Pictures/Globe.png" />
    26                     </PriorityBinding>
     23                        <Binding Path="ImgSource" /> <!--Converter="{x:Static pwgsrv:ImageCacheManager.ImageUrlCachedConverter}"-->
    2724                    </Image.Source>
    2825                </Image>
     
    197194    <DockPanel Name="mainDockPanel"  Margin="5">
    198195        <StackPanel Name="headerStackPanel" DockPanel.Dock="Top" Orientation="Vertical">
    199             <Image Name="ImgPiwigoLogo" MinHeight="50" MinWidth="50"
     196            <StackPanel Name="headerStackPanelLogo" Orientation="Horizontal" >
     197                <Image Name="ImgPiwigoLogo" MinHeight="50" MinWidth="50"
    200198                   Source="pack://application:,,,/Pictures/PiwigoLogo.png"
    201199                   ToolTip="www.piwigo.org" Stretch="None" HorizontalAlignment="Left" />
     200                <Image Name="ImgGlobe"
     201                   Visibility="{Binding Source={x:Static pwgdto:PwgModelManager.Instance}, Path=booCmdRunning, Converter={StaticResource AdvBooltoVisibilityConverterReversal}}"
     202                   Source="pack://application:,,,/Pictures/Globe.png"
     203                   ToolTip="www.piwigo.org" Stretch="None" HorizontalAlignment="Right"/>
     204            </StackPanel>
    202205            <StackPanel Name="connectStackPanel" Orientation="Horizontal" VerticalAlignment="Center"  Margin="5"
    203206                        DataContext="{Binding Source={StaticResource Session}}">
     
    210213                <TextBox Height="23" Name="TbUrl" Width="300" Text="{Binding Path=ServeurName, Mode=TwoWay}"/>
    211214                <CheckBox Margin="2" VerticalAlignment="Center" IsChecked="{Binding Path=SaveSetting, Mode=TwoWay}">Save settings</CheckBox>
    212                 <Button Margin="2" Command="{x:Static pwgcmd:PwgCmdProvider.PwgCmdConnect}" Visibility="{pwgui:SwitchBinding IsConnected, Hidden, Visible}">Conect</Button>
    213                 <Button Margin="2" Command="{x:Static pwgcmd:PwgCmdProvider.PwgCmdDisconnect}" Visibility="{pwgui:SwitchBinding IsConnected, Visible, Hidden}">Disconect</Button>
     215                <Button Margin="2" Command="{x:Static pwgcmd:PwgCmdProvider.PwgCmdConnect}" Visibility="{Binding Path=IsConnected, Converter={StaticResource AdvBooltoVisibilityConverterReversal}}">Conect</Button>
     216                <Button Margin="2" Command="{x:Static pwgcmd:PwgCmdProvider.PwgCmdDisconnect}" Visibility="{Binding Path=IsConnected, Converter={StaticResource AdvBooltoVisibilityConverter}}">Disconect</Button>
    214217            </StackPanel>
    215            <ProgressBar IsIndeterminate="True" />         
    216218        </StackPanel>
     219        <ListView Name="listViewLogUiInfo"  DockPanel.Dock="Bottom"
     220                  DataContext="{Binding Source={x:Static pwgdto:PwgModelManager.Instance}, Path=lstMsgInfo}"
     221                  ItemsSource="{Binding }" />
    217222
    218223        <ListView Name="listViewCategory"  DockPanel.Dock="Left" MinWidth="100"
     
    221226                  DataContext="{Binding Source={StaticResource Categories}}"
    222227                  ItemsSource="{Binding }" MouseDoubleClick="listViewCategory_MouseDoubleClick" />
     228       
    223229        <ListView Name="listViewImage"  DockPanel.Dock="Right"  MinWidth="500"
    224230                  Style="{DynamicResource PhotoListStyle}"
  • extensions/PiwigoLib/PiwigoWpf/MainWindow.xaml.cs

    r11904 r11922  
    2525        {
    2626            InitializeComponent();
     27            PwgCmdEvents.CmdRunningChanged += new PwgCmdEvents.CmdRunningChangedHandler(PwgCmdEventsConsumer.PwgCmdEvents_CmdRunningChanged);
     28            PwgCmdEvents.CmdSendUiInfo += new PwgCmdEvents.CmdSendUiInfoHandler(PwgCmdEventsConsumer.PwgCmdEvents_CmdSendUiInfo);
    2729        }
    28 
     30       
    2931        private void listViewCategory_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    3032        {
  • extensions/PiwigoLib/PiwigoWpf/PiwigoWpf.csproj

    r11920 r11922  
    7878    </ApplicationDefinition>
    7979    <Compile Include="Command\PwgCmdDisconnect.cs" />
     80    <Compile Include="Command\PwgCmdEventsConsumer.cs" />
    8081    <Compile Include="Command\PwgCmdGetImageforCategory.cs" />
    8182    <Compile Include="Command\PwgCmdProvider.cs" />
    8283    <Compile Include="Command\PwgCmdConnect.cs" />
    83     <Compile Include="Command\PwgCmdBase.cs" />
     84    <Compile Include="Command\AsyncCommand.cs" />
     85    <Compile Include="Command\PwgCommandEvents.cs" />
    8486    <Compile Include="DTO\Helper\PwgImageListWPFHelper.cs" />
    8587    <Compile Include="DTO\Helper\PwgImageWPFHelper.cs" />
     
    8890    <Compile Include="DTO\Helper\PwgSessionWPFHelper.cs" />
    8991    <Compile Include="DTO\PwgModelManager.cs" />
     92    <Compile Include="Helper\AdvBooltoVisibilityConverter.cs" />
    9093    <Compile Include="Helper\AppHelper.cs" />
    9194    <Compile Include="DTO\AsyncObservableCollection.cs" />
  • extensions/PiwigoLib/PiwigoWpf/Services/ImageCacheManager.cs

    r11911 r11922  
    3939        static ImageCacheManager()
    4040        {
     41            Int32 a, b;
     42            ThreadPool.GetMaxThreads(out a, out b);
     43            if (a>20) a = 20;
     44            ThreadPool.SetMaxThreads(a, b);
    4145        }
    4246
     
    211215            public String GetImageFilename(PwgImageWPF aImageWPF)
    212216                {
    213                     String retValue = String.Empty;
     217                    String retImgSrc = String.Empty;
    214218                    if (aImageWPF == null)
    215219                    {
    216                         return retValue;
     220                        return retImgSrc;
    217221                    }
    218222
     
    223227                        if (!File.Exists(localFile))
    224228                        {
     229                            retImgSrc = GetDefaultImage();
     230
    225231                            ThreadPool.QueueUserWorkItem((WaitCallback)delegate
    226232                            {
     
    240246                                image.Save(localFile);
    241247
     248                                aImageWPF.ImgSource = localFile;
    242249                            });
    243 
    244                             retValue = localFile;
    245                         }
     250                        }
     251                        else
     252                        {
     253                            retImgSrc = localFile;
     254                        }
     255                        return retImgSrc;
    246256                    }
    247257                    else
     
    249259                        throw new ApplicationException("Current category not set before using image cache.");
    250260                    }
    251                     return retValue;
    252261                }
    253262
Note: See TracChangeset for help on using the changeset viewer.