public ProjectInformation(Project proj)
        {
            InitializeComponent();
            ThreadHelper.ThrowIfNotOnUIThread();
            txtProjectName.Text = proj.Name;

            var imported = ScriptGenAssemblyCache.GetForProj(proj);

            lblVersion.Content = imported.Version;

            AddLink(lnkFromDirectory, imported.AssemblyDirectory);
            AddLink(lnkCachedPath, imported.CachePath);
            AddLink(lnkCachedBasePath, ScriptGenAssemblyCache.CacheBasePath);

            _messageTimer          = new DispatcherTimer();
            _messageTimer.Interval = TimeSpan.FromSeconds(5);
            _messageTimer.Tick    += _messageTimer_Tick;;

            Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;

            AddCurrentImports();

#if DEBUG
            pnlDebugActions.Visibility = Visibility.Visible;
#endif

            _proj = proj;
        }
예제 #2
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            foreach (Project proj in VsHelper.GetSelectedCsharpProjects())
            {
                if (!ConfigProcessing.ConfigExistsForProject(proj))
                {
                    string configPath = ScriptGenAssemblyCache.GetForProj(proj)?.GetConfigFilepath(proj.FullName);
                    if (string.IsNullOrEmpty(configPath))
                    {
                        VsShellUtilities.ShowMessageBox(
                            ServiceProvider,
                            "Failed to find target configuration file path.  It is possible you need to update the Nuget Package.",
                            "Add Config Failed",
                            OLEMSGICON.OLEMSGICON_CRITICAL,
                            OLEMSGBUTTON.OLEMSGBUTTON_OK,
                            OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                        return;
                    }


                    if (!File.Exists(configPath))
                    {
                        ScriptGenAssemblyCache.GetForProj(proj).CreateNewConfigFile(configPath);
                    }
                    proj.ProjectItems.AddFromFile(configPath);
                }
            }
        }
 private void AddCurrentImports()
 {
     lstImports.Items.Clear();
     foreach (var vers in ScriptGenAssemblyCache.GetAllLoaded())
     {
         lstImports.Items.Add(vers);
     }
 }
 private void btnManualLoad_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrEmpty(txtMnlName.Text) && !string.IsNullOrEmpty(txtMnlDir.Text))
     {
         ScriptGenAssemblyCache.LoadFromDirectory(txtMnlName.Text, txtMnlDir.Text);
         AddCurrentImports();
         txtMnlDir.Clear();
         txtMnlName.Clear();
     }
 }
예제 #5
0
        /// <summary>
        /// Determines if script generation is enabled
        /// </summary>
        /// <param name="projPath">The path of the project</param>
        /// <returns>True if enabled</returns>
        public static bool IsGenEnabledForProject(Project proj)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            IConfigOptions opt = ScriptGenAssemblyCache.GetForProj(proj)?.ConfigManager.GetForProject(proj.FullName);

            if (opt != null && opt.Enabled)
            {
                return(true);
            }

            return(false);
        }
예제 #6
0
        /// <summary>
        /// Gets whether a config file exists for the solution and it added to the project
        /// </summary>
        /// <returns>True if it exists and is added</returns>
        public static bool ConfigExistsForProject(Project proj)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            string configPath = ScriptGenAssemblyCache.GetForProj(proj)?.GetConfigFilepath(proj.FullName);

            if (string.IsNullOrEmpty(configPath))
            {
                return(false);
            }
            bool configExists = File.Exists(configPath);

            bool existsButNotAdded = (configExists && !VsHelper.SolutionItemExists(configPath));

            return(configExists && !existsButNotAdded);
        }
예제 #7
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            VsHelper.Initialize(this);
            ScriptGenAssemblyCache.TryClearCache();

            _buildEvents = VsHelper.Current.Dte.Events.BuildEvents;
            _buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;
            _buildEvents.OnBuildDone  += BuildEvents_OnBuildDone;
            AddConfigCommand.Initialize(this);
            GenerateScriptsCommand.Initialize(this);
            InstallNugetPackageCommand.Initialize(this);
            ClearCacheCommand.Initialize(this);
            base.Initialize();
        }
예제 #8
0
        protected async override System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            ScriptGenAssemblyCache.TryClearCache();

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            VsHelper.Initialize(this);
            _buildEvents = VsHelper.Current.Dte.Events.BuildEvents;
            _buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;
            _buildEvents.OnBuildDone  += BuildEvents_OnBuildDone;
            AddConfigCommand.Initialize(this);
            GenerateScriptsCommand.Initialize(this);
            InstallNugetPackageCommand.Initialize(this);
            DebugInfoCommand.Initialize(this);
            await base.InitializeAsync(cancellationToken, progress);

            await UpgradeConfigCommand.InitializeAsync(this);
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var question = MessageBox.Show("Selecting this command will regenerate the config file.  Any unsupported options will be removed, but all others should remain unchanged." +
                                           "\r\rDo you want to continue?", "Upgrade Config?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (question == DialogResult.No)
            {
                return;
            }

            var item         = GetSelectedItem();
            var proj         = item.ContainingProject;
            var importedTool = ScriptGenAssemblyCache.GetForProj(proj);

            importedTool.UpgradeConfig(importedTool.GetConfigFilepath(proj.FullName));
        }
        private void ClearCache_Click(object sender, RoutedEventArgs e)
        {
            string message;

            if (!ScriptGenAssemblyCache.ClearCache())
            {
                // Show a message box to prove we were here
                message = "The cache is in use and cannot be cleared.  It will attempt again next time Visual Studio is restarted.";
                ScriptGenAssemblyCache.MarkForClear();
            }
            else
            {
                message = "Cache succesfully cleared.";
            }
            txtClearResult.Text = message;

            _messageTimer.Stop();
            _messageTimer.Start();
        }
예제 #11
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            string message;

            if (!ScriptGenAssemblyCache.ClearCache())
            {
                // Show a message box to prove we were here
                message = "The cache is in use and cannot be cleared.  It will attempt again next time Visual Studio is restarted.";
                ScriptGenAssemblyCache.MarkForClear();
            }
            else
            {
                message = "Cache succesfully cleared.";
            }
            VsShellUtilities.ShowMessageBox(
                this.ServiceProvider,
                message,
                "Clear Cache",
                OLEMSGICON.OLEMSGICON_INFO,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
        }
예제 #12
0
        /// <summary>
        /// Creates a config file for the given solution
        /// </summary>
        public static void CreateForProject(Project proj)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            string configPath = ScriptGenAssemblyCache.GetForProj(proj)?.ConfigManager.GetConfigFilepath(proj.FullName);

            if (!File.Exists(configPath))
            {
                IConfigOptions config = ScriptGenAssemblyCache.GetForProj(proj).ConfigManager.CreateNew();

                FileInfo projFile = new FileInfo(proj.FullName);

                Uri projUri = new Uri(projFile.Directory.FullName, UriKind.Absolute);
                Uri fileUri = new Uri(Path.Combine(projFile.Directory.FullName, "Scripts"), UriKind.Absolute);

                string relative = projUri.MakeRelativeUri(fileUri).ToString();
                relative = "." + relative.Substring(projFile.Directory.Name.Length);
                config.ServerObjectsResultFilepath = relative + "/ServerObjects.ts";

                ScriptGenAssemblyCache.GetForProj(proj).ConfigManager.Save(config, configPath);
            }
            proj.ProjectItems.AddFromFile(configPath);
        }
예제 #13
0
        /// <summary>
        /// Event handler for the build event, which will silently generate the typescript files
        /// </summary>
        /// <param name="Scope">the build scope</param>
        /// <param name="Action">The build action</param>
        private void BuildEvents_OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            Workspace             workspace   = VsHelper.Current.GetCurrentWorkspace();
            List <EnvDTE.Project> enabledProj = ConfigProcessing.GetEnabledProjectsForSolution();

            if (enabledProj.Count > 0)
            {
                foreach (EnvDTE.Project proj in enabledProj)
                {
                    BuildHelper.StartBuild(proj.FullName);
                    try
                    {
                        ScriptGenAssemblyCache.GetForProj(proj).GenerateScripts(workspace, proj.FullName, false);
                    }
                    catch (Exception e)
                    {
                        VsHelper.SetStatusBar("There was an error generating scripts.  Scripts will be generated by MSBuild: " + e.Message);
                        BuildHelper.EndBuild(proj.FullName);
                    }
                }
            }
        }
예제 #14
0
        private void MenuItem_BeforeQueryStatus(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            OleMenuCommand button = (OleMenuCommand)sender;

            button.Visible = false;

            var item = GetSelectedItem();

            if (item == null)
            {
                return;
            }

            var proj = item.ContainingProject;

            var importedTool = ScriptGenAssemblyCache.GetForProj(proj);

            if (importedTool is NullImportedTool)
            {
                return;
            }

            string configPath = importedTool.GetConfigFilepath(proj.FullName);

            if (configPath != item.FileNames[0])
            {
                return;
            }

            if (!importedTool.CanUpgradeConfig(configPath))
            {
                return;
            }

            button.Visible = true;
        }
예제 #15
0
 /// <summary>
 /// Determines if script generation is enabled
 /// </summary>
 /// <param name="projPath">The path of the project</param>
 /// <returns>True if enabled</returns>
 public static bool IsGenEnabledForProject(Project proj)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     return(ScriptGenAssemblyCache.GetForProj(proj)?.IsEnabledForProject(proj.FullName) ?? false);
 }