Exemple #1
0
        public void TestCardCoverage()
        {
            //This is to test to ensure the properties exist; this would not be used in practice
            var sequence = new Sequence()
            {
                ViewMode = ViewMode.Gallery
            };

            sequence.SetDefaults();

            Assert.NotNull(sequence.ToString());
            Assert.NotNull(sequence.ToJson());


            var sequenceNew = new SequenceNew()
            {
                TemplateId = ""
            };

            Assert.NotNull(sequenceNew.TemplateId);
            sequenceNew.SetDefaults();
            Assert.NotNull(sequenceNew.ToJson());
            Assert.NotNull(sequenceNew.ToString());

            var sequencePatch = new SequencePatch().SetDefaults();

            Assert.NotNull(sequencePatch.ToJson());
            Assert.NotNull(sequencePatch.ToString());


            var sequenceUpdate = new SequenceUpdate().SetDefaults();

            Assert.NotNull(sequenceUpdate.ToJson());
            Assert.NotNull(sequenceUpdate.ToString());
        }
Exemple #2
0
            /// <summary>
            /// Create single sequence.
            /// </summary>
            /// <param name="assignmentId">Id of the assignment</param>
            /// <param name="sequence">sequence to create</param>
            /// <returns>Created sequence</returns>
            public async Task <Sequence> CreateSequence(string assignmentId, SequenceNew sequence)
            {
                var request  = new CreateSequenceRequest(sequence, assignmentId);
                var response = await base.ExecuteRequestAsync(request);

                return(response.Content);
            }
Exemple #3
0
        //We position the cards by their position in the array
        public static void PositionCardsInSequence(SequenceNew sequence)
        {
            var cards = sequence.Cards;

            for (var index = 0; index < cards.Count; index += 1)
            {
                var card = cards[index];
                card.Position = index + 1;//Position is 1-indexed
            }
        }
Exemple #4
0
        public static CardNew AddCardToSequence(string cardId, SequenceNew sequence)
        {
            var card = CreateCardNew(cardId);

            sequence.Cards.Add(card);

            //Position cards after adding this card to the sequence -- technically this is unoptimized (the sort should occur after adding all cards), but we're working with a small set of cards and this leads to cleaner code for tests
            PositionCardsInSequence(sequence);
            return(card);
        }
        static SequenceNew CreateSequence()
        {
            var sequence = new SequenceNew
            {
                Id       = "sequence1",
                ViewMode = ViewMode.Native //This is the default view mode and will generally be used
            };

            CardNew labelHelloCard = CreateLabelCard("Hello World");

            labelHelloCard.Position = 1;
            labelHelloCard.Id       = "card1"; //This could be a UUID -- as long as it's unique within the sequence, we're good

            //@skydocs.start(cards.tags)
            CardNew photoCaptureCard = CreatePhotoCaptureCard();

            photoCaptureCard.Position = 2;
            photoCaptureCard.Id       = "card2";

            //We'll add a tag to the photo capture card so we can identify it when we handle the card updated event
            //An IMPORTANT NOTE is that any tags on this photo capture card will be added to any photos captured by this card, in the photo's metadata
            photoCaptureCard.Tags = new System.Collections.Generic.List <string>
            {
                PHOTO_CAPTURE_TAG
            };

            CardNew markCompleteCard = CreateMarkCompleteCard();

            markCompleteCard.Position = 3;
            markCompleteCard.Id       = "card3";

            //We'll add a tag to the mark complete card so we can look for it later when we handle the event
            markCompleteCard.Tags = new System.Collections.Generic.List <string>
            {
                MARK_COMPLETE_TAG
            };
            //@skydocs.end()

            //Set the cards to live in the sequence. We could create more cards and add them in a similar manner
            sequence.Cards = new System.Collections.Generic.List <CardNew>
            {
                labelHelloCard
                , photoCaptureCard
                , markCompleteCard
            };

            return(sequence);
        }
Exemple #6
0
        static async Task CreateBulkAssignment()
        {
            //@skydocs.start(assignments.bulkcreate)
            //Retrieve the user to whom we'd like to assign this assignment
            var assignUser = await GetUserIdForUsername(TEST_ACCOUNT_USERNAME);

            if (assignUser == null)
            {
                Console.Error.WriteLine("User does not exist for bulk assignment creation");
                return;
            }

            //Create the assignment body
            var assignment = new AssignmentNew
            {
                AssignedTo    = assignUser,
                Description   = "This is an assignment created by the SDK example.",
                IntegrationId = SkyManager.IntegrationId,
                Name          = ASSIGNMENT_NAME
            };

            //Create a sequence -- theoretically, this would be better placed in another function
            //We have placed this inline within this function for clarity in this example
            var sequenceOne = new SequenceNew
            {
                Id       = ROOT_SEQUENCE_ID,
                ViewMode = ViewMode.Native //This is the default view mode and will generally be used
            };

            //Create a card for sequence1
            var sequenceOneCardOne = new CardNew
            {
                Footer     = "Select to create a card that points to a new sequence",
                Id         = CREATE_CARD_ID, //As long as the ID is unique within the sequence, we're good to go
                Label      = "Append Card",
                Position   = 1,              //Position of cards is 1-indexed
                Size       = 2,              //Size can be 1, 2, or 3 and determines how much of the screen a card takes up (3 being fullscreen)
                Layout     = new LayoutText(),
                Selectable = true,
                Component  = new ComponentCompletion()
                {
                    Done = new DoneOnSelect()
                }
            };

            //Set the card to live in sequence1. We could create more cards and add them in a similar manner
            sequenceOne.Cards = new System.Collections.Generic.List <CardNew>
            {
                sequenceOneCardOne
            };

            //Add the sequence to the assignment
            assignment.Sequences = new System.Collections.Generic.List <SequenceNew>
            {
                sequenceOne
            };

            //Set the sequence to be the root sequence. This is especially important if we have more than one sequence
            assignment.RootSequence = sequenceOne.Id;

            //Create the request for the assignment creation API
            var request = new Skylight.Api.Assignments.V1.AssignmentRequests.CreateAssignmentRequest(assignment);

            //Now, the magic happens -- we make a single API call to create this assignment, sequences/cards and all.
            var result = await SkyManager.ApiClient.ExecuteRequestAsync(request);

            //Handle the resulting status code appropriately
            switch (result.StatusCode)
            {
            case System.Net.HttpStatusCode.Forbidden:
                Console.Error.WriteLine("Error creating assignment: Permission forbidden.");
                break;

            case System.Net.HttpStatusCode.Unauthorized:
                Console.Error.WriteLine("Error creating assignment: Method call was unauthenticated.");
                break;

            case System.Net.HttpStatusCode.Created:
                Console.WriteLine("Assignment successfully created.");
                break;

            default:
                Console.Error.WriteLine("Unhandled assignment creation status code: " + result.StatusCode);
                break;
            }
            //@skydocs.end()
        }
Exemple #7
0
        static async Task CreateCardSequence(string assignmentId, string sequenceId)
        {
            var newSequenceId = "sequence" + numSequencesCreated;

            //@skydocs.start(sequences.create)
            var newSequence = new SequenceNew()
            {
                Id = newSequenceId
            };

            var newSequenceCard = new CardNew()
            {
                Footer     = "Select to delete this sequence",
                Id         = DELETE_CARD_ID, //As long as the ID is unique within the sequence, we're good to go
                Label      = "Delete Sequence",
                Position   = 1,              //Position of cards is 1-indexed
                Size       = 2,              //Size can be 1, 2, or 3 and determines how much of the screen a card takes up (3 being fullscreen)
                Layout     = new LayoutText(),
                Selectable = true,
                Component  = new ComponentCompletion()
                {
                    Done = new DoneOnSelect()
                }
            };

            newSequence.Cards = new System.Collections.Generic.List <CardNew> {
                newSequenceCard
            };

            //Create our sequence
            var sequenceCreateResult = await SkyManager.ApiClient.ExecuteRequestAsync(new Skylight.Api.Assignments.V1.SequenceRequests.CreateSequenceRequest(newSequence, assignmentId));

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

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

            case System.Net.HttpStatusCode.NotFound:
                Console.Error.WriteLine("Error creating sequence: Assignment not found.");
                throw new Exception("Error creating sequence.");

            case System.Net.HttpStatusCode.Created:
                Console.WriteLine("Successfully created sequence.");
                break;

            default:
                Console.Error.WriteLine("Unhandled sequence creation status code: " + sequenceCreateResult.StatusCode);
                throw new Exception("Error creating sequence.");
            }
            //@skydocs.end()

            //Get our current sequence's cards information so we can add a new card to it
            var sequenceInfoRequest = await SkyManager.ApiClient.ExecuteRequestAsync(new Skylight.Api.Assignments.V1.CardRequests.GetSequenceCardsRequest(assignmentId, sequenceId));

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

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

            case System.Net.HttpStatusCode.NotFound:
                Console.Error.WriteLine("Error retrieving sequence: Assignment or sequence not found.");
                throw new Exception("Error retrieving sequence.");

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

            default:
                Console.Error.WriteLine("Unhandled sequence retrieval status code: " + sequenceInfoRequest.StatusCode);
                throw new Exception("Error retrieving sequence.");
            }

            var numCardsInSequence = sequenceInfoRequest.Content.Count;

            //@skydocs.start(cards.create)
            var openSequenceCard = new CardNew()
            {
                Footer     = "Enter " + newSequenceId,
                Id         = "card" + numSequencesCreated, //As long as the ID is unique within the sequence, we're good to go
                Label      = "Sequence " + numSequencesCreated,
                Position   = numCardsInSequence + 1,       //Position of cards is 1-indexed
                Size       = 1,                            //Size can be 1, 2, or 3 and determines how much of the screen a card takes up (3 being fullscreen)
                Layout     = new LayoutText(),
                Selectable = true,
                Component  = new ComponentOpenSequence()
                {
                    SequenceId = newSequenceId
                }
            };

            var cardCreateResult = await SkyManager.ApiClient.ExecuteRequestAsync(new Skylight.Api.Assignments.V1.CardRequests.CreateCardsRequest(new System.Collections.Generic.List <CardNew> {
                openSequenceCard
            }, assignmentId, ROOT_SEQUENCE_ID));

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

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

            case System.Net.HttpStatusCode.NotFound:
                Console.Error.WriteLine("Error creating card: Assignment or sequence not found.");
                throw new Exception("Error creating card.");

            case System.Net.HttpStatusCode.Created:
                Console.WriteLine("Successfully created card.");
                break;

            default:
                Console.Error.WriteLine("Unhandled card creation status code: " + cardCreateResult.StatusCode);
                throw new Exception("Error creating card.");
            }
            //@skydocs.end()

            //Increment how many sequences we've created
            numSequencesCreated += 1;
        }