Esempio n. 1
0
        private void IssueControlOnBaseButtonClicked(object sender, EventArgs eventArgs)
        {
            var issue = new Issue();

            if (InputPorts[0].Data == null || InputPorts[1].Data == null || InputPorts[2].Data == null) return;
            // Common Information
            issue.CreatedAt = DateTime.Now;
            issue.Author = _controller.IntBase.APICore.UserName;
            issue.Id = Guid.NewGuid();

            // User Control Stuff
            issue.Description = _issueControl.DescriptionTextBox.Text;
            var teamMember = _issueControl.ResponsibleUserComboBox.SelectedItem as TeamMember;
            if (teamMember != null)
                issue.Responsible = teamMember.User;

            var project = InputPorts[0].Data as Project;
            
            // Create the Issue
            if (project != null)
            {
                issue.ProjectId = project.Id;
                _controller.IntBase.APICore.CreateIssue(issue, project.Id);
            }
               
            Issue createdIssue = null;

            // Download the Issue
            if (project == null) return;

            foreach (var item in _controller.IntBase.APICore.GetIssues(project.Id).Where(item => item.Id == issue.Id))
            {
                createdIssue = item;
            }

            // Screenshot Stuff
            var image = RenderFrameworkElement(InputPorts[2].ConnectedConnectors[0].StartPort.ParentNode);

            var encoder = new JpegBitmapEncoder();
            var photolocation = _controller.IntBase.UserDirectory + Guid.NewGuid() + ".jpg"; //file name 

            encoder.Frames.Add(BitmapFrame.Create(image));

            using (var filestream = new FileStream(photolocation, FileMode.Create))
                encoder.Save(filestream);

            var fs = File.OpenRead(photolocation);
            var bytes = new byte[fs.Length];
            fs.Read(bytes, 0, Convert.ToInt32(fs.Length));

            try
            {
                if (createdIssue != null)
                    createdIssue.AddAttachment(photolocation, bytes);
            }
            catch (Exception)
            {
                // ignored
            }

            // Pin Stuff
            if (InputPorts[1].Data.GetType() != typeof (List<GenericElement>)) return;
            var genericElements = InputPorts[1].Data as List<GenericElement>;
            if (genericElements == null) return;
            foreach (var item in genericElements)
            {
                var pin = new Pin
                {
                    ObjectId = item.Id
                };
                try
                {
                    issue.AddPin(pin);
                }
                catch (Exception)
                {
                    // ignored
                }
            }
        }