Esempio n. 1
0
        /// <summary>
        /// Gets the unique ID of the recorder specified by <paramref name="recorderName"/>.
        /// </summary>
        /// <param name="recorderName">Name of the recorder to get 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>
        /// <returns>Returns the unique ID, if found. Else, will return Guid.Empty.</returns>
        public static Guid GetRecorderID(string recorderName, IRemoteRecorderManagement rrMgr, RemoteRecorderManagement42.AuthenticationInfo rrAuth)
        {
            Guid rrID = Guid.Empty;

            // Handle no recorder name here
            if (recorderName.Equals(""))
            {
                return(rrID);
            }

            // set the recorderName to lowercase for insensitive lookup
            recorderName = recorderName.ToLowerInvariant();

            if (recorderIds.ContainsKey(recorderName))
            {
                return(recorderIds[recorderName]);
            }

            if (recorderIds.Count > 0)
            {
                return(Guid.Empty);
            }

            bool lastPage       = false;
            int  resultsPerPage = 5;
            int  pageNumber     = 0;

            while (!lastPage)
            {
                RemoteRecorderManagement42.Pagination rrPage = new RemoteRecorderManagement42.Pagination()
                {
                    MaxNumberResults = resultsPerPage,
                    PageNumber       = pageNumber
                };

                ListRecordersResponse rrResponse = rrMgr.ListRecorders(rrAuth, rrPage, RecorderSortField.Name);
                if (resultsPerPage * (pageNumber + 1) >= rrResponse.TotalResultCount)
                {
                    lastPage = true;
                }
                // Populate the lookup map with the lowercase'd names of the recorders
                foreach (RemoteRecorder rr in rrResponse.PagedResults)
                {
                    recorderIds[rr.Name.ToLowerInvariant()] = rr.Id;
                }
                // keep looking
                pageNumber++;
            }
            // If rrID stays empty then remote recorder wasn't found or handle the case in which not found
            return(GetRecorderID(recorderName, rrMgr, rrAuth));
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to get any remote recorder with the provided <paramref name="rrAuth"/> credentials.
        /// </summary>
        /// <param name="rrMgr">The client in which holds the information about the recorders</param>
        /// <param name="rrAuth">The authentication information for which to access the information from <paramref name="rrMgr"/>.</param>
        /// <returns>A code that determines the result of the attempted login.</returns>
        public static LoginResults TryLoginGetRecorder(IRemoteRecorderManagement rrMgr, RemoteRecorderManagement42.AuthenticationInfo rrAuth)
        {
            try
            {
                var pagination = new RemoteRecorderManagement42.Pagination {
                    MaxNumberResults = 1, PageNumber = 0
                };
                var recorderListResponse = rrMgr.ListRecorders(rrAuth, pagination, RecorderSortField.Name);

                // no Remote Recorders found
                if (recorderListResponse.TotalResultCount < 1)
                {
                    return(LoginResults.NoAccess);
                }
            }
            catch
            {
                // ListRecorders throws an exception if authentication fails either incorrect credentials or not admin.
                return(LoginResults.Failure);
            }
            return(LoginResults.Success);
        }