Ejemplo n.º 1
0
        private async Task InstallAppAsyncV3(AppBundle bundle, IProgress <ProgressValue> progress)
        {
            //https://github.com/pebble/libpebble2/blob/master/libpebble2/services/install.py

            var meta = AppMetaData.FromAppBundle(bundle);

            var bytes  = meta.GetBytes();
            var result = await _pebble.BlobDBClient.Delete(BlobDatabase.App, meta.UUID.Data);

            result = await _pebble.BlobDBClient.Insert(BlobDatabase.App, meta.UUID.Data, bytes);

            if (result.Response == BlobStatus.Success)
            {
                var startPacket = new AppRunStatePacket();
                startPacket.Command = AppRunState.Start;
                startPacket.UUID    = meta.UUID;
                //app_fetch = self._pebble.send_and_read(AppRunState(data=AppRunStateStart(uuid=app_uuid)), AppFetchRequest)

                var runStateResult = await _pebble.SendMessageAsync <AppFetchRequestPacket>(Endpoint.AppRunState, startPacket.GetBytes());

                if (!runStateResult.Success)
                {
                    throw new InvalidOperationException("Pebble replied invalid run state");
                }

                if (!meta.UUID.Equals(runStateResult.UUID))
                {
                    var response = new AppFetchResponsePacket();
                    response.Response = AppFetchStatus.InvalidUUID;
                    await _pebble.SendMessageNoResponseAsync(Endpoint.AppFetch, response.GetBytes());

                    throw new InvalidOperationException("The pebble requested the wrong UUID");
                }

                var putBytesResponse = await _pebble.PutBytesClient.PutBytes(bundle.App, TransferType.Binary, appInstallId : (uint)runStateResult.AppId);

                if (!putBytesResponse)
                {
                    throw new InvalidOperationException("Putbytes failed");
                }

                if (bundle.HasResources)
                {
                    putBytesResponse = await _pebble.PutBytesClient.PutBytes(bundle.Resources, TransferType.Resources, appInstallId : (uint)runStateResult.AppId);

                    if (!putBytesResponse)
                    {
                        throw new InvalidOperationException("Putbytes failed");
                    }
                }

                //TODO: add worker to manifest and transfer it if necassary
                //if (bundle.HasWorker)
                //{
                //await PutBytesV3(bundle.Worker, TransferType.Worker, runStateResult.AppId);
                //}
            }
            else
            {
                throw new DataMisalignedException("BlobDB Insert Failed");
            }
        }