Esempio n. 1
0
        private void ReLoadIssueMenu(ToolStripMenuItem menu, DTO.WorkDatas.Issue issue)
        {
            this.Utils.Safe(this.MainMenu, () =>
            {
                menu.Text  = $"{issue.Key} :: {issue.Summary}";
                menu.Image = (Recursos.Get <Icon>($"Priority{issue.Priority}") ?? Resources.refresh).ToBitmap();

                // Ver
                if (!menu.SubMenus(p => p.Text == "Ver").Any())
                {
                    menu.DropDownItems.Add(new ToolStripMenuItem("Ver", Resources.scroll_view.ToBitmap(), (sender, e) => this.Utils.Action.OpenIssue(sender.GetTag <DTO.WorkDatas.Issue>())).Do(m => m.Tag = issue));
                }

                // Cargar Horas
                if (!menu.SubMenus(p => p.Text == "Registrar Trabajo").Any())
                {
                    menu.DropDownItems.Add(new ToolStripMenuItem("Registrar Trabajo", Resources.stopwatch.ToBitmap(), (sender, e) =>
                                                                 this.Utils.Safe(this.Utils.MainForm, () => { new Forms.Tools.RegisterWork(sender.GetTag <string>()).ShowDialog(); })).Do(m => m.Tag = issue.Key)
                                           );
                }

                // Abrir en Explorador
                if (!menu.SubMenus(p => p.Text == "Abrir en Explorador").Any())
                {
                    menu.DropDownItems.Add(this.Utils.Menu.CreateOpenUrlMenu("Abrir en Explorador", BLL.Factory.Jira.Config.GetIssueUrl(issue.Key)));
                }

                // Adjuntos (index:1)
                var mAdjuntos = menu.SubMenus(p => p.Text == "Adjuntos").SingleOrDefault();
                if (mAdjuntos == null)
                {
                    menu.DropDownItems.Add(mAdjuntos = new ToolStripMenuItem("Adjuntos", Resources.books.ToBitmap()));
                }
                mAdjuntos.Visible = issue.Adjuntos.Count > 0;

                if (issue.Adjuntos.Count > 0)
                {
                    mAdjuntos.RemoveMenus(p => !issue.Adjuntos.Select(a => a.Filename).Contains(((DTO.WorkDatas.Attachment)p.Tag).Filename));   // elimino los menús de archivos que ya no están mas

                    foreach (var adj in issue.Adjuntos.Where(p => !mAdjuntos.SubMenus().Select(a => ((DTO.WorkDatas.Attachment)a.Tag).Filename).Contains(p.Filename)))
                    {
                        mAdjuntos.DropDownItems.Add(
                            this.Utils.Menu.CreateOpenUrlMenu(adj.Filename, adj.Content, Recursos.GetImageForFile(adj.Filename, adj.MimeType)).Do(m => m.Tag = adj)
                            );
                    }
                }

                // Transiciones (index:2)
                var mTransicion = menu.SubMenus(p => p.Text == "Mover").SingleOrDefault();
                if (mTransicion == null)
                {
                    menu.DropDownItems.Add(mTransicion = new ToolStripMenuItem("Mover", Resources.navigate_right.ToBitmap()));
                }
                mTransicion.Visible = (issue.Transitions?.Count ?? 0) > 0;

                if ((issue.Transitions?.Count ?? 0) > 0)
                {
                    foreach (var m in mTransicion.SubMenus())   // oculto todos los submenús
                    {
                        m.Visible = false;
                    }

                    foreach (var tran in issue.Transitions)
                    {
                        var mExists = mTransicion.SubMenus(m => ((DTO.WorkDatas.Transition)m.GetTag <dynamic>().tran).Id == tran.Id).SingleOrDefault();

                        if (mExists != null)
                        {
                            mExists.Visible = true;
                        }
                        else
                        {
                            mTransicion.DropDownItems.Add(this.Utils.Menu.CreateTransitionMenu(issue, tran));
                        }
                    }
                }
            });
        }
Esempio n. 2
0
        private void OnIssueChangeData(object sender, IEnumerable <Issue.Changes> changes)
        {
            var issue = (Issue)sender;

            string header = null;
            string body   = "";

            var actions = new List <Forms.Notification.NotificationAction>()
            {
                new Forms.Notification.NotificationAction()
                {
                    Text    = "Ver",
                    Image   = Resources.scroll_view.ToBitmap(),
                    OnClick = (a) => this.Utils.Action.OpenIssue((Issue)a.Tag),
                    Tag     = issue
                },
                new Forms.Notification.NotificationAction()
                {
                    Text    = "Abrir",
                    Image   = Resources.earth_view.ToBitmap(),
                    OnClick = (a) => {
                        this.Utils.Action.DoOpenUrl(BLL.Factory.Jira.Config.GetIssueUrl((string)a.Tag));
                    },
                    Tag = issue.Key
                }
            };


            foreach (var change in changes)
            {
                bool show = false;
                if (change.Property == "Priority" && BLL.Factory.Config.Global.Alarmas.IssuePriorityChanged)
                {
                    show = true;
                }
                if (change.Property == "Adjuntos" && BLL.Factory.Config.Global.Alarmas.IssueAdjuntoChanged)
                {
                    show = true;
                }
                if (change.Property == "Comments" && BLL.Factory.Config.Global.Alarmas.IssueCommentChanged)
                {
                    show = true;
                }

                if (show)
                {
                    if (header != null)
                    {
                        header = Recursos.Get <string>($"MsgIssueChangeHeader");
                    }
                    else
                    {
                        header = Recursos.Get <string>($"MsgIssueChangeHeader_{change.Property}");
                    }

                    var content = Recursos.Get <string>($"MsgIssueChangeBody_{change.Property}");

                    string insert = null;
                    string delete = null;
                    string update = null;
                    if (change.OldValue == null && change.NewValue != null)
                    {
                        insert = Recursos.Get <string>($"MsgIssueChangeBody_{change.Property}_insert");
                    }
                    if (change.OldValue != null && change.NewValue == null)
                    {
                        delete = Recursos.Get <string>($"MsgIssueChangeBody_{change.Property}_delete");
                    }
                    if (change.OldValue != null && change.NewValue != null)
                    {
                        update = Recursos.Get <string>($"MsgIssueChangeBody_{change.Property}_update");
                    }

                    content = content.Replace("{update}", update)
                              .Replace("{delete}", delete)
                              .Replace("{insert}", insert)
                              .Replace("{old}", change.OldValue?.ToString())
                              .Replace("{new}", change.NewValue?.ToString());

                    body += content;



                    // Acciones especiales
                    if (change.Property == "Adjuntos" && change.OldValue == null && change.NewValue != null)
                    {
                        actions.Add(new Forms.Notification.NotificationAction()
                        {
                            Text    = change.NewValue.ToString(),
                            Image   = Resources.book_blue_find.ToBitmap(),
                            Tag     = new { issue, file = change.NewValue },
                            OnClick = (obj) => this.Utils.Action.DoOpenUrl(((Issue)((dynamic)obj.Tag).issue).GetAdjunto((string)((dynamic)obj.Tag).file).Content)
                        });
                    }
                }
            }

            if (header == null) // nada que mostrar
            {
                return;
            }

            header = header.Replace("{issue}", issue.Key);

            var info = new Forms.Notification.NotificationType()
            {
                Header       = header,
                Body         = body,
                Image        = Resources.scroll_refresh.ToBitmap(),
                TimerToClose = null,
                Actions      = actions
            };

            ShowNotification(info);
        }