public void TestConstructor() { ObjectIdentifier oid = new ObjectIdentifier(new byte[] { 0x2B, 0x06, 0x99, 0x37 }); Assert.Equal(new uint[] { 1, 3, 6, 3255 }, oid.ToNumerical()); var o = ObjectIdentifier.Create(new uint[] { 1, 3, 6 }, 3255); Assert.Equal(oid, o); }
private static ObjectIdentifier GetIdForGet(IDefinition def) { if (def.Type == DefinitionType.Scalar) { return(ObjectIdentifier.Create(def.GetNumericalForm(), 0)); } uint index; using (FormIndex form = new FormIndex()) { form.ShowDialog(); index = form.Index; } return(ObjectIdentifier.Create(def.GetNumericalForm(), index)); }
public void TestException() { Assert.Throws <ArgumentNullException>(() => new ObjectIdentifier((uint[])null)); Assert.Throws <ArgumentException>(() => new ObjectIdentifier(new uint[] { 1 })); Assert.Throws <ArgumentException>(() => new ObjectIdentifier(new uint[] { 5, 8 })); Assert.Throws <ArgumentException>(() => new ObjectIdentifier(new uint[] { 1, 80 })); Assert.Throws <ArgumentNullException>(() => new ObjectIdentifier(new Tuple <int, byte[]>(0, new byte[] { 0 }), null)); Assert.Throws <ArgumentException>(() => new ObjectIdentifier(new Tuple <int, byte[]>(0, new byte[] { 0 }), new MemoryStream())); // ReSharper disable RedundantCast Assert.Throws <ArgumentNullException>(() => new ObjectIdentifier(new uint[] { 1, 3 }).CompareTo((ObjectIdentifier)null)); // ReSharper restore RedundantCast Assert.Throws <ArgumentNullException>(() => ObjectIdentifier.Convert((uint[])null)); Assert.Throws <ArgumentNullException>(() => ObjectIdentifier.Convert((string)null)); var oid = new ObjectIdentifier(new uint[] { 1, 3 }); Assert.Throws <ArgumentException>(() => oid.CompareTo(80)); Assert.Throws <ArgumentNullException>(() => ObjectIdentifier.Create(null, 0)); Assert.Throws <ArgumentNullException>(() => oid.AppendBytesTo(null)); }
static bool ParseNode(MIBNode parent, XmlNode node, ObjectIdentifier baseOid) { var oidParts = baseOid.ToNumerical(); var oid = ObjectIdentifier.Create(oidParts, uint.Parse(node.Attributes.GetNamedItem("id").Value)); var name = node.Attributes.GetNamedItem("name").Value; var mnode = new MIBNode { Name = name, Oid = oid, Parent = parent }; var typeStr = node.Attributes.GetNamedItem("type").Value.Replace("[]", "Array"); mnode.Type = (MIBType)Enum.Parse(typeof(MIBType), typeStr, true); _Oids[oid] = mnode; if (parent != null) { parent.AddChild(mnode); } foreach (var child in node.ChildNodes.OfType <XmlNode>().Where((n) => n.Name == "symbol")) { mnode.AddValueMapping(int.Parse(child.Attributes.GetNamedItem("value").Value), child.Attributes.GetNamedItem("name").Value); } foreach (var child in node.ChildNodes.OfType <XmlNode>().Where((n) => n.Name == "node")) { if (!ParseNode(mnode, child, oid)) { return(false); } } return(true); }
private static ObjectIdentifier GetIdForGetNext(IDefinition def) { return(def.Type == DefinitionType.Scalar ? ObjectIdentifier.Create(def.GetNumericalForm(), 0) : new ObjectIdentifier(def.GetNumericalForm())); }