Esempio n. 1
0
        public async Task RefreshAssetLists()
        {
            //Get the current assets on the robot
            IGetAudioListResponse audioListResponse = await _misty.GetAudioListAsync();

            if (audioListResponse.Status == ResponseStatus.Success && audioListResponse.Data.Count() > 0)
            {
                AudioList = audioListResponse.Data;
            }

            IGetImageListResponse imageListResponse = await _misty.GetImageListAsync();

            if (imageListResponse.Status == ResponseStatus.Success && imageListResponse.Data.Count() > 0)
            {
                ImageList = imageListResponse.Data;
            }

            IGetVideoListResponse videoListResponse = await _misty.GetVideoListAsync();

            if (videoListResponse.Status == ResponseStatus.Success && videoListResponse.Data.Count() > 0)
            {
                VideoList = videoListResponse.Data;
            }
        }
Esempio n. 2
0
        private async Task LoadAssets()
        {
            //Get the current assets on the robot
            IGetAudioListResponse audioListResponse = await _misty.GetAudioListAsync();

            if (audioListResponse.Status == ResponseStatus.Success && audioListResponse.Data.Count() > 0)
            {
                _audioList = audioListResponse.Data;
            }

            IGetImageListResponse imageListResponse = await _misty.GetImageListAsync();

            if (imageListResponse.Status == ResponseStatus.Success && imageListResponse.Data.Count() > 0)
            {
                _imageList = imageListResponse.Data;
            }

            IGetVideoListResponse videoListResponse = await _misty.GetVideoListAsync();

            if (videoListResponse.Status == ResponseStatus.Success && videoListResponse.Data.Count() > 0)
            {
                _videoList = videoListResponse.Data;
            }

            //Load the assets in the Assets/SkillAssets folder to the robot if they are missing or if ReloadAssets is passed in
            StorageFolder skillAssetFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets\SkillAssets");

            IList <StorageFile> assetFileList = (await skillAssetFolder.GetFilesAsync()).ToList();

            foreach (StorageFile storageFile in assetFileList)
            {
                if (_reloadAssets ||
                    (!_audioList.Any(x => x.Name == storageFile.Name) &&
                     !_imageList.Any(x => x.Name == storageFile.Name) &&
                     !_videoList.Any(x => x.Name == storageFile.Name)))
                {
                    StorageFile file = await skillAssetFolder.GetFileAsync(storageFile.Name);

                    IRandomAccessStreamWithContentType stream = await file.OpenReadAsync();

                    byte[] contents = new byte[stream.Size];
                    await stream.AsStream().ReadAsync(contents, 0, contents.Length);

                    if (storageFile.Name.EndsWith(".mp3") ||
                        storageFile.Name.EndsWith(".wav") ||
                        storageFile.Name.EndsWith(".wma") ||
                        storageFile.Name.EndsWith(".aac"))
                    {
                        if ((await _misty.SaveAudioAsync(storageFile.Name, contents, false, true)).Status == ResponseStatus.Success)
                        {
                            _audioList.Add(new AudioDetails {
                                Name = storageFile.Name, SystemAsset = false
                            });
                            _misty.SkillLogger.LogInfo($"Uploaded audio asset '{storageFile.Name}'");
                        }
                        else
                        {
                            _misty.SkillLogger.Log($"Failed to upload audio asset '{storageFile.Name}'");
                        }
                    }
                    else if (storageFile.Name.EndsWith(".mp4") ||
                             storageFile.Name.EndsWith(".wmv"))
                    {
                        if ((await _misty.SaveVideoAsync(storageFile.Name, contents, false, true)).Status == ResponseStatus.Success)
                        {
                            _videoList.Add(new VideoDetails {
                                Name = storageFile.Name, SystemAsset = false
                            });
                            _misty.SkillLogger.LogInfo($"Uploaded video asset '{storageFile.Name}'");
                        }
                        else
                        {
                            _misty.SkillLogger.Log($"Failed to upload video asset '{storageFile.Name}'");
                        }
                    }
                    else if (storageFile.Name.EndsWith(".jpg") ||
                             storageFile.Name.EndsWith(".jpeg") ||
                             storageFile.Name.EndsWith(".png") ||
                             storageFile.Name.EndsWith(".gif"))
                    {
                        if ((await _misty.SaveImageAsync(storageFile.Name, contents, false, true, 0, 0)).Status == ResponseStatus.Success)
                        {
                            _imageList.Add(new ImageDetails {
                                Name = storageFile.Name, SystemAsset = false
                            });
                            _misty.SkillLogger.LogInfo($"Uploaded image asset '{storageFile.Name}'");
                        }
                        else
                        {
                            _misty.SkillLogger.Log($"Failed to upload image asset '{storageFile.Name}'");
                        }
                    }
                    else
                    {
                        _misty.SkillLogger.Log($"Unknown extension for asset '{storageFile.Name}', could not load to robot.");
                    }
                }
            }
        }