private void PublishItemCallback(object sender, EventArgs e) { if (_dte.SelectedItems.Count != 1) { return; } SelectedItem item = _dte.SelectedItems.Item(1); Project project = item.Project; CrmConn selectedConnection = GetSelectedConnection(project); if (selectedConnection == null) { return; } Guid assemblyId = SelectedAssemblyItem.Item.AssemblyId; if (assemblyId == Guid.Empty) { return; } CrmConnection connection = CrmConnection.Parse(selectedConnection.ConnectionString); UpdateAndPublishSingle(connection, project); }
private void PublishItemCallback(object sender, EventArgs e) { if (_dte.SelectedItems.Count != 1) { return; } SelectedItem item = _dte.SelectedItems.Item(1); ProjectItem projectItem = item.ProjectItem; //projectItem.IsDirty throws a not implemented exception for a .rdl file CrmConn selectedConnection = GetSelectedConnection(projectItem); if (selectedConnection == null) { return; } Guid reportId = GetMapping(projectItem, selectedConnection); if (reportId == Guid.Empty) { return; } CrmConnection connection = CrmConnection.Parse(selectedConnection.ConnectionString); UpdateAndPublishSingle(connection, projectItem, reportId); }
private void PublishItemCallback(object sender, EventArgs e) { if (_dte.SelectedItems.Count != 1) { return; } SelectedItem item = _dte.SelectedItems.Item(1); Project project = item.Project; CrmConn selectedConnection = (CrmConn)SharedGlobals.GetGlobal("SelectedConnection", _dte); if (selectedConnection == null) { return; } Guid assemblyId = SelectedAssemblyItem.Item.AssemblyId; if (assemblyId == Guid.Empty) { return; } var client = new CrmServiceClient(selectedConnection.ConnectionString); UpdateAndPublishSingle(client, project); }
private void PublishItemCallback(object sender, EventArgs e) { if (_dte.SelectedItems.Count != 1) { return; } SelectedItem item = _dte.SelectedItems.Item(1); ProjectItem projectItem = item.ProjectItem; CrmConn selectedConnection = (CrmConn)SharedGlobals.GetGlobal("SelectedConnection", _dte); if (selectedConnection == null) { return; } Guid reportId = GetMapping(projectItem, selectedConnection); if (reportId == Guid.Empty) { return; } var connection = new CrmServiceClient(selectedConnection.ConnectionString); UpdateAndPublishSingle(connection, projectItem, reportId); }
private void Connections_SelectionChanged(object sender, SelectionChangedEventArgs e) { _selectedConn = (CrmConn)Connections.SelectedItem; if (_selectedConn != null) { Connect.IsEnabled = !string.IsNullOrEmpty(_selectedConn.Name); Delete.IsEnabled = !string.IsNullOrEmpty(_selectedConn.Name); ModifyConnection.IsEnabled = !string.IsNullOrEmpty(_selectedConn.Name); if (_connectionAdded) { _connectionAdded = false; } else { UpdateSelectedConnection(false); } } else { Connect.IsEnabled = false; Delete.IsEnabled = false; ModifyConnection.IsEnabled = false; } Publish.IsEnabled = false; Assemblies.IsEnabled = false; }
private void Connections_SelectionChanged(object sender, SelectionChangedEventArgs e) { List <WebResourceItem> items = (List <WebResourceItem>)WebResourceGrid.ItemsSource; foreach (WebResourceItem webResourceItem in items) { webResourceItem.Publish = false; } CrmConn conn = (CrmConn)Connections.SelectedItem; if (conn != null) { Connect.IsEnabled = !string.IsNullOrEmpty(conn.Name); ModifyConnection.IsEnabled = !string.IsNullOrEmpty(conn.Name); } else { Connect.IsEnabled = false; ModifyConnection.IsEnabled = false; } WebResourceGrid.ItemsSource = null; WebResourceType.ItemsSource = null; WebResourceType.Items.Clear(); WebResourceType.IsEnabled = false; Publish.IsEnabled = false; WebResourceGrid.IsEnabled = false; }
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 void PublishItemCallback(object sender, EventArgs e) { if (_dte.SelectedItems.Count != 1) { return; } SelectedItem item = _dte.SelectedItems.Item(1); ProjectItem projectItem = item.ProjectItem; if (projectItem.IsDirty) { MessageBoxResult result = MessageBox.Show("Save item and publish?", "Unsaved Item", MessageBoxButton.YesNo); if (result != MessageBoxResult.Yes) { return; } projectItem.Save(); } //Build TypeScript project if (projectItem.Name.ToUpper().EndsWith("TS")) { SolutionBuild solutionBuild = _dte.Solution.SolutionBuild; solutionBuild.BuildProject(_dte.Solution.SolutionBuild.ActiveConfiguration.Name, projectItem.ContainingProject.UniqueName, true); } CrmConn selectedConnection = (CrmConn)SharedGlobals.GetGlobal("SelectedConnection", _dte); if (selectedConnection == null) { return; } Guid webResourceId = GetMapping(projectItem, selectedConnection); if (webResourceId == Guid.Empty) { return; } CrmServiceClient connection = new CrmServiceClient(selectedConnection.ConnectionString); //CrmConnection connection = CrmConnection.Parse(selectedConnection.ConnectionString); //Check if < CRM 2011 UR12 (ExecuteMutliple) Version version = Version.Parse(selectedConnection.Version); if (version.Major == 5 && version.Revision < 3200) { UpdateAndPublishSingle(connection, projectItem, webResourceId); } else { UpdateAndPublishMultiple(connection, projectItem, webResourceId); } }
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; } }
private void PublishItem_BeforeQueryStatus(object sender, EventArgs e) { OleMenuCommand menuCommand = sender as OleMenuCommand; if (menuCommand == null) { return; } bool windowOpen = false; foreach (Window window in _dte.Windows) { if (window.Caption != Resources.ResourceManager.GetString("ToolWindowTitle")) { continue; } windowOpen = window.Visible; break; } if (!windowOpen) { menuCommand.Visible = false; return; } if (_dte.SelectedItems.Count != 1) { menuCommand.Visible = false; return; } CrmConn selectedConnection = (CrmConn)SharedGlobals.GetGlobal("SelectedConnection", _dte); if (selectedConnection == null) { menuCommand.Visible = false; return; } if (SelectedAssemblyItem.Item == null) { menuCommand.Visible = false; return; } Guid assemblyId = SelectedAssemblyItem.Item.AssemblyId; menuCommand.Visible = assemblyId != Guid.Empty; }
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; }
private void PublishItemCallback(object sender, EventArgs e) { if (_dte.SelectedItems.Count != 1) { return; } SelectedItem item = _dte.SelectedItems.Item(1); ProjectItem projectItem = item.ProjectItem; if (projectItem.IsDirty) { MessageBoxResult result = MessageBox.Show("Save item and publish?", "Unsaved Item", MessageBoxButton.YesNo); if (result != MessageBoxResult.Yes) { return; } projectItem.Save(); } CrmConn selectedConnection = GetSelectedConnection(projectItem); if (selectedConnection == null) { return; } Guid webResourceId = GetMapping(projectItem, selectedConnection); if (webResourceId == Guid.Empty) { return; } CrmConnection connection = CrmConnection.Parse(selectedConnection.ConnectionString); //Check if < CRM 2011 UR12 (ExecuteMutliple) Version version = Version.Parse(selectedConnection.Version); if (version.Major == 5 && version.Revision < 3200) { UpdateAndPublishSingle(connection, projectItem, webResourceId); } else { UpdateAndPublishMultiple(connection, projectItem, webResourceId); } }
private void PublishItem_BeforeQueryStatus(object sender, EventArgs eventArgs) { OleMenuCommand menuCommand = sender as OleMenuCommand; if (menuCommand == null) { return; } bool windowOpen = false; foreach (Window window in _dte.Windows) { if (window.Caption != Resources.ResourceManager.GetString("ToolWindowTitle")) { continue; } windowOpen = window.Visible; break; } if (!windowOpen) { menuCommand.Visible = false; return; } if (_dte.SelectedItems.Count != 1) { menuCommand.Visible = false; return; } SelectedItem item = _dte.SelectedItems.Item(1); ProjectItem projectItem = item.ProjectItem; CrmConn selectedConnection = GetSelectedConnection(projectItem); if (selectedConnection == null) { menuCommand.Visible = false; return; } Guid webResourceId = GetMapping(projectItem, selectedConnection); menuCommand.Visible = webResourceId != Guid.Empty; }
public NewWebResource(CrmConn connection, Project project, ObservableCollection <ComboBoxItem> projectFiles, Guid selectedSolutionId) { InitializeComponent(); _logger = new Logger(); _connection = connection; bool result = GetSolutions(selectedSolutionId); if (!result) { MessageBox.Show("Error Retrieving Solutions From CRM. See the Output Window for additional details."); DialogResult = false; Close(); } Files.ItemsSource = projectFiles; }
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("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 AddOrUpdateMapping(WebResourceItem item) { CrmConn conn = (CrmConn)Connections.SelectedItem; var project = (Project)((ComboBoxItem)Projects.SelectedItem).Tag; var projectPath = Path.GetDirectoryName(project.FullName); XmlDocument doc = new XmlDocument(); doc.Load(projectPath + "\\CRMDeveloperExtensions.config"); //Update or delete existing mapping XmlNodeList fileNodes = doc.GetElementsByTagName("File"); if (fileNodes.Count > 0) { foreach (XmlNode node in fileNodes) { XmlNode orgId = node["OrgId"]; if (orgId != null && orgId.InnerText.ToUpper() != conn.OrgId.ToUpper()) { continue; } XmlNode webResourceId = node["WebResourceId"]; if (webResourceId != null && webResourceId.InnerText.ToUpper() != item.WebResourceId.ToString().ToUpper().Replace("{", String.Empty).Replace("}", String.Empty)) { continue; } if (string.IsNullOrEmpty(item.BoundFile)) { //Delete var parentNode = node.ParentNode; if (parentNode != null) { parentNode.RemoveChild(node); } } else { //Update XmlNode path = node["Path"]; if (path != null) { path.InnerText = item.BoundFile; } } doc.Save(projectPath + "\\CRMDeveloperExtensions.config"); return; } } //Create new mapping XmlNodeList files = doc.GetElementsByTagName("Files"); if (files.Count > 0) { XmlNode file = doc.CreateElement("File"); XmlNode org = doc.CreateElement("OrgId"); org.InnerText = conn.OrgId; file.AppendChild(org); XmlNode path = doc.CreateElement("Path"); path.InnerText = item.BoundFile; file.AppendChild(path); XmlNode webResourceId = doc.CreateElement("WebResourceId"); webResourceId.InnerText = item.WebResourceId.ToString(); file.AppendChild(webResourceId); XmlNode webResourceName = doc.CreateElement("WebResourceName"); webResourceName.InnerText = item.Name; file.AppendChild(webResourceName); files[0].AppendChild(file); doc.Save(projectPath + "\\CRMDeveloperExtensions.config"); } }
private List <WebResourceItem> HandleMappings(List <WebResourceItem> wrItems) { CrmConn conn = (CrmConn)Connections.SelectedItem; string projectName = ((ComboBoxItem)Projects.SelectedItem).Content.ToString(); Project project = GetProjectByName(projectName); if (project == null) { return(new List <WebResourceItem>()); } var path = Path.GetDirectoryName(project.FullName); XmlDocument doc = new XmlDocument(); doc.Load(path + "\\CRMDeveloperExtensions.config"); XmlNodeList mappedFiles = doc.GetElementsByTagName("File"); List <XmlNode> nodesToRemove = new List <XmlNode>(); foreach (WebResourceItem wrItem in wrItems) { foreach (XmlNode file in mappedFiles) { XmlNode orgIdNode = file["OrgId"]; if (orgIdNode == null) { continue; } if (orgIdNode.InnerText.ToUpper() != conn.OrgId.ToUpper()) { continue; } XmlNode webResourceId = file["WebResourceId"]; if (webResourceId == null) { continue; } if (webResourceId.InnerText.ToUpper() != wrItem.WebResourceId.ToString().ToUpper()) { continue; } XmlNode filePartialPath = file["Path"]; if (filePartialPath == null) { continue; } string filePath = Path.GetDirectoryName(project.FullName) + filePartialPath.InnerText.Replace("/", "\\"); if (!File.Exists(filePath)) { nodesToRemove.Add(file); } else { wrItem.BoundFile = filePartialPath.InnerText; } } } if (nodesToRemove.Count <= 0) { return(wrItems); } XmlNode files = nodesToRemove[0].ParentNode; foreach (XmlNode xmlNode in nodesToRemove) { if (files != null && files.ParentNode != null) { files.RemoveChild(xmlNode); } } doc.Save(path + "\\CRMDeveloperExtensions.config"); return(wrItems); }