static void BuildTreeChildren (Gtk.TreeStore store, Gtk.TreeIter parent, XContainer p)
		{
			foreach (XNode n in p.Nodes) {
				Gtk.TreeIter childIter;
				if (!parent.Equals (Gtk.TreeIter.Zero))
					childIter = store.AppendValues (parent, n);
				else
					childIter = store.AppendValues (n);
				
				XContainer c = n as XContainer;
				if (c != null && c.FirstChild != null)
					BuildTreeChildren (store, childIter, c);
			}
		}
示例#2
0
        void InternalRender(XContainer content, InlineCollection inlines, ListContext list)
        {
            foreach (var item in content.Nodes())
            {
                switch (item.NodeType)
                {
                case XmlNodeType.Element:
                    var e = item as XElement;
                    switch (e.Name.LocalName)
                    {
                    case "list":
                        list = list == null
                                                                        ? new ListContext(e.Attribute("type")?.Value)
                                                                        : new ListContext(e.Attribute("type")?.Value, list);
                        InternalRender(e, inlines, list);
                        list = list.Parent;
                        break;

                    case "para":
                        var isOnlyChildOfItem = list != null && e.Parent.Name == "item" && e.Parent.FirstNode == e.Parent.LastNode && e.Parent.FirstNode == item;
                        if (isOnlyChildOfItem)
                        {
                            ParagraphCount++;
                        }
                        else if (inlines.LastInline != null && inlines.LastInline is LineBreak == false)
                        {
                            inlines.AppendLineWithMargin();
                            ParagraphCount++;
                        }
                        InternalRender(e, inlines, list);
                        if (inlines.FirstInline == null && isOnlyChildOfItem == false)
                        {
                            inlines.Add(new LineBreak());
                        }
                        break;

                    case "listheader":
                        RenderBlockContent(inlines, list, e, BLOCK_OTHER);
                        break;

                    case "h1":
                        RenderBlockContent(inlines, list, e, BLOCK_TITLE).FontSize = ThemeHelper.ToolTipFontSize + 5;
                        break;

                    case "h2":
                        RenderBlockContent(inlines, list, e, BLOCK_TITLE).FontSize = ThemeHelper.ToolTipFontSize + 3;
                        break;

                    case "h3":
                        RenderBlockContent(inlines, list, e, BLOCK_TITLE).FontSize = ThemeHelper.ToolTipFontSize + 2;
                        break;

                    case "h4":
                        RenderBlockContent(inlines, list, e, BLOCK_TITLE).FontSize = ThemeHelper.ToolTipFontSize + 1;
                        break;

                    case "h5":
                        RenderBlockContent(inlines, list, e, BLOCK_TITLE).FontSize = ThemeHelper.ToolTipFontSize + 0.5;
                        break;

                    case "h6":
                        RenderBlockContent(inlines, list, e, BLOCK_TITLE);
                        break;

                    case "code":
                        ++_isCode;
                        var span = RenderBlockContent(inlines, list, e, BLOCK_OTHER);
                        span.FontFamily = GetCodeFont();
                        span.Background = ThemeHelper.ToolWindowBackgroundBrush;
                        span.Foreground = ThemeHelper.ToolWindowTextBrush;
                        --_isCode;
                        break;

                    case "item":
                        RenderBlockContent(inlines, list, e, BLOCK_ITEM);
                        break;

                    case "see":
                    case "seealso":
                        RenderSee(inlines, e);
                        break;

                    case "paramref":
                        RenderParamRef(inlines, e);
                        break;

                    case "typeparamref":
                        RenderTypeParamRef(inlines, e);
                        break;

                    case "c":
                    case "tt":
                        ++_isCode;
                        StyleInner(e, inlines, new Span()
                        {
                            FontFamily = GetCodeFont(), Background = ThemeHelper.ToolWindowBackgroundBrush, Foreground = ThemeHelper.ToolWindowTextBrush
                        });
                        --_isCode;
                        break;

                    case "b":
                    case "strong":
                    case "term":
                        StyleInner(e, inlines, new Bold());
                        break;

                    case "i":
                    case "em":
                        StyleInner(e, inlines, new Italic());
                        break;

                    case "u":
                        StyleInner(e, inlines, new Underline());
                        break;

                    case "a":
                        var a = e.Attribute("href");
                        if (a != null && IsUrl(a))
                        {
                            CreateLink(inlines, e, a);
                        }
                        else
                        {
                            goto case "u";
                        }
                        break;

                    case "br":
                        inlines.Add(new LineBreak());
                        break;

                    case "hr":
                        inlines.AddRange(new Inline[] {
                            new LineBreak(),
                            new InlineUIContainer(new Border {
                                Height     = 1,
                                Background = ThemeHelper.DocumentTextBrush,
                                Margin     = WpfHelper.MiddleVerticalMargin,
                                Opacity    = 0.5
                            }.Bind(FrameworkElement.WidthProperty, new Binding {
                                RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ThemedTipText), 1),
                                Path           = new PropertyPath("ActualWidth")
                            })),
                            new LineBreak()
                        });
                        break;

                    //case "list":
                    //case "description":
                    default:
                        InternalRender(e, inlines, list);
                        break;
                    }
                    break;

                case XmlNodeType.Text:
                    string t = ((XText)item).Value;
                    if (_isCode == 0)
                    {
                        var previous = (item.PreviousNode as XElement)?.Name?.LocalName;
                        if (previous == null || IsInlineElementName(previous) == false)
                        {
                            t = item.NextNode == null?t.Trim() : t.TrimStart();
                        }
                        else if (item.NextNode == null)
                        {
                            t = t.TrimEnd();
                        }
                        if (t.Length == 0)
                        {
                            break;
                        }
                        t = _FixWhitespaces.Replace(t.Replace('\n', ' '), " ");
                    }
                    else
                    {
                        t = t.Replace("\n    ", "\n");
                    }
                    if (t.Length > 0)
                    {
                        inlines.Add(new Run(t));
                    }
                    break;

                case XmlNodeType.CDATA:
                    inlines.Add(_isCode == 0 ? new Run(((XText)item).Value) : new Run(((XText)item).Value.Replace("\n    ", "\n").TrimEnd()));
                    break;

                case XmlNodeType.EntityReference:
                case XmlNodeType.Entity:
                    inlines.Add(new Run(item.ToString()));
                    break;
                }
            }
            var lastNode = content.LastNode;

            if (lastNode != null &&
                (lastNode.NodeType != XmlNodeType.Element || ((XElement)lastNode).Name != "para") &&
                IsInlineElementName((lastNode.PreviousNode as XElement)?.Name.LocalName) == false)
            {
                ParagraphCount++;
            }
        }
示例#3
0
        private static IEnumerable <XmlReader> GetXmlReader(XContainer runtimeElement, string elementName)
        {
            var model = runtimeElement.Elements().First(c => c.Name.LocalName == elementName).Elements().First();

            yield return(XmlReader.Create(new StringReader(model.ToString())));
        }
示例#4
0
 public ConditionNAND(XContainer el) : base(el)
 {
 }
示例#5
0
 public static IEnumerable <XElement> ElementsNoNamespace(this XContainer container, string localName)
 {
     return(container.Elements().Where(e => e.Name.LocalName == localName));
 }
示例#6
0
        private void PackageDocumentsAndTags(PackageDefinition definition, XContainer root)
        {
            //Documents and tags
            if (string.IsNullOrEmpty(definition.ContentNodeId) == false && int.TryParse(definition.ContentNodeId, out var contentNodeId))
            {
                if (contentNodeId > 0)
                {
                    //load content from umbraco.
                    var content = _contentService.GetById(contentNodeId);
                    if (content != null)
                    {
                        var contentXml = definition.ContentLoadChildNodes ? content.ToDeepXml(_serializer) : content.ToXml(_serializer);

                        //Create the Documents/DocumentSet node

                        root.Add(
                            new XElement("Documents",
                                         new XElement("DocumentSet",
                                                      new XAttribute("importMode", "root"),
                                                      contentXml)));

                        // TODO: I guess tags has been broken for a very long time for packaging, we should get this working again sometime
                        ////Create the TagProperties node - this is used to store a definition for all
                        //// document properties that are tags, this ensures that we can re-import tags properly
                        //XmlNode tagProps = new XElement("TagProperties");

                        ////before we try to populate this, we'll do a quick lookup to see if any of the documents
                        //// being exported contain published tags.
                        //var allExportedIds = documents.SelectNodes("//@id").Cast<XmlNode>()
                        //    .Select(x => x.Value.TryConvertTo<int>())
                        //    .Where(x => x.Success)
                        //    .Select(x => x.Result)
                        //    .ToArray();
                        //var allContentTags = new List<ITag>();
                        //foreach (var exportedId in allExportedIds)
                        //{
                        //    allContentTags.AddRange(
                        //        Current.Services.TagService.GetTagsForEntity(exportedId));
                        //}

                        ////This is pretty round-about but it works. Essentially we need to get the properties that are tagged
                        //// but to do that we need to lookup by a tag (string)
                        //var allTaggedEntities = new List<TaggedEntity>();
                        //foreach (var group in allContentTags.Select(x => x.Group).Distinct())
                        //{
                        //    allTaggedEntities.AddRange(
                        //        Current.Services.TagService.GetTaggedContentByTagGroup(group));
                        //}

                        ////Now, we have all property Ids/Aliases and their referenced document Ids and tags
                        //var allExportedTaggedEntities = allTaggedEntities.Where(x => allExportedIds.Contains(x.EntityId))
                        //    .DistinctBy(x => x.EntityId)
                        //    .OrderBy(x => x.EntityId);

                        //foreach (var taggedEntity in allExportedTaggedEntities)
                        //{
                        //    foreach (var taggedProperty in taggedEntity.TaggedProperties.Where(x => x.Tags.Any()))
                        //    {
                        //        XmlNode tagProp = new XElement("TagProperty");
                        //        var docId = packageManifest.CreateAttribute("docId", "");
                        //        docId.Value = taggedEntity.EntityId.ToString(CultureInfo.InvariantCulture);
                        //        tagProp.Attributes.Append(docId);

                        //        var propertyAlias = packageManifest.CreateAttribute("propertyAlias", "");
                        //        propertyAlias.Value = taggedProperty.PropertyTypeAlias;
                        //        tagProp.Attributes.Append(propertyAlias);

                        //        var group = packageManifest.CreateAttribute("group", "");
                        //        group.Value = taggedProperty.Tags.First().Group;
                        //        tagProp.Attributes.Append(group);

                        //        tagProp.AppendChild(packageManifest.CreateCDataSection(
                        //            JsonConvert.SerializeObject(taggedProperty.Tags.Select(x => x.Text).ToArray())));

                        //        tagProps.AppendChild(tagProp);
                        //    }
                        //}

                        //manifestRoot.Add(tagProps);
                    }
                }
            }
        }
示例#7
0
        //Process files in directory and add them to package
        private static void ProcessDirectory(DirectoryInfo directory, string dirPath, string packageDirectory, XContainer filesXml)
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (string.IsNullOrWhiteSpace(packageDirectory))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(packageDirectory));
            }
            if (string.IsNullOrWhiteSpace(dirPath))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(dirPath));
            }
            if (!directory.Exists)
            {
                return;
            }

            foreach (var file in directory.GetFiles())
            {
                AppendFileXml(new FileInfo(Path.Combine(directory.FullName, file.Name)), dirPath + "/" + file.Name, packageDirectory, filesXml);
            }

            foreach (var dir in directory.GetDirectories())
            {
                ProcessDirectory(dir, dirPath + "/" + dir.Name, packageDirectory, filesXml);
            }
        }
示例#8
0
 /// <summary>
 /// Gets an Element with the specified path. For example "Tree/Branch1/Branch2".
 /// </summary>
 public static XElement GetElement(this XContainer parent, string path)
 {
     return(GetNode(parent, path) as XElement);
 }
示例#9
0
        ///// <summary>
        ///// Gets all children elements of this element in its full hierarchy.
        ///// </summary>
        //public static IEnumerable<XElement> GetAllChildren(this XElement container)
        //{
        //    foreach (var c in container.Elements())
        //    {
        //        foreach (var i in c.WithAllChildren())
        //        {
        //            yield return i;
        //        }
        //    }
        //}

        ///// <summary>
        ///// Gets all children elements of this element in its full hierarchy.
        ///// </summary>
        //public static IEnumerable<XElement> WithAllChildren(this XElement container)
        //{
        //    yield return container;

        //    foreach (var i in container.GetAllChildren())
        //    {
        //        yield return i;
        //    }
        //}

        /// <summary>
        /// Adds this node to a specified container and returns it back to be used as fluent API.
        /// </summary>
        public static T AddTo <T>(this T node, XContainer container) where T : XNode
        {
            container.Add(node);
            return(node);
        }
        private void DrawAccounts([NotNull] XContainer element)
        {
            Debug.ArgumentNotNull(element, nameof(element));

            var accounts = element.Descendants(SecurityStruct.Node.Account);

            if (!accounts.Any())
            {
                MainBorder.IsEnabled = false;
                DataNotSpecifiedNotification.Show();
                return;
            }

            var listOfAccounts = new Grid();

            listOfAccounts.ColumnDefinitions.Add(new ColumnDefinition
            {
                Width = GridLength.Auto
            });
            listOfAccounts.ColumnDefinitions.Add(new ColumnDefinition());

            listOfAccounts.RowDefinitions.Add(new RowDefinition());

            var txtAccounts = new TextBlock
            {
                Text   = Rocks.Resources.SecurityField_DrawAccounts_Accounts,
                Margin = new Thickness(0.0, 0.0, 6.0, 0.0),
                Style  = Resources[@"stlHeader"] as Style
            };

            Grid.SetRow(txtAccounts, 0);
            Grid.SetColumn(txtAccounts, 0);
            listOfAccounts.Children.Add(txtAccounts);

            var txtPermissions = new TextBlock
            {
                Text  = Rocks.Resources.SecurityField_DrawAccounts_Permissions,
                Style = Resources[@"stlHeader"] as Style
            };

            Grid.SetRow(txtPermissions, 0);
            Grid.SetColumn(txtPermissions, 1);
            listOfAccounts.Children.Add(txtPermissions);

            var row = 1;

            foreach (var account in accounts)
            {
                listOfAccounts.RowDefinitions.Add(new RowDefinition());

                var accountHeader = new StackPanel
                {
                    Orientation = Orientation.Horizontal
                };
                DrawAccountHeader(account, accountHeader);
                Grid.SetRow(accountHeader, row);
                Grid.SetColumn(accountHeader, 0);
                listOfAccounts.Children.Add(accountHeader);

                var accountPermissions = new StackPanel
                {
                    Margin = new Thickness(0.0, 0.0, 0.0, 12.0)
                };
                DrawAccountPermissions(account, accountPermissions);
                Grid.SetRow(accountPermissions, row);
                Grid.SetColumn(accountPermissions, 1);
                listOfAccounts.Children.Add(accountPermissions);

                row++;
            }

            stkMain.Children.Add(listOfAccounts);
        }
示例#11
0
        private void Map(XContainer root, object obj)
        {
            Type objType = obj.GetType();
            var  props   = from p in objType.GetProperties()
                           let indexAttribute = p.GetAttribute <SerializeAsAttribute>()
                                                where p.CanRead && p.CanWrite
                                                orderby indexAttribute?.Index ?? int.MaxValue
                                                select p;
            SerializeAsAttribute globalOptions   = objType.GetAttribute <SerializeAsAttribute>();
            bool textContentAttributeAlreadyUsed = false;

            foreach (var prop in props)
            {
                var name     = prop.Name;
                var rawValue = prop.GetValue(obj, null);

                if (rawValue == null)
                {
                    continue;
                }

                string value                 = this.GetSerializedValue(rawValue);
                Type   propType              = prop.PropertyType;
                bool   useAttribute          = false;
                bool   setTextContent        = false;
                SerializeAsAttribute options = prop.GetAttribute <SerializeAsAttribute>();

                if (options != null)
                {
                    name = options.Name.HasValue()
                        ? options.Name
                        : name;

                    name = options.TransformName(name);

                    useAttribute = options.Attribute;

                    setTextContent = options.Content;

                    if (textContentAttributeAlreadyUsed && setTextContent)
                    {
                        throw new ArgumentException("Class cannot have two properties marked with " +
                                                    "SerializeAs(Content = true) attribute.");
                    }

                    textContentAttributeAlreadyUsed |= setTextContent;
                }
                else if (globalOptions != null)
                {
                    name = globalOptions.TransformName(name);
                }

                var nsName  = name.AsNamespaced(Namespace);
                var element = new XElement(nsName);
                if (propType.GetTypeInfo().IsPrimitive || propType.GetTypeInfo().IsValueType ||
                    propType == typeof(string))
                {
                    if (useAttribute)
                    {
                        root.Add(new XAttribute(name, value));
                        continue;
                    }
                    else if (setTextContent)
                    {
                        root.Add(new XText(value));
                        continue;
                    }

                    element.Value = value;
                }
                else if (rawValue is IList)
                {
                    var itemTypeName = "";

                    foreach (var item in (IList)rawValue)
                    {
                        if (itemTypeName == "")
                        {
                            var type    = item.GetType();
                            var setting = type.GetAttribute <SerializeAsAttribute>();

                            itemTypeName = setting != null && setting.Name.HasValue()
                                ? setting.Name
                                : type.Name;
                        }

                        var instance = new XElement(itemTypeName.AsNamespaced(Namespace));

                        Map(instance, item);
                        element.Add(instance);
                    }
                }
                else
                {
                    Map(element, rawValue);
                }

                root.Add(element);
            }
        }
        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);
                }
            }
        }
 private void AddFiles(XContainer nuSpec, IEnumerable <string> sourceFiles, string sourceBaseDirectory, string targetDirectory = "")
 {
     AddFiles(nuSpec, sourceFiles.Select(s => new TaskItem(s)), sourceBaseDirectory, targetDirectory);
 }
        private void PackageDictionaryItems(PackageDefinition definition, XContainer root)
        {
            var rootDictionaryItems = new XElement("DictionaryItems");
            var items = new Dictionary <Guid, (IDictionaryItem dictionaryItem, XElement serializedDictionaryValue)>();

            foreach (var dictionaryId in definition.DictionaryItems)
            {
                if (!int.TryParse(dictionaryId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var outInt))
                {
                    continue;
                }

                IDictionaryItem di = _languageService.GetDictionaryItemById(outInt);

                if (di == null)
                {
                    continue;
                }

                items[di.Key] = (di, _serializer.Serialize(di, false));
            }

            // organize them in hierarchy ...
            var itemCount = items.Count;
            var processed = new Dictionary <Guid, XElement>();

            while (processed.Count < itemCount)
            {
                foreach (Guid key in items.Keys.ToList())
                {
                    (IDictionaryItem dictionaryItem, XElement serializedDictionaryValue) = items[key];

                    if (!dictionaryItem.ParentId.HasValue)
                    {
                        // if it has no parent, its definitely just at the root
                        AppendDictionaryElement(rootDictionaryItems, items, processed, key, serializedDictionaryValue);
                    }
                    else
                    {
                        if (processed.ContainsKey(dictionaryItem.ParentId.Value))
                        {
                            // we've processed this parent element already so we can just append this xml child to it
                            AppendDictionaryElement(processed[dictionaryItem.ParentId.Value], items, processed, key, serializedDictionaryValue);
                        }
                        else if (items.ContainsKey(dictionaryItem.ParentId.Value))
                        {
                            // we know the parent exists in the dictionary but
                            // we haven't processed it yet so we'll leave it for the next loop
                            continue;
                        }
                        else
                        {
                            // in this case, the parent of this item doesn't exist in our collection, we have no
                            // choice but to add it to the root.
                            AppendDictionaryElement(rootDictionaryItems, items, processed, key, serializedDictionaryValue);
                        }
                    }
                }
            }

            root.Add(rootDictionaryItems);
示例#15
0
 internal abstract void SerializeInto(XContainer container);
示例#16
0
 private static void AddTrailingIndentation(XContainer container, string containerIndent)
 {
     container.Add(new XText(containerIndent));
 }
示例#17
0
 private static XElement FindReportOnDocument(XContainer xdoc, string reportName)
 {
     return(xdoc.Descendants("Report").SingleOrDefault(r => r.Attribute("name").Value == reportName));
 }
示例#18
0
        private static Dictionary <string, MexPolicy> ReadPolicyBindings(XContainer mexDocument, IReadOnlyDictionary <string, MexPolicy> policies)
        {
            var bindings = new Dictionary <string, MexPolicy>();
            IEnumerable <XElement> bindingElements = mexDocument.Elements().First().Elements(XmlNamespace.Wsdl + "binding");

            foreach (XElement binding in bindingElements)
            {
                IEnumerable <XElement> policyReferences = binding.Elements(XmlNamespace.Wsp + "PolicyReference");
                foreach (XElement policyReference in policyReferences)
                {
                    XAttribute policyUri = policyReference.Attribute("URI");
                    if (policyUri == null || !policies.ContainsKey(policyUri.Value))
                    {
                        continue;
                    }

                    XAttribute bindingName = binding.Attribute("name");
                    if (bindingName == null)
                    {
                        continue;
                    }

                    XElement bindingOperation = binding.Elements(XmlNamespace.Wsdl + "operation").FirstOrDefault();
                    if (bindingOperation == null)
                    {
                        continue;
                    }

                    XElement soapOperation = bindingOperation.Elements(XmlNamespace.Soap12 + "operation").FirstOrDefault();
                    if (soapOperation == null)
                    {
                        continue;
                    }

                    XAttribute soapAction = soapOperation.Attribute("soapAction");
                    if (soapAction == null || (string.Compare(XmlNamespace.Issue.ToString(), soapAction.Value, StringComparison.OrdinalIgnoreCase) != 0 &&
                                               string.Compare(XmlNamespace.Issue2005.ToString(), soapAction.Value, StringComparison.OrdinalIgnoreCase) != 0))
                    {
                        continue;
                    }

                    bool isWsTrust2005 =
                        string.Compare(XmlNamespace.Issue2005.ToString(), soapAction.Value,
                                       StringComparison.OrdinalIgnoreCase) == 0;
                    policies[policyUri.Value].Version = isWsTrust2005 ? WsTrustVersion.WsTrust2005:WsTrustVersion.WsTrust13;


                    XElement soapBinding = binding.Elements(XmlNamespace.Soap12 + "binding").FirstOrDefault();
                    if (soapBinding == null)
                    {
                        continue;
                    }

                    XAttribute soapBindingTransport = soapBinding.Attribute("transport");
                    if (soapBindingTransport != null && string.Compare(WsTrustSoapTransport, soapBindingTransport.Value, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        bindings.Add(bindingName.Value, policies[policyUri.Value]);
                    }
                }
            }

            return(bindings);
        }
示例#19
0
        /// <summary>
        /// Appends a file to package and copies the file to the correct folder.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="packageDirectory">The package directory.</param>
        /// <param name="filesXml">The files xml node</param>
        private static void AppendFileToPackage(string path, string packageDirectory, XContainer filesXml)
        {
            if (!path.StartsWith("~/") && !path.StartsWith("/"))
            {
                path = "~/" + path;
            }

            var serverPath = IOHelper.MapPath(path);

            if (File.Exists(serverPath))
            {
                AppendFileXml(new FileInfo(serverPath), path, packageDirectory, filesXml);
            }
            else if (Directory.Exists(serverPath))
            {
                ProcessDirectory(new DirectoryInfo(serverPath), path, packageDirectory, filesXml);
            }
        }
示例#20
0
 static IEnumerable <XNode> ContentNodes(this XContainer container)
 {
     return(container.Nodes().Where(n => n.NodeType != XmlNodeType.Comment &&
                                    (n.NodeType != XmlNodeType.Text || !string.IsNullOrWhiteSpace(((XText)n).Value))
                                    ));
 }
示例#21
0
        private static void AppendFileXml(FileInfo file, string filePath, string packageDirectory, XContainer filesXml)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(filePath));
            }
            if (string.IsNullOrWhiteSpace(packageDirectory))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(packageDirectory));
            }

            var orgPath     = filePath.Substring(0, (filePath.LastIndexOf('/')));
            var orgName     = filePath.Substring((filePath.LastIndexOf('/') + 1));
            var newFileName = orgName;

            if (File.Exists(packageDirectory.EnsureEndsWith('/') + orgName))
            {
                newFileName = Guid.NewGuid() + "_" + newFileName;
            }

            //Copy file to directory for zipping...
            File.Copy(file.FullName, packageDirectory + "/" + newFileName, true);

            filesXml.Add(new XElement("file",
                                      new XElement("guid", newFileName),
                                      new XElement("orgPath", orgPath == "" ? "/" : orgPath),
                                      new XElement("orgName", orgName)));
        }
示例#22
0
        private static void LoadMinMaxFromRestrictedList <T>(XContainer xParent, string elementName,
                                                             MinMaxFromRestrictedListItem <T> item) where T : struct, IConvertible
        {
            var xFoundElement = xParent.Element(elementName);

            var xUse = xFoundElement?.Element(UseNode);

            if (xUse == null)
            {
                return;
            }

            bool use;

            if (!Load(xFoundElement, UseNode, out use))
            {
                return;
            }

            if (!use)
            {
                return;
            }

            item.Use = true;

            if (typeof(T).IsEnum)
            {
                string value;

                // min
                if (!Load(xFoundElement, MinNode, out value))
                {
                    return;
                }

                if (string.IsNullOrEmpty(value))
                {
                    item.Use = false;
                    return;
                }
                item.Min = LoadEnum <T>(xFoundElement, MinNode);

                // max
                if (!Load(xFoundElement, MaxNode, out value))
                {
                    return;
                }

                if (string.IsNullOrEmpty(value))
                {
                    item.Use = false;
                    return;
                }
                item.Max = LoadEnum <T>(xFoundElement, MaxNode);
            }
            else
            {
                T value;
                if (!Load(xFoundElement, MinNode, out value))
                {
                    return;
                }
                item.Min = value;

                if (!Load(xFoundElement, MaxNode, out value))
                {
                    return;
                }
                item.Max = value;
            }
        }
示例#23
0
 public ConditionNOR(XContainer el) : base(el)
 {
 }
示例#24
0
 // TSX file constructor
 public TmxTileset(XContainer xDoc, string tmxDir) :
     this(xDoc.Element("tileset"), tmxDir)
 {
 }
示例#25
0
 public TestableBundleSerializer(XContainer container) : base(container)
 {
 }
            // CONSIDER: could add a depth count and just not rewrite below that depth.
            private XNode[] Rewrite(XNode node, string currentXmlFilePath, CSharpSyntaxNode originatingSyntax)
            {
                _cancellationToken.ThrowIfCancellationRequested();

                string commentMessage = null;

                if (node.NodeType == XmlNodeType.Element)
                {
                    XElement element = (XElement)node;
                    if (ElementNameIs(element, DocumentationCommentXmlNames.IncludeElementName))
                    {
                        XNode[] rewritten = RewriteIncludeElement(element, currentXmlFilePath, originatingSyntax, out commentMessage);
                        if (rewritten != null)
                        {
                            return(rewritten);
                        }
                    }
                }

                XContainer container = node as XContainer;

                if (container == null)
                {
                    Debug.Assert(commentMessage == null, "How did we get an error comment for a non-container?");
                    return(new XNode[] { node.Copy(copyAttributeAnnotations: false) });
                }

                IEnumerable <XNode> oldNodes = container.Nodes();

                // Do this after grabbing the nodes, so we don't see copies of them.
                container = container.Copy(copyAttributeAnnotations: false);

                // WARN: don't use node after this point - use container since it's already been copied.

                if (oldNodes != null)
                {
                    XNode[] rewritten = RewriteMany(oldNodes.ToArray(), currentXmlFilePath, originatingSyntax);
                    container.ReplaceNodes(rewritten);
                }

                // NOTE: we may modify the values of cref attributes, so don't do this until AFTER we've
                // made a copy.  Also, we only care if we're included text - otherwise we've already
                // processed the cref.
                if (container.NodeType == XmlNodeType.Element && originatingSyntax != null)
                {
                    XElement element = (XElement)container;
                    foreach (XAttribute attribute in element.Attributes())
                    {
                        if (AttributeNameIs(attribute, DocumentationCommentXmlNames.CrefAttributeName))
                        {
                            BindAndReplaceCref(attribute, originatingSyntax);
                        }
                        else if (AttributeNameIs(attribute, DocumentationCommentXmlNames.NameAttributeName))
                        {
                            if (ElementNameIs(element, DocumentationCommentXmlNames.ParameterElementName) ||
                                ElementNameIs(element, DocumentationCommentXmlNames.ParameterReferenceElementName))
                            {
                                BindName(attribute, originatingSyntax, isParameter: true, isTypeParameterRef: false);
                            }
                            else if (ElementNameIs(element, DocumentationCommentXmlNames.TypeParameterElementName))
                            {
                                BindName(attribute, originatingSyntax, isParameter: false, isTypeParameterRef: false);
                            }
                            else if (ElementNameIs(element, DocumentationCommentXmlNames.TypeParameterReferenceElementName))
                            {
                                BindName(attribute, originatingSyntax, isParameter: false, isTypeParameterRef: true);
                            }
                        }
                    }
                }

                if (commentMessage == null)
                {
                    return(new XNode[] { container }); // Already copied.
                }
                else
                {
                    XComment failureComment = new XComment(commentMessage);
                    return(new XNode[] { failureComment, container }); // Already copied.
                }
            }
示例#27
0
 public static T ToXmlObject <T>(this XContainer valor)
 {
     return((T)ToXmlObject(valor, typeof(T)));
 }
示例#28
0
 /// <summary>
 /// Removes all descendant comment nodes for this document or element.
 /// </summary>
 /// <param name="xml">The XML from which to remove all comment nodes.</param>
 public static void RemoveAllComments(this XContainer xml)
 {
     xml.DescendantComments().Remove();
 }
		void BuildTreeChildren (Gtk.TreeStore store, Gtk.TreeIter parent, XContainer p, IList<Block> blocks)
		{
			foreach (XNode node in p.Nodes) {
				var el = node as XElement;
				if (el == null) {
					var startLoc = node.Region.Begin;
					var endLoc = node.Region.End;
					var doc = defaultDocument.Editor.Document;

					var blocksBetween = blocks.Where (n => n.Start.AbsoluteIndex >= doc.GetOffset (startLoc)
						&& n.Start.AbsoluteIndex <= doc.GetOffset (endLoc));

					foreach (var block in blocksBetween) {
						var outlineNode = new OutlineNode (block) {
							Location = new DomRegion (doc.OffsetToLocation (block.Start.AbsoluteIndex),
								doc.OffsetToLocation (block.Start.AbsoluteIndex + block.Length))
						};
						if (!parent.Equals (Gtk.TreeIter.Zero))
							store.AppendValues (parent, outlineNode);
						else
							store.AppendValues (outlineNode);
					}
					continue;
				}

				Gtk.TreeIter childIter;
				if (!parent.Equals (Gtk.TreeIter.Zero))
					childIter = store.AppendValues (parent, new OutlineNode(el));
				else
					childIter = store.AppendValues (new OutlineNode(el));

				BuildTreeChildren (store, childIter, el, blocks);
			}
		}
示例#30
0
 public void Render(XContainer content, InlineCollection inlines)
 {
     InternalRender(content, inlines, null);
 }