Exemple #1
0
        //@skydocs.start(mqtt.cardupdated.componenttype)
        static async Task CardUpdated(object sender, CardUpdatedEventArgs args)
        {
            var cardRequest = new Skylight.Api.Assignments.V1.CardRequests.GetCardRequest(args.AssignmentId, args.SequenceId, args.CardId);
            var response    = await SkyManager.ApiClient.ExecuteRequestAsync(cardRequest);

            var card = response.Content;

            //We could use the card tags (card.Tags), card id (args.CardId), or the component type (see below) of the card to see what action we should take. See the Hello World example for how to use card tags.
            switch (card.Component.ComponentType)
            {
            case ComponentType.CapturePhoto:
                //For a more in-depth example of downloading a captured photo, see the Hello World example.
                Console.WriteLine("Photo captured.");
                break;

            case ComponentType.Completion:
                Console.WriteLine("Completion card selected.");
                break;

            case ComponentType.Scanning:
                var scanComponent = (ComponentScanning)card.Component;
                var scanResult    = scanComponent.Result;
                Console.WriteLine("Scan component updated with scan result: " + scanResult);
                break;

            default:
                break;
            }
        }
Exemple #2
0
        //@skydocs.start(mqtt.cardupdated.cardid)
        static async Task CardUpdated(object sender, CardUpdatedEventArgs args)
        {
            //In this example, we'll first check the assignment to make sure its name matches our assignment's name.
            Assignment assignment = await GetAssignment(args.AssignmentId);

            if (!assignment.Name.Equals(ASSIGNMENT_NAME))
            {
                return;
            }

            //Now handle the card update event based on the card's id
            var shouldResetCard = false;

            switch (args.CardId)
            {
            case CREATE_CARD_ID:
                await CreateCardSequence(args.AssignmentId, args.SequenceId);

                shouldResetCard = true;
                break;

            case DELETE_CARD_ID:
                await DeleteCardSequence(args.AssignmentId, args.SequenceId);

                break;
            }

            //Only progress forward if we're looking to reset the card
            if (!shouldResetCard)
            {
                return;
            }

            Card card = await GetCard(args.AssignmentId, args.SequenceId, args.CardId);

            Console.WriteLine(card.Component.ComponentType);

            //Make sure we're working with the correct card type
            if (card.Component.ComponentType != ComponentType.Completion)
            {
                return;
            }
            Console.WriteLine("Resetting card");

            //Mark the card as not done, to allow the user to select the card again.
            await ResetCard(card);
        }
        //@skydocs.start(mqtt.cardupdated.cardtags)
        //@skydocs.start(media.download)
        static async Task CardUpdated(object sender, CardUpdatedEventArgs args)
        {
            /*
             *  There are many ways we can handle this event. We could:
             *  - use the cardId to determine what action to take
             *  - pull down the card and:
             *      - look at its tags to determine what to do
             *      - look at the card type and decide what to do
             *
             *  For this example, we'll pull down the card and look at its tags (specifically, we'll make sure it has the MARK_COMPLETE_TAG tag that we used earlier)
             */
            var result = await SkyManager.ApiClient.ExecuteRequestAsync(new Skylight.Api.Assignments.V1.CardRequests.GetCardRequest(args.AssignmentId, args.SequenceId, args.CardId));

            //Handle the resulting status code appropriately
            switch (result.StatusCode)
            {
            case System.Net.HttpStatusCode.Forbidden:
                Console.Error.WriteLine("Error getting card: Permission forbidden.");
                throw new Exception("Error getting card.");

            case System.Net.HttpStatusCode.Unauthorized:
                Console.Error.WriteLine("Error getting card: Method call was unauthenticated.");
                throw new Exception("Error getting card.");

            case System.Net.HttpStatusCode.NotFound:
                Console.Error.WriteLine("Error retrieving card: User not found.");
                throw new Exception("Error getting card.");

            case System.Net.HttpStatusCode.OK:
                Console.WriteLine("Successfully retrieved card.");
                break;

            default:
                Console.Error.WriteLine("Unhandled card retrieval status code: " + result.StatusCode);
                throw new Exception("Error getting card.");
            }

            var cardInfo = result.Content;

            if (cardInfo.Tags.Contains(MARK_COMPLETE_TAG))
            {
                //If the card's tags includes a MARK_COMPLETE_TAG, then we'll reassign the assignment
                Console.WriteLine("Card tags contains MARK_COMPLETE_TAG");

                //If the card isn't marked complete, return
                if (!cardInfo.IsDone.HasValue || !cardInfo.IsDone.Value)
                {
                    return;
                }
                Console.WriteLine("Card is marked complete");

                //Otherwise, reassign the assignment
                await DeleteAssignment(args.AssignmentId);

                var assignmentBody = CreateAssignment();
                await AssignToUser(assignmentBody, UserId);
            }
            else if (cardInfo.Tags.Contains(PHOTO_CAPTURE_TAG))
            {
                //If the card's tags includes a PHOTO_CAPTURE_TAG, we'll download the photo that was captured
                var photoCaptureComponent = (ComponentCapturePhoto)cardInfo.Component;
                Console.WriteLine(cardInfo.ToJson());
                var photoCaptureURIs = photoCaptureComponent.Captures;
                foreach (var photoCaptureURI in photoCaptureURIs)
                {
                    await DownloadPhoto(photoCaptureURI);

                    Console.WriteLine(photoCaptureURI);
                }
            }
        }
Exemple #4
0
 static async Task CardUpdated(object sender, CardUpdatedEventArgs args)
 {
 }