Beispiel #1
0
 /// <summary>
 /// Messages received by the logged-in user. Corresponds to the "Received" tab on the website.
 /// </summary>
 /// <param name="flag"></param>
 /// <param name="thread"></param>
 /// <param name="session"></param>
 /// <returns></returns>
 public static List<Message> GetReceivedMessages(PageFlag flag, int id, Session session)
 {
     if (flag == PageFlag.NEWER_THAN)
         return RetrieveMessages(Yammer.HttpUtility.Get(Resources.YAMMER_MESSAGES_RECEIVED + "?newer_than=" + id.ToString(), session));
     else
         return RetrieveMessages(Yammer.HttpUtility.Get(Resources.YAMMER_MESSAGES_RECEIVED + "?older_than=" + id.ToString(), session));
 }
Beispiel #2
0
        public AutoView(Session session)
        {
            InitializeComponent();

            this.WindowState = WindowState.Maximized;
            this.WindowStyle = WindowStyle.None;
            this.ResizeMode = ResizeMode.NoResize;
            this.session = session;

            frameTimer = new System.Windows.Threading.DispatcherTimer();
            frameTimer.Tick += OnFrame;
            frameTimer.Interval = TimeSpan.FromSeconds(1.0 / 60.0);
            frameTimer.Start();

            frameTimer2 = new System.Windows.Threading.DispatcherTimer();
            frameTimer2.Tick += OnFrame2;
            frameTimer2.Interval = TimeSpan.FromSeconds(4.0);
            frameTimer2.Start();

            this.lastTick = Environment.TickCount;

            rand = new Random(this.GetHashCode());

            this.Show();

            this.KeyDown += new System.Windows.Input.KeyEventHandler(AutoView_KeyDown);

            CreateCircles();
            CreateMessagePanels();
        }
Beispiel #3
0
 /// <summary>
 /// Creates http get web request and returns response
 /// </summary>
 /// <param name="url">The URL for the web request</param>
 /// <param name="session">The Yammer<see cref="Session">session</see> object</param>
 /// <returns>http response</returns>
 public static string Get(string url, Session session)
 {
     string nonce, timestamp;
     string signature = GetSignature(WebMethod.GET, session, url, out timestamp, out nonce);
     HttpWebRequest request = CreateWebRequest(url, WebMethod.GET, nonce, timestamp, signature, session);
     return GetWebResponse(request);
 }
Beispiel #4
0
 public static string Get(string url, Session session, NameValueCollection parameters)
 {
     string nonce, timestamp;
     string fullUrl = EncodeUrl(url, parameters);
     string signature = GetSignature(WebMethod.GET, session, fullUrl, out timestamp, out nonce);
     HttpWebRequest request = CreateWebRequest(fullUrl, WebMethod.GET, nonce, timestamp, signature, session);
     return GetWebResponse(request);
 }
Beispiel #5
0
 /// <summary>
 /// Creates http post web request and returns response
 /// </summary>
 /// <param name="url">The URL for the web request</param>
 /// <param name="parameters">the query string parameters</param>
 /// <param name="session">The Yammer<see cref="Session">session</see> object</param>
 /// <returns>http response</returns>
 public static string Post(string url, NameValueCollection parameters, Session session)
 {
     string nonce, timestamp;
     string fullUrl = EncodeUrl(url, parameters);
     string signature = GetSignature(WebMethod.POST, session, fullUrl, out timestamp, out nonce);
     HttpWebRequest request = CreateWebRequest(url, WebMethod.POST, nonce, timestamp, signature, session);
     WritePostData(parameters, request);
     return GetLocationHeader(request);
 }
Beispiel #6
0
        public static string Get(string query, Session session)
        {
            OAuthBase oAuth = new OAuthBase();
            string nonce = oAuth.GenerateNonce();
            string timeStamp = oAuth.GenerateTimeStamp();
            string nurl, nrp;

            Uri uri = new Uri(query);
            string sig = oAuth.GenerateSignature(
                uri,
                session.Auth.ConsumerKey,
                session.Auth.ConsumerSecret,
                session.Auth.TokenKey,
                session.Auth.TokenSecret,
                "GET",
                timeStamp,
                nonce,
                OAuthBase.SignatureTypes.HMACSHA1, out nurl, out nrp);
            sig = HttpUtility.UrlEncode(sig);

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(query);
            req.Method = "GET";
            req.Proxy = session.Proxy;
            string authHeader = string.Empty;
            authHeader = "OAuth " +
                "oauth_consumer_key=\"" + session.Auth.ConsumerKey + "\"," +
                "oauth_token=\"" + session.Auth.TokenKey + "\"," +
                "oauth_nonce=\"" + nonce + "\"," +
                "oauth_timestamp=\"" + timeStamp + "\"," +
                "oauth_signature_method=\"" + "HMAC-SHA1" + "\"," +
                "oauth_version=\"" + "1.0" + "\"," +
                "oauth_signature=\"" + sig + "\"";
            req.ContentType = Constants.HttpPostUrlEncodedContentType;
            req.Headers.Add(Constants.AuthorizationHeaderParameter, authHeader);

            WebResponse res = req.GetResponse();
            StreamReader reader = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
            string data = reader.ReadToEnd();

            res.Close();
            reader.Close();

            return data;
        }
Beispiel #7
0
        /// <summary>
        /// Creates the OAuth header for the http request
        /// </summary>
        /// <param name="method">The <see cref="WebMethod"/> http web method</param>
        /// <param name="nonce">The OAuth nonce string</param>
        /// <param name="timeStamp">The generated OAuth timestamp</param>
        /// <param name="sig">The generatred OAuth signature</param>
        /// <param name="session">The Yammer<see cref="Session">session</see> object</param>
        /// <returns></returns>
        private static string CreateAuthHeader(WebMethod method, string nonce, string timeStamp, string sig, Session session)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("OAuth ");
            if (method == WebMethod.POST)
                sb.Append("realm=\""  + "\",");
            else
                sb.Append("realm=\"\",");
           
            string authHeader = "oauth_consumer_key=\"" + session.AuthKey.ConsumerKey + "\"," +
                                "oauth_token=\"" + session.AuthKey.TokenKey + "\"," +
                                "oauth_nonce=\"" + nonce + "\"," +
                                "oauth_timestamp=\"" + timeStamp + "\"," +
                                "oauth_signature_method=\"" + "PLAINTEXT" + "\"," +
                                "oauth_version=\"" + "1.0" + "\"," +
                                "oauth_signature=\"" + sig + "\"";

           
            sb.Append(authHeader);
            return sb.ToString();

            //Authorization: OAuth realm="", oauth_consumer_key="AMbmZSOP3wHm1cjfvSsRg", oauth_signature_method="HMAC-SHA1", oauth_signature="yLDH5eLS4uUVa3vVbNxvDX9B8aFgnwRSFla3jph9y90%26", oauth_timestamp="1229537444", oauth_nonce="1229537444", oauth_version="1.0"

        }
Beispiel #8
0
 public Messages(Session session)
 {
     this.Session = session;
 }
Beispiel #9
0
        /// <summary>
        /// Creates http multipart post web request and returns response
        /// </summary>
        /// <param name="url">The URL for the web request</param>
        /// <param name="parameters">the query string parameters</param>
        /// <param name="session">The Yammer<see cref="Session">session</see> object</param>
        /// <param name="files">The file path collection to upload</param>
        /// <remarks>Used to upload attachments</remarks>
        /// <returns>http response</returns>
        public static string Upload(string url, NameValueCollection parameters, Session session, List<string> files)
        {
                     
            //MultipartForm form;
            //form = new MultipartForm(url);
            //form.FileContentType = "image/gif";
            //form.setField("body", parameters["body"]);
            //if (files.Count == 1)
            //    form.sendFile(files[0], session);
            //else
            //    if (files.Count > 1)
            //        form.sendFiles(files, session);
            //return "";

            return UploadAttachments(url, parameters, files, session);
        }
Beispiel #10
0
 /// <summary>
 /// Retrieves list of users in network
 /// </summary>
 /// <param name="session"></param>
 /// <returns></returns>
 public static List<User> GetAllUsers(Session session)
 {
     string response = Yammer.HttpUtility.Get(Resources.YAMMER_USERS_ALL, session);
     XmlDocument xdoc = new XmlDocument();
     xdoc.LoadXml(response);
     XmlNodeList nodes = xdoc.SelectNodes("/response/response");
     List<User> users = new List<User>();
     foreach (XmlNode node in nodes)
     {
         User user = (User)Deserialize(typeof(User), "<reference>" + node.InnerXml + "</reference>");
         users.Add(user);
     }
     return users;
 }
Beispiel #11
0
        private void InitialCheck()
        {
            OAuthKey oauth = GetOAuthKey();
            WebProxy proxy = GetProxy();

            //oauth = null; // tmp
            if (oauth == null)
            {
                this.Dispatcher.Invoke(DispatcherPriority.Normal, new AuthPanelShowDelegate(AuthPanelShow));
            }
            try
            {
                Session session = new Session(oauth, proxy);
                this.Session = session;
                Messages messages = new Messages(this.Session);
                MessageObjects allobjects = messages.GetAllMessage();
                this.Dispatcher.Invoke(DispatcherPriority.Normal, new MainPanelShowDelegate(MainPanelShow), allobjects);
            }
            catch (Exception)
            {
                this.Dispatcher.Invoke(DispatcherPriority.Normal, new AuthPanelShowDelegate(AuthPanelShow));
            }
        }
Beispiel #12
0
        private static HttpWebRequest CreateWebRequest(string fullUrl, WebMethod method, string[] oauthParams, Session session)
        {
            string nonce, timeStamp, sig;
            nonce = oauthParams[0];
            timeStamp = oauthParams[1];
            sig = oauthParams[2];
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUrl);
            request.ServicePoint.Expect100Continue = false;
            request.KeepAlive = false;
            request.ProtocolVersion = HttpVersion.Version10;
            request.Method = method.ToString();
            request.Proxy = session.Proxy;
            string authHeader = CreateAuthHeader(method, nonce, timeStamp, sig, session);
            request.ContentType = "text/plain";
            request.Headers.Add("Authorization", authHeader);

            return request;
        }
Beispiel #13
0
 private static void GroupMembership(int id, Session session)
 {
     NameValueCollection parameters = new NameValueCollection();
     parameters.Add("group_id", id.ToString());
     Yammer.HttpUtility.Post(Resources.YAMMER_GROUP_JOIN + id.ToString() + ".xml", parameters, session);
 }
Beispiel #14
0
 /// <summary>
 /// Corresponds to the "Sent" tab on the website.
 /// </summary>
 /// <param name="session"></param>
 /// <returns></returns>
 public static List<Message> GetSentMessages(Session session)
 {
     return RetrieveMessages(Yammer.HttpUtility.Get(Resources.YAMMER_MESSAGES_SENT, session));
 }
Beispiel #15
0
 /// <summary>
 /// Messages received by the logged-in user. Corresponds to the "Received" tab on the website.
 /// </summary>
 /// <param name="session"></param>
 /// <returns></returns>
 public static List<Message> GetReceivedMessages(Session session)
 {
     return RetrieveMessages(Yammer.HttpUtility.Get(Resources.YAMMER_MESSAGES_RECEIVED, session));
 }
Beispiel #16
0
 /// <summary>
 /// Subscribe to tag
 /// </summary>
 /// <param name="id"></param>
 /// <param name="session"></param>
 public static void SubscribeToTag(int id, Session session)
 {
     NameValueCollection parameters = new NameValueCollection();
     parameters.Add("target_type", "tag");
     parameters.Add("target_id", id.ToString());
     string data = Yammer.HttpUtility.Post(Resources.YAMMER_SUBSCRIPTIONS_SUBSCRIBE, parameters, session);
 }
Beispiel #17
0
 /// <summary>
 /// Unsubscribe to tag
 /// </summary>
 /// <param name="id"></param>
 /// <param name="session"></param>
 public static void DeleteSubscriptionToTag(int id, Session session)
 {
     string data = Yammer.HttpUtility.Delete(Resources.YAMMER_RELATIONSHIPS_DELETE + "?target_type=tag" + "&target_id=" + id.ToString(), session);
 }
Beispiel #18
0
 /// <summary>
 /// Returns list of all suggested groups and users
 /// NOT YET IMPLEMENTED
 /// </summary>
 /// <param name="session"></param>
 public static void GetAllSuggestions(Session session)
 {
     string response = Yammer.HttpUtility.Get(Resources.YAMMER_SUGGESTIONS_SHOW_ALL, session);
 }
Beispiel #19
0
 /// <summary>
 /// Creates a new org chart relationship
 /// </summary>
 /// <param name="type"></param>
 /// <param name="email"></param>
 /// <param name="session"></param>
 public static void CreateRelationship(RelationshipType type, string email, Session session)
 {
     NameValueCollection parameters = new NameValueCollection();
     parameters.Add(type.ToString().ToLower(), email);
     Yammer.HttpUtility.Post(Resources.YAMMER_RELATIONSHIPS_CREATE, parameters, session);
 }
Beispiel #20
0
 /// <summary>
 /// Retrieves org chart relationships.
 /// </summary>
 /// <param name="session"></param>
 public static void GetAllRelationships(Session session)
 {
     string response = Yammer.HttpUtility.Get(Resources.YAMMER_RELATIONSHIPS_ALL, session);
 }
Beispiel #21
0
 /// <summary>
 /// Creates intstance of the HttpRequest object
 /// </summary>
 /// <param name="fullUrl">The full URL with querystring for the web request</param>
 /// <param name="method">The <see cref="WebMethod"/> http web method</param>
 /// <param name="nonce">The OAuth nonce string</param>
 /// <param name="timeStamp">The generated OAuth timestamp</param>
 /// <param name="sig">The generatred OAuth signature</param>
 /// <param name="session">The Yammer<see cref="Session">session</see> object</param>
 /// <returns>HttpRequest object</returns>
 private static HttpWebRequest CreateWebRequest(string fullUrl, WebMethod method, string nonce, string timeStamp, string sig, Session session)
 {
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUrl);
     request.Method = method.ToString();
     request.Proxy = session.Proxy;
     string authHeader = CreateAuthHeader(method, nonce, timeStamp, sig, session);
     request.ContentType = "application/x-www-form-urlencoded";
     request.Headers.Add("Authorization", authHeader);
     
     return request;
 }
Beispiel #22
0
        private static string UploadAttachments(string url, NameValueCollection parameters, List<string> fileNames, Session session)
        {
            string nonce, timestamp;
            string beginBoundary = GenerateRandomString(25);
            string contentBoundary = "--" + beginBoundary;
            string endBoundary = contentBoundary + "--";
            string contentTrailer = "\r\n" + endBoundary;
         
            string signature = HttpUtility.GetSignature(WebMethod.POST, session, url, out timestamp, out nonce);
            HttpWebRequest request = HttpUtility.CreateWebRequest(url, WebMethod.POST, nonce, timestamp, signature, beginBoundary, session);
            Version protocolVersion = HttpVersion.Version11;
            string method = WebMethod.POST.ToString();
            string contentType = "multipart/form-data; boundary=" + beginBoundary;
            string contentDisposition = "Content-Disposition: form-data; name=";
            request.Headers.Add("Cache-Control", "no-cache");
            request.KeepAlive = true;
            string postParams = GetPostParameters(parameters, contentBoundary, contentDisposition);

            FileInfo[] fi = new FileInfo[fileNames.Count];
            int i = 0;
            long postDataSize = 0;
            int headerLength = 0;
            List<string> fileHeaders = new List<string>();
            AddFileHeaders(fileNames, contentBoundary, contentDisposition, fi, ref i, ref postDataSize, ref headerLength, fileHeaders);
            request.ContentLength = postParams.Length + headerLength + contentTrailer.Length + postDataSize;
            System.IO.Stream io =  request.GetRequestStream();
            WritePostData(postParams, io, false);
            i = 0;
            foreach (string fileName in fileNames)
            {
                WritePostData(fileHeaders[i], io, false);
                WriteFile(io, fileName);
                i++;
            }
            WritePostData(contentTrailer,io, true);

            string response = GetLocationHeader(request);
            io.Close();
            request = null;

            return response;
        }
Beispiel #23
0
 /// <summary>
 /// Retreives data about current user
 /// </summary>
 /// <param name="session"></param>
 /// <returns></returns>
 public static User GetCurrentUser(Session session)
 {
     string response = Yammer.HttpUtility.Get(Resources.YAMMER_USERS_CURRENT, session);
     XmlDocument xdoc = new XmlDocument();
     xdoc.LoadXml(response);
     XmlNode node = xdoc.SelectSingleNode("/response");
     User user = (User)Deserialize(typeof(User), "<reference>" + node.InnerXml + "</reference>");
     return user;
 }
Beispiel #24
0
        /// <summary>
        /// Leave a group.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="session"></param>
        public static void LeaveGroup(int id, Session session)
        {
            GroupMembership(id, session);

        }
Beispiel #25
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="fullUrl">The full URL with querystring for the web request</param>
 /// <param name="method">The <see cref="WebMethod"/> http web method</param>
 /// <param name="nonce">The OAuth nonce string</param>
 /// <param name="timeStamp">The generated OAuth timestamp</param>
 /// <param name="sig">The generatred OAuth signature</param>
 /// <param name="boundary">The boundary for the http multipart request</param>
 /// <param name="session">The Yammer<see cref="Session">session</see> object</param>
 /// <returns>HttpRequest object</returns>
 public static HttpWebRequest CreateWebRequest(string fullUrl, WebMethod method, string nonce, string timeStamp, string sig, string boundary, Session session)
 {
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUrl);
     request.Method = method.ToString();
     request.Proxy = session.Proxy;
     string authHeader = CreateAuthHeader(method, nonce, timeStamp, sig, session);
     request.ContentType = "multipart/form-data; boundary=" + boundary;
     request.Headers.Add("Authorization", authHeader);
     return request;
 }
Beispiel #26
0
 public Subscriptions(Session session)
 {
     this.Session = session;
 }
Beispiel #27
0
        /// <summary>
        /// Generates OAuth signature for http request
        /// </summary>
        /// <param name="method">The <see cref="WebMethod"/> http web method</param>
        /// <param name="session">he Yammer<see cref="Session">session</see> object</param>
        /// <param name="url">The URL for the web request</param>
        /// <param name="nonce">The OAuth nonce string</param>
        /// <param name="timeStamp">The generated OAuth timestamp</param>
        /// <returns>OAuth signature</returns>
        public static string GetSignature(WebMethod method, Session session, string url, out string timestamp, out string nonce)
        {
            OAuthBase oAuth = new OAuthBase();
            nonce = oAuth.GenerateNonce();
            timestamp = oAuth.GenerateTimeStamp();
            string nurl, nrp;

            Uri uri = new Uri(url);
            string sig = oAuth.GenerateSignature(
                uri,
                session.AuthKey.ConsumerKey,
                session.AuthKey.ConsumerSecret,
                session.AuthKey.TokenKey,
                session.AuthKey.TokenSecret,
                method.ToString(),
                timestamp,
                nonce,
                OAuthBase.SignatureTypes.PLAINTEXT, out nurl, out nrp);

            return System.Web.HttpUtility.UrlEncode(sig);
        }
Beispiel #28
0
 /// <summary>
 /// Retrieves data about user of given id
 /// </summary>
 /// <param name="id"></param>
 /// <param name="session"></param>
 /// <returns></returns>
 public static User GetUserById(int id, Session session)
 {
     string response = Yammer.HttpUtility.Get(Resources.YAMMER_USERS_SINGLE + id.ToString() + ".xml", session);
     XmlDocument xdoc = new XmlDocument();
     xdoc.LoadXml(response);
     XmlNode node = xdoc.SelectSingleNode("/response");
     User user = (User)Deserialize(typeof(User), "<reference>" + node.InnerXml + "</reference>");
     return user;
 }
Beispiel #29
0
 /// <summary>
 /// Messages followed by the logged-in user. Corresponds to the "Following" tab on the website.
 /// </summary>
 /// <param name="session"></param>
 /// <returns></returns>
 public static List<Message> GetFollowingMessages(Session session)
 {
     return RetrieveMessages(Yammer.HttpUtility.Get(Resources.YAMMER_MESSAGES_FOLLOWING, session)); ;
 }
Beispiel #30
0
 /// <summary>
 /// Retrieves data about group of given id
 /// </summary>
 /// <param name="id"></param>
 /// <param name="session"></param>
 /// <returns></returns>
 public static Group GetGroupById(int id, Session session)
 {
     string response = Yammer.HttpUtility.Get(Resources.YAMMER_GROUP_DATA + id.ToString() + ".xml", session);
     XmlDocument xdoc = new XmlDocument();
     xdoc.LoadXml(response);
     XmlNode node = xdoc.SelectSingleNode("/response");
     Group group = (Group)Deserialize(typeof(Group), "<group>" + node.InnerXml + "</group>");
     return group;
 }