Exemplo n.º 1
0
        async void IOnClickListener.OnClick(View view)
        {
            if (!CanCreateAnchor())
            {
                return;
            }

            createAnchorButton.Enabled = false;
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor();

            cloudAnchor.LocalAnchor = PlacedVisual.LocalAnchor;
            cloudAnchor.AppProperties.Add("Shape", PlacedVisual.Shape.ToString());

            isCreatingAnchor = true;
            await CloudAnchorManager.CreateAnchorAsync(cloudAnchor)
            .ContinueWith(async cloudAnchorTask =>
            {
                try
                {
                    CloudSpatialAnchor anchor = await cloudAnchorTask;

                    string anchorId = anchor.Identifier;
                    Log.Debug("ASADemo", "anchorId: " + anchorId);
                    var anchorSharingServiceClient = new AnchorSharingServiceClient(AccountDetails.AnchorSharingServiceUrl);
                    SendAnchorResponse response    = await anchorSharingServiceClient.SendAnchorIdAsync(anchorId);
                }
                catch (CloudSpatialException)
                {
                    // to do
                    //this.CreateAnchorExceptionCompletion($"{ex.Message}, {ex.ErrorCode}");
                }
                catch (Exception)
                {
                    // to do
                    //this.CreateAnchorExceptionCompletion(ex.Message);
                    //visual.SetColor(this, Color.Red);
                }
            });

            AnchorVisual createdAnchor = PlacedVisual;

            PlacedVisual = null;
            OnAnchorCreated?.Invoke(createdAnchor);
        }
        private void TransitionToSaving(AnchorVisual visual)
        {
            Log.Debug("ASADemo:", "transition to saving");
            this.currentStep = DemoStep.SavingAnchor;
            this.EnableCorrectUIControls();
            Log.Debug("ASADemo", "creating anchor");
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor();

            //Date d1 = new Date(2030, 11, 21);
            //cloudAnchor.Expiration = d1;

            visual.CloudAnchor      = cloudAnchor;
            cloudAnchor.LocalAnchor = visual.LocalAnchor;

            this.cloudAnchorManager.CreateAnchorAsync(cloudAnchor)
            .ContinueWith(async cloudAnchorTask =>
            {
                try
                {
                    CloudSpatialAnchor anchor = await cloudAnchorTask;

                    string anchorId = anchor.Identifier;
                    Log.Debug("ASADemo:", "created anchor: " + anchorId);
                    visual.SetColor(this, Color.Green);
                    this.anchorVisuals[anchorId] = visual;
                    this.anchorVisuals.TryRemove(string.Empty, out _);

                    Log.Debug("ASADemo", "recording anchor with web service");
                    Log.Debug("ASADemo", "anchorId: " + anchorId);
                    SendAnchorResponse response = await this.anchorSharingServiceClient.SendAnchorIdAsync(anchorId);
                    this.AnchorPosted(response.AnchorNumber);
                }
                catch (CloudSpatialException ex)
                {
                    this.CreateAnchorExceptionCompletion($"{ex.Message}, {ex.ErrorCode}");
                }
                catch (Exception ex)
                {
                    this.CreateAnchorExceptionCompletion(ex.Message);
                    visual.SetColor(this, Color.Red);
                }
            });
        }
Exemplo n.º 3
0
        public async Task <SendAnchorResponse> SendtoSharingServiceAsync(string anchorId)
        {
            SendAnchorResponse response = null;

            if (anchorId == null)
            {
                throw new ArgumentException("The anchorId was null");
            }

            try
            {
                response = await this.anchorSharingServiceClient.SendAnchorIdAsync(anchorId, "testiOS");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return(response);
        }
Exemplo n.º 4
0
        protected override void AnchorSaveSuccess(CloudSpatialAnchor result)
        {
            base.AnchorSaveSuccess(result);

            Debug.WriteLine("ASADemo", "recording anchor with web service");
            Debug.WriteLine("ASADemo", "anchorId: " + this.anchorId);

            Task.Run(async() =>
            {
                try
                {
                    SendAnchorResponse sendResult = await this.SendtoSharingServiceAsync(this.cloudAnchor.Identifier);
                    this.UpdateMainStatusTitle("Anchor Number: " + sendResult.AnchorNumber);
                    this.MoveToNextStepAfterCreateCloudAnchor();
                }
                catch (Exception ex)
                {
                    this.AnchorSaveFailed(ex.Message);
                }
            });
        }
        protected override void AnchorSaveSuccess(CloudSpatialAnchor result)
        {
            base.AnchorSaveSuccess(result);

            Debug.WriteLine("ASADemo", "recording anchor with web service");
            Debug.WriteLine("ASADemo", "anchorId: " + result.Identifier);

            Task.Run(async() =>
            {
                try
                {
                    SendAnchorResponse sendResult = await this.SendtoSharingServiceAsync(result.Identifier);
                    this.UpdateStatus("Create Success!!");
                    this.UpdateMainStatusTitle("Anchor Number: " + sendResult.AnchorNumber);
                    this.ShowCreateOrLocateMenu();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Failed to save the anchor to the sharing service: '{ex.Message}'.");
                    this.AnchorSaveFailed(ex.Message);
                }
            });
        }