示例#1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var photoClient = new PhotoStationClient();

            photoClient.Initialize(new DemoApiSettings());
            await photoClient.LoginAsync();

            var albums = await photoClient.ListSmartAlbumsAsync();

            //var album = albums.data.items.First(x => x.info.name == "SamsungAlex");
            var album = albums.data.smart_albums.First(x => x.name == "PhotoFrame");

            //var photos = await photoClient.ListPhotosAsync(album.id);
            PhotoItem[] photos = null;
            await photoClient.ListSmartAlbumItemsAsync(album.id);

            var url = photoClient.GetThumbnailUrl(photos[0]);
            await photoClient.GetThumbnailData(url);

            Console.ReadKey();
        }
        private async void HandleCheckCredetialsCommand()
        {
            try
            {
                Message   = string.Empty;
                IsLoading = true;
                photoStationClient.Initialize(new PhotoFrameSettings(Address, UserName, Password)
                {
                    UseHttps = UseHttps
                });
                var result = await photoStationClient.LoginAsync();

                if (result)
                {
                    var albums = await photoStationClient.ListAlbumsAsync();

                    Albums = new ObservableCollection <AlbumItem>(albums?.data?.items);
                    var smartAlbums = await photoStationClient.ListSmartAlbumsAsync();

                    SmartAlbums      = new ObservableCollection <Smart_Album>(smartAlbums?.data?.smart_albums);
                    LoginSuccessfull = true;
                }
                else
                {
                    Message = "Login not successfull.";
                }
            }
            catch (System.Exception e)
            {
                Message = $"Something went wrong:\r\n{e.Message}";
            }
            finally
            {
                IsLoading = false;
            }
        }
示例#3
0
        public async Task LoadData()
        {
            try
            {
                IsLoading = true;
                ShowNoSettingsNotification = false;
                Message = string.Empty;
                var settings = await settingsHelper.LoadAsync();

#if DEBUG
                /*  When debugging or deploying to IoT device use some "predefined" settings. Not included in git
                 *  public class PhotoApiSettings : PhotoFrameSettings
                 *  {
                 *      public PhotoApiSettings() : base("diskstation", "user", "password")
                 *      ...
                 */
                //settings = new PhotoApiSettings();
#endif
                if (settings == null)
                {
                    IsLoading = false;
                    ShowNoSettingsNotification = true;
                    return;
                }

                photoClient.Initialize(settings);
                var loginResult = await photoClient.LoginAsync();

                if (!loginResult)
                {
                    Message = $"Login with user {settings.Username} to {settings.Url} not successfull. Ples got to settings or check your network connection.";
                    return;
                }

                Message = $"Loading images from {settings.Address}.";
                ListItemResponse listResponse = null;

                // ToDo: if smells like duplicate code
                string albumId = null;
                if (settings.UseSmartAlbum)
                {
                    // Known bug when album contains videos
                    var albums = await photoClient.ListSmartAlbumsAsync();

                    var album = albums.data.smart_albums.FirstOrDefault(x => x.name == settings.AlbumName);
                    if (album == null)
                    {
                        return;
                    }

                    albumId      = album.id;
                    listResponse = await photoClient.ListSmartAlbumItemsAsync(albumId, 0, pageSize);
                }
                else
                {
                    var albums = await photoClient.ListAlbumsAsync();

                    var album = albums.data.items.FirstOrDefault(x => x.info.name == settings.AlbumName);
                    if (album == null)
                    {
                        return;
                    }

                    albumId      = album.id;
                    listResponse = await photoClient.ListPhotosAsync(albumId, 0, pageSize);
                }

                var images = listResponse.data?.items?.Select(p => new ImageModel(photoClient.GetBiglUrl(p), p, photoClient)).ToList();
                if (randomOrder)
                {
                    images.Shuffle();
                }

                var tempimages = images.ToList();
                Message = string.Empty;
                Images  = new ObservableCollection <ImageModel>(images);

                for (int i = images.Count; i < listResponse.data.total; i += pageSize)
                {
                    var pagingListResponse = settings.UseSmartAlbum ? (await photoClient.ListSmartAlbumItemsAsync(albumId, i, pageSize)) : (await photoClient.ListPhotosAsync(albumId, i, pageSize));
                    images = pagingListResponse.data?.items?.Select(p => new ImageModel(photoClient.GetBiglUrl(p), p, photoClient)).ToList();
                    tempimages.AddRange(images);
                }

                if (randomOrder)
                {
                    tempimages.Shuffle();
                }
                Images = new ObservableCollection <ImageModel>(tempimages);
            }
            catch (Exception e)
            {
                Message = $"Ooops something went wrong. Sorry! \r\nInfo: {e.Message}";
                Debug.WriteLine(e.Message);
            }
        }