public NewReport(CrmConn connection, Project project, ObservableCollection<ComboBoxItem> projectFiles) { InitializeComponent(); _logger = new Logger(); _connection = connection; _project = project; bool result = GetSolutions(); if (!result) { MessageBox.Show("Error Retrieving Solutions From CRM. See the Output Window for additional details."); DialogResult = false; Close(); } Files.ItemsSource = projectFiles; }
private Guid GetMapping(ProjectItem projectItem, CrmConn selectedConnection) { try { Project project = projectItem.ContainingProject; var projectPath = Path.GetDirectoryName(project.FullName); if (projectPath == null) return Guid.Empty; var boundName = projectItem.FileNames[1].Replace(projectPath, String.Empty).Replace("\\", "/"); if (!File.Exists(projectItem.FileNames[1])) return Guid.Empty; var path = Path.GetDirectoryName(project.FullName); if (!ConfigFileExists(project)) { _logger.WriteToOutputWindow("Error Getting Mapping: Missing CRMDeveloperExtensions.config File", Logger.MessageType.Error); return Guid.Empty; } XmlDocument doc = new XmlDocument(); doc.Load(path + "\\CRMDeveloperExtensions.config"); if (string.IsNullOrEmpty(selectedConnection.ConnectionString)) return Guid.Empty; if (string.IsNullOrEmpty(selectedConnection.OrgId)) return Guid.Empty; var props = _dte.Properties["CRM Developer Extensions", "Settings"]; bool allowPublish = (bool)props.Item("AllowPublishManagedReports").Value; //Get the mapped file info XmlNodeList mappedFiles = doc.GetElementsByTagName("File"); foreach (XmlNode file in mappedFiles) { XmlNode orgIdNode = file["OrgId"]; if (orgIdNode == null) continue; if (orgIdNode.InnerText.ToUpper() != selectedConnection.OrgId.ToUpper()) continue; XmlNode pathNode = file["Path"]; if (pathNode == null) continue; if (pathNode.InnerText.ToUpper() != boundName.ToUpper()) continue; XmlNode isManagedNode = file["IsManaged"]; if (isManagedNode == null) continue; bool isManaged; bool isBool = Boolean.TryParse(isManagedNode.InnerText, out isManaged); if (!isBool) continue; if (isManaged && !allowPublish) return Guid.Empty; XmlNode reportIdNode = file["ReportId"]; if (reportIdNode == null) return Guid.Empty; Guid reportId; bool isGuid = Guid.TryParse(reportIdNode.InnerText, out reportId); if (!isGuid) return Guid.Empty; return reportId; } return Guid.Empty; } catch (Exception ex) { _logger.WriteToOutputWindow("Error Getting Mapping: " + ex.Message + Environment.NewLine + ex.StackTrace, Logger.MessageType.Error); return Guid.Empty; } }
private CrmConn GetSelectedConnection(ProjectItem projectItem) { CrmConn selectedConnection = new CrmConn(); Project project = projectItem.ContainingProject; var projectPath = Path.GetDirectoryName(project.FullName); if (projectPath == null) return selectedConnection; var path = Path.GetDirectoryName(project.FullName); if (!ConfigFileExists(project)) return null; XmlDocument doc = new XmlDocument(); doc.Load(path + "\\CRMDeveloperExtensions.config"); XmlNodeList connections = doc.GetElementsByTagName("Connection"); if (connections.Count == 0) return selectedConnection; //Get the selected Connection info foreach (XmlNode node in connections) { XmlNode selectedNode = node["Selected"]; if (selectedNode == null) continue; bool selected; bool isBool = Boolean.TryParse(selectedNode.InnerText, out selected); if (!isBool) continue; if (!selected) continue; XmlNode connectionStringNode = node["ConnectionString"]; if (connectionStringNode == null) continue; selectedConnection.ConnectionString = DecodeString(connectionStringNode.InnerText); XmlNode orgIdNode = node["OrgId"]; if (orgIdNode == null) continue; selectedConnection.OrgId = orgIdNode.InnerText; XmlNode vesionNode = node["Version"]; if (vesionNode == null) continue; selectedConnection.Version = vesionNode.InnerText; break; } return selectedConnection; }