Esempio n. 1
0
        static void Menu_PostMessage(InputEventArgs e)
        {
            MatchPattern[] patterns = new MatchPattern[] { new MatchPattern("-m", true), new MatchPattern("-a", true) };

            Dictionary<string, string> parameters = Menu.ParseInput(e.Input, patterns);

            string body = string.Empty;
            if (parameters.ContainsKey("-m"))
                body = parameters["-m"];

            List<string> attachmentList = new List<string>();
            if (parameters.ContainsKey("-a"))
                attachmentList.AddRange(parameters["-a"].Split(';'));

            //post message
            Yammer.Message.PostMessage(body, attachmentList);
        }
Esempio n. 2
0
        static void Menu_ViewUser(InputEventArgs e)
        {
            MatchPattern[] patterns = new MatchPattern[] { new MatchPattern("-uid", true), new MatchPattern("-all", false) };
            Dictionary<string, string> parameters = Menu.ParseInput(e.Input, patterns);
            string uid = string.Empty;
            if (parameters.ContainsKey("-uid"))
            {
                uid = parameters["-uid"];
                Yammer.User user = Yammer.User.GetUserByUserName(uid);
                if (user != null)
                {
                    object[] args = new object[] { user.Name, user.JobTitle, user.MugshotUrl, user.WebUrl, user.Contact.PhoneNumbers[0].Number, user.Location };
                    Console.WriteLine(string.Format("UserName:{0}\r\nTitle:{1}\r\nAvatar:{2}\r\nUrl:{3}\r\nMobilePhone:{4}\r\nLocation:{5}", args));
                }
                else
                    Console.WriteLine("User not found");
            }
            else if (parameters.ContainsKey("-all"))
            {
                List<Yammer.User> users = Yammer.User.GetAllUsers();
                foreach (Yammer.User u in users)
                {
                    object[] args = new object[] { u.Name, u.JobTitle, u.MugshotUrl, u.WebUrl, u.Contact.PhoneNumbers.Count > 0 ? u.Contact.PhoneNumbers[0].Number : string.Empty, u.Location };
                    Console.WriteLine(string.Format("UserName:{0}\r\nTitle:{1}\r\nAvatar:{2}\r\nUrl:{3}\r\nMobilePhone:{4}\r\n\r\nLocation:{5}", args));
                }
            }

        }
Esempio n. 3
0
        static void Menu_UpdateUser(InputEventArgs e)
        {
            MatchPattern[] patterns = new MatchPattern[] { new MatchPattern("-uid", true), new MatchPattern("-params", true) };
            Dictionary<string, string> parameters = Menu.ParseInput(e.Input, patterns);

            string uid = string.Empty;
            if (parameters.ContainsKey("-uid"))
                uid = parameters["-uid"];

            Yammer.User user = null;
            if (uid != null && uid != string.Empty)
                user = Yammer.User.GetUserByUserName(uid);

            string attributes = string.Empty;
            Yammer.UserParameters userParams = null;
            List<PropertyInfo> properties = null;
            string[] props = null;

            if (parameters.ContainsKey("-params"))
            {
                attributes = parameters["-params"];
                props = attributes.Split(';');
                userParams = new Yammer.UserParameters();
                properties = new List<PropertyInfo>(userParams.GetType().GetProperties());
            }

            foreach (string prop in props)
            {
                string[] hash = prop.Split('=');

                PropertyInfo property = properties.Find(delegate(PropertyInfo p) { return p.Name == hash[0]; });
                if (property != null)
                    property.SetValue(userParams, hash[1], null);
            }

            if(user != null)
                user.Save(userParams);

        }
Esempio n. 4
0
        static void Menu_DeleteUser(InputEventArgs e)
        {
            MatchPattern[] patterns = new MatchPattern[] { new MatchPattern("-uid", true) };
            Dictionary<string, string> parameters = Menu.ParseInput(e.Input, patterns);
            string uid = string.Empty;
            if (parameters.ContainsKey("-uid"))
                uid = parameters["-uid"];

            if(uid != null && uid != string.Empty)
                Yammer.User.GetUserByUserName(uid).Delete();
        }
Esempio n. 5
0
 public static Dictionary<string, string> ParseInput(string input, MatchPattern[] switches)
 {
     Dictionary<string, string> parameters = new Dictionary<string, string>();
     foreach (MatchPattern mp in switches)
     {
         string pattern = mp.HasValue ? mp.Key + mp.Value : mp.Key;
         System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.Singleline);
         System.Text.RegularExpressions.Match match = regex.Match(input);
         string output = string.Empty;
         if (match.Success)
             parameters.Add(mp.Key, match.Value.Replace(mp.Key, "").Trim().Replace("\"", ""));
     }
     return parameters;
 }