/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { ListFoldersResponse response = new ListFoldersResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("FolderSummaryList", targetDepth)) { var unmarshaller = new ListUnmarshaller <FolderSummary, FolderSummaryUnmarshaller>(FolderSummaryUnmarshaller.Instance); response.FolderSummaryList = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("NextToken", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.NextToken = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("RequestId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.RequestId = unmarshaller.Unmarshall(context); continue; } } response.Status = (int)context.ResponseData.StatusCode; return(response); }
public static ListFoldersResponse Unmarshall(UnmarshallerContext _ctx) { ListFoldersResponse listFoldersResponse = new ListFoldersResponse(); listFoldersResponse.HttpResponse = _ctx.HttpResponse; listFoldersResponse.RequestId = _ctx.StringValue("ListFolders.RequestId"); listFoldersResponse.Success = _ctx.BooleanValue("ListFolders.Success"); listFoldersResponse.ErrorCode = _ctx.StringValue("ListFolders.ErrorCode"); listFoldersResponse.ErrorMessage = _ctx.StringValue("ListFolders.ErrorMessage"); listFoldersResponse.HttpStatusCode = _ctx.IntegerValue("ListFolders.HttpStatusCode"); ListFoldersResponse.ListFolders_Data data = new ListFoldersResponse.ListFolders_Data(); data.PageNumber = _ctx.IntegerValue("ListFolders.Data.PageNumber"); data.PageSize = _ctx.IntegerValue("ListFolders.Data.PageSize"); data.TotalCount = _ctx.IntegerValue("ListFolders.Data.TotalCount"); List <ListFoldersResponse.ListFolders_Data.ListFolders_FoldersItem> data_folders = new List <ListFoldersResponse.ListFolders_Data.ListFolders_FoldersItem>(); for (int i = 0; i < _ctx.Length("ListFolders.Data.Folders.Length"); i++) { ListFoldersResponse.ListFolders_Data.ListFolders_FoldersItem foldersItem = new ListFoldersResponse.ListFolders_Data.ListFolders_FoldersItem(); foldersItem.FolderId = _ctx.StringValue("ListFolders.Data.Folders[" + i + "].FolderId"); foldersItem.FolderPath = _ctx.StringValue("ListFolders.Data.Folders[" + i + "].FolderPath"); data_folders.Add(foldersItem); } data.Folders = data_folders; listFoldersResponse.Data = data; return(listFoldersResponse); }
private void GetAndSetFolderByList() { ListFoldersResponse response = null; int pageNumber = 0; int totalNumberResults = 0; // Set the Max Number results to 1 since we only care about the 'TotalNumberResults' from the first API call Pagination pagination = new Pagination { MaxNumberResults = 1, PageNumber = pageNumber }; response = this.sessionManager.GetFoldersList(this.authentication, new ListFoldersRequest { Pagination = pagination }, searchQuery: null); // Don't save any entries in case totalNumberResults exceeds Threshhold and chances of duplicate Folders never get saved if (response != null) { this.savedFolders = new Dictionary <string, Folder>(); this.savedDupFolders = new Dictionary <string, List <Folder> >(); totalNumberResults = response.TotalNumberResults; } // Setting a threshold if (totalNumberResults > FALLBACK_THRESHHOLD_LIMIT) { this.surpassThreshhold = true; } else { while (totalNumberResults >= ((pageNumber) * RESULTS_PER_PAGE)) { pagination = new Pagination { MaxNumberResults = RESULTS_PER_PAGE, PageNumber = pageNumber }; response = this.sessionManager.GetFoldersList(this.authentication, new ListFoldersRequest { Pagination = pagination }, searchQuery: null); if (response != null) { SaveFolders(response.Results); } pageNumber++; } } }
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); }
private void GetAllMatchingFolders(String folderName, String query) { int totalNumberResults = 0; int pageNumber = 0; Pagination pagination = new Pagination { MaxNumberResults = RESULTS_PER_PAGE, PageNumber = pageNumber }; ListFoldersResponse response = this.sessionManager.GetFoldersList(this.authentication, new ListFoldersRequest { Pagination = pagination }, query); if (response != null) { SaveFolders(response.Results); } if (response.TotalNumberResults > RESULTS_PER_PAGE) { pageNumber++; while (totalNumberResults >= ((pageNumber) * RESULTS_PER_PAGE)) { pagination = new Pagination { MaxNumberResults = RESULTS_PER_PAGE, PageNumber = pageNumber }; response = this.sessionManager.GetFoldersList(this.authentication, new ListFoldersRequest { Pagination = pagination }, searchQuery: query); if (response != null) { SaveFolders(response.Results); } pageNumber++; } } }
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); }
/// <summary> /// Gets the unique ID of the folder specified by <paramref name="folderName"/>. /// </summary> /// <param name="folderName">name fo the folder to the ID for.</param> /// <param name="rrMgr">The client in which holds the information about the recorder <paramref name="recorderName"/>.</param> /// <param name="rrAuth">The authentication information for which to access the information from <paramref name="rrMgr"/>.</param> /// <param name="rrID">The unique ID of a recorder.</param> /// <param name="sessionMgr">The client in which holds the information about the folder <paramref name="folderName"/>.</param> /// <param name="sessionAuth">The authentication information for which to access the information from <paramref name="sessionMgr"/></param> /// <returns>Returns the unique ID, if found. Else, returns Guid.Empty</returns> public static Guid GetFolderID(string folderName, ISessionManagement sessionMgr, SessionManagement46.AuthenticationInfo sessionAuth) { if (folderName != "") { // if the foldername is a guid, trust it literally Guid folderId; if (Guid.TryParse(folderName, out folderId)) { return(folderId); } // otherwise use the sessionmanagement api SessionManagement46.Pagination pagination = new SessionManagement46.Pagination() { MaxNumberResults = 10, PageNumber = 0 }; ListFoldersRequest request = new ListFoldersRequest() { Pagination = pagination, ParentFolderId = Guid.Empty, SortBy = FolderSortField.Relavance }; // try to get the folder up to 3 times ListFoldersResponse response = null; for (int retries = 0; retries < 3; retries++) { try { // Add quotes here to search for exact folder name response = sessionMgr.GetFoldersList(sessionAuth, request, "\"" + folderName + "\""); break; } catch { // catch the FaultException if the request times out. } } // if the response is null, then the GetFoldersList request has failed all retry attempts. // By returning Guid.Empty, the validation process of a ScheduleRecording will catch it as a generic // RecordingValidity.BadFolderID error code. A more descriptive error code can be considered such as // RecordingValidityCode.TimeOutError, and this would have to throw an exception or return a special // Guid to differentiate it from a regular RecordingValidityCode.BadFolderID (ie a Guid with all 1s) if (response == null) { // This is the timeout case, maybe have a special reserved Guid to reflect this. return(Guid.Empty); } // we check the number of results and if there is more than 1 result/match then // folder name is ambiguous (not unique) and so return Guid.Empty if (response.Results.Length == 1) { return(response.Results[0].Id); } else { Console.WriteLine( "{0} results for {1}: {2}", response.Results.Length, folderName, response.Results.Length > 0 ? string.Join("\n\t", response.Results.Select(f => f.Name)) : ""); return(Guid.Empty); } } return(Guid.Empty); }