public void uses_the_default_value()
        {
            var element = new XElement("PropertyGroup");
            element.Add(new XElement("TargetFrameworkVersion", "v4.0"));

            element.Get("AssemblyName", "ClassLibrary1").ShouldEqual("ClassLibrary1");
        }
Пример #2
0
 internal User( WebAgent agent, XElement user )
 {
     this.agent = agent;
     this.username = user.Get( "user_name" );
     this.defaultFormat = user.Get( "user_format_short" );
     this.defaultExpiration = user.Get( "user_expiration" );
     this.avatarUrl = user.Get( "user_avatar_url" );
     this.website = user.Get( "user_website" );
     this.email = user.Get( "user_email" );
     this.location = user.Get( "user_location" );
     this.defaultExposure = user.Get<PasteExposure, int>( "user_private", Int32.Parse );
     this.accountType = user.Get<AccountType, int>( "user_account_type", Int32.Parse );
 }
Пример #3
0
 public TVDBEpisode(XElement element)
 {
     ID = element.GetInt("id").Value;
     Directors = element.Split("Director");
     Name = element.Get("EpisodeName");
     Number = element.GetInt("EpisodeNumber").Value;
     Aired = element.GetDateTime("FirstAired");
     GuestStars = element.Split("GuestStars");
     IMDbID = element.Get("IMDB_ID");
     Language = element.Get("Language");
     Overview = element.Get("Overview");
     Season = element.GetInt("SeasonNumber").Value;
     Writers = element.Split("Writer");
     AbsoluteNumber = element.GetInt("absolute_number");
     Filename = element.Get("filename");
     LastUpdated = element.GetUnixDateTime("lastupdated");
     SeasonID = element.GetInt("seasonid").Value;
     SeriesID = element.GetInt("seriesid").Value;
     Rating = element.GetDouble("Rating");
 }
Пример #4
0
        public static Metrics Metrics(XElement typeNode)
        {
            var memberMetrics = typeNode.Descendants("Member")
                .Where(IsNotGenerated)
                .SelectMany(node => node.Descendants("Metric"));

            var metricsMetaData = new Metrics();
            metricsMetaData[TypeName] = typeNode.Get(Name);
            metricsMetaData[LinesPerMethod] = MemberToxicityFor(LinesOfCode, threasholdLimits[LinesPerMethod], memberMetrics).ToString();
            metricsMetaData[ComplexityPerMethod] = MemberToxicityFor(CyclomaticComplexity, threasholdLimits[CyclomaticComplexity], memberMetrics).ToString();
            metricsMetaData[CouplingPerMethod] = MemberToxicityFor(ClassCoupling, threasholdLimits[ClassCoupling], memberMetrics).ToString();

            return metricsMetaData.ToDictionary();
        }
Пример #5
0
 private object _getValue(XElement element) {
    if (element.HasAttribute("value")) {
       return element.Get("value");
    }
    if (!element.HasElements) {
       return element.Value;
    }
    var valueSet = new Dictionary<string, string>();
    foreach (var child in element.Elements()) {
       var itemTag = child.Name.LocalName;
       if (itemTag != "Value") {
          throw new Exception("Unrecognized tag '{0}'".Substitute(itemTag));
       }
       valueSet.Add(child.Get("name"), child.HasAttribute("value") ? child.Get("value") : child.Value);
    }
    return valueSet;
 }
Пример #6
0
 public void Get_StringValue()
 {
     string value = "A value to test";
     XElement test = new XElement("Node", value);
     string result = test.Get("", "");
     Assert.AreEqual(string.Compare(value, result), 0);
 }
Пример #7
0
 public void Get_IntValue()
 {
     int value = 100;
     XElement test = new XElement("Node", value);
     int result = test.Get("", 0);
     Assert.AreEqual(value, result);
 }
Пример #8
0
 public void Get_IntAttribute()
 {
     int value = 100;
     XElement test = new XElement("Node", new XAttribute("A", value));
     int result = test.Get("A", 0);
     Assert.AreEqual(value, result);
 }
Пример #9
0
 public static bool IsNotGenerated(XElement node)
 {
     if (node.Attribute("File") == null) return true;
     return !generatedFiles.Contains(node.Get("File").ToLower());
 }
Пример #10
0
 /// <summary>Override this method on derived script nodes to convert the node to XML.</summary>
 protected virtual void FromXmlOverride(XElement element) {
    SourceCode = element.Value;
    Title = element.Get("title");
 }
Пример #11
0
 /// <summary>Parses the descriptor properties from the given XML object.</summary>
 /// <param name="element">The XML element to parse.</param>
 protected virtual void ParseXmlOverride(XElement element) {
    _bookmark = element.Get("Bookmark");
    _details = element.Get("Details");
    _help = element.Get("Help");
    _isEnabled = element.Get<bool>("IsEnabled", true);
    _isVisible = element.Get<bool>("IsVisible", true);
    _icon = element.Get("Icon");
    _rating = element.Get<int>("Rating", 0).Limit(0,10);
    _subject = element.Get("Subject");
    _text = element.Get("Text");
 }
Пример #12
0
 /// <summary/>
 protected override void FromXmlOverride(XElement element) {
    base.FromXmlOverride(element);
    if (element.HasAttribute("operation")) {
       Operation = BplClass.Get(element.Get("operation"));
    }
 }
Пример #13
0
 internal Paste( WebAgent agent, XElement paste )
 {
     this.agent = agent;
     this.key = paste.Get( "paste_key" );
     this.timestamp = paste.Get( "paste_date", Int32.Parse );
     this.title = paste.Get( "paste_title" );
     this.size = paste.Get( "paste_size", Int32.Parse );
     this.expireTimestamp = paste.Get( "paste_expire_date", Int32.Parse );
     this.exposure = paste.Get<PasteExposure, int>( "paste_private", Int32.Parse );
     this.formatName = paste.HasValueFor( "paste_format_long" ) ? paste.Get( "paste_format_long" ) : null;
     this.formatId = paste.HasValueFor( "paste_format_short" ) ? paste.Get( "paste_format_short" ) : null;
     this.url = paste.Get( "paste_url" );
     this.views = paste.Get( "paste_hits", Int32.Parse );
 }
Пример #14
0
 /// <summary>Parses the error message properties from the given XML object.</summary>
 /// <param name="element">The XML element to parse.</param>
 protected virtual void ParseXmlOverride(XElement element) {
    Details = element.Get("Details");
    ErrorCode = element.Get("ErrorCode");
    Help = element.Get("Help");
    Severity = element.Get<Severity>("Severity", Severity.Info);
    Text = element.Get("Text");
 }
Пример #15
0
      /// <summary/>
      protected override void ParseXmlOverride(XElement element) {
         base.ParseXmlOverride(element);

         IsExpanded = element.Get<bool>("IsExpanded");
      }
Пример #16
0
      // recursively deserializes a BPL object
      private BplObject _deserializeObject(XElement element) {
         // get class type
         XName tagName = null;
         var xsiTypeAttr = element.Attribute(xsiType);
         if (xsiTypeAttr != null) {
            var t = xsiTypeAttr.Value;
            var k = t.IndexOf(":");
            if (k > 0 && _mapping.Contains(t.Before(k))) {
               tagName = _mapping[t.Before(k)] + t.After(k);
            } else {
               AddError("Unknown BPL type '{0}', {:where}.", t, element);
               return null;
            }
         } else {
            tagName = element.Name;
         }
         var bplClass = BplClass.GetCompatible(tagName);
         if (bplClass == null) {
            AddError("Unknown BPL object '{:name}', {:where}.", element);
            return null;
         }

         // create object
         BplObject bplObject = null;
         try {
            bplObject = bplClass.CreateUninitialized();
         } catch (Exception e) {
            AddError("Failed to create BPL object '{:name}', {:where}. {0}", e.Message, element);
            return null;
         }
         var existingProperties = new HashSet<BplProperty>();

         // read id property, if required
         var identityProperty = bplClass.IdentityProperty;
         if (identityProperty != null) {
            var id = BplIdentity.Get(element.Get(identityProperty.TagName), bplClass.IdentityScope);
            var isEntity = bplClass.IsA<BplEntity>();
            if (id.IsEmpty) {
               if (isEntity) {
                  AddError("Entity Id is missing '{:name}', {:where}.", element);
               }
            } else {
               existingProperties.Add(identityProperty);
               identityProperty.SetValue(bplObject, id);
               if (isEntity && !_resolver.AddTarget(id, bplObject)) {
                  AddError("Encountered duplicate entity Id '{0}', {:where}.", id.ToString(true), element);
               }
            }
         }

         // read properties from attributes
         foreach (var attr in element.Attributes()) {
            if (attr.IsXmlns() || attr.Name == xsiType) continue;
            
            var property = bplClass.GetProperty(attr.Name);
            if (property == null) {
               AddError("Unknown BPL property '{:name}', {:where}.", attr);
               continue;
            }
            if (property.IsCalculated) {
               AddWarning("Calculated BPL property '{:name}' found and ignored, {:where}.", attr);
               continue;
            }
            if (property == identityProperty) continue;
            existingProperties.Add(property);

            try {
               if (property.IsScalar) {
                  _deserializeScalar(bplObject, property, attr);
               } else if (property.IsAssociation && property.IsReference) {
                  _deserializeAssociation(bplObject, property, attr);
               } else if (property.IsArray) {
                  _deserializeArray(bplObject, property, attr);
               } else {
                  AddError("Unexpected BPL property '{:name}' of type '{0}', {:where}.", property.GetType().Name, attr);
               }
            } catch (Exception e) {
               AddError("Invalid value in BPL property '{:name}', {:where}. {0}", e.Message, attr);
            }
         }

         // read properties from child elements
         foreach (var child in element.Elements()) {
            var property = bplClass.GetProperty(child.Name);
            if (property == null) {
               AddError("Unknown BPL property '{:name}', {:where}.", child);
               continue;
            }
            if (existingProperties.Contains(property)) {
               AddError("BPL property '{:name}' is set more than once, {:where}.", child);
               continue;
            }
            existingProperties.Add(property);

            var childItems = child.Elements().ToArray();
            try {
               if (property.IsArray) {
                  _deserializeArray(bplObject, property, childItems);
               } else if (property.IsContainer && property.IsReference) {
                  if (childItems.Length == 1) {
                     _deserializeContainer(bplObject, property, childItems[0]);
                  } else if (childItems.Length > 1) {
                     AddError("BPL property '{:name}' can contain at most one object, {:where}.", child);
                  }
               } else if (property.IsContainer && property.IsCollection) {
                  _deserializeContainer(bplObject, property, childItems);
               } else if (property.IsAssociation && property.IsCollection) {
                  _deserializeAssociation(bplObject, property, childItems);
               } else if (property.IsScalar) {
                  _deserializeScalar(bplObject, property, child);
               } else {
                  AddError("Unexpected BPL property '{:name}' of type '{0}', {:where}.", property.GetType().Name, child);
               }
            } catch (Exception e) {
               AddError("Invalid value in BPL property '{:name}', {:where}. {0}", e.Message, child);
            }
         }

         return bplObject;
      }
Пример #17
0
 public void Get_DateTimeValue()
 {
     DateTime value = DateTime.Now;
     XElement test = new XElement("Node", value);
     DateTime result = test.Get("", DateTime.MinValue);
     Assert.AreEqual(value.Ticks, result.Ticks);
 }
Пример #18
0
 public void Get_FromTryParse()
 {
     string value = "A value to test";
     XElement test = new XElement("Node", value);
     Get_FromTryParse_Class result = test.Get<Get_FromTryParse_Class>("", null);
     Assert.AreEqual(string.Compare(value, result.Value), 0);
 }
Пример #19
0
 private Inline _formatHyperlink(XElement markup) {
    var cref = markup.Get("cref");
    var text = markup.Value.Compact();
    var topic = BplLanguage.Documentation[cref];
    if (!topic.IsUnknown) {
       if (text.IsEmpty()) text = topic.Name;
    } else {
       if (text.IsEmpty()) text = cref;
       cref = null;
    }
    return _formatHyperlink(text, cref);
 }