Example #1
0
        private string GetYouTubeTitle(XNamespace atoms, XElement entry, XNamespace medians)
        {
            string title = string.Empty;

            if (entry.Element(atoms.GetName("title")) != null)
                title = entry.Element(atoms.GetName("title")).Value;

            return title;
        }
        private DateTime GetPublishDate(XNamespace atoms, XElement entry)
        {
            DateTime publish = DateTime.MinValue;
            if (entry.Element(atoms.GetName("published")) != null && entry.Element(atoms.GetName("published")).Value != null)
            {
                DateTime.TryParse(entry.Element(atoms.GetName("published")).Value, out publish);
            }

            return publish;
        }
        private string GetVideoUrl(XNamespace yt, XElement entry)
        {
            string videoUrl = string.Empty;
            string id = string.Empty;
            if (entry.Element(yt.GetName("videoid")) != null && entry.Element(yt.GetName("videoid")).Value != null)
                id = entry.Element(yt.GetName("videoid")).Value.Split(':').Last();

            videoUrl = String.Format(CultureInfo.InvariantCulture, "http://gdata.youtube.com/feeds/api/videos/{0}", id);

            return videoUrl;
        }
Example #4
0
 /// <summary>
 /// Moves <paramref name="element"/> into namespace <paramref name="newNamespace"/>.
 /// </summary>
 /// <param name="element">The element that will be moved into a new namespace.</param>
 /// <param name="newNamespace">The new namespace for the element.</param>
 public static void MoveToNamespace(this XElement element, XNamespace newNamespace)
 {
     foreach (XElement el in element.DescendantsAndSelf())
     {
         el.Name = newNamespace.GetName(el.Name.LocalName);
     }
 }
Example #5
0
        // StartAttribute

        public override void WriteStartAttribute(string prefix, string name, string ns)
        {
            CheckState();
            if (attribute != null)
            {
                throw new InvalidOperationException("There is an open attribute.");
            }
            XElement el = current as XElement;

            if (el == null)
            {
                throw new InvalidOperationException("Current state is not acceptable for startAttribute.");
            }

            // special case: in XmlWriter context, xmlns="blah" is
            // passeed as localName = "xmlns", ns = w3c_xmlns.
            if (prefix.Length == 0 && name == "xmlns" && ns == XNamespace.Xmlns.NamespaceName)
            {
                ns = String.Empty;
            }

            XNamespace xns = XNamespace.Get(ns);

            el.SetAttributeValue(xns.GetName(name), String.Empty);
            attribute = el.LastAttribute;
            FillXmlns(el, prefix, xns);
        }
 public YouTubeSearchResult(XNamespace atomns, XElement entry, XNamespace medians)
 {
     var xElement = entry.Element(atomns.GetName("id"));
     var element = entry.Element(atomns.GetName("id"));
     if (element != null)
         Id = xElement != null
                       ? element.Value.Split(':').Last()
                       : string.Empty;
     ImageUrl = (from thumbnail in entry.Descendants(medians.GetName("thumbnail"))
                 let xAttribute = thumbnail.Attribute("url")
                 where xAttribute != null
                 select xAttribute.Value).FirstOrDefault();
     var xElement1 = entry.Element(atomns.GetName("title"));
     if (xElement1 != null)
         Title = xElement1.Value;
 }
 private XObject GenerateValueExpression(XNamespace ns, IEdmExpression expression)
 {
     // TODO: handle other than constant, other DataTypes
     XObject returnXObject = null;
     switch (expression.ExpressionKind)
     {
         case EdmExpressionKind.Null:
             returnXObject = new XElement(ns.GetName("Null"));
             break;
         case EdmExpressionKind.IntegerConstant:
             var integerConstantExpression = (IEdmIntegerConstantExpression)expression;
             returnXObject = new XAttribute("Int", integerConstantExpression.Value);
             break;
         case EdmExpressionKind.StringConstant:
             var stringConstantExpression = (IEdmStringConstantExpression)expression;
             returnXObject = new XAttribute("String", stringConstantExpression.Value);
             break;
         case EdmExpressionKind.Collection:
             returnXObject = this.GenerateCollectionExpression(ns, (IEdmCollectionExpression)expression);
             break;
         case EdmExpressionKind.Record:
             returnXObject = this.GenerateRecordExpression(ns, (IEdmRecordExpression)expression);
             break;
         default:
             throw new NotSupportedException();
     }
     return returnXObject;
 }
 private CorrelationKey(string keyString, XNamespace provider) : base(GenerateKey(keyString), dictionary)
 {
     Dictionary<XName, InstanceValue> dictionary = new Dictionary<XName, InstanceValue>(2);
     dictionary.Add(provider.GetName("KeyString"), new InstanceValue(keyString, InstanceValueOptions.Optional));
     dictionary.Add(WorkflowNamespace.KeyProvider, new InstanceValue(provider.NamespaceName, InstanceValueOptions.Optional));
     this.KeyString = keyString;
 }
		public static XElement XElementFromElastic(ElasticObject elastic, XNamespace nameSpace = null)
		{
			// we default to empty namespace
			nameSpace = nameSpace ?? string.Empty;
			var exp = new XElement(nameSpace + elastic.InternalName);

			foreach (var a in elastic.Attributes.Where(a => a.Value.InternalValue != null))
			{
				// if we have xmlns attribute add it like XNamespace instead of regular attribute
				if (a.Key.Equals("xmlns", StringComparison.InvariantCultureIgnoreCase))
				{
					nameSpace = a.Value.InternalValue.ToString();
					exp.Name = nameSpace.GetName(exp.Name.LocalName);
				}
				else
				{
					exp.Add(new XAttribute(a.Key, a.Value.InternalValue));
				}
			}

			if (elastic.InternalContent is string)
			{
				exp.Add(new XText(elastic.InternalContent as string));
			}

			foreach (var child in elastic.Elements.Select(c => XElementFromElastic(c, nameSpace)))
			{
				exp.Add(child);
			}

			return exp;
		}
 CorrelationKey(string keyString, XNamespace provider)
     : base(GenerateKey(keyString), new Dictionary<XName, InstanceValue>(2)
     {
         { provider.GetName("KeyString"), new InstanceValue(keyString, InstanceValueOptions.Optional) },
         { WorkflowNamespace.KeyProvider, new InstanceValue(provider.NamespaceName, InstanceValueOptions.Optional) },
     })
 {
     KeyString = keyString;
 }
        /// <summary>
        /// Changes the namespace of every element in the currentNamespace in the element tree to newNamespace
        /// </summary>
        public static void ReplaceNamespace(this XElement element, XNamespace currentNamespace, XNamespace newNamespace)
        {
            if (element.Name.Namespace == currentNamespace)
            {
                element.Name = newNamespace.GetName(element.Name.LocalName);
            }

            foreach (var childNode in element.Elements())
            {
                childNode.ReplaceNamespace(currentNamespace, newNamespace);
            }
        }
        static void SetDefaultNamespace(XElement element, XNamespace newXmlns)
        {
            var currentXmlns = element.GetDefaultNamespace();
            if (currentXmlns == newXmlns)
            {
                return;
            }

            foreach (var descendant in element.DescendantsAndSelf()
                .Where(e => e.Name.Namespace == currentXmlns))
            {
                descendant.Name = newXmlns.GetName(descendant.Name.LocalName);
            }
        }
Example #13
0
		// StartElement

		public override void WriteStartElement (string prefix, string name, string ns)
		{
			CheckState ();

			XNamespace xns = XNamespace.Get (ns ?? String.Empty);
			XElement el = new XElement (xns.GetName (name));
			if (current == null) {
				root.Add (el);
				state = XmlNodeType.Element;
			} else {
				current.Add (el);
				state = XmlNodeType.Element;
			}

			FillXmlns (el, prefix, xns);

			current = el;
		}
Example #14
0
        /// <summary>
        /// Sets the default XML namespace of this System.Xml.Linq.XElement and all its descendants
        /// </summary>

        public static void SetDefaultNamespace(this XElement element, XNamespace newXmlns)
        {
            if (newXmlns == null)
            {
                return;
            }
            var currentXmlns = element.GetDefaultNamespace();

            if (currentXmlns == newXmlns)
            {
                return;
            }

            foreach (var descendant in element.DescendantsAndSelf()
                     .Where(e => e.Name.Namespace == currentXmlns)) //!important
            {
                descendant.Name = newXmlns.GetName(descendant.Name.LocalName);
            }
        }
Example #15
0
 public void ReadElementUntil(XElement source, XName match)
 {
     if (_reader.ReadState != ReadState.Interactive)
     {
         throw new InvalidOperationException("The reader state should be Interactive.");
     }
     if (source.Name != XNamespace.Get(_reader.NamespaceURI).GetName(_reader.LocalName))
     {
         throw new InvalidOperationException(string.Format("The reader should be on an element with the name '{0}'.", source.Name));
     }
     if (_reader.MoveToFirstAttribute())
     {
         do
         {
             XNamespace ns = _reader.Prefix.Length == 0 ? XNamespace.None : XNamespace.Get(_reader.NamespaceURI);
             source.Add(new XAttribute(ns.GetName(_reader.LocalName), _reader.Value));
         } while (_reader.MoveToNextAttribute());
         _reader.MoveToElement();
     }
     if (!_reader.IsEmptyElement)
     {
         _reader.Read();
         if (match != null)
         {
             if (ReadPrologUntil(source, match))
             {
                 return;
             }
         }
         else
         {
             ReadContent(source);
         }
     }
     _reader.Read();
 }
            /// <summary>
            /// Get Arguments, assembly and type from an OMI XML
            /// </summary>
            /// <param name="omiXml">OMI XML</param>
            /// <param name="relativeTo">OMI file Path</param>
            /// <param name="assembly">ILinkableComponent Assembly</param>
            /// <param name="type">ILinkableComponent type</param>
            /// <returns>ILinkableComponent arguments</returns>
            public static List<Argument1> Arguments1(XElement xArguments, XNamespace ns, Uri relativeTo)
            {
                List<Argument1> args = new List<Argument1>();

                string key, value, description;
                bool readOnly;

                foreach (XElement xArg in xArguments.Elements(ns.GetName("Argument")))
                {
                    key = Utilities.Xml.GetAttribute(xArg, "Key");
                    value = Utilities.Xml.GetAttribute(xArg, "Value");
                    value = ResolveArgumentValueV1(relativeTo, key, value);
                    readOnly = Utilities.Xml.GetAttribute(xArg, "ReadOnly", false);
                    description = xArg.Value;

                    args.Add(new Argument1(
                        key,
                        value,
                        readOnly,
                        description));
                }

                return args;
            }
Example #17
0
        bool ReadPrologUntil(XElement source, XName match)
        {
            if (_reader.ReadState != ReadState.Interactive)
            {
                throw new InvalidOperationException("The reader state should be Interactive.");
            }
            do
            {
                switch (_reader.NodeType)
                {
                case XmlNodeType.Element:
                    XName name = XNamespace.Get(_reader.NamespaceURI).GetName(_reader.LocalName);
                    if (name == match)
                    {
                        return(true);
                    }
                    XElement e = new XElement(name);
                    if (_reader.MoveToFirstAttribute())
                    {
                        do
                        {
                            XNamespace ns = _reader.Prefix.Length == 0 ? XNamespace.None : XNamespace.Get(_reader.NamespaceURI);
                            e.Add(new XAttribute(ns.GetName(_reader.LocalName), _reader.Value));
                        } while (_reader.MoveToNextAttribute());
                        _reader.MoveToElement();
                    }
                    source.Add(e);
                    if (!_reader.IsEmptyElement)
                    {
                        _reader.Read();
                        ReadContent(e);
                    }
                    break;

                case XmlNodeType.EndElement:
                    return(false);

                case XmlNodeType.Text:
                case XmlNodeType.SignificantWhitespace:
                case XmlNodeType.Whitespace:
                case XmlNodeType.CDATA:
                case XmlNodeType.Comment:
                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.DocumentType:
                    break;

                case XmlNodeType.EntityReference:
                    if (!_reader.CanResolveEntity)
                    {
                        throw new InvalidOperationException("The reader cannot resolve entity references.");
                    }
                    _reader.ResolveEntity();
                    break;

                case XmlNodeType.EndEntity:
                    break;

                default:
                    throw new InvalidOperationException(string.Format("The reader should not be on a node of type '{0}'.", _reader.NodeType));
                }
            } while (_reader.Read());
            return(false);
        }
 public override XElement ToElement( XNamespace ns )
 {
     var e = new XElement( ns.GetName( Action ) );
       e.Add( new XAttribute( "Include", CsProjPath ) );
       e.Add( new XElement( ns.GetName( "Project" ), "{" + ProjectId + "}" ) );
       e.Add( new XElement( ns.GetName( "Name" ), Name ) );
       return e;
 }
		public YouTubeVideo(XNamespace atomns, XElement entry, XNamespace medians)
        {
            var id = entry.Element(atomns.GetName("id")) != null && entry.Element(atomns.GetName("id")).Value != null
                ? entry.Element(atomns.GetName("id")).Value.Split(':').Last()
                : string.Empty;
		    VideoUrl = "http://gdata.youtube.com/feeds/api/videos/" + id;
            VideoImageUrl = (from thumbnail in entry.Descendants(medians.GetName("thumbnail"))
                select thumbnail.Attribute("url").Value).FirstOrDefault();
            Title = entry.Element(atomns.GetName("title")) != null
                ? entry.Element(atomns.GetName("title")).Value
                : string.Empty;
            Summary = entry.Element(atomns.GetName("summary")) != null
                ? entry.Element(atomns.GetName("summary")).Value
                : string.Empty;
            if (string.IsNullOrEmpty(Summary))
                Summary = entry.Element(atomns.GetName("content")) != null
                    ? entry.Element(atomns.GetName("content")).Value
                    : string.Empty;
            if (string.IsNullOrEmpty(Summary))
                Summary = entry.Element(medians.GetName("group")) != null && 
                          entry.Element(medians.GetName("group")).Element(medians.GetName("description")) != null
                    ? entry.Element(medians.GetName("group")).Element(medians.GetName("description")).Value
                    : string.Empty;
            if (string.IsNullOrEmpty(Summary))
                Summary = Title;
        }
        private string GetYouTubeSummary(XNamespace atoms, XElement entry, XNamespace medians)
        {
            string summary = string.Empty;
            if (entry.Element(atoms.GetName("summary")) != null)
                summary = entry.Element(atoms.GetName("summary")).Value;

            if (string.IsNullOrEmpty(summary))
                if (entry.Element(atoms.GetName("content")) != null)
                    summary = entry.Element(atoms.GetName("content")).Value;

            if (string.IsNullOrEmpty(summary))
                if (entry.Element(medians.GetName("group")) != null && entry.Element(medians.GetName("group")).Element(medians.GetName("description")) != null)
                    summary = entry.Element(medians.GetName("group")).Element(medians.GetName("description")).Value;

            return summary;
        }
 private XObject GenerateRecordExpression(XNamespace ns, IEdmRecordExpression record)
 {
     var recordElement = new XElement(ns.GetName("Record"));
     foreach (var property in record.Properties)
     {
         var propertyValueElement = new XElement(ns.GetName("PropertyValue"));
         propertyValueElement.Add(new XAttribute("Property", property.Name));
         propertyValueElement.Add(GenerateValueExpression(ns, property.Value));
         recordElement.Add(propertyValueElement);
     }
     return recordElement;
 }
        private XObject GenerateCollectionExpression(XNamespace ns, IEdmCollectionExpression collection)
        {
            var collectionElements = new XElement(ns.GetName("Collection"));
            foreach (var element in collection.Elements)
            {
                var elementValue = GenerateValueExpression(ns, element);

                if (elementValue is XAttribute)
                {
                    var collectionElement = new XElement(ns.GetName(((XAttribute)elementValue).Name.ToString()));
                    collectionElement.Add(((XAttribute)elementValue).Value);
                    collectionElements.Add(collectionElement);
                }
                else
                {
                    collectionElements.Add(elementValue);
                }
            }
            return collectionElements;
        }
Example #23
0
 private static bool SetNameSpace(XNamespace aw, XElement xmlElement)
 {
     if (xmlElement.Name.Namespace == XNamespace.None)
     {
         xmlElement.Name = aw.GetName(xmlElement.Name.LocalName);
         foreach (var xElement in xmlElement.Descendants())
         {
             if (xElement.Name.Namespace == XNamespace.None)
             {
                 xElement.Name = aw.GetName(xElement.Name.LocalName);
             }
             else
             {
                 return false;
             }
         }
     }
     return false;
 }
Example #24
0
        public override XElement ToElement( XNamespace ns )
        {
            if ( _originalItemElement != null ) {
            return _originalItemElement;
              }

              XElement e = new XElement( ns.GetName( Action ) );

              e.Add( new XAttribute( "Include", Include ) );
              AddElement( e, "Name", Name );
              AddElement( e, "FusionName", FusionName );
              AddElement( e, "HintPath", HintPath );
              AddElement( e, "Private", Private );
              AddElement( e, "EmbedInteropTypes", EmbedInteropTypes );
              AddElement( e, "Aliases", Aliases );
              AddElement( e, "SpecificVersion", SpecificVersion );
              AddElement( e, "RequiredTargetFramework", RequiredTargetFramework );
              return e;
        }
 public Silverlight4AppManifestAnalyzer()
 {
     _xamlNamespace = XNamespace.Get("http://schemas.microsoft.com/winfx/2006/xaml");
     _nameAttributeName = _xamlNamespace.GetName("Name");
 }