public static void OpenCrmPage(string url, CrmConn selectedConnection, DTE dte) { if (selectedConnection == null) return; string connString = selectedConnection.ConnectionString; if (string.IsNullOrEmpty(connString)) return; string[] connParts = connString.Split(';'); string urlPart = connParts.FirstOrDefault(s => s.ToUpper().StartsWith("URL=")); if (!string.IsNullOrEmpty(urlPart)) { string[] urlParts = urlPart.Split('='); string baseUrl = (urlParts[1].EndsWith("/")) ? urlParts[1] : urlParts[1] + "/"; var props = dte.Properties["CRM Developer Extensions", "General"]; bool useDefaultWebBrowser = (bool)props.Item("UseDefaultWebBrowser").Value; if (useDefaultWebBrowser) //User's default browser System.Diagnostics.Process.Start(baseUrl + url); else //Internal VS browser dte.ItemOperations.Navigate(baseUrl + url); } }
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 (!SharedConfigFile.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", "Web Resource Deployer"]; 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 void GetConnections() { Connections.ItemsSource = null; var path = Path.GetDirectoryName(SelectedProject.FullName); XmlDocument doc = new XmlDocument(); if (!SharedConfigFile.ConfigFileExists(SelectedProject)) { _logger.WriteToOutputWindow("Error Retrieving Connections From Config File: Missing CRMDeveloperExtensions.config file", Logger.MessageType.Error); 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; if (Connections.SelectedIndex == -1 && crmConnections.Count > 0) Connections.SelectedIndex = 0; }