Пример #1
0
        public async void LoadData(SlackAdapter slackAdapter)
        {
            try
            {
                _slackAdapter = slackAdapter;
                _slackAdapter.OnMessagesUpdated += _slackAdapter_OnMessagesUpdated;

                Task tInfo = new Task(LoadInfo);
                tInfo.Start();
                await tInfo;
                OnInfoLoaded?.Invoke(null);

                Task tChannels = new Task(LoadChannels);
                tChannels.Start();
                await tChannels;
                OnChannelsLoaded?.Invoke(null);

                Task tUsers = new Task(LoadUsers);
                tUsers.Start();
                await tUsers;
                OnUsersLoaded?.Invoke(null);
            }
            catch (Exception exp)
            {
            }
        }
        public async void LoadConversation(SlackAdapter slackAdapter, string conversation)
        {
            _slackAdapter = slackAdapter;
            _slackAdapter.OnMessagesUpdated += _slackAdapter_OnMessagesUpdated;
            _currentConversation             = ConversationControler.History(slackAdapter, conversation);
            this.Controls.Clear();
            this.BackColor = Color.WhiteSmoke;

            LoadData();
            //Task t = new Task(LoadData);
            //t.Start();
            // await t; // TODO : add async way to do it
            BuildMessagesInterface();
        }
Пример #3
0
        private void Init()
        {
            if (_slackAdapter == null)
            {
                _slackAdapter = new SlackAdapter();
            }
            _slackMenu.LoadData(_slackAdapter);
            _slackMenu.OnChannelChanged         += _slackMenu_OnChannelChanged;
            _slackMenu.OnUserChanged            += _slackMenu_OnUserChanged;
            _slackInput.OnMessageSendingRequest += _slackInput_OnMessageSendingRequest;
            _slackInput.SlackAdapter             = _slackAdapter;

            if (_slackAdapter.Channels != null && _slackAdapter.Channels.Count > 0)
            {
                Channel defaultChannel = _slackAdapter.Channels.Where(c => c.Name.ToLower().Equals("general")).Count() > 0 ? _slackAdapter.Channels.Where(c => c.Name.ToLower().Equals("general")).FirstOrDefault() : _slackAdapter.Channels.FirstOrDefault();
                RefreshConversation(defaultChannel);
            }
        }
Пример #4
0
        public static List <Im> List(SlackAdapter sa)
        {
            List <Im> ims = null;

            try
            {
                string   answer   = Accessor.JsonPostFormData(sa, URL + ".list");
                Response response = Accessor.Deserialize <Response>(answer);
                if (response.Ok)
                {
                    ims = Accessor.Deserialize <List <Im> >(answer);
                }
            }
            catch
            {
            }

            return(ims);
        }
        public static List <Channel> List(SlackAdapter sa)
        {
            ChannelList channels = null;

            try
            {
                string   answer   = Accessor.JsonPostFormData(sa, URL + ".list");
                Response response = Accessor.Deserialize <Response>(answer);
                if (response.Ok)
                {
                    channels = Accessor.Deserialize <ChannelList>(answer);
                }
            }
            catch
            {
            }

            return(channels == null ? null : channels.Channels);
        }
        public static Emoji List(SlackAdapter sa)
        {
            Emojis emojis = null;

            try
            {
                string   answer   = Accessor.JsonPostFormData(sa, URL + ".list");
                Response response = Accessor.Deserialize <Response>(answer);
                if (response.Ok)
                {
                    emojis = Accessor.Deserialize <Emojis>(answer);
                }
            }
            catch
            {
            }

            return(emojis == null ? null : emojis.Emoji);
        }
Пример #7
0
        public static List <Group> List(SlackAdapter sa)
        {
            List <Group> groups = new List <Group>();

            try
            {
                string   answer   = Accessor.JsonPostFormData(sa, URL + ".list");
                Response response = Accessor.Deserialize <Response>(answer);
                if (response.Ok)
                {
                    groups = Accessor.Deserialize <List <Group> >(answer);
                }
            }
            catch
            {
            }

            return(groups);
        }
Пример #8
0
        public static Team Info(SlackAdapter sa)
        {
            Team team = null;

            try
            {
                string   answer   = Accessor.JsonPostFormData(sa, URL + ".info");
                Response response = Accessor.Deserialize <Response>(answer);
                if (response.Ok)
                {
                    TeamInfo teamInfo = Accessor.Deserialize <TeamInfo>(answer);
                    team = teamInfo.Team != null ? teamInfo.Team : null;
                }
            }
            catch
            {
            }

            return(team);
        }
Пример #9
0
        public static string JsonPostFormData(SlackAdapter slackAdapter, string url, Dictionary <string, string> data = null)
        {
            try
            {
                NameValueCollection outgoingQueryString = HttpUtility.ParseQueryString(String.Empty);
                if (data != null)
                {
                    foreach (var item in data)
                    {
                        outgoingQueryString.Add(item.Key, item.Value);
                    }
                }
                outgoingQueryString.Add(TOKENHEADER, slackAdapter.CurrentToken.Key);
                string postdata = outgoingQueryString.ToString();

                url += "?" + postdata;
                byte[]     dataStream = Encoding.UTF8.GetBytes(string.Empty);
                WebRequest webRequest = WebRequest.Create(url);
                webRequest.Method        = "POST";
                webRequest.ContentType   = "application/json";
                webRequest.ContentLength = dataStream.Length;

                Stream newStream = webRequest.GetRequestStream();
                newStream.Write(dataStream, 0, dataStream.Length);
                newStream.Close();
                WebResponse response = webRequest.GetResponse();

                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    return(reader.ReadToEnd());
                }
            }
            catch (WebException exp)
            {
                using (var reader = new StreamReader(exp.Response.GetResponseStream()))
                {
                    string ret = reader.ReadToEnd();
                    return(string.IsNullOrEmpty(ret) ? exp.Message : ret);
                }
            }
        }
Пример #10
0
        public static string JsonGet(SlackAdapter slackAdapter, string url, Dictionary <string, string> headers = null)
        {
            WebRequest webRequest = WebRequest.Create(url);

            webRequest.Method = "GET";
            webRequest.Headers.Add(TOKENHEADER, slackAdapter.CurrentToken.Key);
            if (headers != null)
            {
                foreach (var item in headers)
                {
                    webRequest.Headers.Add(item.Key, item.Value);
                }
            }
            WebResponse response = webRequest.GetResponse();

            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                return(reader.ReadToEnd());
            }
        }
        public static Conversation History(SlackAdapter sa, string channel)
        {
            Conversation conversation = null;

            try
            {
                Dictionary <string, string> data = new Dictionary <string, string>();
                data.Add("channel", channel);
                string   answer   = Accessor.JsonPostFormData(sa, URL + ".history", data);
                Response response = Accessor.Deserialize <Response>(answer);
                if (response.Ok)
                {
                    conversation = Accessor.Deserialize <Conversation>(answer);
                }
            }
            catch (Exception exp)
            {
            }

            return(conversation);
        }
Пример #12
0
 public void LoadMessage(SlackAdapter slackAdapter, Message message)
 {
     _currentMessage = message;
     _slackAdapter   = slackAdapter;
     if (message.User != null)
     {
         _currentMember = _slackAdapter.Users.Where(s => s.Id.Equals(message.User)).First();
         pictureBox1.Load(_currentMember.Profile.Image_48);
         labelName.Text = _currentMember.Name;
     }
     if (_currentMessage != null)
     {
         System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
         dtDateTime     = dtDateTime.AddSeconds(double.Parse(_currentMessage.Ts.Replace('.', ','))).ToLocalTime();
         labelDate.Text = dtDateTime.ToString("hh:mm tt");
         _textBox.Text  = _currentMessage.Text;
         CleanTextBox();
         AddSmileys();
         AddReaction();
     }
 }
Пример #13
0
        public static string JsonPost(SlackAdapter slackAdapter, string url, string data = "", Dictionary <string, string> headers = null)
        {
            try
            {
                byte[]     dataStream = Encoding.UTF8.GetBytes(data);
                WebRequest webRequest = WebRequest.Create(url);
                webRequest.Method        = "POST";
                webRequest.ContentType   = "application/json";
                webRequest.ContentLength = dataStream.Length;
                webRequest.Headers.Add(TOKENHEADER, slackAdapter.CurrentToken.Key);
                if (headers != null)
                {
                    foreach (var item in headers)
                    {
                        webRequest.Headers.Add(item.Key, item.Value);
                    }
                }

                Stream newStream = webRequest.GetRequestStream();

                newStream.Write(dataStream, 0, dataStream.Length);
                newStream.Close();
                WebResponse response = webRequest.GetResponse();

                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    return(reader.ReadToEnd());
                }
            }
            catch (WebException exp)
            {
                using (var reader = new StreamReader(exp.Response.GetResponseStream()))
                {
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    string ret = reader.ReadToEnd();
                    return(string.IsNullOrEmpty(ret) ? exp.Message : ret);
                }
            }
        }
Пример #14
0
 public SlackControl(SlackAdapter sa)
 {
     _slackAdapter = sa;
     InitializeComponent();
     Init();
 }
Пример #15
0
 public void LoadData(SlackAdapter slackAdapter)
 {
     _slackAdapter = slackAdapter;
     RefreshDgv();
 }
Пример #16
0
 public void LoadData(SlackAdapter slackAdapter)
 {
     labelChannel.Text = "#" + slackAdapter.CurrentChannel.Name;
     labelMembers.Left = labelChannel.Left + labelChannel.Width + 5;
     labelMembers.Text = slackAdapter.CurrentChannel.Members.Count() + " Members";
 }