예제 #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListSessionsResponse response = new ListSessionsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Ids", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance);
                    response.Ids = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("Sessions", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Session, SessionUnmarshaller>(SessionUnmarshaller.Instance);
                    response.Sessions = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
예제 #2
0
        public void CreateListDeleteSession()
        {
            Session session;
            {
                CreateSessionRequest request = new CreateSessionRequest
                {
                    Database = DatabaseUrl
                };
                session = client.CreateSession(request);
                Assert.IsNotNull(session);
                AssertAffinityCount(1);
            }

            {
                ListSessionsRequest request = new ListSessionsRequest
                {
                    Database = DatabaseUrl
                };
                ListSessionsResponse response = client.ListSessions(request);
                Assert.IsNotNull(response);
                Assert.IsNotNull(response.Sessions);
                Assert.IsTrue(response.Sessions.Any(item => item.Name == session.Name));
                AssertAffinityCount(1);
            }

            {
                DeleteSessionRequest request = new DeleteSessionRequest
                {
                    Name = session.Name
                };
                client.DeleteSession(request);
                AssertAffinityCount(0);
            }

            {
                ListSessionsRequest request = new ListSessionsRequest
                {
                    Database = DatabaseUrl
                };
                ListSessionsResponse response = client.ListSessions(request);
                Assert.IsNotNull(response);
                Assert.IsNotNull(response.Sessions);
                Assert.IsFalse(response.Sessions.Any(item => item.Name == session.Name));
                AssertAffinityCount(0);
            }
        }
        public Session[] GetSessionsInDateRange(DateTime start, DateTime end)
        {
            Session[] result = null;

            int  itemPerPage = 10;
            int  pageNum     = 0;
            int  totalItem   = 0;
            int  itemRead    = 0;
            bool firstRun    = true;
            int  resultIndex = 0;

            do
            {
                Pagination pagination = new Pagination()
                {
                    MaxNumberResults = itemPerPage, PageNumber = pageNum
                };
                ListSessionsResponse response = sessionManager.GetSessionsList(this.authentication, new ListSessionsRequest()
                {
                    Pagination = pagination, StartDate = start, EndDate = end
                }, null);
                if (response == null)
                {
                    throw new Exception(string.Format("Unable to fetch sessions between dates {0} and {1}", start.ToString(), end.ToString()));
                }

                totalItem = response.TotalNumberResults;
                itemRead += itemPerPage;
                pageNum++;

                if (firstRun)
                {
                    firstRun = false;
                    result   = new Session[totalItem];
                }

                foreach (Session session in response.Results)
                {
                    result[resultIndex] = session;
                    resultIndex++;
                }
            } while (itemRead < totalItem);

            return(result);
        }
        public bool TryGetSessionId(string sessionName, out Guid sessionId)
        {
            sessionId = Guid.NewGuid();
            Pagination pagination = new Pagination {
                MaxNumberResults = 25, PageNumber = 0
            };
            ListSessionsResponse sessions = this.sessionManager.GetSessionsList(this.authentication, new ListSessionsRequest {
                Pagination = pagination
            }, null);

            Session session = sessions.Results.SingleOrDefault(s => s.Name == sessionName);

            if (session != null)
            {
                sessionId = session.Id;
                return(true);
            }

            return(false);
        }
        /// <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);
        }