private void WaitForConnectionCallBack(IAsyncResult iar) { try { // Get the pipe NamedPipeServerStream pipeServer = (NamedPipeServerStream)iar.AsyncState; // End waiting for the connection pipeServer.EndWaitForConnection(iar); byte[] buffer = new byte[1024]; // Read the incoming message pipeServer.Read(buffer, 0, 1024); // Convert byte buffer to string string jsonRequestMsg = Encoding.UTF8.GetString(buffer, 0, buffer.Length); IpcOperationType type = IpcMessageStore.getIpcOperationType(jsonRequestMsg); string jsonResponseMsg = null; if (type == IpcOperationType.AddIssueRequest) { AddIssueResponse response = handleAddIssueRequest(); jsonResponseMsg = IpcMessageStore.savePayload(IpcOperationType.AddIssueResponse, response); } else if (type == IpcOperationType.OpenViewpointRequest) { VisualizationInfo visInfo = IpcMessageStore.getPayload <VisualizationInfo>(jsonRequestMsg); jsonResponseMsg = "{}"; doOpen3DView(visInfo); } else if (type == IpcOperationType.SelectElementsRequest) { List <Component> components = IpcMessageStore.getPayload <List <Component> >(jsonRequestMsg); jsonResponseMsg = "{}"; selectElements(components, true); } // Send response byte[] _buffer = Encoding.UTF8.GetBytes(jsonResponseMsg); pipeServer.Write(_buffer, 0, _buffer.Length); pipeServer.Flush(); // Kill original sever and create new wait server pipeServer.Close(); pipeServer = null; pipeServer = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); // Recursively wait for the connection again and again.... pipeServer.BeginWaitForConnection(new AsyncCallback(WaitForConnectionCallBack), pipeServer); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void ipcAsyncCallback(IAsyncResult iar) { try { // Get the pipe NamedPipeClientStream pipeStream = ((Tuple <NamedPipeClientStream, Action <object> >)iar.AsyncState).Item1; // End the write pipeStream.EndWrite(iar); byte[] buffer = new byte[1024]; pipeStream.Read(buffer, 0, 1024); string jsonMsg = Encoding.UTF8.GetString(buffer, 0, buffer.Length); IpcOperationType type = IpcMessageStore.getIpcOperationType(jsonMsg); if (type == IpcOperationType.AddIssueResponse) { AddIssueResponse response = IpcMessageStore.getPayload <AddIssueResponse>(jsonMsg); // return payload object in callback in the same UI thread this.Dispatcher.Invoke(() => ((Tuple <NamedPipeClientStream, Action <object> >)iar.AsyncState).Item2(response)); } else if (type == IpcOperationType.Invalid) { // extends other types of IPC responses here... } pipeStream.Flush(); pipeStream.Close(); pipeStream.Dispose(); } catch (Exception oEX) { MessageBox.Show(oEX.Message); } }
/// <summary> /// Add Issue /// </summary> private void AddIssue(string path, bool isBcf, Action <Tuple <Markup, Issue> > callback) { sendIpcRequest(IpcOperationType.AddIssueRequest, null, (o) => { try { AddIssueResponse ipcResponse = o as AddIssueResponse; if (!ipcResponse.isValidRequest) { MessageBox.Show("Please switch to model space as paper space is not supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return; } Markup issue = new Markup(DateTime.Now); string folderIssue = Path.Combine(path, issue.Topic.Guid); if (!Directory.Exists(folderIssue)) { Directory.CreateDirectory(folderIssue); } // copy snapshot from temp file and delete temp file string snapshotPath = Path.Combine(folderIssue, "snapshot.png"); File.Copy(ipcResponse.tempSnapshotPath, snapshotPath); File.Delete(ipcResponse.tempSnapshotPath); 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; } AddIssueDialog aid = new AddIssueDialog(folderIssue, types, assignees, components, priorities, noCom, noPrior, noAssign); aid.Title = "Add Jira Issue"; if (!isBcf) { aid.JiraFieldsBox.Visibility = System.Windows.Visibility.Visible; aid.VerbalStatus.Visibility = System.Windows.Visibility.Collapsed; aid.BcfFieldsBox.Visibility = System.Windows.Visibility.Collapsed; } else { aid.JiraFieldsBox.Visibility = System.Windows.Visibility.Collapsed; aid.BcfFieldsBox.Visibility = System.Windows.Visibility.Visible; } aid.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; aid.ShowDialog(); if (aid.DialogResult.HasValue && aid.DialogResult.Value) { ViewPoint vp = new ViewPoint(true); vp.SnapshotPath = snapshotPath; //int elemCheck = 2; //if (aic.all.IsChecked.Value) // elemCheck = 0; //else if (aic.selected.IsChecked.Value) // elemCheck = 1; vp.VisInfo = ipcResponse.visualizationInfo; //Add annotations for description with snapshot/viewpoint StringBuilder descriptionText = new StringBuilder(); if (!string.IsNullOrWhiteSpace(aid.CommentBox.Text)) { descriptionText.AppendLine(aid.CommentBox.Text); } if (!isBcf) { if (vp.VisInfo != null) { descriptionText.AppendLine(string.Format("{{anchor:<Viewpoint>[^{0}]</Viewpoint>}}", "viewpoint.bcfv")); } if (!string.IsNullOrWhiteSpace(vp.SnapshotPath)) { descriptionText.AppendLine(string.Format("!{0}|thumbnail!", "snapshot.png")); descriptionText.AppendLine(string.Format("{{anchor:<Snapshot>[^{0}]</Snapshot>}}", "snapshot.png")); } } Issue issueJira = new Issue(); if (!isBcf) { issueJira.fields = new Fields(); issueJira.fields.description = descriptionText.ToString().Trim(); issueJira.fields.issuetype = (Issuetype)aid.issueTypeCombo.SelectedItem; issueJira.fields.priority = (Priority)aid.priorityCombo.SelectedItem; if (!string.IsNullOrEmpty(aid.ChangeAssign.Content.ToString()) && aid.ChangeAssign.Content.ToString() != "none") { issueJira.fields.assignee = new User(); issueJira.fields.assignee.name = aid.ChangeAssign.Tag.ToString(); } if (aid.SelectedComponents != null && aid.SelectedComponents.Any()) { issueJira.fields.components = aid.SelectedComponents; } if (!string.IsNullOrWhiteSpace(aid.JiraLabels.Text)) { var labels = aid.JiraLabels.Text.Split(',').ToList(); labels.ForEach(s => s.Trim()); issueJira.fields.labels = labels; } } issue.Viewpoints.Add(vp); issue.Topic.Title = aid.TitleBox.Text; issue.Topic.Description = descriptionText.ToString().Trim(); issue.Topic.AssignedTo = aid.BcfAssignee.Text; issue.Topic.CreationAuthor = string.IsNullOrWhiteSpace(MySettings.Get("username")) ? MySettings.Get("BCFusername") : MySettings.Get("username"); issue.Topic.Priority = aid.BcfPriority.Text; issue.Topic.TopicStatus = aid.VerbalStatus.Text; issue.Topic.TopicType = aid.BcfIssueType.Text; if (!string.IsNullOrWhiteSpace(aid.BcfLabels.Text)) { var labels = aid.BcfLabels.Text.Split(',').ToList(); labels.ForEach(s => s.Trim()); issue.Topic.Labels = labels.ToArray(); } issue.Header[0].IfcProject = ipcResponse.documentGuid; issue.Header[0].Filename = ipcResponse.documentName; issue.Header[0].Date = DateTime.Now; callback(new Tuple <Markup, Issue>(issue, issueJira)); } else { mainPan.DeleteDirectory(folderIssue); } } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } }); }