Interaction logic for AddIssueRevit.xaml
Inheritance: System.Windows.Window
Beispiel #1
0
        /// <summary>
        /// Add Issue
        /// </summary>
        /// <param name="path"></param>
        /// <param name="isBcf"></param>
        /// <returns></returns>
        private Tuple <IssueBCF, Issue> AddIssue(string path, bool isBcf)
        {
            try
            {
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document   doc   = uidoc.Document;

                if (!(uidoc.ActiveView is View3D || uidoc.ActiveView is ViewSheet || uidoc.ActiveView is ViewPlan || uidoc.ActiveView is ViewSection || uidoc.ActiveView is ViewDrafting))
                {
                    MessageBox.Show("I'm sorry,\nonly 3D and 2D views are supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }
                IssueBCF issue = new IssueBCF();

                string folderIssue = Path.Combine(path, issue.guid.ToString());
                if (!Directory.Exists(folderIssue))
                {
                    Directory.CreateDirectory(folderIssue);
                }

                var types      = new ObservableCollection <Issuetype>();
                var assignees  = new List <User>();
                var components = new ObservableCollection <IssueTracker.Classes.Component>();
                var priorities = new ObservableCollection <Priority>();
                var noCom      = true;
                var noPrior    = true;
                var noAssign   = true;

                if (!isBcf)
                {
                    types      = mainPan.jira.TypesCollection;
                    assignees  = mainPan.getAssigneesIssue();
                    components = mainPan.jira.ComponentsCollection;
                    priorities = mainPan.jira.PrioritiesCollection;
                    noCom      =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components ==
                        null;
                    noPrior =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority ==
                        null;
                    noAssign =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee ==
                        null;
                }

                AddIssueRevit air = new AddIssueRevit(uidoc, folderIssue, types, assignees, components, priorities, noCom, noPrior, noAssign);
                air.Title = "Add Jira Issue";
                if (!isBcf)
                {
                    air.VerbalStatus.Visibility = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    air.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed;
                }
                air.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                air.ShowDialog();
                if (air.DialogResult.HasValue && air.DialogResult.Value)
                {
                    issue.snapshot = Path.Combine(folderIssue, "snapshot.png");
                    int elemCheck = 2;
                    if (air.all.IsChecked.Value)
                    {
                        elemCheck = 0;
                    }
                    else if (air.selected.IsChecked.Value)
                    {
                        elemCheck = 1;
                    }

                    Issue issueJira = new Issue();
                    if (!isBcf)
                    {
                        issueJira.fields           = new Fields();
                        issueJira.fields.issuetype = (Issuetype)air.issueTypeCombo.SelectedItem;
                        issueJira.fields.priority  = (Priority)air.priorityCombo.SelectedItem;
                        if (!string.IsNullOrEmpty(air.ChangeAssign.Content.ToString()) &&
                            air.ChangeAssign.Content.ToString() != "none")
                        {
                            issueJira.fields.assignee      = new User();
                            issueJira.fields.assignee.name = air.ChangeAssign.Content.ToString();
                        }

                        if (air.SelectedComponents != null && air.SelectedComponents.Any())
                        {
                            issueJira.fields.components = air.SelectedComponents;
                        }
                    }
                    issue.viewpoint                   = generateViewpoint(elemCheck);
                    issue.markup.Topic.Title          = air.TitleBox.Text;
                    issue.markup.Header[0].IfcProject = ExporterIFCUtils.CreateProjectLevelGUID(doc,
                                                                                                Autodesk.Revit.DB.IFC.IFCProjectLevelGUIDType.Project);
                    string projFilename = (doc.PathName != null && doc.PathName != "")
                        ? System.IO.Path.GetFileName(doc.PathName)
                        : "";
                    issue.markup.Header[0].Filename = projFilename;
                    issue.markup.Header[0].Date     = DateTime.Now;

                    //comment
                    if (!string.IsNullOrWhiteSpace(air.CommentBox.Text))
                    {
                        CommentBCF c = new CommentBCF();
                        c.Comment1   = air.CommentBox.Text;
                        c.Topic      = new CommentTopic();
                        c.Topic.Guid = issue.guid.ToString();
                        ;
                        c.Date         = DateTime.Now;
                        c.VerbalStatus = air.VerbalStatus.Text;
                        // if (air.comboStatuses.SelectedIndex != -1)
                        // c.Status = mainPan.getStatus(air.comboStatuses.SelectedValue.ToString());
                        c.Status = CommentStatus.Unknown;
                        c.Author = (string.IsNullOrWhiteSpace(mainPan.jira.Self.displayName))
                            ? MySettings.Get("BCFusername")
                            : mainPan.jira.Self.displayName;
                        issue.markup.Comment.Add(c);
                    }

                    return(new Tuple <IssueBCF, Issue>(issue, issueJira));
                }
                else
                {
                    mainPan.DeleteDirectory(folderIssue);
                }
            }

            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1);
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Add Issue
        /// </summary>
        /// <param name="path"></param>
        /// <param name="isBcf"></param>
        /// <returns></returns>
        private Tuple <Markup, Issue> AddIssue(string path, bool isBcf)
        {
            try
            {
                UIDocument uidoc = uiapp.ActiveUIDocument;
                Document   doc   = uidoc.Document;

                if (!(uidoc.ActiveView is View3D || uidoc.ActiveView is ViewSheet || uidoc.ActiveView is ViewPlan || uidoc.ActiveView is ViewSection || uidoc.ActiveView is ViewDrafting))
                {
                    MessageBox.Show("I'm sorry,\nonly 3D and 2D views are supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(null);
                }

                Markup issue = new Markup(DateTime.Now);

                string folderIssue = Path.Combine(path, issue.Topic.Guid);
                if (!Directory.Exists(folderIssue))
                {
                    Directory.CreateDirectory(folderIssue);
                }

                var types      = new ObservableCollection <Issuetype>();
                var assignees  = new List <User>();
                var components = new ObservableCollection <IssueTracker.Classes.Component>();
                var priorities = new ObservableCollection <Priority>();
                var noCom      = true;
                var noPrior    = true;
                var noAssign   = true;

                if (!isBcf)
                {
                    types      = mainPan.jira.TypesCollection;
                    assignees  = mainPan.getAssigneesIssue();
                    components = mainPan.jira.ComponentsCollection;
                    priorities = mainPan.jira.PrioritiesCollection;
                    noCom      =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components ==
                        null;
                    noPrior =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority ==
                        null;
                    noAssign =
                        mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee ==
                        null;
                }

                AddIssueRevit air = new AddIssueRevit(uidoc, folderIssue, types, assignees, components, priorities, noCom, noPrior, noAssign);
                air.Title = "Add Jira Issue";
                if (!isBcf)
                {
                    air.JiraFieldsBox.Visibility = System.Windows.Visibility.Visible;
                    air.VerbalStatus.Visibility  = System.Windows.Visibility.Collapsed;
                    air.BcfFieldsBox.Visibility  = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    air.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed;
                    air.BcfFieldsBox.Visibility  = System.Windows.Visibility.Visible;
                }

                air.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
                air.ShowDialog();
                if (air.DialogResult.HasValue && air.DialogResult.Value)
                {
                    ViewPoint vp = new ViewPoint(true);
                    vp.SnapshotPath = Path.Combine(folderIssue, "snapshot.png");
                    int elemCheck = 2;
                    if (air.all.IsChecked.Value)
                    {
                        elemCheck = 0;
                    }
                    else if (air.selected.IsChecked.Value)
                    {
                        elemCheck = 1;
                    }
                    vp.VisInfo = generateViewpoint(elemCheck);

                    //Add annotations for description with snapshot/viewpoint
                    StringBuilder descriptionText = new StringBuilder();
                    if (!string.IsNullOrWhiteSpace(air.CommentBox.Text))
                    {
                        descriptionText.AppendLine(air.CommentBox.Text);
                    }
                    if (!isBcf)
                    {
                        if (vp.VisInfo != null)
                        {
                            descriptionText.AppendLine(string.Format("<Viewpoint>[^{0}]</Viewpoint>", "viewpoint.bcfv"));
                        }
                        if (!string.IsNullOrWhiteSpace(vp.SnapshotPath))
                        {
                            descriptionText.AppendLine(string.Format("<Snapshot>[^{0}]</Snapshot>", "snapshot.png"));
                            descriptionText.AppendLine(string.Format("!{0}|width=200!", "snapshot.png"));
                        }
                    }

                    Issue issueJira = new Issue();
                    if (!isBcf)
                    {
                        issueJira.fields             = new Fields();
                        issueJira.fields.description = descriptionText.ToString().Trim();
                        issueJira.fields.issuetype   = (Issuetype)air.issueTypeCombo.SelectedItem;
                        issueJira.fields.priority    = (Priority)air.priorityCombo.SelectedItem;
                        if (!string.IsNullOrEmpty(air.ChangeAssign.Content.ToString()) &&
                            air.ChangeAssign.Content.ToString() != "none")
                        {
                            issueJira.fields.assignee      = new User();
                            issueJira.fields.assignee.name = air.ChangeAssign.Content.ToString();
                        }

                        if (air.SelectedComponents != null && air.SelectedComponents.Any())
                        {
                            issueJira.fields.components = air.SelectedComponents;
                        }
                    }

                    issue.Viewpoints.Add(vp);
                    issue.Topic.Title          = air.TitleBox.Text;
                    issue.Topic.Description    = descriptionText.ToString().Trim();
                    issue.Topic.AssignedTo     = air.BcfAssignee.Text;
                    issue.Topic.CreationAuthor = MySettings.Get("username");
                    issue.Topic.Priority       = air.BcfPriority.Text;
                    issue.Topic.TopicStatus    = air.VerbalStatus.Text;
                    issue.Topic.TopicType      = air.BcfIssueType.Text;

                    issue.Header[0].IfcProject = ExporterIFCUtils.CreateProjectLevelGUID(doc,
                                                                                         Autodesk.Revit.DB.IFC.IFCProjectLevelGUIDType.Project);
                    string projFilename = (doc.PathName != null && doc.PathName != "")
                  ? System.IO.Path.GetFileName(doc.PathName)
                  : "";
                    issue.Header[0].Filename = projFilename;
                    issue.Header[0].Date     = DateTime.Now;

                    return(new Tuple <Markup, Issue>(issue, issueJira));
                }
                else
                {
                    mainPan.DeleteDirectory(folderIssue);
                }
            }

            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1);
            }
            return(null);
        }
    /// <summary>
    /// Add Issue
    /// </summary>
    /// <param name="path"></param>
    /// <param name="isBcf"></param>
    /// <returns></returns>
    private Tuple<IssueBCF, Issue> AddIssue(string path, bool isBcf)
    {
      try
      {
        UIDocument uidoc = uiapp.ActiveUIDocument;
        Document doc = uidoc.Document;

        if (!(uidoc.ActiveView is View3D || uidoc.ActiveView is ViewSheet || uidoc.ActiveView is ViewPlan || uidoc.ActiveView is ViewSection || uidoc.ActiveView is ViewDrafting))
        {
            MessageBox.Show("I'm sorry,\nonly 3D and 2D views are supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            return null;
        }
        IssueBCF issue = new IssueBCF();

        string folderIssue = Path.Combine(path, issue.guid.ToString());
        if (!Directory.Exists(folderIssue))
          Directory.CreateDirectory(folderIssue);

        var types = new ObservableCollection<Issuetype>();
        var assignees = new List<User>();
        var components = new ObservableCollection<IssueTracker.Classes.Component>();
        var priorities = new ObservableCollection<Priority>();
        var noCom = true;
        var noPrior = true;
        var noAssign = true;

        if (!isBcf)
        {
            types = mainPan.jira.TypesCollection;
            assignees = mainPan.getAssigneesIssue();
            components = mainPan.jira.ComponentsCollection;
            priorities = mainPan.jira.PrioritiesCollection;
            noCom =
                mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.components ==
                null;
            noPrior =
                mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.priority ==
                null;
            noAssign =
                mainPan.jira.ProjectsCollection[mainPan.jiraPan.projIndex].issuetypes[0].fields.assignee ==
                null;

        }

        AddIssueRevit air = new AddIssueRevit(uidoc, folderIssue, types, assignees, components, priorities, noCom, noPrior, noAssign);
        air.Title = "Add Jira Issue";
        if (!isBcf)
            air.VerbalStatus.Visibility = System.Windows.Visibility.Collapsed;
        else
            air.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed;
        air.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
        air.ShowDialog();
          if (air.DialogResult.HasValue && air.DialogResult.Value)
          {
              issue.snapshot = Path.Combine(folderIssue, "snapshot.png");
              int elemCheck = 2;
              if (air.all.IsChecked.Value)
                  elemCheck = 0;
              else if (air.selected.IsChecked.Value)
                  elemCheck = 1;

              Issue issueJira = new Issue();
              if (!isBcf)
              {
                  issueJira.fields = new Fields();
                  issueJira.fields.issuetype =  (Issuetype) air.issueTypeCombo.SelectedItem;
                  issueJira.fields.priority = (Priority) air.priorityCombo.SelectedItem;
                  if (!string.IsNullOrEmpty(air.ChangeAssign.Content.ToString()) &&
                      air.ChangeAssign.Content.ToString() != "none")
                  {
                      issueJira.fields.assignee = new User();
                      issueJira.fields.assignee.name = air.ChangeAssign.Content.ToString();
                  }

                  if (air.SelectedComponents != null && air.SelectedComponents.Any())
                  {
                      issueJira.fields.components = air.SelectedComponents;
                  }
              }
              issue.viewpoint = generateViewpoint(elemCheck);
              issue.markup.Topic.Title = air.TitleBox.Text;
              issue.markup.Header[0].IfcProject = ExporterIFCUtils.CreateProjectLevelGUID(doc,
                  Autodesk.Revit.DB.IFC.IFCProjectLevelGUIDType.Project);
              string projFilename = (doc.PathName != null && doc.PathName != "")
                  ? System.IO.Path.GetFileName(doc.PathName)
                  : "";
              issue.markup.Header[0].Filename = projFilename;
              issue.markup.Header[0].Date = DateTime.Now;

              //comment
              if (!string.IsNullOrWhiteSpace(air.CommentBox.Text))
              {
                  CommentBCF c = new CommentBCF();
                  c.Comment1 = air.CommentBox.Text;
                  c.Topic = new CommentTopic();
                  c.Topic.Guid = issue.guid.ToString();
                  ;
                  c.Date = DateTime.Now;
                  c.VerbalStatus = air.VerbalStatus.Text;
                  // if (air.comboStatuses.SelectedIndex != -1)
                  // c.Status = mainPan.getStatus(air.comboStatuses.SelectedValue.ToString());
                  c.Status = CommentStatus.Unknown;
                  c.Author = (string.IsNullOrWhiteSpace(mainPan.jira.Self.displayName))
                      ? MySettings.Get("BCFusername")
                      : mainPan.jira.Self.displayName;
                  issue.markup.Comment.Add(c);
              }

              return new Tuple<IssueBCF, Issue>(issue, issueJira);


          }
          else
          {
              mainPan.DeleteDirectory(folderIssue);
          }
           
      }

      catch (System.Exception ex1)
      {
        MessageBox.Show("exception: " + ex1);
      }
      return null;

    }