Return to the Panopto API index page
We’ve shown that Visual Studio can crash when dealing with a few hundred sessions, and your server probably has thousands of videos. We should therefore deal with a few videos at a time and loop through them.
By adjusting the standard code on page 100 we can set variables for the pagination and do a quick sum to check if we are at the end
1 2 3 4 5 6 |
bool lastPage = false; int resultsPerPage = 5; int page = 0; while(!lastPage) { |
We set a few variables, the first ensures that the while loop at the end continues until we flag that we are on the last page
1 2 3 4 5 6 |
PanoptoSessionManagement.Pagination pagination = new PanoptoSessionManagement.Pagination { MaxNumberResults = resultsPerPage, PageNumber = page }; PanoptoSessionManagement.ListSessionsRequest request = new PanoptoSessionManagement.ListSessionsRequest { Pagination = pagination }; ISessionManagement sessionMgr = new SessionManagementClient(); ListSessionsResponse response = sessionMgr.GetSessionsList(sessionAuthInfo, request, null); |
We then use our standard code for searching and pagination, but using our resultsPerPage and page variables instead of hard coding them.
1 2 3 4 5 6 7 8 9 10 11 |
if (resultsPerPage * (page + 1) >= response.TotalNumberResults) { lastPage = true; Console.WriteLine("There are {0} results, at {1} results per page and on page {2} means we are on the last page", response.TotalNumberResults, resultsPerPage, page + 1); } else { Console.WriteLine("There are {0} results, at {1} results per page and on page {2} means there are more pages to loop through", response.TotalNumberResults, resultsPerPage, page + 1); } |
This is our calculation to find if we are on the last page. For example
5 results per page * (0 + 1) >= 5000 results // FALSE
5 results per page * (999 + 1) >= 5000 results // TRUE, you are on the last page
Remember that page starts at 0, but needs to be 1 when doing math, hence the (page + 1)
I can now use the code from 201 again
1 2 3 4 5 6 7 8 9 10 11 |
if (response.Results.Length > 0) { foreach (Session session in response.Results) { Console.WriteLine(session.Id + ": " + session.Name); } } else { Console.WriteLine("No sessions found"); } |
Finally we need to increment page by 1 ready for the next loop
1 |
page++ |
Full code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Security.Cryptography.X509Certificates; using ConsolePanoptoAPI.PanoptoAccessManagement; using ConsolePanoptoAPI.PanoptoAuth; using ConsolePanoptoAPI.PanoptoRemoteRecorderManagement; using ConsolePanoptoAPI.PanoptoSessionManagement; using ConsolePanoptoAPI.PanoptoUsageReporting; using ConsolePanoptoAPI.PanoptoUserManagement; // ANY NEW NAMESPACES SHOULD BE ADDED HERE // END OF NAMESPACES namespace ConsolePanoptoAPI { class Program { static bool hasBeenInitialized = false; static void Main(string[] args) { // PUT YOUR AUTHENTICATION DETAILS HERE PanoptoSessionManagement.AuthenticationInfo sessionAuthInfo = new PanoptoSessionManagement.AuthenticationInfo() { UserKey = "api", Password = "s2ezupajePhasaP5" }; // END OF AUTHENTICATION DETAILS // START WRITING CODE HERE bool lastPage = false; int resultsPerPage = 5; int page = 0; while(!lastPage) { PanoptoSessionManagement.Pagination pagination = new PanoptoSessionManagement.Pagination { MaxNumberResults = resultsPerPage, PageNumber = page }; PanoptoSessionManagement.ListSessionsRequest request = new PanoptoSessionManagement.ListSessionsRequest { Pagination = pagination }; ISessionManagement sessionMgr = new SessionManagementClient(); ListSessionsResponse response = sessionMgr.GetSessionsList(sessionAuthInfo, request, null); if (resultsPerPage * (page + 1) >= response.TotalNumberResults) { lastPage = true; Console.WriteLine("There are {0} results, at {1} results per page and on page {2} means we are on the last page", response.TotalNumberResults, resultsPerPage, page + 1); } else { Console.WriteLine("There are {0} results, at {1} results per page and on page {2} means there are more pages to loop through", response.TotalNumberResults, resultsPerPage, page + 1); } if (response.Results.Length > 0) { foreach (Session session in response.Results) { Console.WriteLine(session.Id + ": " + session.Name); } } else { Console.WriteLine("No sessions found"); } page++; } // STOP WRITING CODE HERE Console.WriteLine("Press Enter to exit"); Console.ReadLine(); } /// /// Ensures that our custom certificate validation has been applied /// public static void EnsureCertificateValidation() { if (!hasBeenInitialized) { ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(CustomCertificateValidation); hasBeenInitialized = true; } } /// /// Ensures that server certificate is authenticated /// private static bool CustomCertificateValidation(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error) { return true; } /// /// Creates an auth code. Used when we want to authenticate a user, but don't know their password. /// ///The instance name as set in Panopto > System > Identity Providors ///Username as defined by Panopto ///The full server name as defined by Panopto > System > Settings > General site settings > Web server FQDN ///The key produced through Panopto > System > Identity Providors /// private static string CreateAuthCode(string identityProviderInstanceName, string username, string serverFqdn, string applicationKey) { string payload = identityProviderInstanceName + "\\" + username + "@" + serverFqdn.ToLower() + "|" + applicationKey.ToLower(); var data = Encoding.ASCII.GetBytes(payload); var hashData = new System.Security.Cryptography.SHA1Managed().ComputeHash(data); var hash = string.Empty; foreach (var b in hashData) hash += b.ToString("X2"); return hash; } } } |
Return to the Panopto API index page
Hi
Can we get a sample Python code how to use Soap web service for the ListUser method in UserManagement WSDL.
Thanks