Example #1
0
 private void AddApplicationResources(Project _CurrentProject, string resourcefilename, string content)
 {
     if (Helpers2.IsSharePointVSTemplate(_CurrentProject.DTE, _CurrentProject))
     {
         AddResources(_CurrentProject, "Resources\\AppGlobalResources", resourcefilename, content, SPFileType.AppGlobalResource, "");
     }
     else
     {
         //deploy resx file to 14\Config\Resources
         ProjectItems whereToAdd = Helpers2.GetDeploymentPath(_CurrentProject.DTE, _CurrentProject, SPFileType.RootFile, "CONFIG\\Resources");
         AddResourcesToFolder(whereToAdd.Parent as ProjectItem, resourcefilename, content);
     }
 }
        public override NameValueItem GetNameValueItem(XmlNode node, XmlDocument resdoc, ProjectItem item)
        {
            NameValueItem res = base.GetNameValueItem(node, resdoc, item);

            if (res != null)
            {
                //set the featureid of the listtemplate in field group (important for list instances
                //find the parent feature of item (in the item the listtemplate is defined
                string featureId = Helpers2.GetFeatureIdOfProjectItem(item);
                res.Group = featureId;
            }
            return(res);
        }
Example #3
0
 private void AddGlobalResources(Project _CurrentProject, string resourcefilename, string content)
 {
     if (Helpers2.IsSharePointVSTemplate(_CurrentProject.DTE, _CurrentProject))
     {
         AddResources(_CurrentProject, "Resources\\Resources", resourcefilename, content, SPFileType.RootFile, "Resources");
     }
     else
     {
         //get the folder where to place the resx file
         ProjectItems whereToAdd = Helpers2.GetDeploymentPath(_CurrentProject.DTE, _CurrentProject, SPFileType.RootFile, "Resources");
         AddResourcesToFolder(whereToAdd.Parent as ProjectItem, resourcefilename, content);
     }
 }
Example #4
0
 public static void Play(string strFileName, int sign)
 {
     //Helpers1.PlaySound( strFileName, IntPtr.Zero, Helpers1.PlaySoundFlags.SND_FILENAME | Helpers1.PlaySoundFlags.SND_ASYNC );
     //Helpers1 Helpers1=new Helpers1();
     if (sign == 1)
     {
         Helpers1.PlaySound(strFileName, IntPtr.Zero, Helpers1.PlaySoundFlags.SND_FILENAME | Helpers1.PlaySoundFlags.SND_ASYNC | Helpers1.PlaySoundFlags.SND_NODEFAULT);
     }
     else
     {
         Helpers2.PlaySound(strFileName, IntPtr.Zero, Helpers2.PlaySoundFlags.SND_FILENAME | Helpers2.PlaySoundFlags.SND_ASYNC);
     }
 }
Example #5
0
 private void AddAdminResources(Project _CurrentProject, string resourcefilename, string content)
 {
     //files for central administration
     if (Helpers2.IsSharePointVSTemplate(_CurrentProject.DTE, _CurrentProject))
     {
         AddResources(_CurrentProject, "Resources\\AppGlobalResources", resourcefilename, content, SPFileType.AppGlobalResource, "");
     }
     else
     {
         ProjectItems whereToAdd = Helpers2.GetDeploymentPath(_CurrentProject.DTE, _CurrentProject, SPFileType.RootFile, "CONFIG\\AdminResources");
         AddResourcesToFolder(whereToAdd.Parent as ProjectItem, resourcefilename, content);
     }
 }
Example #6
0
        public override void Execute()
        {
            if (string.IsNullOrEmpty(SiteUrl))
            {
                return;
            }

            EnvDTE.DTE service = this.GetService <EnvDTE.DTE>(true);

            if (!string.IsNullOrEmpty(CurrentProjectName))
            {
                CurrentProject = Helpers.GetProjectByName(service, CurrentProjectName);
            }


            try
            {
                ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(service);

                if (CurrentProject != null)
                {
                    try
                    {
                        //set url for current project
                        ISharePointProject sharePointProject = projectService.Convert <EnvDTE.Project, ISharePointProject>(CurrentProject);
                        sharePointProject.SiteUrl = new Uri(SiteUrl);
                    }
                    catch { }
                }
                else
                {
                    //set url for all projects
                    foreach (ISharePointProject sharePointProject in projectService.Projects)
                    {
                        try
                        {
                            if (sharePointProject.SiteUrl == null)
                            {
                                sharePointProject.SiteUrl = new Uri(SiteUrl);
                                Helpers.LogMessage(service, this, "Settings site url of project  " + sharePointProject.Name + " to " + new Uri(SiteUrl).ToString());
                            }
                        }
                        catch (Exception)
                        {
                            Helpers.LogMessage(service, this, "Could not set site url of project " + sharePointProject.Name + " to " + new Uri(SiteUrl).ToString());
                        }
                    }
                }
            }
            catch { }
        }
        private void SetDeploymentPath(DTE dte, Project project, ProjectItem CreatedProjectItem, SPFileType sPFileType, string evaluatedDeploymentPath)
        {
            //set to content
            if ((sPFileType != SPFileType.CustomCode))
            {
                CreatedProjectItem.Properties.Item("BuildAction").Value = 2;
            }

            //ok, file is placed, but we need set the deployment path
            ISharePointProjectService projectService    = Helpers2.GetSharePointProjectService(dte);
            ISharePointProject        sharePointProject = projectService.Convert <EnvDTE.Project, ISharePointProject>(project);

            sharePointProject.Synchronize();

            if (CreatedProjectItem.Collection.Parent is ProjectItem)
            {
                ProjectItem parentItem = CreatedProjectItem.Collection.Parent as ProjectItem;
                string      name       = parentItem.Name;

                //is the parent element a feature?
                try
                {
                    ISharePointProjectFeature parentIsFeature = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectFeature>(parentItem);
                    if (parentIsFeature != null)
                    {
                        ISharePointProjectItem addedSharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItem>(CreatedProjectItem);
                        if (addedSharePointItem != null)
                        {
                            parentIsFeature.ProjectItems.Add(addedSharePointItem);
                        }
                    }
                }
                catch { }
            }

            try
            {
                //sometimes property deploymentpath is readonly
                //1. new added items need to be validated before
                ISharePointProjectItemFile newaddedSharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItemFile>(CreatedProjectItem);
                newaddedSharePointItem.DeploymentType = Helpers2.GetDeploymentTypeFromFileType(this.DeploymentType);
                if (!string.IsNullOrEmpty(evaluatedDeploymentPath))
                {
                    newaddedSharePointItem.DeploymentPath = evaluatedDeploymentPath;
                }
            }
            catch { }
        }
        private void AddSPDataDefinitionToVSTemplate(DTE dte, Project project, string evaluatedSPDataTemplate, string evaluatedSPDataCategory, string evaluatedSPDataName)
        {
            string spDataContent = GenerateContent(evaluatedSPDataTemplate, "SharePointProjectItem.spdata");

            //1. create the folder for the content type, which means adding the spdata stuff to a folder in the project

            string       targetFolder      = evaluatedSPDataCategory + @"\" + evaluatedSPDataName;
            ProjectItems contentTypeFolder = null;
            ProjectItem  spDataItem        = Helpers2.AddFileToProject(dte, project, targetFolder, "SharePointProjectItem.spdata", spDataContent, true, false, out contentTypeFolder);

            ProjectItem elementFolder = Helpers.FindProjectItemByPath(project, targetFolder);

            Helpers2.AddVSElementToVSPackage(dte, project, elementFolder);

            CreatedElementFolder = elementFolder;
        }
Example #9
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            Cursor.Current = Cursors.WaitCursor;

            list = new List <NameValueItem>();

            if (context != null)
            {
                DTE dte = (DTE)context.GetService(typeof(_DTE));
                Helpers2.AddInternalItems(dte, true, list, "/ns:Elements/ns:ContentType", "http://schemas.microsoft.com/sharepoint/", new XmlNodeHandler("Name", "ID", "Group", "Description"));
            }

            Cursor.Current = Cursors.Default;

            return(new StandardValuesCollection(list.ToArray()));
        }
 protected Project GetTargetProject(DTE dte)
 {
     if (Project != null)
     {
         return(Project);
     }
     if (!string.IsNullOrEmpty(ProjectName))
     {
         Project destinationProject = Helpers.GetProjectByName(dte, ProjectName);
         if (destinationProject != null)
         {
             return(destinationProject);
         }
     }
     return(Helpers2.GetSelectedProject(dte));
 }
        public override void Execute()
        {
            DTE     dte     = (DTE)this.GetService(typeof(DTE));
            Project project = this.GetTargetProject(dte);

            //1. get correct parameters ("$(FeatureName)" as "FeatureX")
            string evaluatedSPDataTemplate = EvaluateParameterAsString(dte, SPDataTemplate);
            string evaluatedSPDataCategory = EvaluateParameterAsString(dte, ElementsCategory);
            string evaluatedSPDataName     = EvaluateParameterAsString(dte, ElementsName);
            string evaluatedDeploymentPath = EvaluateParameterAsString(dte, DeploymentPath);

            //2. create the Element
            if (Helpers2.IsSharePointVSTemplate(dte, project))
            {
                AddSPDataDefinitionToVSTemplate(dte, project, evaluatedSPDataTemplate, evaluatedSPDataCategory, evaluatedSPDataName);
            }
        }
        /// <summary>
        /// Adds a new feature
        /// </summary>
        private void AddFeatureToVSTemplate(DTE dte, Project project, string finalFeatureName)
        {
            string targetFolder    = @"Features\" + finalFeatureName;
            string targetFilename1 = finalFeatureName + ".feature";
            string targetFilename2 = finalFeatureName + ".Template.xml";

            //1. add folder with featurename to folder /Features and place FeatureName.feature in the folder.
            //2. add FeatureName.Template.xml in the same folder
            string featureContent         = GenerateContent(this.sPDataTemplate, targetFilename1);
            string featureTemplateContent = GenerateContent(this.TemplateFileName, targetFilename2);

            CreatedProjectItem = Helpers2.AddFileToProject(dte, project, targetFolder, targetFilename1, featureContent, true, false);
            //CreatedProjectFolder = CreatedProjectItem.Collection.Parent as ProjectItem;
            Helpers2.AddFileToProject(dte, project, targetFolder, targetFilename2, featureTemplateContent, true, false);

            CreatedProjectFolder = Helpers2.AddVSFeatureToVSPackage(dte, project, finalFeatureName);
        }
        public override void Execute()
        {
            DTE     dte     = (DTE)this.GetService(typeof(DTE));
            Project project = this.GetTargetProject(dte);

            //Microsoft.Practices.RecipeFramework.GuidancePackage p = (Microsoft.Practices.RecipeFramework.GuidancePackage)GetService(typeof(Microsoft.Practices.RecipeFramework.Services.IExecutionService));
            //ISite x = p.Site;

            //1. get correct parameters ("$(FeatureName)" as "FeatureX")
            string evaluatedFeatureName = EvaluateParameterAsString(dte, featureName);

            //2. create the Feature
            if (Helpers2.IsSharePointVSTemplate(dte, project))
            {
                AddFeatureToVSTemplate(dte, project, evaluatedFeatureName);
            }
        }
Example #14
0
        private bool SetValue(object currentValue, out object newValue)
        {
            if (currentValue != null)
            {
                newValue = null;
                return(false);
            }

            EnvDTE.DTE dte = this.GetService <EnvDTE.DTE>(true);

            Project currentProject = Helpers.GetSelectedProject(dte);

            //string projectId = currentProject.

            newValue = Helpers2.GetProjectGuid(currentProject).ToString();
            return(true);
        }
        public override void Execute()
        {
            DTE     dte     = GetService <DTE>(true);
            Project project = TargetProject;

            if (project == null)
            {
                project = Helpers.GetSelectedProject(dte);
            }

            if (Helpers2.IsSharePointVSTemplate(dte, project))
            {
                Helpers2.GetOrCreateMappedFolder(project, "RootFile", "SharePointRoot");
            }

            Helpers.ExtractWSPToProject(dte, _WSPFilename, _TargetProject, GetBasePath());
        }
        private void AddElementsDefinitionToVSTemplate(DTE dte, Project project, string evaluatedParentFeatureName, string evaluatedSPDataTemplate, string evaluatedElementsTemplate, string evaluatedElementsCategory, string evaluatedElementsName, string evaluatedTargetFileName)
        {
            string elementsXmlContent = GenerateContent(evaluatedElementsTemplate, "Elements.xml");
            string spDataContent      = GenerateContent(evaluatedSPDataTemplate, "SharePointProjectItem.spdata");

            //1. create the folder for the content type, which means adding the spdata stuff to a folder in the project

            string       targetFolder      = evaluatedElementsCategory + @"\" + evaluatedElementsName;
            ProjectItems contentTypeFolder = null;
            ProjectItem  spDataItem        = Helpers2.AddFileToProject(dte, project, targetFolder, "SharePointProjectItem.spdata", spDataContent, true, false, out contentTypeFolder);

            //2. put the elements.xml in that folder
            CreatedElementFile = Helpers2.AddFile(dte, contentTypeFolder, evaluatedTargetFileName, elementsXmlContent, true, this.Open);

            if (this.DeploymentTypeIsSet)
            {
                //default deployment type is ElementManifest
                Helpers2.SetDeploymentType(CreatedElementFile, this.DeploymentType);
            }
            else
            {
                Helpers2.SetDeploymentType(CreatedElementFile, SPFileType.ElementManifest);
            }

            //Trace.WriteLine("AddElementsDefinitionAction FindProjectItemByPath " + targetFolder);
            ProjectItem elementFolder = Helpers.FindProjectItemByPath(project, targetFolder);

            //3. add the item to the selected feature or to the package
            if (!string.IsNullOrEmpty(evaluatedParentFeatureName))
            {
                //element can be added to a feature
                //Trace.WriteLine("AddElementsDefinitionAction evaluatedParentFeatureName=" + evaluatedParentFeatureName);
                Helpers2.AddVSElementToVSFeature(dte, project, elementFolder, evaluatedParentFeatureName);
            }
            else
            {
                //no featurename is given, we add the element to the package
                //Trace.WriteLine("AddElementsDefinitionAction evaluatedParentFeatureName=null");
                Helpers2.AddVSElementToVSPackage(dte, project, elementFolder);
            }

            CreatedElementFolder = elementFolder;
        }
        public override void Execute()
        {
            if (string.IsNullOrEmpty(DeploymentTarget))
            {
                return;
            }

            var service = this.GetService <DTE>(true);

            if (!string.IsNullOrEmpty(CurrentProjectName))
            {
                CurrentProject = Helpers.GetProjectByName(service, CurrentProjectName);
            }


            try
            {
                ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(service);

                if (CurrentProject != null)
                {
                    try
                    {
                        //set url for current project
                        ISharePointProject sharePointProject = projectService.Convert <Project, ISharePointProject>(CurrentProject);
                        ChangeDeploymentTarget(sharePointProject, DeploymentTarget);
                    }
                    catch { }
                }
                else
                {
                    foreach (ISharePointProject sharePointProject in projectService.Projects)
                    {
                        try
                        {
                            ChangeDeploymentTarget(sharePointProject, DeploymentTarget);
                        }
                        catch { }
                    }
                }
            }
            catch { }
        }
 private void MigrateProject(DTE service, Project project)
 {
     Helpers.LogMessage(service, this, "Migrating project '" + project.Name + "'");
     try
     {
         if (Helpers.IsCustomizationProject(project))
         {
             Helpers2.AddBuildDependency(service, Helpers.GetProjectByName(service, this.DeploymentProject), project);
             MigrateCustomizationProject(service, project);
         }
         else if (project.Name.Equals(this.DeploymentProject, StringComparison.InvariantCultureIgnoreCase))
         {
             MigrateProjectDeployment(project);
         }
     }
     catch (Exception ex)
     {
         Helpers.LogMessage(service, this, "Error: Migration of project '" + project.Name + "' failed: " + ex.Message);
     }
 }
Example #19
0
        public override void Execute()
        {
            if (ExcludeCondition)
            {
                return;
            }
            if (!AdditionalCondition)
            {
                return;
            }

            DTE dte = (DTE)this.GetService(typeof(DTE));

            //1. get correct parameters ("$(FeatureName)" as "FeatureX")
            string evaluatedTargetFileName   = EvaluateParameterAsString(dte, TargetFileName);
            string evaluatedTemplateFileName = EvaluateParameterAsString(dte, TemplateFileName);
            string contents = GenerateContent(evaluatedTemplateFileName, evaluatedTargetFileName);

            if (Helpers2.TemplateContentIsEmpty(contents))
            {
                return;
            }

            try
            {
                //2. save the file to a temporary folder
                SourceFileName = Path.GetTempFileName();
                WriteContentToTempFile(SourceFileName, contents, evaluatedTargetFileName);

                //now run parent action which adds the file to the project
                base.Execute();

                //now we can delete the temp file
                File.Delete(SourceFileName);
            }
            catch (Exception ex)
            {
                Helpers.LogMessage(dte, dte, ex.ToString());
                throw ex;
            }
        }
Example #20
0
        /// <summary>
        /// returns the deployment url for the project
        /// </summary>
        /// <param name="dte"></param>
        /// <param name="project"></param>
        /// <returns></returns>
        internal static string GetSiteUrl(DTE dte, Project project)
        {
            try
            {
                ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(dte);

                if (project != null)
                {
                    try
                    {
                        //set url for current project
                        ISharePointProject sharePointProject = projectService.Convert <EnvDTE.Project, ISharePointProject>(project);
                        return(sharePointProject.SiteUrl.ToString());
                    }
                    catch { }
                }
            }
            catch { }

            return(Helpers.GetApplicationConfigValue(dte, "DebuggingWebApp", "").ToString());
        }
        private bool ItemIsDeployable(ProjectItem pitem)
        {
            string sourcefilename = Helpers.GetFullPathOfProjectItem(pitem);

            if (!Helpers2.IsFileDeployableToHive(sourcefilename))
            {
                return(false);
            }

            try
            {
                ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(pitem.DTE);

                try
                {
                    ISharePointProjectItemFile selectedSharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItemFile>(pitem);
                    if (selectedSharePointItem != null && selectedSharePointItem.DeploymentPath != "")
                    {
                        return(true);
                    }
                }
                catch { }
            }
            catch { }

            //check if the parent is folder 12
            try
            {
                string itemPath    = Helpers.GetFullPathOfProjectItem(pitem);
                string projectPath = Helpers.GetProjectFolder(pitem.ContainingProject);
                itemPath = itemPath.Substring(projectPath.Length + 1);
                if (itemPath.StartsWith(@"12") || itemPath.StartsWith(@"14") || itemPath.StartsWith(@"15") || itemPath.StartsWith(@"SharePointRoot", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }
            }
            catch { }

            return(false);
        }
Example #22
0
        //[Output]
        //public ProjectItem CreatedProjectFolder { get; set; }

        //[Output]
        //public ProjectItem CreatedProjectItem { get; set; }

        public override void Execute()
        {
            DTE     dte     = (DTE)this.GetService(typeof(DTE));
            Project project = this.GetTargetProject(dte);

            string evaluatedSPDataTemplate = EvaluateParameterAsString(dte, SPDataTemplate);
            string evaluatedTemplate       = EvaluateParameterAsString(dte, TemplateFileName);
            string evaluatedSPDataCategory = EvaluateParameterAsString(dte, SPDataCategory);
            string evaluatedSPDataName     = EvaluateParameterAsString(dte, SPDataName);
            string evaluatedTargetFileName = EvaluateParameterAsString(dte, TargetFileName);
            string evaluatedDeploymentPath = EvaluateParameterAsString(dte, DeploymentPath);

            //2. create the Element
            if (Helpers2.IsSharePointVSTemplate(dte, project))
            {
                AddSPDataDefinitionToVSTemplate(dte, project, evaluatedSPDataTemplate, evaluatedTemplate, evaluatedSPDataCategory, evaluatedSPDataName, evaluatedTargetFileName, evaluatedDeploymentPath);
            }
            else
            {
                base.Execute();
            }
        }
        public override void Execute()
        {
            DTE dte = base.GetService <DTE>(true);

            Project _dependingProject = Helpers.GetProjectByName(dte, this.DependingProject);
            Project _sourceProject    = Helpers.GetProjectByName(dte, this.SourceProject);

            if (_dependingProject == null || _sourceProject == null)
            {
                return;
            }

            try
            {
                Helpers2.AddBuildDependency(dte, _dependingProject, _sourceProject);
            }
            catch (Exception ex)
            {
                Helpers.LogMessage(dte, this, ex.ToString());

                MessageBox.Show(ex.ToString());
            }
        }
Example #24
0
        private void AddResources(Project _CurrentProject, string folderName, string resourcefilename, string content, SPFileType deploymentFileType, string deploymentPath)
        {
            //in VSS we would create an empty element "Resources" and would add the resource.resx there with different deploymenttargets
            //1. erstelle folder "Resources" und packe Text\Resources\SharePointProjectItem.spdata.t4 rein
            //2. packe file da hinein und setze noch schnell den deployment path
            //1. erstelle Folder Resources\AppResources

            ProjectItems contentTypeFolder       = null;
            string       SPDataTemplate          = @"Text\Resources\SharePointProjectItem.spdata.t4";
            string       evaluatedSPDataTemplate = EvaluateParameterAsString(_CurrentProject.DTE, SPDataTemplate);
            string       spDataContent           = GenerateContent(evaluatedSPDataTemplate, "SharePointProjectItem.spdata");
            ProjectItem  spDataItem = Helpers2.AddFileToProject(_CurrentProject.DTE, _CurrentProject, folderName, "SharePointProjectItem.spdata", spDataContent, false, false, out contentTypeFolder);

            //add the resx file or the content to the folder
            ProjectItem resourceFileItem = AddResourcesToFolder(contentTypeFolder.Parent as ProjectItem, resourcefilename, content);

            //ensure that the resources element folder is part of package
            Helpers2.AddVSElementToVSPackage(_CurrentProject.DTE, _CurrentProject, contentTypeFolder.Parent as ProjectItem);

            //set the deployment type to Resource, AppGlobalResource
            Helpers2.SetDeploymentType(resourceFileItem, deploymentFileType);

            Helpers2.SetDeploymentPath(resourceFileItem, deploymentPath);
        }
Example #25
0
        public override void Execute()
        {
            DTE service = (DTE)this.GetService(typeof(DTE));

            try
            {
                if (projectItem != null)
                {
                    Helpers.LogMessage(service, this, "*********** SharePointService Properties ********************");
                    try
                    {
                        ISharePointProjectService projectService    = Helpers2.GetSharePointProjectService(service);
                        ISharePointProject        sharePointProject = projectService.Convert <Project, ISharePointProject>(project);

                        try
                        {   //is it a feature
                            ISharePointProjectFeature sharePointFeature = projectService.Convert <ProjectItem, ISharePointProjectFeature>(projectItem);
                        }
                        catch { }

                        try
                        {   //is it a feature
                            ISharePointProjectItem sharePointItem = projectService.Convert <ProjectItem, ISharePointProjectItem>(projectItem);
                        }
                        catch { }

                        try
                        {   //is it a feature
                            ISharePointProjectItemFile sharePointItemFile = projectService.Convert <ProjectItem, ISharePointProjectItemFile>(projectItem);
                        }
                        catch { }

                        try
                        {   //is it a mapped folder
                            IMappedFolder sharePointMappedFolder = projectService.Convert <ProjectItem, IMappedFolder>(projectItem);
                        }
                        catch { }

                        try
                        {   //is it a mapped folder
                            ISharePointProjectPackage sharePointProjectPackage = projectService.Convert <ProjectItem, ISharePointProjectPackage>(projectItem);
                        }
                        catch { }
                    }
                    catch {}

                    //codelements
                    Helpers.LogMessage(service, this, "*********** EnvDTE CodeElements ********************");

                    foreach (CodeElement codeElement in projectItem.FileCodeModel.CodeElements)
                    {
                        try
                        {
                            Helpers.LogMessage(service, this, "codeElement.FullName: " + codeElement.FullName);
                            Helpers.LogMessage(service, this, "codeElement.Type: " + codeElement.GetType().ToString());
                            Helpers.LogMessage(service, this, "codeElement.Kind: " + codeElement.Kind.ToString());
                        }
                        catch {}
                    }

                    Helpers.LogMessage(service, this, "*********** EnvDTE Properties ********************");
                    for (int i = 0; i < projectItem.Properties.Count; i++)
                    {
                        try
                        {
                            string name  = projectItem.Properties.Item(i).Name;
                            string value = "";
                            try
                            {
                                value = projectItem.Properties.Item(i).Value.ToString();
                            }
                            catch (Exception)
                            {
                            }
                            Helpers.LogMessage(service, this, name + "=" + value);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else if (project != null)
                {
                    for (int i = 0; i < project.Properties.Count; i++)
                    {
                        try
                        {
                            string name  = project.Properties.Item(i).Name;
                            string value = "";
                            try
                            {
                                value = project.Properties.Item(i).Value.ToString();
                            }
                            catch (Exception)
                            {
                            }
                            Helpers.LogMessage(service, this, name + "=" + value);

                            if (project.Properties.Item(i).Collection.Count > 0)
                            {
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Helpers.LogMessage(service, this, ex.ToString());
            }
        }
 public override void Undo()
 {
     //in error case try delete dummy file
     Helpers2.DeleteDummyFile((DTE)this.GetService(typeof(DTE)), null, false);
 }
        private void AddFileInternal(DTE dte, Project project, string evaluatedSourceFileName, string evaluatedTargetFileName, string evaluatedDeploymentPath)
        {
            if (!Path.IsPathRooted(evaluatedSourceFileName))
            {
                evaluatedSourceFileName = Path.Combine(GetTemplateBasePath(), evaluatedSourceFileName);
            }

            //ok, check the parameters
            if (!File.Exists(evaluatedSourceFileName))
            {
                //ignore this action if no source file is found, used e.g. in contenttype when no file is given
                return;
            }
            if (string.IsNullOrEmpty(evaluatedTargetFileName))
            {
                evaluatedTargetFileName = Path.GetFileName(evaluatedSourceFileName);
            }

            //targetfolder specified, find the project item
            if (!string.IsNullOrEmpty(TargetFolder) && (ParentProjectFolder == null))
            {
                //overwrite target folder
                ParentProjectFolder  = Helpers.GetFolder(project, TargetFolder, true);
                CreatedProjectFolder = this.ParentProjectFolder;
            }

            if (Helpers2.IsSharePointVSTemplate(dte, project))
            {
                if (this.ParentProjectItem != null)
                {
                    //used to add code files to a parent file
                    CreatedProjectItem = Helpers.AddFromTemplate(ParentProjectItem.ProjectItems, evaluatedSourceFileName, evaluatedTargetFileName, Overwrite);
                    if (DeploymentTypeIsSet)
                    {
                        SetDeploymentPath(dte, project, CreatedProjectItem, this.DeploymentType, evaluatedDeploymentPath);
                    }
                }
                else if (this.ParentProjectFolder != null)
                {
                    //we place the file directly in the given folder
                    //and mapped the item to the deployment location
                    CreatedProjectItem = Helpers.AddFromTemplate(this.ParentProjectFolder.ProjectItems, evaluatedSourceFileName, evaluatedTargetFileName, Overwrite);
                    if (DeploymentTypeIsSet)
                    {
                        SetDeploymentPath(dte, project, CreatedProjectItem, this.DeploymentType, evaluatedDeploymentPath);
                    }
                }
                else if (DeploymentTypeIsSet)
                {
                    //place the file in a mapped folder
                    ProjectItems whereToAdd = Helpers2.GetDeploymentPath(dte, project, this.DeploymentType, evaluatedDeploymentPath);
                    CreatedProjectItem = Helpers.AddFromTemplate(whereToAdd, evaluatedSourceFileName, evaluatedTargetFileName, Overwrite);
                    //do not set the deploymentpath as we already placed the file in the mapped folder location
                }
                else if (project != null)
                {
                    CreatedProjectItem = Helpers.AddFromTemplate(project.ProjectItems, evaluatedSourceFileName, evaluatedTargetFileName, Overwrite);
                }
                else
                {
                    throw new Exception("Don't know where to place the file");
                }
            }

            if (CreatedProjectItem != null)
            {
                //set the build action
                if (CreatedProjectItem.Name.EndsWith(".resx", StringComparison.InvariantCultureIgnoreCase))
                {
                    CreatedProjectItem.Properties.Item("BuildAction").Value = 2;
                }
            }


            if (this.Open)
            {
                if (this.CreatedProjectItem != null)
                {
                    Window window = this.CreatedProjectItem.Open("{00000000-0000-0000-0000-000000000000}");
                    window.Visible = true;
                    window.Activate();
                }
            }
        }
Example #28
0
        public override bool IsEnabledFor(object target)
        {
            Helpers.Log("XmlMergeReference");

            if (!(target is ProjectItem))
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(this.SharePointVersions))
            {
                try
                {
                    if (!Helpers.SolutionHasVersion(Helpers.GetDTEFromTarget(target), SharePointVersions))
                    {
                        return(false);
                    }
                }
                catch (Exception)
                {
                }
            }

            try
            {
                if (XPath != "")
                {
                    //ok, item is clicked, we search now for a child element which contains the needed xpath,
                    //if we find a element, we return true
                    if (target is ProjectItem)
                    {
                        ProjectItem pitem = target as ProjectItem;
                        if (pitem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile)
                        {
                            //is the xml file clicked?
                            try
                            {
                                if (pitem.Name.EndsWith(".XML", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    return(Helpers2.IsXPathInFile(pitem, this.XPath, this.XPathNamespace));
                                }
                            }
                            catch { }
                        }
                        else
                        {
                            if (pitem.ProjectItems != null)
                            {
                                //folder is clicked, we search for xml files below the folder which contains the needed xpath
                                foreach (ProjectItem childItem in pitem.ProjectItems)
                                {
                                    if (childItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile)
                                    {
                                        if (childItem.Name.EndsWith(".XML", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            if (Helpers2.IsXPathInFile(childItem, this.XPath, this.XPathNamespace))
                                            {
                                                return(true);
                                            }
                                        }
                                    }
                                    //sometimes files have childs
                                    foreach (ProjectItem subchildItem in childItem.ProjectItems)
                                    {
                                        if (subchildItem.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile)
                                        {
                                            if (subchildItem.Name.EndsWith(".XML",
                                                                           StringComparison.InvariantCultureIgnoreCase))
                                            {
                                                if (Helpers2.IsXPathInFile(subchildItem, this.XPath, this.XPathNamespace))
                                                {
                                                    return(true);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            return(false);
        }
Example #29
0
        public override void Execute()
        {
            if (ExcludeCondition)
            {
                return;
            }
            if (!AdditionalCondition)
            {
                return;
            }

            DTE     dte     = (DTE)this.GetService(typeof(DTE));
            Project project = this.GetTargetProject(dte);

            string evaluatedTemplateFileName = EvaluateParameterAsString(dte, TemplateFileName);


            string templateContent = GenerateContent(evaluatedTemplateFileName, "Resources.resx");

            if (Helpers2.TemplateContentIsEmpty(templateContent))
            {
                //do nothing if no content has been generated
                return;
            }

            //get the project where we pla
            Project globalresproject = Helpers.GetResourcesProject(dte);
            Project selectedproject  = Helpers.GetSelectedProject(dte);

            string resourcesFilename = "";

            if (FeatureResources)
            {
                //for feature resources name is "Resources.resx"
                resourcesFilename = "Resources.resx";
            }
            else if (ApplicationResources)
            {
                resourcesFilename = Helpers.GetOutputNameWithoutExtensions(selectedproject) + ".AppResources.resx";
            }
            else
            {
                //global resources get the name of the current project project
                resourcesFilename = Helpers.GetOutputNameWithoutExtensions(selectedproject) + ".resx";
            }

            //1. find a resourcefile
            if (ApplicationResources)
            {
                if (globalresproject != null)
                {
                    //global resources project -> use the file 12/resources
                    AddApplicationResources(globalresproject, resourcesFilename, templateContent);
                }
                else
                {
                    AddApplicationResources(selectedproject, resourcesFilename, templateContent);
                }
            }
            else if (FeatureResources)
            {
                string evaluatedFeatureName = EvaluateParameterAsString(dte, FeatureName);

                //Find the feature folder

                ProjectItem folderOfFeature = Helpers2.GetFolderOfFeature(project, evaluatedFeatureName);
                if (folderOfFeature != null)
                {
                    if (Helpers2.IsSharePointVSTemplate(dte, project))
                    {
                        //put resources.resx directly into under the feature
                        AddResourcesToFolder(folderOfFeature, resourcesFilename, templateContent);
                    }
                    else
                    {
                        //now add a folder "Resources" in the feature and put the "Resource.<culture>.resx" there
                        ProjectItems whereToAdd = Helpers.GetProjectItemsByPath(folderOfFeature.ProjectItems, "Resources");
                        AddResourcesToFolder(whereToAdd.Parent as ProjectItem, resourcesFilename, templateContent);
                    }
                }
            }
            else if (AdminResources)
            {
                //put the content into
                if (globalresproject != null)
                {
                    //global resources project -> use the file 12/resources
                    AddAdminResources(globalresproject, resourcesFilename, templateContent);
                }
                else
                {
                    AddAdminResources(selectedproject, resourcesFilename, templateContent);
                }
            }
            else
            {
                //put the content into
                if (globalresproject != null)
                {
                    //global resources project -> use the file 12/resources
                    AddGlobalResources(globalresproject, resourcesFilename, templateContent);
                }
                else
                {
                    AddGlobalResources(selectedproject, resourcesFilename, templateContent);
                }
            }
        }
Example #30
0
        public override void Execute()
        {
            DTE service = (DTE)this.GetService(typeof(DTE));

            Helpers.ShowProgress(service, "Generating WSDL...", 10);

            string defaultIISAPP = Helpers.GetDefaultIISWebApp();

            string workingDirectory = Path.Combine(Path.GetTempPath(), "SPALMWSDL" + Guid.NewGuid().ToString());

            Directory.CreateDirectory(workingDirectory);

            ProjectItem asmxfileParentFolder = (ProjectItem)WebServiceFile.ProjectItems.Parent;

            //build if necessary
            Helpers.WriteToOutputWindow(service, "Compile to get actual version of dll");
            Project project = WebServiceFile.ContainingProject;

            service.Solution.SolutionBuild.BuildProject(service.Solution.SolutionBuild.ActiveConfiguration.Name, project.UniqueName, true);

            //get the asmx file and copy to /_layouts
            string projectpath   = Helpers.GetFullPathOfProjectItem(project);
            string projectfolder = Path.GetDirectoryName(projectpath);

            bool   ASMXFileExisted        = false;
            string fullasmxtarget         = "";
            string asmxfilename           = WebServiceFile.Name;
            string asmxfilenamewithoutext = asmxfilename.Substring(0, asmxfilename.LastIndexOf("."));
            string asmxfullPath           = Helpers.GetFullPathOfProjectItem(WebServiceFile);

            if (File.Exists(asmxfullPath))
            {
                string targetfolder = Helpers.GetSharePointHive() + @"\TEMPLATE\LAYOUTS";
                Helpers.WriteToOutputWindow(service, "Copying asmx file to _layouts folder");
                fullasmxtarget = Path.Combine(targetfolder, asmxfilename);
                if (File.Exists(fullasmxtarget))
                {
                    ASMXFileExisted = true;
                }
                File.Copy(asmxfullPath, fullasmxtarget, true);
            }

            //add the assembly to the gac
            string OutputFileName = project.Properties.Item("OutputFileName").Value.ToString();
            string OutputPath     = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString();
            string assemblypath   = Path.Combine(Path.Combine(projectfolder, OutputPath), OutputFileName);

            if (!File.Exists(assemblypath))
            {
                //check GAC folder of project
                assemblypath = Path.Combine(projectfolder, "GAC");
                if (Directory.Exists(assemblypath))
                {
                    assemblypath = Path.Combine(assemblypath, OutputFileName);
                }
            }

            if (!File.Exists(assemblypath))
            {
                string message = "Warning: No assembly in project found";
                Helpers.LogMessage(service, this, message);
                MessageBox.Show(message);
            }

            if (File.Exists(assemblypath))
            {
                string gacutilpath = Helpers.GetGACUtil(service);
                //sear
                if (File.Exists(gacutilpath))
                {
                    Helpers.ShowProgress(service, "Generating WSDL...", 30);
                    Helpers.WriteToOutputWindow(service, "Install dll in GAC", false);
                    Helpers.RunProcess(service, gacutilpath, "/if " + assemblypath, true, workingDirectory, false);
                    Helpers.WriteToOutputWindow(service, "IISReset to force reload of dll", false);
                    Helpers.ShowProgress(service, "Generating WSDL...", 60);
                    Helpers.LogMessage(service, this, "IISRESET...");
                    Helpers.RunProcess(service, "iisreset", "", true, workingDirectory, false);
                }
                else
                {
                    string message =
                        "GACUTIL.exe not found on your system.\nPlease install .net or Windows SDK.\ni.e. Windows SDK 7.1 http://www.microsoft.com/download/en/details.aspx?id=8442";
                    Helpers.LogMessage(service, this, message);
                    MessageBox.Show(message);
                }
            }


            //call disco.exe
            Helpers.LogMessage(service, this, "Getting path to disco.exe...");
            string discopath = Helpers.GetDiscoPath();

            if (discopath != "")
            {
                if (!defaultIISAPP.StartsWith("http:"))
                {
                    defaultIISAPP = "http://" + defaultIISAPP;
                }

                Helpers.ShowProgress(service, "Generating WSDL...", 80);
                string discoargument = " " + defaultIISAPP + "/_layouts" + Helpers.GetVersionedFolder(service) + "/" + asmxfilename;

                Helpers.LogMessage(service, this, "Ping server...");
                DeploymentHelpers.PingServer(service, discoargument, 20000);

                Helpers.LogMessage(service, this, "Running disco.exe...");
                Helpers.RunProcess(service, discopath, discoargument, true, workingDirectory, false);
            }
            else
            {
                string message = "Disco.exe not found on your system.\nPlease install .net or Windows SDK.\ni.e. Windows SDK 7.1 http://www.microsoft.com/download/en/details.aspx?id=8442";
                Helpers.LogMessage(service, this, message);
                MessageBox.Show(message);
            }
            //adding results to the project
            //WebService1.disco
            string finalwsdlpath  = "";
            string finaldiscopath = "";

            string[] wsdls = Directory.GetFiles(workingDirectory, "*.wsdl");
            if (wsdls.Length > 0)
            {
                finalwsdlpath = wsdls[0];
            }
            string[] discos = Directory.GetFiles(workingDirectory, "*.disco");
            if (discos.Length > 0)
            {
                finaldiscopath = discos[0];
            }
            if (File.Exists(finalwsdlpath) && File.Exists(finaldiscopath))
            {
                string SharePointVersion = Helpers.GetInstalledSharePointVersion();

                //replace text in the files

                /*To register namespaces of the Windows SharePoint Services object model, open both the .disco and .wsdl files and replace the opening XML processing instruction -- <?xml version="1.0" encoding="utf-8"?> -- with instructions such as the following:
                 * <%@ Page Language="C#" Inherits="System.Web.UI.Page" %>
                 * <%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
                 * <%@ Import Namespace="Microsoft.SharePoint.Utilities" %>
                 * <%@ Import Namespace="Microsoft.SharePoint" %>
                 * <% Response.ContentType = "text/xml"; %>
                 */
                Helpers.ShowProgress(service, "Generating WSDL...", 90);

                StringBuilder wsdlreplaced = new StringBuilder();
                TextReader    wsdlreader   = new StreamReader(finalwsdlpath);
                string        input        = null;
                while ((input = wsdlreader.ReadLine()) != null)
                {
                    if (input.TrimStart(null).StartsWith("<?xml version="))
                    {
                        wsdlreplaced.AppendLine("<%@ Page Language=\"C#\" Inherits=\"System.Web.UI.Page\" %>");
                        wsdlreplaced.AppendLine("<%@ Assembly Name=\"Microsoft.SharePoint, Version=" + SharePointVersion + ".0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %>");
                        wsdlreplaced.AppendLine("<%@ Import Namespace=\"Microsoft.SharePoint.Utilities\" %> ");
                        wsdlreplaced.AppendLine("<%@ Import Namespace=\"Microsoft.SharePoint\" %>");
                        wsdlreplaced.AppendLine("<% Response.ContentType = \"text/xml\"; %>");
                    }
                    else if (input.TrimStart(null).StartsWith("<soap:address"))
                    {
                        wsdlreplaced.AppendLine("<soap:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />");
                    }
                    else if (input.TrimStart(null).StartsWith("<soap12:address"))
                    {
                        wsdlreplaced.AppendLine("<soap12:address location=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> />");
                    }
                    else
                    {
                        wsdlreplaced.AppendLine(input);
                    }
                }
                wsdlreader.Close();
                TextWriter wsdlwriter = new StreamWriter(finalwsdlpath);
                wsdlwriter.Write(wsdlreplaced.ToString());
                wsdlwriter.Close();

                StringBuilder discoreplaced = new StringBuilder();
                TextReader    discoreader   = new StreamReader(finaldiscopath);
                string        discoinput    = null;
                while ((discoinput = discoreader.ReadLine()) != null)
                {
                    if (discoinput.TrimStart(null).StartsWith("<?xml version="))
                    {
                        discoreplaced.AppendLine("<%@ Page Language=\"C#\" Inherits=\"System.Web.UI.Page\" %>");
                        discoreplaced.AppendLine("<%@ Assembly Name=\"Microsoft.SharePoint, Version=" + SharePointVersion + ".0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c\" %>");
                        discoreplaced.AppendLine("<%@ Import Namespace=\"Microsoft.SharePoint.Utilities\" %> ");
                        discoreplaced.AppendLine("<%@ Import Namespace=\"Microsoft.SharePoint\" %>");
                        discoreplaced.AppendLine("<% Response.ContentType = \"text/xml\"; %>");
                    }
                    else if (discoinput.TrimStart(null).StartsWith("<contractRef"))
                    {
                        discoreplaced.AppendLine("<contractRef ref=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request) + \"?wsdl\"),Response.Output); %> docRef=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns=\"http://schemas.xmlsoap.org/disco/scl/\" />");
                    }
                    else if (discoinput.TrimStart(null).StartsWith("<soap address="))
                    {
                        //before
                        //<soap address="http://tfsrtm08/_layouts/WebService1.asmx" xmlns:q1="http://SMC.Supernet.Web.WebServices/" binding="q1:WebService1Soap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

                        //replaced
                        //<soap address=<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %> xmlns:q1="http://tempuri.org/" binding="q1:HelloWorld" xmlns="http://schemas.xmlsoap.org/disco/soap/" />

                        //we replace the field adress
                        string originalstring = discoinput;

                        string beforeaddress = originalstring.Substring(0, originalstring.IndexOf(" address=") + 9);
                        string afteraddress  = originalstring.Substring(originalstring.IndexOf("\"", originalstring.IndexOf(" address=") + 11));

                        //skip the quot
                        afteraddress = afteraddress.Substring(1);
                        discoreplaced.AppendLine(beforeaddress + "<% SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SPWeb.OriginalBaseUrl(Request)),Response.Output); %>" + afteraddress);
                    }
                    else
                    {
                        discoreplaced.AppendLine(discoinput);
                    }
                }
                discoreader.Close();
                TextWriter discowriter = new StreamWriter(finaldiscopath);
                discowriter.Write(discoreplaced.ToString());
                discowriter.Close();

                //files renaming needed
                //WebService.wsdl -> WebServiceWSDL.aspx
                //WebService.disco -> WebServiceDisco.aspx
                string renamedwsdlpath  = Path.Combine(workingDirectory, asmxfilenamewithoutext + "WSDL.aspx");
                string renameddiscopath = Path.Combine(workingDirectory, asmxfilenamewithoutext + "Disco.aspx");

                File.Copy(finalwsdlpath, renamedwsdlpath);
                File.Copy(finaldiscopath, renameddiscopath);

                //add the files to the project
                ProjectItem wsdlItem  = Helpers.AddFile(asmxfileParentFolder, renamedwsdlpath);
                ProjectItem discoItem = Helpers.AddFile(asmxfileParentFolder, renameddiscopath);

                //set the deployment target of the files to the same as the parent
                if (Helpers2.IsSharePointVSTemplate(service, project))
                {
                    Helpers2.CopyDeploymentPath(WebServiceFile, wsdlItem);
                    Helpers2.CopyDeploymentPath(WebServiceFile, discoItem);
                }
            }
            else
            {
                string message = "Created WSDL and DISCO files not found. Creation failed.";
                Helpers.LogMessage(service, this, message);
                MessageBox.Show(message);
            }

            try
            {
                //delete temp folder
                Directory.Delete(workingDirectory, true);

                //clean up everything what we have copied to the layouts folder
                if (ASMXFileExisted)
                {
                    File.Delete(fullasmxtarget);
                }
            }
            catch (Exception)
            {
            }

            Helpers.HideProgress(service);
        }