예제 #1
0
 private void btnTestSlack_Click(object sender, RoutedEventArgs e)
 {
     if ((this.gvSlack.SelectedItems.Count == 1) && (this.gvSlack.SelectedItem is SlackObject))
     {
         SlackObject selectedItem = this.gvSlack.SelectedItem as SlackObject;
         new Notificator().Slack(Notificator.NotificationType.Restock, selectedItem);
     }
 }
예제 #2
0
        internal void Slack(NotificationType type, SlackObject rec = null)
        {
            List <SlackObject> list = null;

            if (rec != null)
            {
                list = new List <SlackObject> {
                    rec
                };
            }
            else if (type == NotificationType.Restock)
            {
                list = (from x in Global.SETTINGS.SLACK
                        where x.SlackType == SlackObject.SlackMessageEnum.Restock
                        select x).ToList <SlackObject>();
            }
            else if (type == NotificationType.Atc)
            {
                list = (from x in Global.SETTINGS.SLACK
                        where x.SlackType == SlackObject.SlackMessageEnum.Atc
                        select x).ToList <SlackObject>();
            }
            else if (type != NotificationType.Paypal)
            {
                list = (from x in Global.SETTINGS.SLACK
                        where x.SlackType == SlackObject.SlackMessageEnum.Checkout
                        select x).ToList <SlackObject>();
            }
            else
            {
                list = (from x in Global.SETTINGS.SLACK
                        where x.SlackType == SlackObject.SlackMessageEnum.PayPal
                        select x).ToList <SlackObject>();
            }
            if (list != null)
            {
                foreach (SlackObject obj2 in list)
                {
                    try
                    {
                        string      username;
                        SlackClient client  = new SlackClient(obj2.Hook);
                        string      message = obj2.Message;
                        if (rec != null)
                        {
                            message = "TESTING MESSAGE";
                        }
                        else
                        {
                            message = message.Replace("#product_url#", this._url).Replace("#product_title#", this._productName).Replace("#time#", DateTime.Now.ToLocalTime().ToString("dd/MM/yy hh:mm:sstt", CultureInfo.InvariantCulture)).Replace("#rnd#", "(" + _rnd.Next(0, 20).ToString() + ")").Replace("#paypal#", this._task.PaypalLink).Replace("#orderno#", this._task.OrderNo).Replace("#profile_name#", this._task.CheckoutProfile).Replace("#size#", this._task.PickedSize).Replace("#website#", this._task.HomeUrl).Replace("#task_name#", this._task.Name);
                        }
                        if (this._task != null)
                        {
                            Global.SETTINGS.PROFILES.First <ProfileObject>(x => x.Id == this._task.CheckoutId);
                            if (this._task.Login)
                            {
                                message = message.Replace("#username#", this._task.Username).Replace("#password#", this._task.Password);
                            }
                        }
                        string channel = obj2.Channel;
                        if (channel[0] != '#')
                        {
                            channel = "#" + channel;
                        }
                        if (message.Contains("#img#") && !string.IsNullOrEmpty(this._task.ImgUrl))
                        {
                            message  = message.Replace("#img#", "");
                            username = obj2.Username;
                            EveAIO.Notifications.Attachment attachment = new EveAIO.Notifications.Attachment {
                                ImageUrl = this._task.ImgUrl,
                                Title    = ""
                            };
                            client.PostMessage(message, username, channel, attachment);
                        }
                        else
                        {
                            username = obj2.Username;
                            client.PostMessage(message, username, channel, null);
                        }
                    }
                    catch (Exception exception)
                    {
                        if (this._task != null)
                        {
                            Global.Logger.Error($"Task '{this._task.Name}': error sending slack message", exception);
                        }
                        else
                        {
                            Global.Logger.Error("Error sending slack test message", exception);
                        }
                    }
                }
            }
        }