public NewWebResource(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("AllowPublishManagedWebResources").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 webResourceIdNode = file["WebResourceId"]; if (webResourceIdNode == null) return Guid.Empty; Guid webResourceId; bool isGuid = Guid.TryParse(webResourceIdNode.InnerText, out webResourceId); if (!isGuid) return Guid.Empty; return webResourceId; } 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; }
private void GetConnections(Project vsProject) { Connections.Items.Clear(); var path = Path.GetDirectoryName(vsProject.FullName); XmlDocument doc = new XmlDocument(); if (!File.Exists(path + "\\CRMDeveloperExtensions.config")) return; doc.Load(path + "\\CRMDeveloperExtensions.config"); XmlNodeList connections = doc.GetElementsByTagName("Connection"); if (connections.Count == 0) return; List<CrmConn> crmConnections = new List<CrmConn>(); foreach (XmlNode node in connections) { CrmConn conn = new CrmConn(); XmlNode nameNode = node["Name"]; if (nameNode != null) conn.Name = nameNode.InnerText; XmlNode connectionStringNode = node["ConnectionString"]; if (connectionStringNode != null) conn.ConnectionString = DecodeString(connectionStringNode.InnerText); XmlNode orgIdNode = node["OrgId"]; if (orgIdNode != null) conn.OrgId = orgIdNode.InnerText; XmlNode versionNode = node["Version"]; if (versionNode != null) conn.Version = versionNode.InnerText; crmConnections.Add(conn); } Connections.ItemsSource = crmConnections; }