Beispiel #1
0
        private void ButtonRemoveStep_Click(object sender, RoutedEventArgs e)
        {
            var type  = (CrmPluginType)ListPluginTypes.SelectedItem;
            var steps = ListTypeSteps.SelectedItems.Cast <CrmTypeStep>().ToList();

            var isConfirmed = DteHelper.IsConfirmed(
                "Are you sure you want to DELETE steps(s):" +
                $" {steps.Select(step => step.Name).Aggregate((step1Name, step2Name) => step1Name + ", " + step2Name)}?",
                "Step(s) Deletion");

            if (!isConfirmed)
            {
                return;
            }

            new Thread(() =>
            {
                try
                {
                    steps.ForEach(step =>
                    {
                        assemblyRegistration.DeleteTypeStep(step.Id);
                        Dispatcher.Invoke(() => type.Children.Remove(step));
                    });
                }
                catch (Exception exception)
                {
                    PopException(exception);
                }
                finally
                {
                    HideBusy();
                }
            }).Start();
        }
        private void DeleteObsoleteTypes()
        {
            var pluginClasses = AssemblyHelper.GetClasses <IPlugin>();
            var wfClasses     = AssemblyHelper.GetClasses <CodeActivity>();

            var existingTypes = CrmAssemblyHelper.GetCrmTypes(Id, Context);

            var nonExistentTypes = existingTypes
                                   .Where(pluginType => !pluginClasses.Contains(pluginType.TypeName) &&
                                          !wfClasses.Contains(pluginType.TypeName)).ToList();

            // delete non-existing types
            if (nonExistentTypes.Any())
            {
                if (DteHelper.IsConfirmed("Please confirm that you want to DELETE non-existent types in this assembly." +
                                          " This means that all its steps will be deleted!", "Type deletion"))
                {
                    UpdateStatus("Deleting non-existent types ... ", 1);

                    nonExistentTypes.ForEach(pluginType => DeleteTree(pluginType.Id,
                                                                      Dependency.Enums.RequiredComponentType.PluginType));

                    UpdateStatus("Finished deleting non-existent types.", -1);
                }
                else
                {
                    throw new Exception("Can't update assembly with obsolete types in the system.");
                }
            }
        }
Beispiel #3
0
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            // can't fetch assembly without an ID
            if (assemblyRegistration.Id == Guid.Empty)
            {
                DteHelper.ShowInfo("Can't delete a non-existent assembly.", "Non-existent assembly!");
                return;
            }

            if (DteHelper.IsConfirmed("Are you sure you want to UNregister this plugin?" +
                                      " This means that the plugin and all its steps will be deleted!", "Unregistration"))
            {
                new Thread(() =>
                {
                    try
                    {
                        assemblyRegistration.DeleteAssembly(assemblyRegistration.Id);
                        crmAssembly.Clear();
                    }
                    catch (Exception exception)
                    {
                        PopException(exception);
                    }
                    finally
                    {
                        UpdateStatus("", false);
                    }
                }).Start();
            }
        }
Beispiel #4
0
        private void ButtonRemoveImage_Click(object sender, RoutedEventArgs e)
        {
            var step   = (CrmTypeStep)ListTypeSteps.SelectedItem;
            var images = ListStepImages.SelectedItems.Cast <CrmStepImage>().ToList();

            var isConfirmed = DteHelper.IsConfirmed(
                "Are you sure you want to DELETE image(s):" +
                $" {images.Select(image => image.Name).Aggregate((image1Name, image2Name) => image1Name + ", " + image2Name)}?",
                "Image(s) Deletion");

            if (!isConfirmed)
            {
                return;
            }

            new Thread(() =>
            {
                try
                {
                    images.ForEach(image =>
                    {
                        assemblyRegistration.DeleteStepImage(image.Id);
                        Dispatcher.Invoke(() => step.Children.Remove(image));
                    });
                }
                catch (Exception exception)
                {
                    PopException(exception);
                }
                finally
                {
                    HideBusy();
                }
            }).Start();
        }
Beispiel #5
0
 private void DeletePluginCallback(object sender, EventArgs args)
 {
     try
     {
         if (DteHelper.IsConfirmed("Are you sure you want to UNregister this plugin?" +
                                   " This means that the plugin and all its steps will be deleted!", "Unregistration"))
         {
             Status.Update(">>>>> Starting new session <<<<<");
             DeletePlugin();
         }
     }
     catch (UserException e)
     {
         VsShellUtilities.ShowMessageBox(ServiceProvider.GlobalProvider, e.Message, "Error", OLEMSGICON.OLEMSGICON_WARNING,
                                         OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
     }
     catch (Exception e)
     {
         var error1 = "[ERROR] " + e.Message
                      + (e.InnerException != null ? "\n" + "[ERROR] " + e.InnerException.Message : "");
         Status.Update(error1);
         Status.Update(e.StackTrace);
         Status.Update("Unable to delete assembly, see error above.");
         var error2 = e.Message + "\n" + e.StackTrace;
         MessageBox.Show(error2, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     finally
     {
         Status.Update(">>>>> DONE! <<<<<");
     }
 }
Beispiel #6
0
        private void ButtonNewSettings_Click(object sender, RoutedEventArgs e)
        {
            var isMigrate = DteHelper.IsConfirmed("Current settings will be deleted and new settings will be created.\r\n\r\n"
                                                  + "Would you like to proceed?",
                                                  ">> WARNING << Settings Reset");

            if (isMigrate)
            {
                settings = Configuration.CreateNewSettings();
                Initialise();
                DteHelper.ShowInfo("Settings has been reset.",
                                   "Settings Reset");
            }
        }
Beispiel #7
0
        private void ButtonDeleteFilter_Click(object sender, RoutedEventArgs e)
        {
            if (EntityFilterList.EntityFilters.Count <= 1)
            {
                PopException(new Exception("Can't delete the last filter profile."));
                return;
            }

            if (DteHelper.IsConfirmed("Are you sure you want to delete this filter profile? This will affect other entities!",
                                      "Confirm delete action ..."))
            {
                EntityFilterList.EntityFilters.Remove(EntityFilterList.GetSelectedFilter());
            }
        }
Beispiel #8
0
        private void ButtonDeleteSettings_Click(object sender, RoutedEventArgs e)
        {
            if (settingsArray.SettingsList.Count <= 1)
            {
                PopException(new Exception("Can't delete the last settings profile."));
                return;
            }

            if (DteHelper.IsConfirmed("Are you sure you want to delete this settings profile?",
                                      "Confirm delete action ..."))
            {
                settingsArray.SettingsList.Remove(settingsArray.GetSelectedSettings());
                settingsArray.SelectedSettingsIndex = 0;
            }
        }
        public int Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace,
                            IntPtr[] rgbOutputFileContents, out uint pcbOutput, IVsGeneratorProgress pGenerateProgress)
        {
            bstrInputFileContents.Require(nameof(bstrInputFileContents));
            wszInputFilePath.RequireNotEmpty(nameof(wszInputFilePath));

            Status.Clear();

            var dte = Package.GetGlobalService(typeof(SDTE)) as DTE2;

            Configuration.FileName = Path.GetFileNameWithoutExtension(wszInputFilePath);

            var project = dte.GetSelectedProject();
            var file    = $@"{project.GetPath()}\{Configuration.FileName}.dat";

            if (File.Exists(file))
            {
                var isMigrate = DteHelper.IsConfirmed("Pre-v7 settings found, which will be converted to the current format.\r\n\r\n"
                                                      + "Only the LAST selected profile will be migrated -- all other profiles will be DELETED.\r\n\r\n"
                                                      + "If unsure, reinstall pre-v7 Generator and select the profile you would like migrated,"
                                                      + " and then upgrade again.\r\n\r\n"
                                                      + "Would you like to proceed?",
                                                      ">> WARNING << Settings Migration");

                if (isMigrate)
                {
                    isMigrate = DteHelper.IsConfirmed("Only the LAST selected profile will be migrated"
                                                      + " -- all other profiles will be DELETED.\r\n\r\n"
                                                      + "Are you sure?",
                                                      ">> WARNING << Settings Migration");
                }

                if (!isMigrate)
                {
                    return(Cancel(wszInputFilePath, rgbOutputFileContents, out pcbOutput));
                }
            }

            var m = new Login(dte);

            m.ShowModal();
            context = m.Context;

            if (context == null)
            {
                return(Cancel(wszInputFilePath, rgbOutputFileContents, out pcbOutput));
            }

            Status.Update("[Generator] Generating code from template ... ");

            if (!(Package.GetGlobalService(typeof(STextTemplating)) is ITextTemplating t4))
            {
                throw new ArgumentNullException(nameof(t4), "Failed to build T4 object.");
            }

            if (!(t4 is ITextTemplatingSessionHost sessionHost))
            {
                throw new ArgumentNullException(nameof(sessionHost), "Failed to build Session Host object.");
            }

            context.Namespace              = wszDefaultNamespace;
            context.FileName               = Configuration.FileName;
            sessionHost.Session            = sessionHost.CreateSession();
            sessionHost.Session["Context"] = context;

            var cb = new Callback();

            t4.BeginErrorSession();
            var content = t4.ProcessTemplate(wszInputFilePath, bstrInputFileContents, cb);

            t4.EndErrorSession();

            // Append any error/warning to output window
            foreach (var err in cb.ErrorMessages)
            {
                // The templating system (eg t4.ProcessTemplate) will automatically add error/warning to the ErrorList
                Status.Update($"[Generator] [{(err.Warning ? "WARN" : "ERROR")}] {err.Message} {err.Line}, {err.Column}");
            }

            // If there was an output directive in the TemplateFile, then cb.SetFileExtension() will have been called.
            if (!string.IsNullOrWhiteSpace(cb.FileExtension))
            {
                extension = cb.FileExtension;
            }

            Status.Update("[Generator] [DONE] Generating code.");

            Status.Update("[Generator] Writing code to disk ... ");

            SaveOutputContent(rgbOutputFileContents, out pcbOutput, content);

            Status.Update("[Generator] [DONE] Writing code.");

            return(VSConstants.S_OK);
        }
 public bool IsConfirmed(string message)
 {
     return(DteHelper.IsConfirmed(message, "Confirmation ..."));
 }