Beispiel #1
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;
            }
        }
Beispiel #2
0
 public StatusObserver(TargetDevice device)
 {
     this.api    = device.Api;
     this.status = device.Status;
 }