Esempio n. 1
0
        // The <Resource> element refers to any file stored inside a FEATURE\MyFeature folder.  NOT just .resx files.

        private void AddResourceDefinitionFiles(DirectoryInfo parentDir, int baseIndex, List <ResourceDefinition> resourceDefinitionList)
        {
            foreach (FileInfo file in parentDir.GetFiles())
            {
                if (FileProvider.IncludeFile(file))
                {
                    string relativePath = file.FullName.Substring(baseIndex);

                    // If the file has not been defined by the feature, then use the resources tag to include the file.
                    if (!this.ElementFiles.Exists(delegate(string path)
                    {
                        return(path.Equals(relativePath, StringComparison.InvariantCultureIgnoreCase));
                    }
                                                  ))
                    {
                        ResourceDefinition resourceDefinition = new ResourceDefinition();

                        resourceDefinition.Location = relativePath;

                        resourceDefinitionList.Add(resourceDefinition);
                    }

                    Log.Verbose("Resources file added: " + relativePath);

                    // Always include the file in the WSP file
                    this.AddToCab(file.FullName, relativePath);
                }
            }

            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
            {
                AddResourceDefinitionFiles(childDir, baseIndex, resourceDefinitionList);
            }
        }
Esempio n. 2
0
        private void AddTemplateFileReferences(DirectoryInfo parentDir, List <TemplateFileReference> templateFileReferenceList, int pathIndex)
        {
            foreach (FileInfo file in parentDir.GetFiles())
            {
                if (FileProvider.IncludeFile(file))
                {
                    string locationPath = file.FullName.Substring(pathIndex);

                    if (!DoLocationExist(templateFileReferenceList, locationPath))
                    {
                        // Do not include webtemp*.xml file, because they are handle by the SiteDefinitionManifest
                        if (!this.ReservedFiles.ContainsKey(file.FullName))
                        {
                            TemplateFileReference templateFileReference = new TemplateFileReference();
                            templateFileReference.Location = locationPath;

                            templateFileReferenceList.Add(templateFileReference);

                            Log.Verbose("TemplateFile added: " + locationPath);

                            //this.CabFiles.Add(new string[] { file.FullName, locationPath });
                            this.AddToCab(file.FullName, locationPath);
                        }
                    }
                }
            }

            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
            {
                AddTemplateFileReferences(childDir, templateFileReferenceList, pathIndex);
            }
        }
Esempio n. 3
0
        private void FindWebTempFiles(DirectoryInfo parentDir, List <WebTempFileDefinition> webTempFileDefinitionList, string siteDefinitionName, int pathIndex)
        {
            string webTempFileName = "webtemp" + siteDefinitionName + ".xml";

            foreach (FileInfo file in parentDir.GetFiles())
            {
                // parentDir.Name.Equals(siteDefinitionName, StringComparison.InvariantCultureIgnoreCase))
                // Do the file match the SiteDefinition name and directory
                if (file.Name.Equals(webTempFileName, StringComparison.InvariantCultureIgnoreCase))
                {
                    // Create a new WebTempFileDefinition for the file
                    WebTempFileDefinition webTempFileDefinition = new WebTempFileDefinition();
                    webTempFileDefinition.Location = file.FullName.Substring(pathIndex);

                    // Add the file to the list of reserved files so it do not get included in the TemplateFiles section
                    this.ReservedFiles.Add(file.FullName, file);

                    // Add the file to list of cab files
                    string filePath = file.FullName.Substring(pathIndex);
                    //this.CabFiles.Add(new string[] { file.FullName, filePath });
                    this.AddToCab(file.FullName, filePath);


                    webTempFileDefinitionList.Add(webTempFileDefinition);
                }
            }

            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
            {
                FindWebTempFiles(childDir, webTempFileDefinitionList, siteDefinitionName, pathIndex);
            }
        }
Esempio n. 4
0
        private void AddRootFileReferences(DirectoryInfo parentDir, List <RootFileReference> rootFileReferenceList, int pathIndex)
        {
            // Do not include the "template" folder
            if (!parentDir.Name.Equals("template", StringComparison.InvariantCultureIgnoreCase))
            {
                foreach (FileInfo file in parentDir.GetFiles())
                {
                    if (FileProvider.IncludeFile(file))
                    {
                        string spPathName = file.FullName.Substring(pathIndex);
                        if (!DoLocationExist(rootFileReferenceList, spPathName))
                        {
                            RootFileReference rootFileReference = new RootFileReference();
                            rootFileReference.Location = spPathName;

                            rootFileReferenceList.Add(rootFileReference);

                            Log.Verbose("Root file added: " + rootFileReference.Location);

                            this.AddToCab(file.FullName, spPathName);
                        }
                    }
                }

                foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
                {
                    AddRootFileReferences(childDir, rootFileReferenceList, pathIndex);
                }
            }
        }
        private void AddClassResources(DirectoryInfo parentDir, int baseIndex, List <ClassResourceDefinition> classResourceDefinitionList)
        {
            foreach (FileInfo file in parentDir.GetFiles())
            {
                if (FileProvider.IncludeFile(file))
                {
                    string spPathName = file.FullName.Substring(baseIndex);

                    ClassResourceDefinition classResourceDefinition = new ClassResourceDefinition();

                    classResourceDefinition.FileName = file.Name;
                    classResourceDefinition.Location = spPathName;

                    classResourceDefinitionList.Add(classResourceDefinition);

                    Log.Verbose("ClassResource added: " + spPathName);

                    //this.CabFiles.Add(new string[] { file.FullName, spPathName });
                    this.AddToCab(file.FullName, spPathName);
                }
            }
            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
            {
                AddClassResources(childDir, baseIndex, classResourceDefinitionList);
            }
        }
        private void AddApplicationResourceFileDefinitions(DirectoryInfo parentDir, int baseIndex, Dictionary <string, object> items)
        {
            foreach (FileInfo file in parentDir.GetFiles())
            {
                if (FileProvider.IncludeFile(file))
                {
                    string locationPath = file.FullName.Substring(baseIndex);

                    if (!items.ContainsKey(locationPath))
                    {
                        ApplicationResourceFileDefinition applicationResourceFileDefinition = new ApplicationResourceFileDefinition();

                        applicationResourceFileDefinition.Location = locationPath;

                        items.Add(locationPath, applicationResourceFileDefinition);

                        Log.Verbose("Application Resource File: " + locationPath);

                        this.AddToCab(file.FullName, locationPath);
                    }
                }
            }

            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
            {
                AddApplicationResourceFileDefinitions(childDir, baseIndex, items);
            }
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="siteDefinitionsDir"></param>
        /// <returns></returns>
        public SiteDefinitionManifestFileReference[] BuildSiteDefinitionManifestFileReference(DirectoryInfo siteDefinitionsDir, SiteDefinitionManifestFileReference[] siteDefinitionManifests)
        {
            List <SiteDefinitionManifestFileReference> siteDefinitionManifestFileReferenceList =
                (siteDefinitionManifests != null) ? new List <SiteDefinitionManifestFileReference>(siteDefinitionManifests) : new List <SiteDefinitionManifestFileReference>();

            int webTemplatePathIndex = siteDefinitionsDir.FullName.LastIndexOf(@"\") + 1;

            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(siteDefinitionsDir))
            {
                if (!DoLocationExist(siteDefinitionManifestFileReferenceList, childDir.Name))
                {
                    // Create a new SiteDefinitionManifestFileReference
                    SiteDefinitionManifestFileReference siteDefinitionManifestFileReference = new SiteDefinitionManifestFileReference();
                    siteDefinitionManifestFileReference.Location = childDir.Name;

                    Log.Verbose("SiteDefinition added: " + siteDefinitionManifestFileReference.Location);

                    // find the webtemp configuration for the site definition
                    WebTempFileDefinition[] arrWebTempFileDefinitions = BuildWebTempFileDefinition(siteDefinitionsDir.Parent, childDir.Name, webTemplatePathIndex);

                    // Test that there is a webtemp configuration for this site definition
                    if (arrWebTempFileDefinitions != null)
                    {
                        siteDefinitionManifestFileReference.WebTempFile = AppendArray <WebTempFileDefinition>(siteDefinitionManifestFileReference.WebTempFile, arrWebTempFileDefinitions);

                        int siteDefinitionPathIndex = childDir.FullName.LastIndexOf(@"\") + 1;

                        // Add files to the cab list
                        AddSiteDefinitionManifestFiles(childDir, siteDefinitionPathIndex);

                        siteDefinitionManifestFileReferenceList.Add(siteDefinitionManifestFileReference);
                    }
                    else
                    {
                        // did not find a webtemp configuration for the site definition,
                        // therefore add to IncludeTemplateDirectory list, so the files
                        // gets included by the TemplateFiles section.
                        this.IncludeTemplateDirectory.Add(childDir);

                        Log.Warning("No webtemp configuration for sitedefinition '" + siteDefinitionManifestFileReference.Location + "' was found.");
                    }
                }
            }

            if (siteDefinitionManifestFileReferenceList.Count == 0)
            {
                return(null);
            }
            return(siteDefinitionManifestFileReferenceList.ToArray());
        }
        private void FindAssembliesInDirectory(DirectoryInfo parentDir, SolutionDeploymentTargetType targetType, Dictionary <string, AssemblyInfo> assembliesFound)
        {
            foreach (FileInfo dllFileInfo in parentDir.GetFiles("*.dll"))
            {
                if (FileProvider.IncludeFile(dllFileInfo))
                {
                    AddCandidateAssembly(dllFileInfo, targetType, assembliesFound);
                }
            }

            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
            {
                FindAssembliesInDirectory(childDir, targetType, assembliesFound);
            }
        }
Esempio n. 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parentDir"></param>
        /// <param name="pathIndex"></param>
        private void AddSiteDefinitionManifestFiles(DirectoryInfo parentDir, int pathIndex)
        {
            foreach (FileInfo file in parentDir.GetFiles())
            {
                if (FileProvider.IncludeFile(file))
                {
                    string filePath = file.FullName.Substring(pathIndex);

                    //this.CabFiles.Add(new string[] { file.FullName, filePath });
                    this.AddToCab(file.FullName, filePath);
                }
            }
            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
            {
                AddSiteDefinitionManifestFiles(childDir, pathIndex);
            }
        }
        /// <summary>
        /// Find and builds the Features going into the wsp file.
        /// </summary>
        /// <param name="parentDir">The feature directory</param>
        /// <returns>FeatureManifestReference[]</returns>
        public FeatureManifestReference[] BuildFeatureManifestReference(DirectoryInfo parentDir, FeatureManifestReference[] featureManifests)
        {
            List <FeatureManifestReference> featureManifestReferenceList = (featureManifests != null) ? new List <FeatureManifestReference>(featureManifests) : new List <FeatureManifestReference>();

            if (IncludeFeatures)
            {
                int pathIndex = parentDir.FullName.Length + 1;
                foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
                {
                    string featurePath = childDir.FullName + @"\feature.xml";
                    if (File.Exists(featurePath))
                    {
                        // Only add the feature.xml file, do not add any other file to the manifest.xml
                        FileInfo file = new FileInfo(featurePath);

                        if (FileProvider.IncludeFile(file))
                        {
                            string locationPath = file.FullName.Substring(pathIndex);

                            if (!DoLocationExist(featureManifestReferenceList, locationPath))
                            {
                                FeatureManifestReference feature = new FeatureManifestReference();
                                feature.Location = locationPath;

                                featureManifestReferenceList.Add(feature);

                                Log.Verbose("Feature added: " + feature.Location);

                                // Get the elementfiles
                                ElementFiles.AddRange(GetElementFiles(file, childDir));
                            }
                        }
                    }
                }
            }
            if (featureManifestReferenceList.Count == 0)
            {
                return(null);
            }
            return(featureManifestReferenceList.ToArray());
        }
Esempio n. 11
0
        /// <summary>
        /// Find and load all webtemplates files in the solution
        /// </summary>
        /// <param name="parentDir"></param>
        /// <param name="webTemps"></param>
        private void LoadWebTemplates(DirectoryInfo parentDir, Dictionary <string, XmlDocument> webTemps)
        {
            if (parentDir.Name.Equals("xml", StringComparison.InvariantCultureIgnoreCase))
            {
                foreach (FileInfo file in parentDir.GetFiles("*.xml"))
                {
                    // Is the file a webtemp*.xml file
                    if (file.Name.StartsWith("webtemp", StringComparison.InvariantCultureIgnoreCase))
                    {
                        XmlDocument webTempDoc = new XmlDocument();
                        webTempDoc.Load(file.FullName);
                        webTemps.Add(file.FullName, webTempDoc);
                    }
                }
            }

            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
            {
                LoadWebTemplates(childDir, webTemps);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Builds an entire solution.
        /// When more than one project in a solution, all projects gets build into the same WSP package.
        /// </summary>
        public void BuildSolution()
        {
            Dictionary <string, AssemblyInfo> assembliesFound = new Dictionary <string, AssemblyInfo>(StringComparer.InvariantCultureIgnoreCase);

            if (!Config.Current.BuildSolution)
            {
                // Set the Project path to the solution path
                //Config.Current.ProjectPath = Config.Current.SolutionPath;
                BuildProject(assembliesFound);
            }
            else
            {
                DirectoryInfo solutionDir = new DirectoryInfo(Config.Current.SolutionPath);
                foreach (DirectoryInfo dir in FileProvider.GetDirectories(solutionDir))
                {
                    // Reinitialize the Config object to ensure that its clean.
                    //Config.Current.ReInitialize();
                    Config.Current.ProjectPath = dir.FullName;

                    BuildProject(assembliesFound);
                }
                Config.Current.ProjectPath = Config.Current.SolutionPath;
            }

            SetWSS40SolutionProperties(this.Solution);

            // Create AssemblyFileReferences, add CodeGroups and CodeAccessSecurity
            this.Solution.Assemblies = BuildAssemblyFileReference(assembliesFound);

            // Add the CAS policy, if enabled
            if (Config.Current.BuildCAS)
            {
                this.Solution.CodeAccessSecurity = AppendArray <PolicyItemDefinition>(this.Solution.CodeAccessSecurity, BuildPolicyItemDefinition());
            }


            string compatibilityNote = null;

            if (this.IsWSS40)
            {
                compatibilityNote = "Solution compatibility: SharePoint 2010";
            }
            else
            {
                compatibilityNote = "Solution compatibility: SharePoint 2007 and SharePoint 2010";
            }

            // Create the wsp manifest file
            this.ManifestContent = Serializer.ObjectToXML(this.Solution, this.IsWSS40);

            // Add a note
            int index = this.ManifestContent.IndexOf("\r\n");

            if (index > 0)
            {
                this.ManifestContent = this.ManifestContent.Insert(index, "<!-- Solution created by WSPBuilder. " + DateTime.Now.ToString() + " * " + compatibilityNote + " -->");
            }

            if (Config.Current.BuildCAS)
            {
                // Apply the permissions to the PolicyItemDefinitions
                // This happens here after the serialization, because the wsp shema definition
                // do not implement the IPermission object in a useful way.
                // This is the last solution to the problem I wanted to implement, but the only
                // one I was able to get to work properly.
                this.ManifestContent = ApplyPolicyPermissions(this.ManifestContent);
            }

            // Replace tokens in files with the Replacement Parameters.
            CreateFilesWithReplacementParameters();

            Log.Information(compatibilityNote);
        }
Esempio n. 13
0
        public TemplateFileReference[] BuildTemplateFileReference(DirectoryInfo parentDir, TemplateFileReference[] templateFileReferences)
        {
            List <TemplateFileReference> templateFileReferenceList =
                (templateFileReferences != null) ? new List <TemplateFileReference>(templateFileReferences) : new List <TemplateFileReference>();

            int parentPathIndex = parentDir.FullName.Length + 1; // Plus one for the slash

            // Add features
            string pathFeatures = parentDir.FullName + @"\features";

            if (Directory.Exists(pathFeatures))
            {
                DirectoryInfo featuresDir = new DirectoryInfo(pathFeatures);

                this.Solution.FeatureManifests = BuildFeatureManifestReference(featuresDir, this.Solution.FeatureManifests);

                // Add Features resources files.
                this.Solution.Resources = AppendArray <ResourceDefinition>(this.Solution.Resources, BuildResourceDefinition(featuresDir));
            }

            // Add sitedefinitions
            if (Directory.Exists(parentDir.FullName + @"\sitetemplates"))
            {
                this.Solution.SiteDefinitionManifests = BuildSiteDefinitionManifestFileReference(new DirectoryInfo(parentDir.FullName + @"\sitetemplates"), this.Solution.SiteDefinitionManifests);
            }

            // Every other file gets added to the TemplateFileReference
            foreach (DirectoryInfo childDir in FileProvider.GetDirectories(parentDir))
            {
                switch (childDir.Name.ToLower())
                {
                case "features":  break;     // Do nothing here

                case "sitetemplates": break; // Do nothing here

                default: AddTemplateFileReferences(childDir, templateFileReferenceList, parentPathIndex); break;
                }
            }

            // Find and add files in the TEMPLATE folder
            foreach (FileInfo file in parentDir.GetFiles())
            {
                if (FileProvider.IncludeFile(file))
                {
                    string locationPath = file.FullName.Substring(parentPathIndex);

                    if (!DoLocationExist(templateFileReferenceList, locationPath))
                    {
                        TemplateFileReference templateFileReference = new TemplateFileReference();
                        templateFileReference.Location = locationPath;

                        templateFileReferenceList.Add(templateFileReference);

                        //this.CabFiles.Add(new string[] { file.FullName, locationPath });
                        this.AddToCab(file.FullName, locationPath);
                    }
                }
            }


            // Add the directories in the IncludeTemplateDirectory list
            foreach (DirectoryInfo childDir in IncludeTemplateDirectory)
            {
                AddTemplateFileReferences(childDir, templateFileReferenceList, parentPathIndex);
            }

            if (templateFileReferenceList.Count == 0)
            {
                return(null);
            }
            return(templateFileReferenceList.ToArray());
        }