示例#1
0
        public async Task TestAwake()
        {
            Connection conn = new Connection();

            bool result = await conn.GetAwakeAsync();

            Assert.IsTrue(result);
        }
示例#2
0
        internal static async Task<Connection> CreateSession()
        {
            Connection conn = new Connection();
            bool result = await conn.SigninAsync(ValidUsername, ValidPassword);

            if (result)
                return conn;
            else
                throw new Exception("Failed to authenticate");
        }
 public async Task TestLogout()
 {
     Connection conn = new Connection();
     bool result = await conn.SigninAsync(Credentials.ValidUsername, Credentials.ValidPassword);
     Assert.IsTrue(result);
     Assert.IsTrue(conn.Authenticated);
     result = await conn.SignoffAsync();
     Assert.IsTrue(result);
     Assert.IsNull(conn.CurrentUser);
     Assert.IsFalse(conn.Authenticated);
 }
        public async Task TestValidAuthentication()
        {
            Connection conn = new Connection();
            conn.CurrentUserIdentified += conn_CurrentUserIdentified;
            bool result = await conn.SigninAsync(Credentials.ValidUsername, Credentials.ValidPassword);
            Assert.IsTrue(result);
            Assert.IsTrue(conn.Authenticated);

            //Wait a maximum of 5 seconds.
            handle.WaitOne(5000);

            Assert.IsTrue(eventRaised);
            Assert.AreEqual(Credentials.ValidUsername, conn.CurrentUser.Name, true);

            await conn.SignoffAsync();

            Assert.IsFalse(conn.Authenticated);
            Assert.IsNull(conn.CurrentUser);
        }
 /// <summary>
 /// Retreives (or creates) a conversation on the given connection. You can use this to handle conversations asynchronously
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="u"></param>
 /// <returns></returns>
 public static Conversation GetConversationWith(this User u, Connection conn)
 {
     return GetConversationWith(conn, u);
 }
 /// <summary>
 /// Retreives the conversation with the given user on the given connection, this is a blocking call
 /// </summary>
 /// <param name="u">The conversation partner</param>
 /// <param name="conn">The connection on which to run the query</param>
 /// <returns></returns>
 public static IEnumerable<Message> ConversationWith(this User u, Connection conn)
 {
     return ConversationWith(conn, u.UserId);
 }
示例#7
0
        private static async void mainLoop()
        {
            //Create a new connection
            Connection conn = new Connection();
            bool authenticated = false;

            //Check if sparklr is online
            if (!await conn.GetAwakeAsync())
            {
                Console.WriteLine("Sparklr is offline :(");
            }
            else
            {
                Console.WriteLine("Sparklr is online");

                //Now we need to authenticate
                while (!authenticated)
                {
                    suppressOutput = true;
                    Console.WriteLine("Username:"******"Password:"******"Signed in");

                while (conn.CurrentUser == null)
                    Thread.Sleep(100);

                //Get the number of notifications
                Notification[] notifications = await conn.GetNotificationsAsync();

                Console.WriteLine("You have {0} notifications:", notifications.Length);

                foreach (Notification n in notifications)
                    Console.WriteLine("\t{0}", n.NotificationText);

                /*
                 * Now we can get a list of all messages for example.
                 * The Inbox is associated with the connection to allow
                 * applications where multiple connections exist in parallel.
                 * First you need to refresh the inbox manually.
                 */

                Console.WriteLine("Refreshing inbox");
                await conn.RefreshInboxAsync();

                //After the refresh we can dump the messages.
                Console.WriteLine("You have {0} conversations.", conn.Inbox.Count);

                int index = 0;
                foreach (Message m in conn.Inbox)
                {
                    Console.WriteLine("{3}: Converstation with {0}(@{1}):\t{2}", m.Author.Name, m.Author.Handle, m.Content, index);
                    index++;
                }

                //We now let the user select a conversation he wants to read on the console.
                Console.WriteLine("Enter the conversation you want to read.");

                suppressOutput = true;
                int selected = Convert.ToInt32(Console.ReadLine());
                suppressOutput = false;

                if (selected < index && selected >= 0)
                {
                    Console.WriteLine("Retreiving conversation with {0}.", conn.Inbox[selected].Author.Name);

                    //We retreive the appropriate connection.
                    Conversation conversation = conn.GetConversationWith(conn.Inbox[selected].Author);

                    Console.WriteLine("Loading messages...");

                    //Now we can load more messages until everything is loaded. Messages will be loaded in chunks of 30 messages per request.
                    //You most likely don't even need all messages, so you can load them on demand

                    //There is also an extension method that returns an IEnumerable<Message>, it is however synchronous.
                    //You can retreive the IEnumerable by calling conn.ConversationWith(USER) and using it driectly
                    //Example: foreach(Message m in conn.ConversationWith(USER))

                    while (conversation.NeedsRefresh)
                    {
                        Console.WriteLine("Loading more messages, we currently loaded {0} messages in total", conversation.Messages.Count);
                        await conversation.LoadMore();
                    }

                    suppressOutput = true;
                    //Now we can iterate over all retreived messages and print them to the console.
                    foreach (Message m in conversation.Messages)
                    {
                        Console.WriteLine("{0}:\t{1}", m.Author.Name.PadRight(16, ' '), m.Content);
                    }
                    suppressOutput = false;

                    //And now we send a message on our own
                    Console.WriteLine("Enter a message to send (or press enter to skip)");

                    suppressOutput = true;
                    string content = Console.ReadLine();
                    suppressOutput = false;

                    if (content != String.Empty)
                    {
                        await conversation.SendMessage(content);
                    }
                }

                // And now we send a message on our own
                Console.WriteLine("Enter a post to send (or press enter to skip)");

                suppressOutput = true;
                string post = Console.ReadLine();
                suppressOutput = false;

                if (post != String.Empty)
                {
                    bool result = await conn.SubmitPostAsync(post);

                    if(result)
                    {
                        Console.WriteLine("Post sent succesfully");
                    }
                    else
                    {
                        Console.WriteLine("Something went wrong");
                    }
                }


                //Finally we sign out.
                await conn.SignoffAsync();
                Console.WriteLine("Signed out");
                done = true;
            }
        }
示例#8
0
 public async Task TestUsersWithoutAuth()
 {
     Connection conn = new Connection();
     User u = await conn.GetUserAsync(100);
 }
 /// <summary>
 /// Retreives the stream for the given user
 /// </summary>
 /// <param name="u"></param>
 /// <param name="conn"></param>
 /// <returns></returns>
 public static Task<Stream> GetStreamAsync(this User u, Connection conn)
 {
     return Stream.InstanciateStreamAsync(u, conn);
 }
 /// <summary>
 /// Retreives mentions of a user on the given connection
 /// </summary>
 /// <param name="u">The user for which to retreive the mentions</param>
 /// <param name="conn">The connection on which the query is run</param>
 /// <returns>Mentions (cached)</returns>
 public static async Task<Mentions> GetMentionsAsync(this User u, Connection conn)
 {
     return await Mentions.InstanciateMentionsAsync(u, conn);
 }
 public async Task TestInvalidAuthentication()
 {
     Connection conn = new Connection();
     bool result = await conn.SigninAsync(Credentials.ValidUsername, Credentials.InvalidPassword);
     Assert.IsFalse(result);
 }
示例#12
0
 public async Task TestNotAuthorized()
 {
     Connection conn = new Connection();
     var response = await conn.GetInboxAsync();
 }
示例#13
0
 public async Task TestNotificationsNotAuthorized()
 {
     Connection conn = new Connection();
     await conn.GetNotificationsAsync();
 }