當前位置: 首頁>>代碼示例>>C#>>正文


C# XContainer.ElementAnyNamespace方法代碼示例

本文整理匯總了C#中System.Xml.Linq.XContainer.ElementAnyNamespace方法的典型用法代碼示例。如果您正苦於以下問題:C# XContainer.ElementAnyNamespace方法的具體用法?C# XContainer.ElementAnyNamespace怎麽用?C# XContainer.ElementAnyNamespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Linq.XContainer的用法示例。


在下文中一共展示了XContainer.ElementAnyNamespace方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddReleaseNotes

        private void AddReleaseNotes(XContainer nuSpec)
        {
            if (string.IsNullOrWhiteSpace(ReleaseNotesFile))
            {
                return;
            }

            ReleaseNotesFile = fileSystem.GetFullPath(ReleaseNotesFile);

            if (!fileSystem.FileExists(ReleaseNotesFile))
            {
                LogWarning("OCT901", string.Format("The release notes file: {0} does not exist or could not be found. Release notes will not be added to the package.", ReleaseNotesFile));
                return;
            }

            LogMessage("Adding release notes from file: " + ReleaseNotesFile);

            var notes = fileSystem.ReadFile(ReleaseNotesFile);

            var package = nuSpec.ElementAnyNamespace("package");
            if (package == null) throw new Exception(string.Format("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid."));

            var metadata = package.ElementAnyNamespace("metadata");
            if (metadata == null) throw new Exception(string.Format("The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid."));

            var releaseNotes = metadata.ElementAnyNamespace("releaseNotes");
            if (releaseNotes == null)
            {
                metadata.Add(new XElement("releaseNotes", notes));
            }
            else
            {
                releaseNotes.Value = notes;
            }
        }
開發者ID:tobio,項目名稱:OctoPack,代碼行數:35,代碼來源:CreateOctoPackPackage.cs

示例2: AddFiles

        private void AddFiles(XContainer nuSpec, IEnumerable<ITaskItem> sourceFiles, string sourceBaseDirectory, string targetDirectory = "", string relativeTo = "")
        {
            var package = nuSpec.ElementAnyNamespace("package");
            if (package == null) throw new Exception("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");

            var files = package.ElementAnyNamespace("files");
            if (files == null)
            {
                files = new XElement("files");
                package.Add(files);
            }

            if (!string.IsNullOrWhiteSpace(relativeTo) && Path.IsPathRooted(relativeTo))
            {
                relativeTo = fileSystem.GetPathRelativeTo(relativeTo, sourceBaseDirectory);
            }

            foreach (var sourceFile in sourceFiles)
            {
                var destinationPath = sourceFile.ItemSpec;
                var link = sourceFile.GetMetadata("Link");
                if (!string.IsNullOrWhiteSpace(link))
                {
                    destinationPath = link;
                }

                if (Path.IsPathRooted(destinationPath))
                {
                    destinationPath = fileSystem.GetPathRelativeTo(destinationPath, sourceBaseDirectory);
                }

                if (!string.IsNullOrWhiteSpace(relativeTo))
                {                  
                    if (destinationPath.StartsWith(relativeTo, StringComparison.OrdinalIgnoreCase))
                    {
                        destinationPath = destinationPath.Substring(relativeTo.Length);
                    }
                }

                destinationPath = Path.Combine(targetDirectory, destinationPath);

                var sourceFilePath = Path.Combine(sourceBaseDirectory, sourceFile.ItemSpec);

                sourceFilePath = Path.GetFullPath(sourceFilePath);

                if (!fileSystem.FileExists(sourceFilePath))
                {
                    LogMessage("The source file '" + sourceFilePath + "' does not exist, so it will not be included in the package", MessageImportance.High);
                    continue;
                }

                if (seenBefore.Contains(sourceFilePath))
                {
                    continue;
                }

                seenBefore.Add(sourceFilePath);

                var fileName = Path.GetFileName(destinationPath);
                if (string.Equals(fileName, "app.config", StringComparison.OrdinalIgnoreCase))
                {
                    if (fileSystem.FileExists(AppConfigFile))
                    {
                        var configFileName = Path.GetFileName(AppConfigFile);
                        destinationPath = Path.GetDirectoryName(destinationPath);
                        destinationPath = Path.Combine(destinationPath, configFileName);
                        files.Add(new XElement("file",
                                new XAttribute("src", AppConfigFile),
                                new XAttribute("target", destinationPath)
                                ));

                        LogMessage("Added file: " + destinationPath, MessageImportance.Normal);                        
                    }
                    continue;
                }

                if (new[] {"Deploy.ps1", "DeployFailed.ps1", "PreDeploy.ps1", "PostDeploy.ps1"}.Any(f => string.Equals(f, fileName, StringComparison.OrdinalIgnoreCase)))
                {
                    var isNonRoot = destinationPath.Contains('\\') || destinationPath.Contains('/');
                    if (isNonRoot && !IgnoreNonRootScripts)
                    {
                        LogWarning("OCTNONROOT", "As of Octopus Deploy 2.4, PowerShell scripts that are not at the root of the package will not be executed. The script '" + destinationPath + "' lives in a subdirectory, so it will not be executed. If you want Octopus to execute this script, move it to the root of your project. If you don't want it to be executed, you can ignore this warning, or suppress it by setting the MSBuild property OctoPackIgnoreNonRootScripts=true");
                    }
                }

                var isTypeScript = string.Equals(Path.GetExtension(sourceFilePath), ".ts", StringComparison.OrdinalIgnoreCase);
                if (isTypeScript)
                {
                    if (IncludeTypeScriptSourceFiles)
                    {
                        files.Add(new XElement("file",
                            new XAttribute("src", sourceFilePath),
                            new XAttribute("target", destinationPath)
                            ));
        
                        LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
                    }

                    var changedSource = Path.ChangeExtension(sourceFilePath, ".js");
                    var changedDestination = Path.ChangeExtension(destinationPath, ".js");
//.........這裏部分代碼省略.........
開發者ID:tobio,項目名稱:OctoPack,代碼行數:101,代碼來源:CreateOctoPackPackage.cs

示例3: GetVersionElementFromNuSpec

        private static XElement GetVersionElementFromNuSpec(XContainer nuSpec)
        {
            var package = nuSpec.ElementAnyNamespace("package");
            if (package == null)
                throw new Exception(
                    "The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");

            var metadata = package.ElementAnyNamespace("metadata");
            if (metadata == null)
                throw new Exception(
                    "The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid.");

            var version = metadata.ElementAnyNamespace("version");
            if (version == null)
                throw new Exception(
                    "The NuSpec file does not contain a <version> XML element. The NuSpec file appears to be invalid.");
            return version;
        }
開發者ID:OctopusDeploy,項目名稱:OctoPack,代碼行數:18,代碼來源:CreateOctoPackPackage.cs

示例4: AddFiles

        private void AddFiles(XContainer nuSpec, IEnumerable<ITaskItem> sourceFiles, string sourceBaseDirectory, string targetDirectory = "")
        {
            var package = nuSpec.ElementAnyNamespace("package");
            if (package == null) throw new Exception("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");

            var files = package.ElementAnyNamespace("files");
            if (files == null)
            {
                files = new XElement("files");
                package.Add(files);
            }

            foreach (var sourceFile in sourceFiles)
            {
                var destinationPath = sourceFile.ItemSpec;
                var link = sourceFile.GetMetadata("Link");
                if (!string.IsNullOrWhiteSpace(link))
                {
                    destinationPath = link;
                }

                if (Path.IsPathRooted(destinationPath))
                {
                    destinationPath = fileSystem.GetPathRelativeTo(destinationPath, sourceBaseDirectory);
                }

                destinationPath = Path.Combine(targetDirectory, destinationPath);

                var sourceFilePath = Path.Combine(sourceBaseDirectory, sourceFile.ItemSpec);

                LogMessage("Including file: " + sourceFile, MessageImportance.Normal);

                files.Add(new XElement("file",
                    new XAttribute("src", Path.GetFullPath(sourceFilePath)),
                    new XAttribute("target", destinationPath)
                    ));
            }
        }
開發者ID:nipampatel,項目名稱:OctoPack,代碼行數:38,代碼來源:CreateOctoPackPackage.cs

示例5: UpdatePackageIdWithAppendValue

        private void UpdatePackageIdWithAppendValue(XContainer nuSpec)
        {
            if (string.IsNullOrWhiteSpace(AppendToPackageId))
            {
                return;
            }

            var package = nuSpec.ElementAnyNamespace("package");
            if (package == null) throw new Exception(string.Format("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid."));

            var metadata = package.ElementAnyNamespace("metadata");
            if (metadata == null) throw new Exception(string.Format("The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid."));

            var packageId = metadata.ElementAnyNamespace("id");
            if (packageId == null) throw new Exception(string.Format("The NuSpec file does not contain a <id> XML element. The NuSpec file appears to be invalid."));

            packageId.Value = string.Format("{0}.{1}", packageId.Value, AppendToPackageId.Trim());
        }
開發者ID:polewskm,項目名稱:OctoPack,代碼行數:18,代碼來源:CreateOctoPackPackage.cs

示例6: AddFiles

        private void AddFiles(XContainer nuSpec, IEnumerable<ITaskItem> sourceFiles, string sourceBaseDirectory, string targetDirectory = "", string relativeTo = "")
        {
            var package = nuSpec.ElementAnyNamespace("package");
            if (package == null) throw new Exception("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid.");

            var files = package.ElementAnyNamespace("files");
            if (files == null)
            {
                files = new XElement("files");
                package.Add(files);
            }

            if (!string.IsNullOrWhiteSpace(relativeTo) && Path.IsPathRooted(relativeTo))
            {
                relativeTo = fileSystem.GetPathRelativeTo(relativeTo, sourceBaseDirectory);
            }

            foreach (var sourceFile in sourceFiles)
            {
                var destinationPath = sourceFile.ItemSpec;
                var link = sourceFile.GetMetadata("Link");
                if (!string.IsNullOrWhiteSpace(link))
                {
                    destinationPath = link;
                }

                if (Path.IsPathRooted(destinationPath))
                {
                    destinationPath = fileSystem.GetPathRelativeTo(destinationPath, sourceBaseDirectory);
                }

                if (!string.IsNullOrWhiteSpace(relativeTo))
                {
                    if (destinationPath.StartsWith(relativeTo, StringComparison.OrdinalIgnoreCase))
                    {
                        destinationPath = destinationPath.Substring(relativeTo.Length);
                    }
                }

                destinationPath = Path.Combine(targetDirectory, destinationPath);

                var sourceFilePath = Path.Combine(sourceBaseDirectory, sourceFile.ItemSpec);

                sourceFilePath = Path.GetFullPath(sourceFilePath);

                var isTypeScript = string.Equals(Path.GetExtension(sourceFilePath), ".ts", StringComparison.OrdinalIgnoreCase);
                if (isTypeScript)
                {
                    if (IncludeTypeScriptSourceFiles)
                    {
                        files.Add(new XElement("file",
                            new XAttribute("src", sourceFilePath),
                            new XAttribute("target", destinationPath)
                            ));

                        LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
                    }

                    var changedSource = Path.ChangeExtension(sourceFilePath, ".js");
                    var changedDestination = Path.ChangeExtension(destinationPath, ".js");
                    if (fileSystem.FileExists(changedSource))
                    {
                        files.Add(new XElement("file",
                            new XAttribute("src", changedSource),
                            new XAttribute("target", changedDestination)
                            ));

                        LogMessage("Added file: " + changedDestination, MessageImportance.Normal);
                    }
                }
                else
                {
                    files.Add(new XElement("file",
                        new XAttribute("src", sourceFilePath),
                        new XAttribute("target", destinationPath)
                        ));

                    LogMessage("Added file: " + destinationPath, MessageImportance.Normal);
                }
            }
        }
開發者ID:pawelpabich,項目名稱:OctoPack,代碼行數:81,代碼來源:CreateOctoPackPackage.cs

示例7: UpdateVersionWithAppendValue

        private void UpdateVersionWithAppendValue(XContainer nuSpec)
        {
            if (string.IsNullOrWhiteSpace(AppendToVersion))
            {
                return;
            }

            var package = nuSpec.ElementAnyNamespace("package");
            if (package == null) throw new Exception(string.Format("The NuSpec file does not contain a <package> XML element. The NuSpec file appears to be invalid."));

            var metadata = package.ElementAnyNamespace("metadata");
            if (metadata == null) throw new Exception(string.Format("The NuSpec file does not contain a <metadata> XML element. The NuSpec file appears to be invalid."));

            var version = metadata.ElementAnyNamespace("version");
            if (version == null) throw new Exception(string.Format("The NuSpec file does not contain a <version> XML element. The NuSpec file appears to be invalid."));

            version.Value = string.Format("{0}-{1}", PackageVersion ?? version.Value, AppendToVersion.Trim());
            PackageVersion = version.Value;
        }
開發者ID:asizikov,項目名稱:OctoPack,代碼行數:19,代碼來源:CreateOctoPackPackage.cs


注:本文中的System.Xml.Linq.XContainer.ElementAnyNamespace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。