コード例 #1
0
        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;
            }

            CrmServiceClient client = SharedConnection.GetCurrentConnection(selectedConnection.ConnectionString, WindowType, _dte);

            UpdateAndPublishSingle(client, project);
        }
コード例 #2
0
        private async void UpdateAssembly(AssemblyItem assemblyItem)
        {
            string  projectName = ConnPane.SelectedProject.Name;
            Project project     = GetProjectByName(projectName);

            if (project == null)
            {
                return;
            }

            string connString = ConnPane.SelectedConnection.ConnectionString;

            if (connString == null)
            {
                return;
            }
            CrmServiceClient client = SharedConnection.GetCurrentConnection(connString, WindowType, _dte);

            LockMessage.Content    = "Updating...";
            LockOverlay.Visibility = Visibility.Visible;

            bool success = await Task.Run(() => UpdateCrmAssembly(assemblyItem, client));

            LockOverlay.Visibility = Visibility.Hidden;

            if (success)
            {
                return;
            }

            MessageBox.Show("Error Updating Assembly. See the Output Window for additional details.");
            _dte.StatusBar.Clear();
        }
コード例 #3
0
        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;
            }

            CrmServiceClient client = SharedConnection.GetCurrentConnection(selectedConnection.ConnectionString, WindowType, _dte);

            UpdateAndPublishSingle(client, projectItem, reportId);
        }
コード例 #4
0
        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 client = SharedConnection.GetCurrentConnection(selectedConnection.ConnectionString, WindowType, _dte);

            //Check if < CRM 2011 UR12 (ExecuteMutliple)
            Version version = Version.Parse(selectedConnection.Version);

            if (version.Major == 5 && version.Revision < 3200)
            {
                UpdateAndPublishSingle(client, projectItem, webResourceId);
            }
            else
            {
                UpdateAndPublishMultiple(client, projectItem, webResourceId);
            }
        }
コード例 #5
0
        private bool GetSolutions(Guid selectedSolutionId)
        {
            try
            {
                List <CrmSolution> solutions = new List <CrmSolution>();

                CrmServiceClient client = SharedConnection.GetCurrentConnection(_connection.ConnectionString, WindowType, _dte);
                QueryExpression  query  = new QueryExpression
                {
                    EntityName = "solution",
                    ColumnSet  = new ColumnSet("friendlyname", "solutionid", "uniquename"),
                    Criteria   = new FilterExpression
                    {
                        Conditions =
                        {
                            new ConditionExpression
                            {
                                AttributeName = "ismanaged",
                                Operator      = ConditionOperator.Equal,
                                Values        = { false }
                            },
                            new ConditionExpression
                            {
                                AttributeName = "isvisible",
                                Operator      = ConditionOperator.Equal,
                                Values        = { true  }
                            }
                        }
                    },
                    LinkEntities =
                    {
                        new LinkEntity
                        {
                            LinkFromEntityName    = "solution",
                            LinkFromAttributeName = "publisherid",
                            LinkToEntityName      = "publisher",
                            LinkToAttributeName   = "publisherid",
                            Columns     = new ColumnSet("customizationprefix"),
                            EntityAlias = "publisher"
                        }
                    },
                    Orders =
                    {
                        new OrderExpression
                        {
                            AttributeName = "friendlyname",
                            OrderType     = OrderType.Ascending
                        }
                    }
                };

                EntityCollection results = client.RetrieveMultiple(query);


                foreach (Entity entity in results.Entities)
                {
                    CrmSolution solution = new CrmSolution
                    {
                        SolutionId = entity.Id,
                        Name       = entity.GetAttributeValue <string>("friendlyname"),
                        Prefix     = entity.GetAttributeValue <AliasedValue>("publisher.customizationprefix").Value.ToString(),
                        UniqueName = entity.GetAttributeValue <string>("uniquename")
                    };

                    solutions.Add(solution);
                }

                //Default on top
                var i    = solutions.FindIndex(s => s.SolutionId == new Guid("FD140AAF-4DF4-11DD-BD17-0019B9312238"));
                var item = solutions[i];
                solutions.RemoveAt(i);
                solutions.Insert(0, item);

                if (selectedSolutionId != Guid.Empty)
                {
                    var sel = solutions.FindIndex(s => s.SolutionId == selectedSolutionId);
                    if (sel != -1)
                    {
                        Solutions.SelectedIndex = sel;
                    }
                }

                Solutions.ItemsSource = solutions;

                return(true);
            }
            catch (FaultException <OrganizationServiceFault> crmEx)
            {
                _logger.WriteToOutputWindow("Error Retrieving Solutions From CRM: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, Logger.MessageType.Error);
                return(false);
            }
            catch (Exception ex)
            {
                _logger.WriteToOutputWindow("Error Retrieving Solutions From CRM: " + ex.Message + Environment.NewLine + ex.StackTrace, Logger.MessageType.Error);
                return(false);
            }
        }
コード例 #6
0
        private bool CreateWebResource(Guid solutionId, string uniqueName, int type, string prefix, string name, string displayName, string filePath, string relativePath)
        {
            try
            {
                CrmServiceClient client      = SharedConnection.GetCurrentConnection(_connection.ConnectionString, WindowType, _dte);
                Entity           webResource = new Entity("webresource");
                webResource["name"]            = prefix + name;
                webResource["webresourcetype"] = new OptionSetValue(type);
                if (!string.IsNullOrEmpty(displayName))
                {
                    webResource["displayname"] = displayName;
                }

                if (type == 8)
                {
                    webResource["silverlightversion"] = "4.0";
                }

                string extension = Path.GetExtension(filePath);

                List <string> imageExs = new List <string>()
                {
                    ".ICO", ".PNG", ".GIF", ".JPG"
                };
                string content;
                //TypeScript
                if (extension != null && (extension.ToUpper() == ".TS"))
                {
                    content = File.ReadAllText(Path.ChangeExtension(filePath, ".js"));
                    webResource["content"] = EncodeString(content);
                }
                //Images
                else if (extension != null && imageExs.Any(s => extension.ToUpper().EndsWith(s)))
                {
                    content = EncodedImage(filePath, extension);
                    webResource["content"] = content;
                }
                //Everything else
                else
                {
                    content = File.ReadAllText(filePath);
                    webResource["content"] = EncodeString(content);
                }

                Guid id = client.Create(webResource);

                _logger.WriteToOutputWindow("New Web Resource Created: " + id, Logger.MessageType.Info);

                //Add to the choosen solution (not default)
                if (solutionId != new Guid("FD140AAF-4DF4-11DD-BD17-0019B9312238"))
                {
                    AddSolutionComponentRequest scRequest = new AddSolutionComponentRequest
                    {
                        ComponentType      = 61,
                        SolutionUniqueName = uniqueName,
                        ComponentId        = id
                    };
                    AddSolutionComponentResponse response =
                        (AddSolutionComponentResponse)client.Execute(scRequest);

                    _logger.WriteToOutputWindow("New Web Resource Added To Solution: " + response.id, Logger.MessageType.Info);
                }

                NewId   = id;
                NewType = type;
                NewName = prefix + name;
                if (!string.IsNullOrEmpty(displayName))
                {
                    NewDisplayName = displayName;
                }
                NewBoundFile  = relativePath;
                NewSolutionId = solutionId;

                return(true);
            }
            catch (FaultException <OrganizationServiceFault> crmEx)
            {
                _logger.WriteToOutputWindow("Error Creating Web Resource: " + crmEx.Message + Environment.NewLine + crmEx.StackTrace, Logger.MessageType.Error);
                return(false);
            }
            catch (Exception ex)
            {
                _logger.WriteToOutputWindow("Error Creating Web Resource: " + ex.Message + Environment.NewLine + ex.StackTrace, Logger.MessageType.Error);
                return(false);
            }
        }
コード例 #7
0
        private async Task <bool> GetPlugins(string connString)
        {
            _dte.StatusBar.Text = "Connecting to CRM...";
            _dte.StatusBar.Animate(true, vsStatusAnimation.vsStatusAnimationSync);
            LockMessage.Content    = "Working...";
            LockOverlay.Visibility = Visibility.Visible;

            CrmServiceClient client = SharedConnection.GetCurrentConnection(ConnPane.SelectedConnection.ConnectionString, WindowType, _dte);

            _dte.StatusBar.Text = "Getting assemblies...";

            EntityCollection results = await Task.Run(() => RetrieveAssembliesFromCrm(client));

            if (results == null)
            {
                SharedConnection.ClearCurrentConnection(WindowType, _dte);
                _dte.StatusBar.Clear();
                _dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationSync);
                LockOverlay.Visibility = Visibility.Hidden;
                MessageBox.Show("Error Retrieving Assemblies. See the Output Window for additional details.");
                return(false);
            }

            _logger.WriteToOutputWindow("Retrieved Assemblies From CRM", Logger.MessageType.Info);

            ObservableCollection <AssemblyItem> assemblies = new ObservableCollection <AssemblyItem>();

            AssemblyItem emptyItem = new AssemblyItem
            {
                AssemblyId = Guid.Empty,
                Name       = String.Empty
            };

            assemblies.Add(emptyItem);

            foreach (var entity in results.Entities)
            {
                AssemblyItem aItem = new AssemblyItem
                {
                    AssemblyId         = entity.Id,
                    Name               = entity.GetAttributeValue <string>("name"),
                    Version            = Version.Parse(entity.GetAttributeValue <string>("version")),
                    DisplayName        = entity.GetAttributeValue <string>("name") + " (" + entity.GetAttributeValue <string>("version") + ")",
                    IsWorkflowActivity = false
                };

                //Only need to process the 1st assembly/type combination returned
                if (assemblies.Count(a => a.AssemblyId == aItem.AssemblyId) > 0)
                {
                    continue;
                }

                if (entity.Contains("plugintype.isworkflowactivity"))
                {
                    aItem.IsWorkflowActivity = (bool)entity.GetAttributeValue <AliasedValue>("plugintype.isworkflowactivity").Value;
                }

                aItem.DisplayName += (aItem.IsWorkflowActivity) ? " [Workflow]" : " [Plug-in]";

                assemblies.Add(aItem);
            }

            assemblies             = HandleMappings(assemblies);
            Assemblies.ItemsSource = assemblies;
            if (assemblies.Count(a => !string.IsNullOrEmpty(a.BoundProject)) > 0)
            {
                Assemblies.SelectedItem = assemblies.First(a => !string.IsNullOrEmpty(a.BoundProject));
            }
            Assemblies.IsEnabled = true;

            _dte.StatusBar.Clear();
            _dte.StatusBar.Animate(false, vsStatusAnimation.vsStatusAnimationSync);
            LockOverlay.Visibility = Visibility.Hidden;

            return(true);
        }