Example #1
0
        public override void Execute()
        {
            if (!ProcessTemplate)
            {
                return;
            }

            IDictionaryService dictionaryService = GetService <IDictionaryService>();

            this.template        = ArgumentsHelper.ReplaceToken(this.Template, dictionaryService);
            this.dynamicTemplate = ArgumentsHelper.ReplaceToken(this.DynamicTemplate, dictionaryService);
            if (!string.IsNullOrEmpty(dynamicTemplate))
            {
                this.template = dynamicTemplate;
            }
            if (template == null)
            {
                throw new ArgumentNullException("Template");
            }
            string templateBasePath = base.GetTemplateBasePath();

            if (!Path.IsPathRooted(template))
            {
                Template = Path.Combine(templateBasePath, template);
            }
            string templateFilename = new FileInfo(template).FullName;

            if (!templateFilename.StartsWith(templateBasePath))
            {
                throw new ArgumentException(string.Empty);
            }
            string templateContent = File.ReadAllText(templateFilename);

            this.Content = base.Render(templateContent, templateFilename);
        }
Example #2
0
        /// <summary>
        /// Uses <see cref="DteHelper.FindItemByName"/> to search for the item specified by the "Name" attributte
        /// </summary>
        /// <param name="currentValue"></param>
        /// <param name="newValue"></param>
        /// <returns></returns>
        /// <seealso cref="ValueProvider.OnBeginRecipe"/>
        /// <seealso cref="DteHelper.FindItemByName"/>
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            if (currentValue == null)
            {
                IDictionaryService dictservice = (IDictionaryService)
                                                 ServiceHelper.GetService(this, typeof(IDictionaryService));

                string itemFullName = ArgumentsHelper.ReplaceToken(itemFullNameExpression, dictservice);

                Project project = dictservice.GetValue(projectArgumentName) as Project;

                if (project != null)
                {
                    try
                    {
                        newValue = DteHelper.FindItemByName(project.ProjectItems, itemFullName, true);
                    }
                    catch
                    {
                        //With Web projects without any subfolder this method throws an exception
                        newValue = DteHelper.FindItemByName(project.ProjectItems, itemFullName, false);
                    }

                    if (newValue != null)
                    {
                        return(true);
                    }
                }
            }

            newValue = currentValue;
            return(false);
        }
Example #3
0
        public override void Execute()
        {
            if (string.IsNullOrEmpty(RuntimeProviderBaseType))
            {
                RuntimeProviderBaseType = RuntimeProviderRootType;
            }

            IDictionaryService dictionaryService = GetService <IDictionaryService>();

            providerInfo                                 = new ProviderInfo();
            providerInfo.Namespace                       = Namespace;
            providerInfo.ExtendedNamespace               = ExtendedNamespace;
            providerInfo.NamespacesConfiguration         = NamespacesConfiguration;
            providerInfo.NamespacesRuntime               = NamespacesRuntime;
            providerInfo.ProviderName                    = ProviderName;
            providerInfo.RuntimeConfigurationBaseType    = RuntimeConfigurationBaseType;
            providerInfo.RuntimeProviderBaseType         = RuntimeProviderBaseType;
            providerInfo.RuntimeProviderRootType         = RuntimeProviderRootType;
            providerInfo.ConfigurationElementType        = ConfigurationElementType;
            providerInfo.IncludeConfigurationTypeElement = IncludeConfigurationTypeElement;
            providerInfo.RuntimeClassName                = !string.IsNullOrEmpty(RuntimeClassName) ? RuntimeClassName : GenerateRuntimeClassName();
            providerInfo.ConfigurationClassName          = !string.IsNullOrEmpty(ConfigurationClassName) ? ConfigurationClassName : GenerateConfigurationClassName();
            providerInfo.GenerateRuntimeConstructors     = GenerateRuntimeConstructors;

            DefaultRuntimeImplementationTemplate = ArgumentsHelper.ReplaceToken(DefaultRuntimeImplementationTemplate, dictionaryService);
        }
Example #4
0
        public override object EditValue(ITypeDescriptorContext context,
                                         IServiceProvider provider, object value)
        {
            IDictionaryService dictionaryService = (IDictionaryService)provider.GetService(typeof(IDictionaryService));

            initialDirectory = ArgumentsHelper.ReplaceToken(initialDirectoryExpression, dictionaryService);

            object svc = provider.GetService(typeof(IWindowsFormsEditorService));

            if (svc == null)
            {
                return(base.EditValue(context, provider, value));
            }

            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.Title            = Title;
            fileDialog.InitialDirectory = InitialDirectory;
            fileDialog.Filter           = FileFilter;
            fileDialog.FilterIndex      = 1;
            fileDialog.RestoreDirectory = true;
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                return(fileDialog.FileName);
            }
            else
            {
                return(string.Empty);
            }
        }
Example #5
0
        public override bool OnBeginRecipe(object currentValue, out object newValue)
        {
            IDictionaryService dictionaryService = (IDictionaryService)GetService <IDictionaryService>();
            string             typeFullName      = ArgumentsHelper.ReplaceToken(typeFullNameExpression, dictionaryService);
            DTE  vs   = GetService <DTE>();
            Type type = TypeHelper.GetType(vs, typeFullName, useProjectItemWrapper);

            if (type != null)
            {
                newValue = type;
                return(true);
            }
            newValue = null;
            return(false);
        }
Example #6
0
        public override void Execute()
        {
            DTE    vs = GetService <DTE>();
            string resourcesFileName = Resources.get_FileNames(1);

            SourceControlHelper.EnsureWritable(vs, resourcesFileName);
            IDictionaryService dictionaryService = GetService <IDictionaryService>();

            ResourcesHelper.AddResource(resourcesFileName,
                                        ArgumentsHelper.ReplaceToken(ResourceName, dictionaryService),
                                        ArgumentsHelper.ReplaceToken(ResourceValue, dictionaryService));
            VSProjectItem vsResources = Resources.Object as VSProjectItem;

            if (vsResources != null && RunCustomTool)
            {
                vsResources.RunCustomTool();
            }
        }
Example #7
0
        public override void Execute()
        {
            IDictionaryService dictionaryService = (IDictionaryService)GetService <IDictionaryService>();

            DesignTimeNodeInfo = new DesignTimeNodeInfo();
            DesignTimeNodeInfo.DesignTimeProperties  = DesignTimeProperties;
            DesignTimeNodeInfo.ConfigurationType     = RuntimeConfigurationType;
            DesignTimeNodeInfo.ConfigurationBaseType = RuntimeConfigurationType != null ? RuntimeConfigurationType.BaseType : null;
            DesignTimeNodeInfo.BaseNodeName          = ArgumentsHelper.ReplaceToken(BaseNodeName, dictionaryService);
            DesignTimeNodeInfo.ParentUINodeName      = ParentUINodeName;
            DesignTimeNodeInfo.NodeName            = ArgumentsHelper.ReplaceToken(NodeName, dictionaryService);
            DesignTimeNodeInfo.Namespace           = Namespace;
            DesignTimeNodeInfo.ExtendedNamespace   = ExtendedNamespace;
            DesignTimeNodeInfo.Cardinality         = this.Cardinality;
            DesignTimeNodeInfo.AbstractNode        = AbstractNode;
            DesignTimeNodeInfo.PolymorphicProvider = IsPolymorphic();
            DesignTimeNodeInfo.ProviderName        = ProviderName;
        }
Example #8
0
        /// <summary>
        /// The method that creates a new item from the intput string.
        /// </summary>
        public override void Execute()
        {
            if (!AddItem)
            {
                return;
            }

            DTE vs = GetService <DTE>();
            IDictionaryService dictionaryService       = GetService <IDictionaryService>();
            string             targetFileNameProcessed = ArgumentsHelper.ReplaceToken(targetFileName, ReplaceToken, dictionaryService);

            if (!string.IsNullOrEmpty(itemName))
            {
                itemName = ArgumentsHelper.ReplaceToken(itemName, ReplaceToken, dictionaryService);
            }
            string tempfile = Path.GetTempFileName();

            try
            {
                IUIService  uiService         = (IUIService)GetService(typeof(IUIService));
                ProjectItem parentProjectItem = null;
                if (!string.IsNullOrEmpty(itemName))
                {
                    parentProjectItem = DteHelper.FindItemByName(Project.ProjectItems, itemName, true);
                    if (parentProjectItem == null)
                    {
                        try
                        {
                            parentProjectItem = Project.ProjectItems.AddFolder(itemName, Resources.NewFolderKind);
                        }catch
                        {
                            uiService.ShowMessage(string.Format(Resources.ErrCreatingNewFolder, ItemName));
                            parentProjectItem = null;
                        }
                    }
                }
                else if (Item != null)
                {
                    parentProjectItem = Item;
                }
                if (parentProjectItem != null)
                {
                    projectItem = DteHelper.FindItemByName(parentProjectItem.ProjectItems, targetFileNameProcessed, false);
                }
                else
                {
                    projectItem = DteHelper.FindItemByName(Project.ProjectItems, targetFileNameProcessed, false);
                }

                if (PromptForOverwriting && projectItem != null)
                {
                    DialogResult result = uiService.ShowMessage(string.Format(Resources.FileAlreadyExists, targetFileNameProcessed), Resources.FileAlreadyExistsCaption, MessageBoxButtons.OKCancel);
                    if (result == DialogResult.Cancel)
                    {
                        CancelByTheUser = true;
                        return;
                    }
                }

                if (projectItem != null)
                {
                    projectItem.Delete();
                }
                using (StreamWriter sw = new StreamWriter(tempfile, false, Encoding.UTF8))
                {
                    sw.WriteLine(content);
                }
                if (parentProjectItem != null)
                {
                    projectItem = parentProjectItem.ProjectItems.AddFromTemplate(tempfile, targetFileNameProcessed);
                }
                else
                {
                    projectItem = project.ProjectItems.AddFromTemplate(tempfile, targetFileNameProcessed);
                }

                if (open && projectItem != null)
                {
                    Window wnd = projectItem.Open(Constants.vsViewKindPrimary);
                    wnd.Visible = true;
                    wnd.Activate();
                }
            }
            finally
            {
                File.Delete(tempfile);
            }
        }
Example #9
0
        private object GenerateArgumentValue()
        {
            IDictionaryService dictionaryService = (IDictionaryService)GetService <IDictionaryService>();

            return(ArgumentsHelper.ReplaceToken(expressionArgument, tokenSeparator, dictionaryService));
        }