Esempio n. 1
0
        public bool Test()
        {
            try
            {
                EnvDTE.DTE             dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
                IAssetReferenceService referenceService = (IAssetReferenceService)GetService(typeof(IAssetReferenceService));
                object item = DteHelper.GetTarget(dte);
                //MessageBox.Show("Coneccion exitosa.- a " + _Server.Information.Product.ToString(),  Fwk.GuidPk.Properties.Resources.ProductTitle);


                //templateFilename = new Uri(templateFilename).LocalPath;
                StringBuilder items = new StringBuilder();
                //VsBoundReference vsTarget = null;
                if (item is Project)
                {
                    foreach (ProjectItem i in ((Project)item).ProjectItems)
                    {
                        items.AppendLine(i.Name);
                    }
                    //vsTarget = new ProjectReference(templateFilename, (Project)item);
                }

                MessageBox.Show(items.ToString(), Fwk.GuidPk.Properties.Resources.ProductTitle);
            }
            catch (Exception ex)
            {
                MessageBox.Show(Fwk.CodeGenerator.HelperFunctions.GetAllMessageException(ex), Fwk.GuidPk.Properties.Resources.ProductTitle);
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            var service = base.GetService <DTE>(true);

            newValue = string.Empty;
            string selectedFolderPath = DteHelper.GetFilePathRelative((ProjectItem)DteHelper.GetTarget(service));

            string[] pathParts =
                selectedFolderPath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar },
                                         StringSplitOptions.RemoveEmptyEntries);
            if (pathParts.Length > 3)
            {
                if (pathParts[1] == TemplateConfiguration.GetConfiguration().ExtRootFolderName&&
                    (pathParts[2].Equals(ExtJsClassType.Model.ToString(), StringComparison.InvariantCultureIgnoreCase) ||
                     pathParts[2].Equals(ExtJsClassType.View.ToString(), StringComparison.InvariantCultureIgnoreCase) ||
                     pathParts[2].Equals(ExtJsClassType.Store.ToString(), StringComparison.InvariantCultureIgnoreCase) ||
                     pathParts[2].Equals(ExtJsClassType.Controller.ToString(), StringComparison.InvariantCultureIgnoreCase)))
                {
                    for (var i = 3; i < pathParts.Length; i++)
                    {
                        newValue += pathParts[i] + ".";
                    }
                }
            }
            return(true);
        }
        /// <summary>
        /// Adds the template reference to the IAssetReferenceService
        /// </summary>
        public override void Execute()
        {
            DTE vs = GetService <DTE>(true);
            IAssetReferenceService referenceService = GetService <IAssetReferenceService>(true);
            object item = DteHelper.GetTarget(vs);

            if (item == null)
            {
                throw new InvalidOperationException("There is no valid target to reference the template.");
            }

            if (item is Project)
            {
                addedReference = new ProjectReference(recipeName, (Project)item);
            }
            else if (item is Solution)
            {
                addedReference = new SolutionReference(recipeName, (Solution)item);
            }
            else if (item is ProjectItem)
            {
                addedReference = new ProjectItemReference(recipeName, (ProjectItem)item);
            }
            else
            {
                throw new NotSupportedException("Current selection is unsupported.");
            }

            referenceService.Add(addedReference);

            MessageBox.Show("The new reference was successfully added.", "New Reference",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 4
0
        /// <summary>
        /// It sets all the items with the appropiate values
        /// </summary>
        public override void Execute()
        {
            if (MessageBox.Show(Properties.Resources.Actions_ItemsBuildProps_Confirmation,
                                Properties.Resources.Actions_ItemsBuildProps_Title, MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            DTE         vs   = (DTE)GetService(typeof(DTE));
            ProjectItem item = (ProjectItem)DteHelper.GetTarget(vs);

            vs.StatusBar.Highlight(true);
            if (item.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFolder)
            {
                SetPropertiesOfFolder(item);
            }
            if (applied)
            {
                Trace.TraceInformation(Properties.Resources.Actions_ItemsBuildProps_Success);
                vs.StatusBar.Text = Properties.Resources.Actions_ItemsBuildProps_Success;
            }
            else
            {
                Trace.TraceInformation(Properties.Resources.Actions_ItemsBuildProps_Fail);
                vs.StatusBar.Text = Properties.Resources.Actions_ItemsBuildProps_Fail;
            }
            vs.StatusBar.Highlight(false);
        }
Esempio n. 5
0
        public override void Execute()
        {
            DTE vs = GetService <DTE>(true);
            IAssetReferenceService referenceService = GetService <IAssetReferenceService>(true);
            object item = DteHelper.GetTarget(vs);

            CreateFolderAndFiles(Project);
        }
Esempio n. 6
0
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            var    service            = base.GetService <DTE>(true);
            string solutionFolderPath = Path.GetDirectoryName(service.Solution.FullName);

            newValue = Path.Combine(solutionFolderPath,
                                    DteHelper.GetFilePathRelative((ProjectItem)DteHelper.GetTarget(service)));
            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Adds the template reference to the IAssetReferenceService
        /// </summary>
        public override void Execute()
        {
            EnvDTE.DTE             dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
            IAssetReferenceService referenceService = (IAssetReferenceService)GetService(typeof(IAssetReferenceService));
            object item = DteHelper.GetTarget(dte);



            if (item == null)
            {
                MessageBox.Show("There is no valid target to reference the template");
                return;
            }
            templateFilename = new Uri(templateFilename).LocalPath;

            VsBoundReference vsTarget = null;

            if (item is Project)
            {
                vsTarget = new ProjectReference(templateFilename, (Project)item);
            }
            else if (item is Solution)
            {
                vsTarget = new SolutionReference(templateFilename, (Solution)item);
            }
            else if (item is ProjectItem)
            {
                vsTarget = new ProjectItemReference(templateFilename, (ProjectItem)item);
            }
            else if (item is EnvDTE80.SolutionFolder)
            {
                vsTarget = new ProjectReference(templateFilename, ((EnvDTE80.SolutionFolder)item).Parent);
            }
            if (item == null || vsTarget == null)
            {
                MessageBox.Show(string.Format(
                                    CultureInfo.CurrentCulture,
                                    "Target {0} specified for reference to asset {1} doesn't exist.",
                                    "target", templateFilename));
                return;
            }
            if (!File.Exists(templateFilename) || !templateFilename.EndsWith(".vstemplate", StringComparison.InvariantCultureIgnoreCase))
            {
                MessageBox.Show(string.Format(
                                    CultureInfo.CurrentCulture,
                                    "The filename specified for the template \"{0}\" does not exist.",
                                    templateFilename));
                return;
            }
            newReference = new BoundTemplateReference(templateFilename, vsTarget);
            referenceService.Add(newReference);
            MessageBox.Show("The new reference was successfully added", "New Reference",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 8
0
 private void SetUnfoldingRoot()
 {
     if (template.VSKind == WizardRunKind.AsMultiProject)
     {
         EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
         if (dte.SelectedItems != null && dte.SelectedItems.Count == 1)
         {
             this.unfoldingRoot = DteHelper.GetTarget(dte) as Project;
         }
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Uses <see cref="DteHelper.GetTarget"/> to obtain the new ProjectItem object
 /// </summary>
 /// <param name="currentValue"></param>
 /// <param name="newValue"></param>
 /// <returns></returns>
 public override bool OnBeforeActions(object currentValue, out object newValue)
 {
     if (currentValue == null)
     {
         DTE    dte    = (DTE)GetService(typeof(DTE));
         object target = DteHelper.GetTarget(dte);
         if (target is ProjectItem)
         {
             newValue = target;
             return(true);
         }
     }
     newValue = currentValue;
     return(false);
 }
        public override void Execute()
        {
            if (!IsValid)
            {
                return;
            }

            try
            {
                var service        = base.GetService <DTE>(true);
                var selectedFolder = (ProjectItem)DteHelper.GetTarget(service);
                CreateProjectItem(selectedFolder);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format(ErrorMessages.GeneralError, ex.Message), MessageType.Error,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                IsValid = false;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Adds the template reference to the IAssetReferenceService
        /// </summary>
        public override void Execute()
        {
            DTE vs = GetService <DTE>(true);
            IAssetReferenceService referenceService = GetService <IAssetReferenceService>(true);
            object item = DteHelper.GetTarget(vs);

            CreateFolderAndFiles(Project);



            if (item == null)
            {
                throw new InvalidOperationException("There is no valid target to create any DAC .");
            }

            if (item is EnvDTE.Project)
            {
                EnvDTE.Project p = (EnvDTE.Project)item;

                // p.ProjectItems.AddFromFile();
            }
            else if (item is Solution)
            {
                // addedReference = new SolutionReference(recipeName, (Solution)item);
            }
            else if (item is ProjectItem)
            {
                //  addedReference = new ProjectItemReference(recipeName, (ProjectItem)item);
            }
            else
            {
                throw new NotSupportedException("Current selection is unsupported.");
            }

            //referenceService.Add(addedReference);

            //MessageBox.Show("The new reference was successfully added.", "New Reference",
            //    MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 12
0
        private void LoadInitialState()
        {
            if (this.template.ExtensionData.Recipe == null)
            {
                return;
            }
            DTE dte = (DTE)GetService(typeof(DTE));
            IAssetReferenceService referenceService = (IAssetReferenceService)
                                                      this.Package.GetService(typeof(IAssetReferenceService), false);

            if (referenceService != null)
            {
                IAssetReference templateAsset = null;
                try
                {
                    object target = DteHelper.GetTarget(dte);
                    templateAsset = referenceService.GetReferenceFor(this.Template.FileName, target);
                    if (templateAsset == null)
                    {
                        if (this.Template.Kind == TemplateKind.Project && target is Project)                         // If the template is been unfolded, then check the parent folder
                        {
                            Project parentProject = (target as Project).ParentProjectItem.ContainingProject;
                            if (parentProject != null)                             // Parent folder exist, check the reference to the template
                            {
                                templateAsset = referenceService.GetReferenceFor(this.Template.FileName, parentProject);
                            }
                            else                             // The parent folder is the solution root, check the reference in the solutioin root
                            {
                                templateAsset = referenceService.GetReferenceFor(this.Template.FileName, dte.Solution);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    templateAsset = null;
                }
                if (templateAsset != null)
                {
                    IPersistenceService persistenceService = (IPersistenceService)this.Package.GetService(typeof(IPersistenceService), false);
                    if (persistenceService != null)
                    {
                        IDictionary hashStored = persistenceService.LoadState(this.Template.PackageName, templateAsset);
                        if (hashStored != null)
                        {
                            ArrayList toremove = new ArrayList(hashStored.Count);
                            foreach (DictionaryEntry keyValuePair in hashStored)
                            {
                                if (this.templateDictionary.GetValue(keyValuePair.Key) == null)
                                {
                                    try
                                    {
                                        this.templateDictionary.SetValue(keyValuePair.Key, keyValuePair.Value);
                                    }
                                    catch
                                    {
                                        string appliesTo;
                                        try
                                        {
                                            appliesTo = templateAsset.AppliesTo;
                                        }
                                        catch (Exception e)
                                        {
                                            Trace.TraceWarning(e.Message);
                                            appliesTo = Properties.Resources.Reference_AppliesToThrew;
                                        }
                                        // Invalid initial state should just be ignored.
                                        Trace.TraceWarning(Properties.Resources.Template_IgnoreKeyInitialState, keyValuePair.Key, templateAsset.AppliesTo);
                                        toremove.Add(keyValuePair.Key);
                                    }
                                }
                            }
                            foreach (object key in toremove)
                            {
                                hashStored.Remove(key);
                            }
                            if (toremove.Count != 0)
                            {
                                // Save the updated one without the offending values.
                                persistenceService.SaveState(this.template.PackageName, templateAsset, hashStored);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 13
0
 protected object GetTarget()
 {
     return(DteHelper.GetTarget(ServiceProvider.GetService <DTE>(true)));
 }
Esempio n. 14
0
        public SolutionPickerForm(DTE dte, IUnboundAssetReference reference)
        {
            InitializeComponent();
            this.picker                   = new SolutionPickerControl(dte, reference, DteHelper.GetTarget(dte), null);
            this.picker.Dock              = System.Windows.Forms.DockStyle.Fill;
            this.picker.SelectionChanged += new SelectionChangedEventHandler(OnSelectionChanged);
            this.pnlContainer.Controls.Add(this.picker);
            string appliesTo;

            try
            {
                appliesTo = reference.AppliesTo;
            }
            catch (Exception)
            {
                appliesTo = Properties.Resources.Reference_AppliesToThrew;
                //It's better to continue executing the action and not stop because of the caption in the label
                //throw new RecipeExecutionException(reference.AssetName,
                //	string.Format(CultureInfo.CurrentCulture,
                //	Properties.Resources.Reference_InvalidAttributes, "AppliesTo"), e);
            }
            this.messageText.Text = String.Format(
                System.Globalization.CultureInfo.InvariantCulture,
                this.messageText.Text,
                appliesTo);
        }
Esempio n. 15
0
        void EnvDTE.IDTWizard.Execute(object Application, int hwndOwner, ref object[] ContextParams, ref object[] CustomParams, ref EnvDTE.wizardResult retval)
        {
            IVsTemplate vsTemplate = null;

            try
            {
                DTE dte = new DTETemplate((DTE)Application);
                CustomParams[0] = Environment.ExpandEnvironmentVariables((string)CustomParams[0]);

                if (!Path.IsPathRooted((string)CustomParams[0]) && CustomParams.Length >= 2)
                {
                    var guidancePackageName = (string)CustomParams[1];

                    var guidancePackageConfigurationFile = RecipeManager.GetConfigurationFile(RecipeManagerPackage.Singleton, guidancePackageName);

                    if (!string.IsNullOrEmpty(guidancePackageConfigurationFile))
                    {
                        var template = Path.Combine(Path.GetDirectoryName(guidancePackageConfigurationFile), (string)CustomParams[0]);

                        if (File.Exists(template))
                        {
                            CustomParams[0] = template;
                        }
                    }
                }
                string templateFileName             = (string)CustomParams[0];
                IVsTemplatesService templateService = (IVsTemplatesService)
                                                      ServiceHelper.GetService(
                    (IRecipeManagerService)
                    new VsServiceProvider(Application).GetService(typeof(IRecipeManagerService)),
                    typeof(IVsTemplatesService), this);
                vsTemplate = templateService.GetTemplate(templateFileName);
                string wizardKind = ((string)ContextParams[0]).ToUpper(CultureInfo.InvariantCulture);
                if (wizardKind == Constants.vsWizardNewProject)
                {
                    string destDir = (string)ContextParams[2];
                    //Web projects can pass in an empty directory, if so don't create the dest directory.
                    if ((new System.Uri(destDir)).IsFile)
                    {
                        Directory.CreateDirectory(destDir);
                    }

                    //If adding the project as exclusive, close the current solution then check to see if a
                    //  solution name is specified. If so, then create Ona solution with that name.
                    if (((bool)ContextParams[4]) == true)
                    {
                        vsPromptResult promptResult = dte.ItemOperations.PromptToSave;
                        if (promptResult == vsPromptResult.vsPromptResultCancelled)
                        {
                            retval = wizardResult.wizardResultCancel;
                            return;
                        }
                        dte.Solution.Close(false);
                        if (string.IsNullOrEmpty(((string)ContextParams[5])) == false)
                        {
                            dte.Solution.Create(destDir, ((string)ContextParams[5]));
                        }
                        ContextParams[4] = false;
                    }
                    // Create a new Solution Folder for the multiproject template
                    else if (vsTemplate.VSKind == WizardRunKind.AsMultiProject)
                    {
                        string folderName = (string)ContextParams[1];
                        if (dte.SelectedItems.Count == 1)
                        {
                            object item = DteHelper.GetTarget(dte);
                            if (item is Solution2)
                            {
                                ((Solution2)item).AddSolutionFolder(folderName);
                            }
                            else if (item is Project)
                            {
                                SolutionFolder slnFolder = (SolutionFolder)(((Project)item).Object);
                                slnFolder.AddSolutionFolder(folderName);
                            }
                        }
                    }
                }

                // Pre-fill state with context parameters.
                context = new System.Collections.Specialized.HybridDictionary();
                // See http://msdn.microsoft.com/library/en-us/vsintro7/html/vxlrfcontextparamsenum.asp
                string kind = ((string)ContextParams[0]).ToUpper();
                if (kind == Constants.vsWizardNewProject.ToUpper())
                {
                    FillNewProject(ContextParams, context);
                }
                else if (kind == Constants.vsWizardAddSubProject.ToUpper())
                {
                    FillAddSubProject(ContextParams, context);
                }
                else if (kind == Constants.vsWizardAddItem.ToUpper())
                {
                    FillAddItem(ContextParams, context);
                }

                IDTWizard wizard = new Microsoft.VisualStudio.TemplateWizard.Wizard();
                wizard.Execute(dte, hwndOwner, ref ContextParams, ref CustomParams, ref retval);
            }
            catch (Exception ex)
            {
                retval = wizardResult.wizardResultCancel;
                if (!(ex is COMException) || ((COMException)ex).ErrorCode != VSConstants.E_ABORT)
                {
                    ErrorHelper.Show(this.Site, ex);
                }
            }
            finally
            {
                Debug.Assert(UnfoldTemplate.UnfoldingTemplates.Count == 0);
                UnfoldTemplate.UnfoldingTemplates.Clear();
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Selects the introduction page html to be at the top of the windows
        /// </summary>
        public override void Execute()
        {
            DTE         vs = GetService <DTE>(true);
            ProjectItem actionClassFile = (ProjectItem)DteHelper.GetTarget(vs);

            if ((actionClassFile == null) || (actionClassFile.FileCodeModel == null) ||
                (actionClassFile.FileCodeModel.CodeElements == null) ||
                (actionClassFile.FileCodeModel.CodeElements.Count == 0))
            {
                return;
            }

            string fieldName = "";

            if ((ParameterName.Length > 1) && (ParameterName[0] >= 'A') && (ParameterName[0] <= 'Z'))
            {
                fieldName = char.ToLower(parameterName[0], CultureInfo.CurrentCulture) +
                            parameterName.Substring(1);
            }
            else
            {
                fieldName = "_" + parameterName;
            }

            string attribute;

            if (ParameterIsOutput)
            {
                attribute = "Output";
            }
            else
            {
                attribute = "Input";
            }
            bool addedProperty = false;

            foreach (CodeElement element in actionClassFile.FileCodeModel.CodeElements)
            {
                if (element.Kind == vsCMElement.vsCMElementNamespace)
                {
                    foreach (CodeElement elementNamespace in ((CodeNamespace)element).Members)
                    {
                        if (elementNamespace.Kind == vsCMElement.vsCMElementClass)
                        {
                            #region Look where to insert the property
                            object    whereToInsert = null;
                            CodeClass classAction   = (CodeClass)elementNamespace;

                            CodeProperty foundProperty = null;
                            foreach (CodeElement classElement in classAction.Members)
                            {
                                if (foundProperty != null)
                                {
                                    if (classElement.Kind == vsCMElement.vsCMElementVariable)
                                    {
                                        // Then insert after this declaration of variable that was after the property
                                        whereToInsert = classElement;
                                    }
                                }
                                if (classElement.Kind == vsCMElement.vsCMElementProperty)
                                {
                                    foundProperty = (CodeProperty)classElement;
                                    bool hasAttribute = false;
                                    for (int i = 1; i <= foundProperty.Attributes.Count; i++)
                                    {
                                        if (foundProperty.Attributes.Item(i).Name == attribute)
                                        {
                                            hasAttribute = true;
                                            break;
                                        }
                                    }
                                    if (!hasAttribute)
                                    {
                                        foundProperty = null;
                                    }
                                }
                            }
                            if (foundProperty != null)
                            {
                                if (whereToInsert == null)
                                {
                                    whereToInsert = foundProperty;
                                }
                            }
                            else if (whereToInsert == null)
                            {
                                whereToInsert = 0;
                            }

                            #endregion

                            CodeProperty prop = classAction.AddProperty(ParameterName, ParameterName, ParameterType, whereToInsert, vsCMAccess.vsCMAccessPublic, actionClassFile.Name);

                            TextPoint getTextTP = prop.Getter.GetStartPoint(vsCMPart.vsCMPartBody);
                            EditPoint getText   = getTextTP.CreateEditPoint();
                            getText.ReplaceText(prop.Getter.GetEndPoint(vsCMPart.vsCMPartBody),
                                                string.Format(CultureInfo.InvariantCulture, "return {0};", fieldName), (int)vsEPReplaceTextOptions.vsEPReplaceTextNormalizeNewlines);
                            getText.SmartFormat(getTextTP);

                            TextPoint setTextTP = prop.Setter.GetStartPoint(vsCMPart.vsCMPartBody);
                            EditPoint setText   = setTextTP.CreateEditPoint();
                            setText.ReplaceText(0, string.Format(CultureInfo.InvariantCulture, "{0}=value;", fieldName), 0);
                            setText.SmartFormat(setTextTP);

                            if (ParameterIsOutput)
                            {
                                prop.AddAttribute(attribute, "", 0);
                            }
                            else
                            {
                                prop.AddAttribute(attribute, "true", 0);
                            }
                            classAction.AddVariable(fieldName, ParameterType, prop, vsCMAccess.vsCMAccessPrivate, actionClassFile.Name);

                            // Stop adding property, just the first class found
                            addedProperty = true;
                            break;
                        }
                    }
                    if (addedProperty)
                    {
                        break;
                    }
                }
            }
        }