Exemplo n.º 1
0
        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.");
            }
        }
Exemplo n.º 2
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()
        }