public SessionManagementWrapper(string username, string password)
        {
            this.sessionManager = new SessionManagementClient();

            // Ensure server certificate is validated
            CertificateValidation.EnsureCertificateValidation();

            this.authentication = new AuthenticationInfo()
            {
                UserKey  = username,
                Password = password
            };
        }
Example #2
0
        /// <summary>
        /// Sets up the access to the server.
        /// </summary>
        /// <param name="userName">The username of the account that has access to schedule recordings.</param>
        /// <param name="password">The password associated with the account <paramref name="userName"/>.</param>
        /// <param name="siteName">The name of the site in which to gain access to.</param>
        /// <param name="rrMgr">The client in which holds the information about the recorders available.</param>
        /// <param name="rrAuth">The authentication information for which to access the information from <paramref name="rrMgr"/>.</param>
        /// <param name="sessionMgr">The client in which holds the information about the sessions.</param>
        /// <param name="sessionAuth">The authentication information for which to access the information from <paramref name="sessionMgr"/>.</param>
        public static void SetupSiteAccess(string userName,
                                           string password,
                                           string siteName,
                                           out IRemoteRecorderManagement rrMgr,
                                           out Utilities.RemoteRecorderManagement42.AuthenticationInfo rrAuth,
                                           out ISessionManagement sessionMgr,
                                           out Utilities.SessionManagement46.AuthenticationInfo sessionAuth)
        {
            if (siteName == "")
            {
                // sitename was not configured
                throw new System.Configuration.ConfigurationErrorsException("Sitename was not configured.");
            }
            // rr manager setup
            rrMgr = new RemoteRecorderManagementClient(
                new BasicHttpBinding(BasicHttpSecurityMode.Transport)
            {
                MaxReceivedMessageSize = Properties.Settings.Default.HttpBindingMessageSize,
                SendTimeout            = Properties.Settings.Default.HttpBindingTimeout,
                ReceiveTimeout         = Properties.Settings.Default.HttpBindingTimeout
            },
                new EndpointAddress("https://" + siteName + "/Panopto/PublicAPI/4.2/RemoteRecorderManagement.svc")
                );

            // rr auth info setup
            rrAuth          = new Utilities.RemoteRecorderManagement42.AuthenticationInfo();
            rrAuth.UserKey  = userName;
            rrAuth.Password = password;

            // session manager setup
            sessionMgr = new SessionManagementClient(
                new BasicHttpBinding(BasicHttpSecurityMode.Transport)
            {
                MaxReceivedMessageSize = Properties.Settings.Default.HttpBindingMessageSize,
                SendTimeout            = Properties.Settings.Default.HttpBindingTimeout,
                ReceiveTimeout         = Properties.Settings.Default.HttpBindingTimeout
            },
                new EndpointAddress("https://" + siteName + "/Panopto/PublicAPI/4.6/SessionManagement.svc")
                );

            // session auth info
            sessionAuth          = new Utilities.SessionManagement46.AuthenticationInfo();
            sessionAuth.UserKey  = userName;
            sessionAuth.Password = password;
        }
Example #3
0
        private static bool AreThereCourseFoldersInTheRoot(string username, string password)
        {
            PanoptoSessionManagement.AuthenticationInfo sessionAuthInfo = new PanoptoSessionManagement.AuthenticationInfo()
            {
                UserKey  = username,
                Password = password
            };

            bool returnAreThereCoursesInTheRoot = false;
            bool lastPage       = false;
            int  resultsPerPage = 100;
            int  page           = 0;

            ISessionManagement sessionMgr = new SessionManagementClient();

            while (!lastPage)
            {
                PanoptoSessionManagement.Pagination pagination = new PanoptoSessionManagement.Pagination {
                    MaxNumberResults = resultsPerPage, PageNumber = page
                };
                ListFoldersResponse response = sessionMgr.GetFoldersList(sessionAuthInfo, new ListFoldersRequest {
                    Pagination = pagination, ParentFolderId = Guid.Empty, SortIncreasing = true
                }, null);

                if (resultsPerPage * (page + 1) >= response.TotalNumberResults)
                {
                    lastPage = true;
                }

                if (response.Results.Length > 0)
                {
                    if (response.Results.Any(folder => Regex.IsMatch(folder.Name, "^[A-Z]{4}[0-9]{4}-.+$") && folder.ParentFolder.Equals(null)))
                    {
                        returnAreThereCoursesInTheRoot = true;
                        writeLine("Courses found in the root");
                        break;
                    }
                }

                page++;
            }

            return(returnAreThereCoursesInTheRoot);
        }
Example #4
0
        /// <summary>
        /// Constructor to create a SessionManagement including
        /// necessary information to create the SOAP API calls
        /// </summary>
        /// <param name="site">Panopto Site</param>
        /// <param name="username">admin username</param>
        /// <param name="password">password associated with username</param>
        public SessionManagementWrapper(string site, string username, string password)
        {
            // Update Service endpoint to reflect specified server name
            UriBuilder sessionManagementUriBuilder = new UriBuilder();

            sessionManagementUriBuilder.Scheme = "https";
            sessionManagementUriBuilder.Host   = site;
            sessionManagementUriBuilder.Path   = @"Panopto/PublicAPI/4.6/SessionManagement.svc";

            this.sessionManagement = new SessionManagementClient(
                new BasicHttpBinding(BasicHttpSecurityMode.Transport)
            {
                MaxReceivedMessageSize = 10000000,
                SendTimeout            = TimeSpan.FromMinutes(10),
                ReceiveTimeout         = TimeSpan.FromMinutes(10)
            },
                new EndpointAddress(sessionManagementUriBuilder.Uri));

            this.authentication = new AuthenticationInfo()
            {
                UserKey  = username,
                Password = password
            };
        }
Example #5
0
        private static List<Session> searchForSessions(AuthenticationInfo auth, SessionManagementClient smc, Folder folder)
        {
            List<Session> sessionsToIndex = new List<Session>();
            try
            {
                // Search for all sessions in this folder
                Guid folderId = folder.Id;

                Pagination pagination = new Pagination { PageNumber = 0, MaxNumberResults = maxPerPage };
                ListSessionsRequest sessionRequest = new ListSessionsRequest { Pagination = pagination, FolderId = folderId};
                ListSessionsResponse response = smc.GetSessionsList(auth, sessionRequest, "");

                if (response.TotalNumberResults == 0)
                {
                    Console.WriteLine("Found 0 results.");
                }
                else
                {
                    int pagesOfResults = response.TotalNumberResults / maxPerPage;

                    // List the sessions from the initial request
                    foreach (Session session in response.Results)
                    {
                        // Add sessions to the list.
                        sessionsToIndex.Add(session);
                    }

                    // If there are more pages, make additional network requests
                    for (int page = 1; page < pagesOfResults; page++)
                    {
                        pagination = new Pagination { PageNumber = page, MaxNumberResults = maxPerPage };
                        sessionRequest = new ListSessionsRequest { Pagination = pagination, FolderId = folderId };
                        response = smc.GetSessionsList(auth, sessionRequest, "");

                        // List the sessions from the initial request
                        foreach (Session session in response.Results)
                        {
                            // Add sessions to the list.
                            sessionsToIndex.Add(session);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("Error while searching for sessions in folder: {0} - {1}", folder.Name, e.Message));
            }
            return sessionsToIndex;
        }
Example #6
0
        private static void Main(string[] args)
        {
            var hosts = new[] {
                new { ConfigName = "testing", Description = "Via SLB and ELB" }
            };

            foreach (var host in hosts)
            {
                Console.WriteLine("Testing: {0} ({1})", host.Description, host.ConfigName);

                try
                {
                    SessionManagementClient smc = new SessionManagementClient();
                    AuthenticationInfo auth = new AuthenticationInfo();

                    // Use an account that is a member of groups that have the right permissions.
                    auth.Password = "******";
                    auth.UserKey = "testAccount";
                    auth.AuthCode = String.Empty;

                    // Names of folders to scan
                    string[] folderNames = new string[] { "One Folder", "Some other folder name" };

                    List<Session> sessions = new List<Session>();

                    Pagination pagination = new Pagination { PageNumber = 0, MaxNumberResults = maxPerPage };
                    ListFoldersRequest request = new ListFoldersRequest { Pagination = pagination };

                    // Get all the folders we need to index
                    foreach (string folderName in folderNames)
                    {
                        ListFoldersResponse response = smc.GetFoldersList(auth, request, folderName);
                        foreach (Folder folder in response.Results)
                        {
                            // Confirm we found a folder with the exact right name, then add.
                            if (folder.Name.ToLower() == folderName.ToLower())
                            {
                                Console.WriteLine("\tSearching folder: " + folderName);
                                sessions.AddRange(searchForSessions(auth, smc, folder));
                            }
                        }
                    }

                    if (sessions.Count > 0)
                    {
                        string gsaStream = sessionsAsGsaStream(sessions);

                        Console.WriteLine("\tAll sessions: \n" + gsaStream);
                    }
                    else
                    {
                        Console.WriteLine("\tFound zero sessions.");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("\tError: " + e.Message);
                }

                Console.WriteLine();
            }

            Console.WriteLine("\nCompleted");
            Console.ReadLine();
        }
        /// <summary>
        /// Get stats for all sessions user has access to.
        /// </summary>
        /// <param name="serverName">Server name</param>
        /// <param name="authUserKey">User name</param>
        /// <param name="authPassword">Password</param>
        /// <param name="errorMessage">Error message</param>
        /// <returns>String containing stats of all sessions</returns>
        public static string GetAllSessionStats(string serverName, string authUserKey, string authPassword, out string errorMessage)
        {
            string sessionStats = "Session ID, Session Name, Username, % Viewed, Last View Date, Folder Name\n";

            //List<Guid> sessionIds = new List<Guid>();
            errorMessage = "Query in progress.";

            if (!String.IsNullOrWhiteSpace(serverName) && !String.IsNullOrWhiteSpace(authUserKey) && !String.IsNullOrWhiteSpace(authPassword))
            {
                try
                {
                    // Permissions for user management
                    SessionManagement.AuthenticationInfo sessionAuth = new SessionManagement.AuthenticationInfo()
                    {
                        UserKey  = authUserKey,
                        Password = authPassword
                    };

                    SessionManagementClient smc = new SessionManagementClient(
                        new BasicHttpsBinding(), new EndpointAddress(string.Format(SessionManagementEndpointFormat, serverName)));
                    ListSessionsRequest request = new ListSessionsRequest();

                    SessionManagement.Pagination pagination = new SessionManagement.Pagination();
                    pagination.MaxNumberResults = MaxPerPage;
                    pagination.PageNumber       = 0;
                    request.Pagination          = pagination;

                    // Query newer sessions first.
                    request.SortBy         = SessionSortField.Date;
                    request.SortIncreasing = false;

                    int totalPages = int.MaxValue; // not set yet

                    while (request.Pagination.PageNumber < totalPages)
                    {
                        ListSessionsResponse sessionsResponse = smc.GetSessionsList(sessionAuth, request, null);

                        Session[] sessions = sessionsResponse.Results;
                        foreach (Session session in sessions)
                        {
                            sessionStats += GetAllStatsForSession(serverName, authUserKey, authPassword, session.Id, session.Name, session.FolderName, session.Duration);
                        }

                        // This is examined at the first call.
                        if (totalPages == int.MaxValue)
                        {
                            int maxEntries = Math.Min(sessionsResponse.TotalNumberResults, CapSessions);
                            totalPages = (maxEntries + MaxPerPage - 1) / MaxPerPage;
                        }

                        request.Pagination.PageNumber++;
                    }
                }

                catch (Exception e)
                {
                    errorMessage = e.Message;
                }
            }
            else
            {
                errorMessage = "Please enter servername, username, and password.";
            }

            return(sessionStats);
        }
Example #8
0
        private static int RunCourseHierarchy(string username, string password)
        {
            // PUT YOUR AUTHENTICATION DETAILS HERE
            PanoptoSessionManagement.AuthenticationInfo sessionAuthInfo = new PanoptoSessionManagement.AuthenticationInfo()
            {
                UserKey  = username,
                Password = password
            };

            PanoptoAccessManagement.AuthenticationInfo accessAuthInfo = new PanoptoAccessManagement.AuthenticationInfo()
            {
                UserKey  = username,
                Password = password
            };

            bool lastPage       = false;
            int  resultsPerPage = 100;
            int  page           = 0;

            Dictionary <Guid, string> allRootFoldersDictionary = new Dictionary <Guid, string>();
            Dictionary <Guid, string> subjectFoldersDictionary = new Dictionary <Guid, string>();
            Dictionary <Guid, string> courseFoldersDictionary  = new Dictionary <Guid, string>();

            ISessionManagement sessionMgr = new SessionManagementClient();
            IAccessManagement  accessMgr  = new AccessManagementClient();

            while (!lastPage)
            {
                PanoptoSessionManagement.Pagination pagination = new PanoptoSessionManagement.Pagination {
                    MaxNumberResults = resultsPerPage, PageNumber = page
                };
                ListFoldersResponse response = sessionMgr.GetFoldersList(sessionAuthInfo, new ListFoldersRequest {
                    Pagination = pagination, SortIncreasing = true
                }, null);

                if (resultsPerPage * (page + 1) >= response.TotalNumberResults)
                {
                    lastPage = true;
                }

                if (response.Results.Length > 0)
                {
                    foreach (Folder folder in response.Results)
                    {
                        if (Regex.IsMatch(folder.Name, "^[A-Z]{4}$"))
                        {
                            subjectFoldersDictionary.Add(folder.Id, folder.Name);
                        }
                        else if (Regex.IsMatch(folder.Name, "^[A-Z]{4}[0-9]{4}$"))
                        {
                            courseFoldersDictionary.Add(folder.Id, folder.Name);
                        }
                        else if (Regex.IsMatch(folder.Name, "^[A-Z]{4}[0-9]{4}-.+$") && folder.ParentFolder.Equals(null))
                        {
                            allRootFoldersDictionary.Add(folder.Id, folder.Name);
                        }
                    }
                }

                page++;
            }

            foreach (var key in allRootFoldersDictionary.Keys)
            {
                if (allRootFoldersDictionary[key].Length > 8)
                {
                    string subject       = allRootFoldersDictionary[key].Substring(0, 4);
                    string course        = allRootFoldersDictionary[key].Substring(0, 8);
                    Guid   subjectFolder = Guid.Empty;
                    Guid   courseFolder  = Guid.Empty;

                    FolderAccessDetails folderAccessDetails = accessMgr.GetFolderAccessDetails(accessAuthInfo, key);

                    if (subjectFoldersDictionary.ContainsValue(subject))
                    {
                        subjectFolder = subjectFoldersDictionary.FirstOrDefault(x => x.Value == subject).Key;
                    }
                    else
                    {
                        Folder newFolder = sessionMgr.AddFolder(sessionAuthInfo, allRootFoldersDictionary[key].Substring(0, 4), null, false);
                        subjectFoldersDictionary.Add(newFolder.Id, newFolder.Name);
                        subjectFolder = newFolder.Id;
                    }

                    foreach (Guid creatorGroup in folderAccessDetails.GroupsWithCreatorAccess)
                    {
                        try
                        {
                            accessMgr.GrantGroupAccessToFolder(accessAuthInfo, subjectFolder, creatorGroup,
                                                               AccessRole.Viewer);
                        }
                        catch
                        {
                            // do nothing
                        }
                    }
                    foreach (Guid viewerGroup in folderAccessDetails.GroupsWithViewerAccess)
                    {
                        try
                        {
                            accessMgr.GrantGroupAccessToFolder(accessAuthInfo, subjectFolder, viewerGroup, AccessRole.Viewer);
                        }
                        catch
                        {
                            // do nothing
                        }
                    }

                    if (courseFoldersDictionary.ContainsValue(course))
                    {
                        courseFolder = courseFoldersDictionary.FirstOrDefault(x => x.Value == course).Key;
                    }
                    else
                    {
                        Folder newFolder = sessionMgr.AddFolder(sessionAuthInfo, allRootFoldersDictionary[key].Substring(0, 8), subjectFolder, false);
                        courseFoldersDictionary.Add(newFolder.Id, newFolder.Name);
                        courseFolder = newFolder.Id;
                    }

                    foreach (Guid creatorGroup in folderAccessDetails.GroupsWithCreatorAccess)
                    {
                        try
                        {
                            accessMgr.GrantGroupAccessToFolder(accessAuthInfo, courseFolder, creatorGroup, AccessRole.Creator);
                        }
                        catch
                        {
                            // do nothing
                        }
                    }

                    foreach (Guid viewerGroup in folderAccessDetails.GroupsWithViewerAccess)
                    {
                        try
                        {
                            accessMgr.GrantGroupAccessToFolder(accessAuthInfo, courseFolder, viewerGroup, AccessRole.Viewer);
                        }
                        catch
                        {
                        }
                    }

                    sessionMgr.UpdateFolderParent(sessionAuthInfo, key, courseFolder);
                }
            }

            return(allRootFoldersDictionary.Count);
        }
Example #9
0
        /// <summary>
        /// Main application method
        /// </summary>
        static void Main(string[] args)
        {
            try
            {
                // Parse args
                if (!ParseArgs(args))
                {
                    Usage();
                    return;
                }

                // Instantiate service clients
                ISessionManagement sessionMgr = new SessionManagementClient();
                IRemoteRecorderManagement rrMgr = new RemoteRecorderManagementClient();

                // Ensure server certificate is validated
                EnsureCertificateValidation();

                // Create auth info. For this sample, we will be passing auth info into all of the PublicAPI web service calls
                // instead of using IAuth.LogonWithPassword() (which is the alternative method).
                SessionManagementService.AuthenticationInfo sessionAuthInfo = new SessionManagementService.AuthenticationInfo()
                                                                              {
                                                                                  UserKey = user,
                                                                                  Password = password
                                                                              };

                RemoteRecorderManagementService.AuthenticationInfo rrAuthInfo = new RemoteRecorderManagementService.AuthenticationInfo()
                                                                                {
                                                                                    UserKey = user,
                                                                                    Password = password
                                                                                };

                int resultPerPage = 10;
                int totalResult = 0;
                int readResult = 0;
                int pageNumber = 0;
                Folder folder = null;
                // Find folder
                do
                {
                    ScheduleTool.SessionManagementService.Pagination pagination = new ScheduleTool.SessionManagementService.Pagination { MaxNumberResults = resultPerPage, PageNumber = pageNumber };
                    ListFoldersResponse response = sessionMgr.GetFoldersList(sessionAuthInfo, new ListFoldersRequest { Pagination = pagination }, null);
                    folder = response.Results.FirstOrDefault(a => a.Name == folderName);

                    totalResult = response.TotalNumberResults;
                    readResult += resultPerPage;
                    pageNumber++;

                    if (folder != null)
                    {
                        break;
                    }
                } while (readResult < totalResult);

                Assert(folder != null, "Could not find specified folder - " + folderName);

                // Find RR
                totalResult = 0;
                readResult = 0;
                pageNumber = 0;
                RemoteRecorder recorder = null;
                do
                {
                    ScheduleTool.RemoteRecorderManagementService.Pagination rrPagination = new ScheduleTool.RemoteRecorderManagementService.Pagination { MaxNumberResults = resultPerPage, PageNumber = pageNumber };
                    ListRecordersResponse rrResponse = rrMgr.ListRecorders(rrAuthInfo, rrPagination, RecorderSortField.Name);
                    recorder = rrResponse.PagedResults.FirstOrDefault(a => a.Name == rrName);

                    totalResult = rrResponse.TotalResultCount;
                    readResult += resultPerPage;
                    pageNumber++;

                    if (recorder != null)
                    {
                        break;
                    }
                } while (readResult < totalResult);

                Assert(recorder != null, "Could not find specified recorder - " + rrName);
                List<ScheduleTool.RemoteRecorderManagementService.RecorderSettings> recorderSettings = new List<RecorderSettings>();
                recorderSettings.Add(new RecorderSettings { RecorderId = recorder.Id });

                // Schedule back-to-back recordings
                DateTime timeBase = DateTime.UtcNow;

                for (int i = 0; i < numRecordings; i++)
                {
                    DateTime startTime = timeBase + TimeSpan.FromMinutes(recordingMins * i);
                    DateTime endTime = timeBase + TimeSpan.FromMinutes(recordingMins * (i + 1));
                    ScheduledRecordingResult result = rrMgr.ScheduleRecording(rrAuthInfo, "TestRecording" + (i+1).ToString(), folder.Id, false, startTime, endTime, recorderSettings.ToArray());
                    Assert(!result.ConflictsExist, "Unable to schedule test recording due to conflicts");
                }

                Console.WriteLine("Recordings have been scheduled");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }