Exemple #1
0
        public override void Exec(vsCommandExecOption executeOption, ref object varIn, ref object varOut)
        {
            string magicDrawPath = m_addInSettings.UMLModellerPath;

            if (magicDrawPath != string.Empty && System.IO.File.Exists(magicDrawPath) && System.IO.File.Exists(m_solutionManager.ModelFilePath))
            {
                try
                {
                    if (m_addInSettings.AutoMakeModelFileWritable)
                    {
                        System.IO.FileAttributes attr = System.IO.File.GetAttributes(m_solutionManager.ModelFilePath);
                        if ((attr & System.IO.FileAttributes.ReadOnly) != 0)
                        {
                            attr -= System.IO.FileAttributes.ReadOnly;
                            System.IO.File.SetAttributes(m_solutionManager.ModelFilePath, attr);
                        }
                    }
                    //AddInUtils.ShowWarning("Path: " + magicDrawPath + "\nArgs: " + "\"" + m_solutionManager.ModelFilePath + "\"");
                    System.Diagnostics.Process.Start(magicDrawPath, "\"" + m_solutionManager.ModelFilePath + "\"");
                }
                catch (Exception e)
                {
                    AddInUtils.ShowError("An unexpected error occured while trying to launch the external UML modeling tool: " + e.Message);
                }
            }
            else
            {
                AddInUtils.ShowError("The external UML modeling tool could not be found.  Please ensure the path is correct in the Android/VS options page (Tools | Options | AndroMDA | Tools)");
            }
        }
        public void RunSchemaExport()
        {
            try
            {
                if (IsSchemaExportProjectAvailable && m_schemaExportProject != null)
                {
                    if (m_addInSettings.PassSchemaExportArguments)
                    {
                        Property prop = m_schemaExportProject.Project.ConfigurationManager.ActiveConfiguration.Properties.Item("StartArguments");
                        prop.Value = m_addInSettings.SchemaExportCommandLine;
                    }

                    string solutionName = VSSolutionUtils.GetSolutionName(m_applicationObject.Solution);
                    // Activate the solution explorer window
                    m_applicationObject.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate();
                    // Grab the UIHierarchy object for the schema export project
                    UIHierarchyItem item = ((UIHierarchy)m_applicationObject.ActiveWindow.Object).GetItem(solutionName + "\\" + m_schemaExportProject.Name);
                    // Select the project
                    item.Select(vsUISelectionType.vsUISelectionTypeSelect);
                    // Execute the Debug.StartNewInstance command
                    m_applicationObject.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance", string.Empty);
                }
                else
                {
                    AddInUtils.ShowWarning("The schema export project for this solution could not be found.\nPlease ensure the following variables are set correctly in mda\\project.properties\n\nmaven.andromda.schemaexport.available=true\nmaven.andromda.schemaexport.dir=<path to schema export project>");
                }
            }
            catch (Exception e)
            {
                AddInUtils.ShowError(e.Message);
            }
        }
Exemple #3
0
        /// <summary>
        /// Called when the add-in is loaded
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="connectMode">The connect mode.</param>
        /// <param name="addInInst">The add in inst.</param>
        /// <param name="custom">The custom.</param>
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            try
            {
                if (connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == ext_ConnectMode.ext_cm_Solution)
                {
                    return;
                }

                // If the Add-In is already connected return
                if (m_connected)
                {
                    return;
                }

                m_applicationObject = (DTE)application;
                m_addInInstance     = (AddIn)addInInst;

                // Don't load the add-in if the following parameters were passed to the app
                string command_line = m_applicationObject.CommandLineArguments.ToLower();
                foreach (string sw in new string[] { "/build", "/rebuild", "/clean", "/deploy" })
                {
                    if (command_line.IndexOf(sw) != -1)
                    {
                        return;
                    }
                }

                m_addInSettings = new AddInSettings(m_applicationObject);

                if (m_addInSettings.ShowWelcomeWizard)
                {
                    Dialogs.WelcomeWizard welcome = new Dialogs.WelcomeWizard(m_addInSettings);
                    welcome.ShowDialog();
                    m_addInSettings.ShowWelcomeWizard = welcome.ShowWizardAgain;
                }

                m_solutionManager = new MDASolutionManager(m_applicationObject, m_addInSettings);
                BindEvents();
                CreateCommands();
                RegisterCommands();
                RegisterToolbar();
                Velocity.Init();
                m_connected = true;
            }
            catch (Exception e)
            {
                AddInUtils.ShowError("An exception occured while trying to instantiate the add-in: " + e.ToString());
            }
        }
Exemple #4
0
        public override void Exec(vsCommandExecOption executeOption, ref object varIn, ref object varOut)
        {
            CodeFunction2 currentMethod = CodeModelUtils.GetCurrentMethod(m_application);

            if (IsCommandAvailable(currentMethod))
            {
                AndroMDA.VS80AddIn.Dialogs.PropertyMapperDialog propertyMapper = new AndroMDA.VS80AddIn.Dialogs.PropertyMapperDialog(currentMethod, m_addInSettings);
                if (propertyMapper.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    // User clicked OK
                    AddInUtils.InsertCodeInMethod(currentMethod, propertyMapper.GeneratedCode);
                    m_application.StatusBar.Text = "Android/VS: Code inserted";
                }
            }
        }
 public void RunMaven()
 {
     if (IsEnabled)
     {
         if (m_mavenProxy.OutputWindow == null)
         {
             OutputWindowPane owp = GetOutputWindowPane("AndroMDA");
             m_mavenProxy.OutputWindow     = m_applicationObject.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
             m_mavenProxy.OutputWindowPane = owp;
         }
         m_mavenProxy.Start();
     }
     else
     {
         AddInUtils.ShowError("You must have an MDA-enabled solution loaded to run Maven.");
     }
 }
 public void RefreshGeneratedFiles()
 {
     if (IsEnabled)
     {
         try
         {
             DoRefreshGeneratedFiles();
             m_applicationObject.StatusBar.Progress(false, string.Empty, 0, 0);
             m_applicationObject.StatusBar.Text = "Android/VS: Solution resync complete";
         }
         catch (Exception e)
         {
             AddInUtils.ShowError("An error occured while trying to resynchronize the project tree: " + e.Message);
         }
     }
     else
     {
         AddInUtils.ShowError("You must have an MDA-enabled solution loaded to resync generated files.");
     }
 }
Exemple #7
0
        public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
        {
            switch (disconnectMode)
            {
            case ext_DisconnectMode.ext_dm_HostShutdown:
            case ext_DisconnectMode.ext_dm_UserClosed:
                break;

            case ext_DisconnectMode.ext_dm_SolutionClosed:
            case ext_DisconnectMode.ext_dm_UISetupComplete:
                return;
            }

            // If the add-in is not active, do not disconnect
            if (!m_connected)
            {
                return;
            }

            try
            {
                // Stop maven if it is runing
                if (m_solutionManager.IsMavenRunning)
                {
                    m_solutionManager.StopMaven();
                }
                // Save the position/state of the toolbar
                SaveToolbarSettings();
                UnregisterCommands();
                UnbindEvents();
                m_solutionManager = null;
            }
            catch (Exception e)
            {
                AddInUtils.ShowError("An exception occured in OnDisconnect(): " + e.ToString());
            }
            finally
            {
                m_connected = false;
            }
        }
        public void InitializeSolution()
        {
            m_solutionIsUsingMDA = MDAConfigFilesExist(m_applicationObject.Solution);
            m_enabled            = false;
            if (m_solutionIsUsingMDA)
            {
                try
                {
                    // Notify the user that the solution is using MDA
                    m_applicationObject.StatusBar.Text = "Android/VS: Solution is AndroMDA-enabled.  Loading configuration...";
                    m_applicationObject.StatusBar.Highlight(true);

                    // Get the solution path
                    string solutionPath = VSSolutionUtils.GetSolutionPath(m_applicationObject.Solution);

                    /// Load the properties file and set the the root directory
                    if (Maven1PropertiesExist(m_applicationObject.Solution))
                    {
                        // Load the properties directly from the project.properties file
                        m_projectProperties.LoadFromFile(GetMaven1ProjectPropertiesPath(m_applicationObject.Solution));
                        m_projectProperties["maven.version"] = "1";
                    }
                    else if (Maven2PropertiesExist(m_applicationObject.Solution))
                    {
                        // Load the properties from the pom.xml
                        m_projectProperties.LoadFromXML(GetMaven2ProjectPropertiesPath(m_applicationObject.Solution), "maven.andromda.");
                        m_projectProperties["maven.version"] = "2";
                    }
                    else
                    {
                        throw new Exception("Unable to locate the project's properties file.");
                    }
                    m_projectProperties["maven.src.dir"] = solutionPath + "\\mda\\src";
                    m_projectProperties["project.build.sourceDirectory"] = solutionPath + "\\mda\\src\\uml";
                    m_projectProperties["pom.basedir"] = solutionPath + "\\mda";

                    if (m_projectProperties["maven.version"] == "2" && m_mavenProxy is Maven1Proxy)
                    {
                        m_mavenProxy = new Maven2Proxy(m_applicationObject, m_addInSettings);
                    }
                    else if (m_projectProperties["maven.version"] == "1" && m_mavenProxy is Maven2Proxy)
                    {
                        m_mavenProxy = new Maven1Proxy(m_applicationObject, m_addInSettings);
                    }

                    m_mavenProxy.Completed += new EventHandler(m_mavenProxy_Completed);

                    ////
                    ////  Resolve the core and common projects
                    ////

                    //m_coreProject = null;
                    //m_commonProject = null;
                    m_schemaExportProject = null;

                    // Iterate through the projects and search for the core and common directories
                    foreach (Project p in m_applicationObject.Solution.Projects)
                    {
                        try
                        {
                            // Get the project's directory
                            string projectPath = FileUtils.GetPathFromFilename(p.FileName);

                            /*
                             * // Check if the current (core) directory is the same as the project directory
                             * if (FileUtils.CompareDirectories(projectPath, m_projectProperties.GetPath("maven.andromda.core.dir")))
                             * {
                             *  // if so this is the core project
                             *  string generatedPath = m_projectProperties.GetPath("maven.andromda.core.generated.dir");
                             *  string manualPath = m_projectProperties.GetPath("maven.andromda.core.manual.dir");
                             *  m_coreProject = new MDAProject(p, FileUtils.GetFilename(projectPath), projectPath, generatedPath, manualPath);
                             *
                             * }
                             *
                             * // Check if the current (common) directory is the same as the project directory
                             * if (FileUtils.CompareDirectories(projectPath, m_projectProperties.GetPath("maven.andromda.common.dir")))
                             * {
                             *  // if so this is the common project
                             *  string generatedPath = m_projectProperties.GetPath("maven.andromda.common.generated.dir");
                             *  m_commonProject = new MDAProject(p, FileUtils.GetFilename(projectPath), projectPath, generatedPath, string.Empty);
                             * }
                             */

                            // Check if the current (schemaexport) directory is the same as the project directory
                            if (IsSchemaExportProjectAvailable && FileUtils.CompareDirectories(projectPath, m_projectProperties.GetPath("maven.andromda.schemaexport.dir")))
                            {
                                // if so this is the common project
                                m_schemaExportProject = new MDAProject(p, FileUtils.GetFilename(projectPath), projectPath, string.Empty, string.Empty);
                            }
                        }
                        catch (NotImplementedException)
                        {
                            // Swallow this exception (it means the project was not loaded for some reason)
                        }
                    }

                    /*
                     * // Show an error message if either the core or common projects could not be found
                     * if (m_coreProject == null || m_commonProject == null)
                     * {
                     *  string errorMessage = "The AndroMDA configuration was loaded, but the ";
                     *  if (m_coreProject == null)
                     *  {
                     *      errorMessage += "core (" + m_projectProperties["maven.andromda.core.assembly.name"] + ") ";
                     *      if (m_commonProject == null) { errorMessage += "and "; }
                     *  }
                     *  if (m_commonProject == null) { errorMessage += "common (" + m_projectProperties["maven.andromda.common.assembly.name"] + ") "; }
                     *  errorMessage += "project";
                     *  if (m_commonProject == null && m_coreProject == null) errorMessage += "s";
                     *  errorMessage += " could not be found in the solution.";
                     *  throw new Exception(errorMessage);
                     * }
                     */
                    m_solutionSettings = new ConfigFile(solutionPath + "\\mda\\android.user.properties");
                    m_applicationObject.StatusBar.Highlight(false);
                    m_applicationObject.StatusBar.Text = "Android/VS: AndroMDA configuration loaded.";
                    m_enabled = true;
                }
                catch (Exception e)
                {
                    m_enabled = false;
                    AddInUtils.ShowWarning("An error occured while trying to load the AndroMDA configuration.  When you fix the problem click the 'Reload MDA Config' button.\n\n" + e.Message);
                }
            }
        }
Exemple #9
0
        public override void Exec(vsCommandExecOption executeOption, ref object varIn, ref object varOut)
        {
            CodeFunction2 currentMethod = CodeModelUtils.GetCurrentMethod(m_application);

            if (IsCommandAvailable(currentMethod))
            {
                try
                {
                    ConversionCodeGenerator codeGenerator = new ConversionCodeGenerator();

                    CodeParameter2 param = currentMethod.Parameters.Item(1) as CodeParameter2;

                    ArrayList toProperties;
                    ArrayList fromProperties;

                    try
                    {
                        toProperties = CodeModelUtils.GetPropertiesFromType(currentMethod.Type.CodeType);
                    }
                    catch (NotImplementedException)
                    {
                        throw new Exception("Method return type '" + currentMethod.Type.AsString + "' could not be resolved.");
                    }

                    try
                    {
                        fromProperties = CodeModelUtils.GetPropertiesFromType(param.Type.CodeType);
                    }
                    catch (NotImplementedException)
                    {
                        throw new Exception("Method parameter type '" + param.Type.AsString + "' could not be resolved.");
                    }

                    foreach (CodeProperty toProperty in toProperties)
                    {
                        bool   mapped       = false;
                        string toName       = toProperty.Name;
                        string toNameNoDots = toName.Replace(".", string.Empty);
                        string toType       = toProperty.Type.AsFullName;

                        foreach (CodeProperty fromProperty in fromProperties)
                        {
                            string fromName       = fromProperty.Name;
                            string fromNameNoDots = fromName.Replace(".", string.Empty);
                            if (fromName == toName || fromName == toNameNoDots || fromNameNoDots == toNameNoDots)
                            {
                                string fromType = fromProperty.Type.AsFullName;
                                if (fromType.Replace("?", string.Empty) == toType.Replace("?", string.Empty))
                                {
                                    codeGenerator.AddProperty(toName, toType, fromName, fromType);
                                    mapped = true;
                                    break;
                                }
                            }
                        }

                        if (!mapped)
                        {
                            codeGenerator.AddProperty(toName, toType);
                        }
                    }

                    AddInUtils.InsertCodeInMethod(currentMethod, codeGenerator.GenerateCode(currentMethod));

                    m_application.StatusBar.Text = "Android/VS: Code inserted";
                }
                catch (Exception e)
                {
                    m_application.StatusBar.Text = "Android/VS: Unable to insert code: " + e.Message;
                    m_application.StatusBar.Highlight(true);
                }
            }
            else
            {
                m_application.StatusBar.Text = "Android/VS: Unable to insert code";
            }
        }