Beispiel #1
0
        public override async Task LoadContents()
        {
            var loader = new RemoteApiContentsLoader(TargetDevice);
            await TargetDevice.Observer.StartAsync();

            try
            {
                OnProgressMessage("Progress_ChangingCameraState");

                var StateChangeCanceller = new CancellationTokenSource(15000);
                try
                {
                    if (!await PlaybackModeHelper.MoveToContentTransferModeAsync(TargetDevice, StateChangeCanceller))
                    {
                        DebugUtil.Log(() => "ModeTransition failed");
                        throw new Exception();
                    }
                }
                finally
                {
                    StateChangeCanceller = null;
                }
                DebugUtil.Log(() => "ModeTransition successfully finished");

                OnProgressMessage("Progress_FetchingContents");
                loader.PartLoaded += RemoteContentsLoader_PartLoaded;
                await loader.Load(ApplicationSettings.GetInstance().RemoteContentsSet, Canceller);

                DebugUtil.Log(() => "RemoteApiContentsLoader completed");
            }
            catch (StorageNotSupportedException)
            {
                // This will never happen on camera devices.
                DebugUtil.Log(() => "storage scheme is not supported");
                OnErrorMessage("Viewer_StorageAccessNotSupported");
            }
            catch (NoStorageException)
            {
                DebugUtil.Log(() => "No storages");
                OnErrorMessage("Viewer_NoStorage");
            }
            catch (Exception e)
            {
                DebugUtil.Log(() => e.StackTrace);
                OnErrorMessage("Viewer_FailedToLoadContents");
            }
            finally
            {
                loader.PartLoaded -= RemoteContentsLoader_PartLoaded;
            }
        }
Beispiel #2
0
        public static async Task SetUp(TargetDevice device, StreamProcessor liveview, CancellationTokenSource cancel = null)
        {
            DebugUtil.Log(() => "Set up control");
            try
            {
                await device.Api.RetrieveApiList();

                var info = await device.Api.Camera.GetApplicationInfoAsync().ConfigureAwait(false);

                cancel.ThrowIfCancelled();

                device.Api.Capability.Version = new ServerVersion(info.Version);

                await device.Observer.StartAsync().ConfigureAwait(false);

                cancel.ThrowIfCancelled();

                if (device.Api.AvContent != null && device.Observer.IsPlaybackMode())
                {
                    DebugUtil.Log(() => "This device support ContentsTransfer mode. Turn on Shooting mode at first.");
                    if (!await PlaybackModeHelper.MoveToShootingModeAsync(device, cancel).ConfigureAwait(false))
                    {
                        throw new Exception();
                    }
                    cancel.ThrowIfCancelled();
                }

                if (device.Api.Capability.IsSupported("startRecMode"))
                {
                    await device.Api.Camera.StartRecModeAsync().ConfigureAwait(false);

                    cancel.ThrowIfCancelled();
                }

                // No need to check runtime availability. We have to open stream except in audio mode.
                if (device.Status.ShootMode.Current != ShootModeParam.Audio)
                {
                    if (!await OpenLiveviewStream(device.Api, liveview).ConfigureAwait(false))
                    {
                        DebugUtil.Log(() => "Failed to open liveview connection.");
                        throw new Exception("Failed to open liveview connection.");
                    }
                    cancel.ThrowIfCancelled();
                }

                if (device.Api.Capability.IsSupported("setCurrentTime"))
                {
                    try
                    {
                        await device.Api.System.SetCurrentTimeAsync( //
                            DateTimeOffset.UtcNow, (int)DateTimeOffset.Now.Offset.TotalMinutes).ConfigureAwait(false);
                    }
                    catch (RemoteApiException) { } // This API always fails on some models.
                    cancel.ThrowIfCancelled();
                }
            }
            catch (RemoteApiException e)
            {
                DebugUtil.Log(() => "Failed setup: " + e.StatusCode);
                device.Observer.Stop();
                throw;
            }
            catch (OperationCanceledException)
            {
                DebugUtil.Log(() => "Operation cancelled");
                device.Observer.Stop();
                throw;
            }
        }