Example #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;
            }

            var client = new CrmServiceClient(selectedConnection.ConnectionString);

            UpdateAndPublishSingle(client, project);
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            //This gets executed as each code file is loaded
            //1st
            if (!(GetGlobalService(typeof(DTE)) is DTE dte))
            {
                return;
            }

            //bool useIntellisense = UserOptionsGrid.GetUseIntellisense(dte);
            //if (!useIntellisense)
            //    return;

            if (!(SharedGlobals.GetGlobal("CrmService", dte) is CrmServiceClient client))
            {
                return;
            }

            ITextView textView = AdapterService.GetWpfTextView(textViewAdapter);

            if (textView == null)
            {
                return;
            }

            CrmCompletionCommandHandler CreateCommandHandler() => new CrmCompletionCommandHandler(textViewAdapter, textView, this);

            textView.Properties.GetOrCreateSingletonProperty(CreateCommandHandler);

            if (CrmMetadata.Metadata == null)
            {
                CrmMetadata.GetMetadata(client);
            }
        }
Example #3
0
        public void SolutionEventsOnBeforeClosing()
        {
            try
            {
                if (!(GetGlobalService(typeof(DTE)) is DTE dte))
                {
                    throw new ArgumentNullException(Core.Resources.Resource.ErrorMessage_ErrorAccessingDTE);
                }

                SharedGlobals.SetGlobal("UseCrmIntellisense", null, dte);

                if (SharedGlobals.GetGlobal("CrmService", dte) != null)
                {
                    SharedGlobals.SetGlobal("CrmService", null, dte);
                }

                if (SharedGlobals.GetGlobal("CrmMetadata", dte) != null)
                {
                    SharedGlobals.SetGlobal("CrmMetadata", null, dte);
                    OutputLogger.WriteToOutputWindow("Clearing metadata", MessageType.Info);
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.LogException(Logger, null, ex);
                throw;
            }
        }
Example #4
0
        private void GetUserOptions(DTE dte)
        {
            var intellisenseOptions = (UserOptionsGridIntellisense)GetDialogPage(typeof(UserOptionsGridIntellisense));

            SharedGlobals.SetGlobal("IntellisenseEntityTriggerCharacter", intellisenseOptions.IntellisenseEntityTriggerCharacter, dte);
            SharedGlobals.SetGlobal("IntellisenseFieldTriggerCharacter", intellisenseOptions.IntellisenseFieldTriggerCharacter, dte);
            SharedGlobals.SetGlobal("UseIntellisense", intellisenseOptions.UseIntellisense, dte);

            var loggingOptions = (UserOptionsGridLogging)GetDialogPage(typeof(UserOptionsGridLogging));

            SharedGlobals.SetGlobal("ExtensionLoggingEnabled", loggingOptions.ExtensionLoggingEnabled, dte);
            SharedGlobals.SetGlobal("ExtensionLogFilePath", loggingOptions.ExtensionLogFilePath, dte);
            SharedGlobals.SetGlobal("XrmToolingLogFilePath", loggingOptions.XrmToolingLogFilePath, dte);
            SharedGlobals.SetGlobal("XrmToolingLoggingEnabled", loggingOptions.XrmToolingLoggingEnabled, dte);

            var templateOptions = (UserOptionsGridTemplates)GetDialogPage(typeof(UserOptionsGridTemplates));

            SharedGlobals.SetGlobal("CustomTemplatesPath", templateOptions.CustomTemplatesPath, dte);
            SharedGlobals.SetGlobal("DefaultKeyFileName", templateOptions.DefaultKeyFileName, dte);

            var toolsOptions = (UserOptionsGridTools)GetDialogPage(typeof(UserOptionsGridTools));

            SharedGlobals.SetGlobal("CrmSvcUtilToolPath", toolsOptions.CrmSvcUtilToolPath, dte);
            SharedGlobals.SetGlobal("PluginRegistrationToolPath", toolsOptions.PluginRegistrationToolPath, dte);
            SharedGlobals.SetGlobal("SolutionPackagerToolPath", toolsOptions.SolutionPackagerToolPath, dte);

            var webBrowserOptions = (UserOptionsGridWebBrowser)GetDialogPage(typeof(UserOptionsGridWebBrowser));

            SharedGlobals.SetGlobal("UseInternalBrowser", webBrowserOptions.UseInternalBrowser, dte);
        }
Example #5
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;
            }

            var connection = new CrmServiceClient(selectedConnection.ConnectionString);

            UpdateAndPublishSingle(connection, projectItem, reportId);
        }
Example #6
0
        private static void DisplayCrmIntellisense(object sender, EventArgs eventArgs)
        {
            if (!(sender is OleMenuCommand menuCommand))
            {
                return;
            }

            bool useIntellisense = UserOptionsHelper.GetOption <bool>(UserOptionProperties.UseIntellisense);

            if (!useIntellisense)
            {
                return;
            }

            var value = SharedGlobals.GetGlobal("UseCrmIntellisense", _dte);

            if (value == null)
            {
                menuCommand.Visible = menuCommand.CommandID.ID == 264;
                return;
            }

            bool isEnabled = (bool)value;

            if (isEnabled)
            {
                menuCommand.Visible = menuCommand.CommandID.ID != 264;
            }
            else
            {
                menuCommand.Visible = menuCommand.CommandID.ID == 264;
            }
        }
Example #7
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 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 SetGlobalConnection(CrmServiceClient client)
        {
            if (!(Package.GetGlobalService(typeof(DTE)) is DTE dte))
            {
                return;
            }

            SharedGlobals.SetGlobal("CrmService", client, dte);
        }
Example #9
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;
        }
Example #10
0
        private static void ToggleCrmIntellisense(object sender, EventArgs e, DTE dte)
        {
            bool isEnabled;
            var  value = SharedGlobals.GetGlobal("UseCrmIntellisense", dte);

            if (value == null)
            {
                isEnabled = false;
                SharedGlobals.SetGlobal("UseCrmIntellisense", true, dte);
            }
            else
            {
                isEnabled = (bool)value;
                SharedGlobals.SetGlobal("UseCrmIntellisense", !isEnabled, dte);
            }

            ExLogger.LogToFile(Logger, $"{Resource.Message_CRMIntellisenseEnabled}: {!isEnabled}", LogLevel.Info);

            if (!isEnabled) //On
            {
                if (HostWindow.IsCrmDexWindowOpen(dte) && SharedGlobals.GetGlobal("CrmService", dte) != null)
                {
                    return;
                }
            }
            else
            {
                if (!HostWindow.IsCrmDexWindowOpen(dte) && SharedGlobals.GetGlobal("CrmService", dte) != null)
                {
                    SharedGlobals.SetGlobal("CrmService", null, dte);
                }

                CrmMetadata.Metadata = null;
                SharedGlobals.SetGlobal("CrmMetadata", null, dte);

                ExLogger.LogToFile(Logger, Resource.Message_ClearingMetadata, LogLevel.Info);
                OutputLogger.WriteToOutputWindow(Resource.Message_ClearingMetadata, MessageType.Info);

                return;
            }

            var result = MessageBox.Show(Resource.MessageBox_ConnectToCrm, Resource.MessageBox_ConnectToCrm_Title,
                                         MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }

            ConnectToCrm();
        }
Example #11
0
        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 = (CrmConn)SharedGlobals.GetGlobal("SelectedConnection", _dte);

            if (selectedConnection == null)
            {
                menuCommand.Visible = false;
                return;
            }

            Guid webResourceId = GetMapping(projectItem, selectedConnection);

            menuCommand.Visible = webResourceId != Guid.Empty;
        }
Example #12
0
        public void SolutionEventsOnBeforeClosing()
        {
            SharedGlobals.SetGlobal("UseCrmIntellisense", null, _dte);

            if (SharedGlobals.GetGlobal("CrmService", _dte) != null)
            {
                SharedGlobals.SetGlobal("CrmService", null, _dte);
            }

            if (SharedGlobals.GetGlobal("CrmMetadata", _dte) != null)
            {
                SharedGlobals.SetGlobal("CrmMetadata", null, _dte);
                OutputLogger.WriteToOutputWindow("Clearing metadata", MessageType.Info);
            }
        }
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            //This gets executed 1st as each code file is loaded
            if (!(Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(DTE)) is DTE dte))
            {
                return;
            }

            if (!(SharedGlobals.GetGlobal("CrmService", dte) is CrmServiceClient client))
            {
                return;
            }

            if (!IsIntellisenseEnabled(dte))
            {
                return;
            }

            ITextView textView = AdapterService.GetWpfTextView(textViewAdapter);

            if (textView == null)
            {
                return;
            }

            CrmJsCompletionCommandHandler CreateCommandHandler() => new CrmJsCompletionCommandHandler(textViewAdapter, textView, this);

            textView.Properties.GetOrCreateSingletonProperty(CreateCommandHandler);

            var metadata = SharedGlobals.GetGlobal("CrmMetadata", dte);

            if (metadata != null)
            {
                return;
            }

            var infoBar      = new InfoBar(false);
            var infoBarModel = CreateMetadataInfoBar();

            infoBar.ShowInfoBar(infoBarModel);

            GetData(client, infoBar);
        }
Example #14
0
        public bool IsIntellisenseEnabled(DTE dte)
        {
            var useIntellisense = UserOptionsHelper.GetOption <bool>(UserOptionProperties.UseIntellisense);

            if (!useIntellisense)
            {
                return(false);
            }

            var value = SharedGlobals.GetGlobal("UseCrmIntellisense", dte);

            if (value == null)
            {
                return(false);
            }

            var isEnabled = (bool?)value;

            return(!(bool)!isEnabled);
        }
        void ICompletionSource.AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            if (!PositionHelper.IsStringLiteral(session, _mTextBuffer))
            {
                return;
            }

            if (!(Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(DTE)) is DTE dte))
            {
                return;
            }

            var metadata = (List <Completion>)SharedGlobals.GetGlobal("CrmMetadata", dte);

            if (metadata == null)
            {
                if (CrmMetadata.Metadata == null)
                {
                    return;
                }

                var strList = CrmMetadata.Metadata;
                metadata = new List <Completion>();
                foreach (var completionValue in strList)
                {
                    metadata.Add(new Completion(completionValue.Name, completionValue.Replacement,
                                                completionValue.Description, MonikerHelper.GetImage(completionValue.MetadataType), null));
                }

                SharedGlobals.SetGlobal("CrmMetadata", metadata, dte);
            }

            completionSets.Add(new CompletionSet(
                                   "CRM",
                                   "CRM",
                                   FindTokenSpanAtPosition(session.GetTriggerPoint(_mTextBuffer), session),
                                   metadata,
                                   null)
                               );
        }
 private static void SetGlobalConnection(CrmServiceClient client)
 {
     SharedGlobals.SetGlobal("CrmService", client);
 }
Example #17
0
        public static T GetOption <T>(UserOptionProperty userOptionProperty)
        {
            var option = SharedGlobals.GetGlobal(userOptionProperty.Name);

            return((T)option);
        }
Example #18
0
 public static void SetOption <T>(UserOptionProperty userOptionProperty, T value)
 {
     SharedGlobals.SetGlobal(userOptionProperty.Name, value);
 }