Beispiel #1
0
            /// <summary>
            /// Create an assignment.
            /// </summary>
            /// <param name="assignment">assignment to create</param>
            /// <returns>Created assignment</returns>
            private async Task <Assignment> CreateAssignment(AssignmentNew assignment)
            {
                var request  = new CreateAssignmentRequest(assignment);
                var response = await base.ExecuteRequestAsync(request);

                return(response.Content);
            }
        static async Task AssignToUser(AssignmentNew assignment, string userId)
        {
            //Set the assignment's user
            assignment.AssignedTo = userId;

            //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.");
                throw new Exception("Error creating assignment.");

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

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

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

        static AssignmentNew CreateAssignment()
        {
            //Create the assignment body
            var assignment = new AssignmentNew
            {
                Description   = "This is an assignment created by the SDK Hello World.",
                IntegrationId = SkyManager.IntegrationId, //It's important for us to specify the integrationId here, in order for us to receive events related to this assignment (like `Mark Complete`)
                Name          = "SDK Hello World Assignment " + AssignmentCount
            };

            //Increment our assignment count
            AssignmentCount += 1;

            var sequence = CreateSequence();

            //Add the sequence to the assignment. If we had more sequences, we would add them here.
            assignment.Sequences = new System.Collections.Generic.List <SequenceNew>
            {
                sequence
            };

            //Set this sequence to be the root sequence
            assignment.RootSequence = sequence.Id;

            return(assignment);
        }
Beispiel #4
0
        public static SequenceNew AddSequenceToAssignment(string sequenceId, AssignmentNew assignment)
        {
            var sequence = CreateSequenceNew(sequenceId);

            assignment.Sequences.Add(sequence);
            return(sequence);
        }
Beispiel #5
0
        //Shared methods
        public static async Task <string> CreateAssignment(AssignmentNew assignment)
        {
            var createRequest  = new CreateAssignmentRequest(assignment);
            var createResponse = await SkyManager.ApiClient.ExecuteRequestAsync(createRequest);

            return(createResponse.Content.Id);
        }
Beispiel #6
0
            /// <summary>
            /// This method should be used for creating assignment that exceeds API maximum payload size
            /// It will split creating of the assignment in multiple parts
            /// In order to use this method, this Manager should be provided with maximum payload size that API supports
            /// </summary>
            /// <param name="assignment">Assignment model to create</param>
            /// <returns>Created assignment</returns>
            /// <exception cref="ArgumentNullException">Thrown when assignment model is null</exception>
            /// <exception cref="ArgumentException">Thrown when maximum payload size that API supports was not provided</exception>
            private async Task <Assignment> CreateAssignmentInMultipleRequests(AssignmentNew assignment)
            {
                if (assignment == null)
                {
                    throw new ArgumentNullException(nameof(assignment));
                }

                var payloadSize = GetEstimatedPayloadSize(assignment);

                if (payloadSize >= _maxApiPayloadSize)
                {
                    var sequences = assignment.Sequences.ToList();
                    assignment.Sequences = new List <SequenceNew>();

                    var createdAssignment = await CreateAssignment(assignment);

                    await ProcessSequencesCreation(createdAssignment.Id, sequences);

                    return(createdAssignment);
                }

                return(await CreateAssignment(assignment));
            }
Beispiel #7
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()
        }