public Task <List <ConfigurationDiff> > Compare(XElement configElements1, XElement configElements2) { var elementName = ElementName; var element1 = ShouldBeExcluded(configElements1) ? null : configElements1.Name.LocalName == elementName ? configElements1 : configElements1.Element(elementName); var element2 = ShouldBeExcluded(configElements2) ? null : configElements2.Name.LocalName == elementName ? configElements2 : configElements2.Element(elementName); if (element1 == null && element2 == null) { return(Task.FromResult(new List <ConfigurationDiff>())); } if (element1 == null || element2 == null || !XElementExtensions.DeepEqualsWithNormalization(element1, element2)) { var diff = XElementExtensions.DeepEqualsWithNormalizationString(element1, element2); return(Task.FromResult(new List <ConfigurationDiff> { new ConfigurationDiff() { Identifier = $"{ElementName}-{diff}", ConfigurationItem1 = element1 == null ? null : new ConfigurationElement { Value = element1.ToString(), LineNum = element1.GetLineNumber() }, ConfigurationItem2 = element2 == null ? null : new ConfigurationElement { Value = element2.ToString(), LineNum = element2.GetLineNumber() }, } })); } return(Task.FromResult(new List <ConfigurationDiff>())); }
protected virtual XElement CreateVariable(PrintContext printContext, bool skipNumber, bool emptyNumber) { Item renderingItem = this.RenderingItem; XElement xelement = RenderItemHelper.CreateXElement("Variable", renderingItem, printContext.Settings.IsClient, (Item)null, true); if (renderingItem.Fields["Find"] != null && renderingItem.Fields["Replace"] != null) { if (printContext.Settings.IsClient && renderingItem.Fields["PageXML"] != null) { XElementExtensions.AddInnerXml(xelement, renderingItem.Fields["PageXML"].Value, false); } var findElement = new XElement("Find", (object)renderingItem["Find"]); xelement.Add(findElement); if (printContext.Settings.Parameters.ContainsKey("Variables") && (SafeDictionary <string, object>)printContext.Settings.Parameters["Variables"] != null) { var variables = (SafeDictionary <string, object>)printContext.Settings.Parameters["Variables"]; var variable = variables.FirstOrDefault(v => v.Key == (string)renderingItem["Find"]); var replaceElement = new XElement("Replace", (object)variable.Value); xelement.Add(replaceElement); } else { var replaceElement = new XElement("Replace", (object)renderingItem["Replace"]); xelement.Add(replaceElement); } } return(xelement); }
public void GetNamespacesInScopeFailsWithNullThis() { var e = Assert.Throws <ArgumentNullException>(() => XElementExtensions.GetNamespacesInScope(null)); Assert.Equal("element", e.ParamName); }
private void NewRuleCommandHandler() { XElement element = null; SignalRule signalRule = null; element = XElementExtensions.NewSignalRule(); signalRule = element.ToTypeSignalRule(); if (element != null && signalRule != null) { NewRuleViewModel newRuleViewModel = new NewRuleViewModel { SignalRule = signalRule }; // here we have to open a new rule dialog. _dialogContainerService.ShowDialog(newRuleViewModel); if (newRuleViewModel.Result == DialogResult.Success) { if (this.SignalRules != null && _document != null) { _document.Root.Add(element, Environment.NewLine); this.SignalRules.Add(signalRule); this.IsDirty = true; this.PrimaryCommand.RaiseCanExecuteChanged(); } } } }
public void IntToBooleanTrue() { int integer = 1; bool expected = true; bool actual = XElementExtensions.ToBoolean(integer); Assert.AreEqual(expected, actual); }
public void IntToBooleanFalse() { int integer = 0; bool expected = false; bool actual = XElementExtensions.ToBoolean(integer); Assert.AreEqual(expected, actual); }
public void BooleanToIntTrue() { bool boolean = true; int expected = 1; int actual = XElementExtensions.ToInt(boolean); Assert.AreEqual(expected, actual); }
public void BooleanToIntFalse() { bool boolean = false; int expected = 0; int actual = XElementExtensions.ToInt(boolean); Assert.AreEqual(expected, actual); }
public static Tuple <HierarchyConfigData, Guid> Deserialize(XElement xelem) { var hcd = new HierarchyConfigData(); var guid = Guid.Parse(xelem.Attribute("id").Value); { var dir = xelem.Element("directories"); if (dir == null) { throw new Exception("Missing <directories> element"); } if (XElementExtensions.ParseBool(dir.Attribute("null").Value)) { hcd = null; } else { var dat = HierarchyConfigEntry.Deserialize(dir.Elements().Single()); hcd.Entry = dat; } } { var dir = xelem.Element("selectednote"); if (dir == null) { throw new Exception("Missing <selectednote> element"); } if (XElementExtensions.ParseBool(dir.Attribute("null").Value)) { hcd.SelectedNote = null; } else { hcd.SelectedNote = dir.Value; } } { var dir = xelem.Element("selectedpath"); if (dir == null) { throw new Exception("Missing <selectedpath> element"); } if (XElementExtensions.ParseBool(dir.Attribute("null").Value)) { hcd.SelectedFolder = null; } else { hcd.SelectedFolder = DirectoryPath.Deserialize(dir.Elements()); } } return(Tuple.Create(hcd, guid)); }
private bool IsEqual(DependentAssemblyBinding configSectionInfo1, DependentAssemblyBinding configSectionInfo2) { if (configSectionInfo1 == null && configSectionInfo2 == null) { return(true); } return(XElementExtensions.DeepEqualsWithNormalization(configSectionInfo1.Element, configSectionInfo2.Element)); }
public AlephTheme Generate() { var t = new AlephTheme(_name, _version, _compatibility, _filename, _source, _author, _themetype); foreach (var propdef in AlephTheme.THEME_PROPERTIES) { var v = TryGetProperty(propdef.Item1); if (v == null) { continue; } if (v.IsIndirect) { t.AddProperty(propdef.Item1, v); continue; } switch (propdef.Item2) { case AlephTheme.AlephThemePropType.Color: v.DirectValue = ColorRef.Parse(v.XmlDirectValue); break; case AlephTheme.AlephThemePropType.Brush: v.DirectValue = BrushRef.Parse(v.XmlDirectValue); break; case AlephTheme.AlephThemePropType.Thickness: v.DirectValue = ThicknessRef.Parse(v.XmlDirectValue); break; case AlephTheme.AlephThemePropType.Integer: v.DirectValue = int.Parse(v.XmlDirectValue); break; case AlephTheme.AlephThemePropType.Double: v.DirectValue = double.Parse(v.XmlDirectValue, NumberStyles.Float, CultureInfo.InvariantCulture); break; case AlephTheme.AlephThemePropType.Boolean: v.DirectValue = XElementExtensions.ParseBool(v.XmlDirectValue); break; case AlephTheme.AlephThemePropType.CornerRadius: v.DirectValue = CornerRadiusRef.Parse(v.XmlDirectValue); break; default: throw new NotSupportedException(); } t.AddProperty(propdef.Item1, v); } return(t); }
public void GetConvertedValueFromDescendantDoubleElement_ParentElementNull_ThrowArgumentNullException() { // Call void Call() => XElementExtensions.GetConvertedValueFromDescendantDoubleElement <TypeConverter>(null, "0"); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("parentElement", exception.ParamName); }
private (string Diff, string Value) IsEqual(ConfigSectionInfo configSectionInfo1, ConfigSectionInfo configSectionInfo2) { if ((configSectionInfo1 == null && configSectionInfo2 == null) || (configSectionInfo1?.Element == null && configSectionInfo2?.Element == null)) { return(null, null); } return(XElementExtensions.DeepEqualsWithNormalizationString(configSectionInfo1.Element, configSectionInfo2.Element)); }
public void GetDescendantElement_ParentElementNull_ThrowArgumentNullException() { // Call void Call() => XElementExtensions.GetDescendantElement(null, ""); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("parentElement", exception.ParamName); }
protected virtual DateTime GetPublishDate(XElement item) { var dateString = item.TryGetValue("pubDate"); if (dateString.IsNullOrWhiteSpace()) { throw new UnsupportedFeedException("Rss feed must have a pubDate element with a valid publish date."); } return(XElementExtensions.ParseDate(dateString)); }
protected override DateTime GetPublishDate(XElement item) { var dateString = TryGetNewznabAttribute(item, "usenetdate"); if (!dateString.IsNullOrWhiteSpace()) { return(XElementExtensions.ParseDate(dateString)); } return(base.GetPublishDate(item)); }
public virtual SyncAttempt <XElement> SerializeEmpty(TObject item, SyncActionType change, string alias) { logger.Debug(serializerType, "Base: Serializing Empty Element {alias} {change}", alias, change); if (string.IsNullOrEmpty(alias)) { alias = ItemAlias(item); } var node = XElementExtensions.MakeEmpty(ItemKey(item), change, alias); return(SyncAttempt <XElement> .Succeed("Empty", node, ChangeType.Removed)); }
protected override DateTime GetPublishDate(XElement item) { var attributes = item.Elements("attr").ToList(); var usenetdateElement = attributes.SingleOrDefault(e => e.Attribute("name").Value.Equals("usenetdate", StringComparison.CurrentCultureIgnoreCase)); if (usenetdateElement != null) { var dateString = usenetdateElement.Attribute("value").Value; return(XElementExtensions.ParseDate(dateString)); } return(base.GetPublishDate(item)); }
public static HierarchyConfigEntry Deserialize(XElement xelem) { if (xelem.Name != "dir") { throw new Exception("missing <dir> element"); } return(new HierarchyConfigEntry ( xelem.Attribute("name").Value, XElementExtensions.ParseBool(xelem.Attribute("expanded").Value), DirectoryPath.StrDeserialize(xelem.Attribute("path").Value), xelem.Elements().Select(Deserialize).ToList() )); }
public AlephTheme Generate() { var t = new AlephTheme(_name, _version, _compatibility, _filename, _source, false); foreach (var propdef in AlephTheme.THEME_PROPERTIES) { switch (propdef.Item2) { case AlephTheme.AlephThemePropType.Color: t.AddProperty(propdef.Item1, ColorRef.Parse(GetProperty(propdef.Item1))); break; case AlephTheme.AlephThemePropType.Brush: t.AddProperty(propdef.Item1, BrushRef.Parse(GetProperty(propdef.Item1))); break; case AlephTheme.AlephThemePropType.Thickness: t.AddProperty(propdef.Item1, ThicknessRef.Parse(GetProperty(propdef.Item1))); break; case AlephTheme.AlephThemePropType.Integer: t.AddProperty(propdef.Item1, int.Parse(GetProperty(propdef.Item1))); break; case AlephTheme.AlephThemePropType.Double: t.AddProperty(propdef.Item1, double.Parse(GetProperty(propdef.Item1), NumberStyles.Float, CultureInfo.InvariantCulture)); break; case AlephTheme.AlephThemePropType.Boolean: t.AddProperty(propdef.Item1, XElementExtensions.ParseBool(GetProperty(propdef.Item1))); break; case AlephTheme.AlephThemePropType.CornerRadius: t.AddProperty(propdef.Item1, CornerRadiusRef.Parse(GetProperty(propdef.Item1))); break; default: throw new NotSupportedException(); } } return(t); }
private static bool GetAppDataBool(Dictionary <string, Dictionary <string, object> > appData, Tuple <string, string> path, bool defValue) { if (appData == null) { return(defValue); } if (!appData.TryGetValue(path.Item1, out var values)) { return(defValue); } if (!values.TryGetValue(path.Item2, out var value)) { return(defValue); } if (value is bool bvalue) { return(bvalue); } return(XElementExtensions.TryParseBool(value?.ToString()) ?? defValue); }
public void WhenIsNull_ThenThrowException() { Assert.Throws <ArgumentNullException>(() => XElementExtensions.HasAttribute(null, "type")); }
public void MakeEmpty_Makes_EmptyNode() { var e = XElementExtensions.MakeEmpty(_key, SyncActionType.Delete, _alias); Assert.AreEqual(_emptyNode.ToString(), e.ToString()); }
public ActionResult NewPost(string postto, string title, string desc, string postby, string groupId) { List <Post> lstpost = new List <Post>(); Group grp = new Group(); int grpId = Convert.ToInt32(groupId); Post postModel = new Post(); postModel.id = Guid.NewGuid().GetHashCode(); postModel.TopicTitle = title; postModel.TopicDescription = desc; postModel.PostedTo = postto; if (postby != "Name") { postModel.PostedBy = "Anonymous"; } else { postModel.PostedBy = Convert.ToString(Session["Name"]); } postModel.PostedbyId = Convert.ToInt32(Session["id"]); postModel.PostedDate = DateTime.Now; postModel.Replies = null; if (string.IsNullOrEmpty(postto) || string.IsNullOrEmpty(title) || string.IsNullOrEmpty(desc) || string.IsNullOrEmpty(postby)) { TempData["FailureMsg"] = "All the fields are compulsory."; return(View(postModel)); } lstpost.Add(postModel); using (DISCUSSEntities dbcontext = new DISCUSSEntities()) { grp = dbcontext.Groups.Where(t => t.id == grpId).Select(i => i).FirstOrDefault(); if (grp != null) { try { if (!String.IsNullOrEmpty(grp.groupContent)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(grp.groupContent); var xEle = GetElement(lstpost); XmlNode xmlnde = doc.ImportNode(XElementExtensions.ToXmlElement(xEle.FirstOrDefault()), true); doc.DocumentElement.AppendChild(xmlnde); var xmlstring = doc.OuterXml; grp.groupContent = xmlstring; dbcontext.SaveChanges(); } else { var xEle = new XElement("Posts", GetElement(lstpost)); var xdoc = new XDocument(xEle); var xmlstring = GetXMLAsString(DocumentExtensions.ToXmlDocument(xdoc)); grp.groupContent = xmlstring; dbcontext.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(View()); } } } Session["GroupId"] = grpId; return(Json("Success")); }
public void WhenSutIsNull_ThenThrowException() { Assert.Throws <ArgumentNullException>(() => XElementExtensions.GetChildElement(null, "A")); }
protected override DateTime GetPublishDate(XElement item) { var dateString = item.TryGetValue("pubDate") + " +0000"; return(XElementExtensions.ParseDate(dateString)); }