public void NoErrorNonRepeater0() { var handler = new GetBulkMessageHandler(); var context = SnmpContextFactory.Create( new GetBulkRequestMessage( 300, VersionCode.V2, new OctetString("lextm"), 0, 2, new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.1.0")) } ), new IPEndPoint(IPAddress.Loopback, 100), new UserRegistry(), null, null); var store = new ObjectStore(); store.Add(new SysDescr()); store.Add(new SysObjectId()); store.Add(new SysUpTime()); store.Add(new SysContact()); store.Add(new SysName()); Assert.Throws<ArgumentNullException>(() => handler.Handle(null, null)); Assert.Throws<ArgumentNullException>(() => handler.Handle(context, null)); handler.Handle(context, store); var noerror = (ResponseMessage)context.Response; Assert.AreEqual(ErrorCode.NoError, noerror.ErrorStatus); Assert.AreEqual(new ObjectIdentifier("1.3.6.1.2.1.1.2.0"), noerror.Variables()[0].Id); Assert.AreEqual(new ObjectIdentifier("1.3.6.1.2.1.1.3.0"), noerror.Variables()[1].Id); Assert.AreEqual(2, noerror.Variables().Count); }
public void GenErrorNonRepeater0() { var handler = new GetBulkMessageHandler(); var mock = new Mock<ScalarObject>(new ObjectIdentifier("1.3.6.1.2.1.1.2.0")); mock.Setup(foo => foo.Data).Throws<Exception>(); mock.Setup(foo => foo.MatchGet(new ObjectIdentifier("1.3.6.1.2.1.1.2.0"))).Returns(mock.Object); mock.Setup(foo => foo.MatchGetNext(new ObjectIdentifier("1.3.6.1.2.1.1.1.0"))).Returns(mock.Object); var store = new ObjectStore(); store.Add(new SysDescr()); store.Add(mock.Object); var context = SnmpContextFactory.Create( new GetBulkRequestMessage( 300, VersionCode.V2, new OctetString("lextm"), 0, 2, new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.1.0")) } ), new IPEndPoint(IPAddress.Loopback, 100), new UserRegistry(), null, null); handler.Handle(context, store); var genError = (ResponseMessage)context.Response; Assert.AreEqual(ErrorCode.GenError, genError.ErrorStatus); }
public void BadValue() { var handler = new SetV1MessageHandler(); var mock = new Mock<ScalarObject>(new ObjectIdentifier("1.3.6.1.2.1.1.4.0")); mock.Setup(foo => foo.Data).Throws<Exception>(); mock.Setup(foo => foo.MatchGet(new ObjectIdentifier("1.3.6.1.2.1.1.4.0"))).Returns(mock.Object); mock.SetupSet(foo => foo.Data = new Integer32(400)).Throws<ArgumentException>(); var store = new ObjectStore(); store.Add(mock.Object); var context = SnmpContextFactory.Create( new SetRequestMessage( 300, VersionCode.V1, new OctetString("lextm"), new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.4.0"), new Integer32(400)) } ), new IPEndPoint(IPAddress.Loopback, 100), new UserRegistry(), null, null); handler.Handle(context, store); var badValue = (ResponseMessage)context.Response; Assert.AreEqual(ErrorCode.BadValue, badValue.ErrorStatus); }
public void AddRemove() { Id<TestObject> id; TestObject o, p; UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.AreEqual(1, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(1))); p = objstore[new Id<TestObject>(1)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(6, "hi", 5.4F); id = objstore.Add(o); Assert.AreEqual(2, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(2))); p = objstore[new Id<TestObject>(2)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); objstore.Remove(new Id<TestObject>(1)); Assert.IsFalse(objstore.IsPresent(new Id<TestObject>(1))); o = new TestObject(7, "xx", 1.1F); id = objstore.Add(o); Assert.AreEqual(3, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(3))); p = objstore[new Id<TestObject>(3)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); objstore.Remove(new Id<TestObject>(3)); int count = 0; foreach (TestObject x in objstore.All) { Assert.AreEqual(x, new TestObject(6, "hi", 5.4F)); ++count; } Assert.AreEqual(1, count); undomgr.EndCommand(57); }
public void NoSuchName() { var handler = new GetNextV1MessageHandler(); var store = new ObjectStore(); store.Add(new SysDescr()); var context = SnmpContextFactory.Create( new GetNextRequestMessage( 300, VersionCode.V1, new OctetString("lextm"), new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.2.0")) } ), new IPEndPoint(IPAddress.Loopback, 100), new UserRegistry(), null, null); handler.Handle(context, store); var noSuchName = (ResponseMessage)context.Response; Assert.AreEqual(ErrorCode.NoSuchName, noSuchName.ErrorStatus); }
public void EndOfMibView() { var handler = new GetNextMessageHandler(); var store = new ObjectStore(); store.Add(new SysDescr()); var context = SnmpContextFactory.Create( new GetNextRequestMessage( 300, VersionCode.V1, new OctetString("lextm"), new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.2.0")) } ), new IPEndPoint(IPAddress.Loopback, 100), new UserRegistry(), null, null); handler.Handle(context, store); var endOfMibView = (ResponseMessage)context.Response; Assert.AreEqual(new ObjectIdentifier("1.3.6.1.2.1.1.2.0"), endOfMibView.Variables()[0].Id); Assert.AreEqual(new EndOfMibView(), endOfMibView.Variables()[0].Data); }
public void Save() { UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); objstore.Add(new TestObject(5, "hello", 5.4F)); objstore.Add(new TestObject(7, "hi", 3.4F)); objstore.Add(new TestObject(9, "bat", 9.9F)); undomgr.EndCommand(57); undomgr.BeginCommand(58, "Command2"); objstore.Add(new TestObject(11, "foo", 1.4F)); objstore.Replace(new Id<TestObject>(2), new TestObject(8, "goodbye", 9.4F)); objstore.Remove(new Id<TestObject>(1)); undomgr.EndCommand(58); TextWriter writer = new StringWriter(); XmlTextWriter xmloutput = new XmlTextWriter(writer); xmloutput.Formatting = Formatting.Indented; xmloutput.Namespaces = false; xmloutput.WriteStartDocument(); xmloutput.WriteStartElement("testobjects"); objstore.Save(xmloutput); xmloutput.WriteEndElement(); xmloutput.WriteEndDocument(); xmloutput.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <testobjects> <testobject id=""2"" x=""8"" f=""9.4"">goodbye</testobject> <testobject id=""3"" x=""9"" f=""9.9"">bat</testobject> <testobject id=""4"" x=""11"" f=""1.4"">foo</testobject> </testobjects>", writer.ToString()); }
public void Replace() { Id<TestObject> id; TestObject o, p; UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.AreEqual(1, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(1))); p = objstore[new Id<TestObject>(1)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(6, "hi", 5.4F); id = objstore.Add(o); Assert.AreEqual(2, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(2))); p = objstore[new Id<TestObject>(2)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(11, "mr ed", 9.7F); objstore.Replace(new Id<TestObject>(1), o); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(1))); p = objstore[new Id<TestObject>(1)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); o = new TestObject(13, "baz", 2.4F); objstore.Replace(new Id<TestObject>(2), o); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(2))); p = objstore[new Id<TestObject>(2)]; Assert.AreEqual(o, p); Assert.IsFalse(o == p); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(11, "mr ed", 9.7F), new TestObject(13, "baz", 2.4F) }); }
public void Present() { Id<TestObject> id; TestObject o; UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.AreEqual(1, id.id); Assert.IsTrue(objstore.IsPresent(new Id<TestObject>(1))); Assert.IsFalse(objstore.IsPresent(new Id<TestObject>(2))); objstore.CheckPresent(new Id<TestObject>(1)); try { objstore.IsPresent(new Id<TestObject>(2)); Assert.Fail("should throw"); } catch { } }
public void LoadModifySave() { Id<TestObject> id; UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); string xmlText = @"<?xml version=""1.0"" encoding=""utf-16""?> <testobjects> <testobject id=""2"" x=""8"" f=""9.4"">goodbye</testobject> <testobject id=""4"" x=""11"" f=""1.4"">foo</testobject> </testobjects>"; XmlInput xmlinput = new XmlInput(new StringReader(xmlText), "testfile"); xmlinput.CheckElement("testobjects"); xmlinput.Read(); objstore.Load(xmlinput); xmlinput.Dispose(); undomgr.BeginCommand(57, "Command1"); id = objstore.Add(new TestObject(5, "hello", 5.4F)); Assert.AreEqual(5, id.id); id = objstore.Add(new TestObject(9, "bat", 9.9F)); Assert.AreEqual(6, id.id); undomgr.EndCommand(57); undomgr.BeginCommand(58, "Command2"); objstore.Replace(new Id<TestObject>(2), new TestObject(-9, "elvis", 9.1F)); objstore.Remove(new Id<TestObject>(4)); undomgr.EndCommand(58); TextWriter writer = new StringWriter(); XmlTextWriter xmloutput = new XmlTextWriter(writer); xmloutput.Formatting = Formatting.Indented; xmloutput.Namespaces = false; xmloutput.WriteStartDocument(); xmloutput.WriteStartElement("testobjects"); objstore.Save(xmloutput); xmloutput.WriteEndElement(); xmloutput.WriteEndDocument(); xmloutput.Close(); Assert.AreEqual( @"<?xml version=""1.0"" encoding=""utf-16""?> <testobjects> <testobject id=""2"" x=""-9"" f=""9.1"">elvis</testobject> <testobject id=""5"" x=""5"" f=""5.4"">hello</testobject> <testobject id=""6"" x=""9"" f=""9.9"">bat</testobject> </testobjects>", writer.ToString()); }
public void ChangeNum() { int changeNum; Id<TestObject> id; TestObject o; UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); changeNum = objstore.ChangeNum; undomgr.BeginCommand(57, "Command1"); o = new TestObject(5, "hello", 5.4F); id = objstore.Add(o); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; objstore.Remove(new Id<TestObject>(1)); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; id = objstore.Add(o); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; objstore.Replace(new Id<TestObject>(2), o); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; undomgr.EndCommand(57); undomgr.Undo(); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; undomgr.Redo(); Assert.IsTrue(changeNum < objstore.ChangeNum); changeNum = objstore.ChangeNum; }
public void NoError() { var handler = new SetV1MessageHandler(); var context = SnmpContextFactory.Create( new SetRequestMessage( 300, VersionCode.V1, new OctetString("lextm"), new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.4.0"), new OctetString("test")) } ), new IPEndPoint(IPAddress.Loopback, 100), new UserRegistry(), null, null); var store = new ObjectStore(); store.Add(new SysContact()); Assert.Throws<ArgumentNullException>(() => handler.Handle(null, null)); Assert.Throws<ArgumentNullException>(() => handler.Handle(context, null)); handler.Handle(context, store); var noerror = (ResponseMessage)context.Response; Assert.AreEqual(ErrorCode.NoError, noerror.ErrorStatus); Assert.AreEqual(new OctetString("test"), noerror.Variables()[0].Data); }
public SnmpClient() { // TODO: Based on sample var store = new ObjectStore(); store.Add(new SysDescr()); store.Add(new SysObjectId()); store.Add(new SysUpTime()); store.Add(new SysContact()); store.Add(new SysName()); store.Add(new SysLocation()); store.Add(new SysServices()); store.Add(new SysORLastChange()); store.Add(new SysORTable()); store.Add(new IfNumber()); store.Add(new IfTable()); var users = new UserRegistry(); users.Add(new OctetString("neither"), DefaultPrivacyProvider.DefaultPair); users.Add(new OctetString("authen"), new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("authentication")))); var getv1 = new GetV1MessageHandler(); var getv1Mapping = new HandlerMapping("v1", "GET", getv1); var getv23 = new GetMessageHandler(); var getv23Mapping = new HandlerMapping("v2,v3", "GET", getv23); var setv1 = new SetV1MessageHandler(); var setv1Mapping = new HandlerMapping("v1", "SET", setv1); var setv23 = new SetMessageHandler(); var setv23Mapping = new HandlerMapping("v2,v3", "SET", setv23); var getnextv1 = new GetNextV1MessageHandler(); var getnextv1Mapping = new HandlerMapping("v1", "GETNEXT", getnextv1); var getnextv23 = new GetNextMessageHandler(); var getnextv23Mapping = new HandlerMapping("v2,v3", "GETNEXT", getnextv23); var getbulk = new GetBulkMessageHandler(); var getbulkMapping = new HandlerMapping("v2,v3", "GETBULK", getbulk); var v1 = new Version1MembershipProvider(new OctetString("public"), new OctetString("public")); var v2 = new Version2MembershipProvider(new OctetString("public"), new OctetString("public")); var v3 = new Version3MembershipProvider(); var membership = new ComposedMembershipProvider(new IMembershipProvider[] { v1, v2, v3 }); var handlerFactory = new MessageHandlerFactory(new[] { getv1Mapping, getv23Mapping, setv1Mapping, setv23Mapping, getnextv1Mapping, getnextv23Mapping, getbulkMapping }); var pipelineFactory = new SnmpApplicationFactory(store, membership, handlerFactory); _engine = new SnmpEngine(pipelineFactory, new Listener { Users = users }, new EngineGroup()); }
public MainForm() { // TODO: this is a hack. review it later. var store = new ObjectStore(); store.Add(new SysDescr()); store.Add(new SysObjectId()); store.Add(new SysUpTime()); store.Add(new SysContact()); store.Add(new SysName()); store.Add(new SysLocation()); store.Add(new SysServices()); store.Add(new SysORLastChange()); store.Add(new SysORTable()); store.Add(new IfNumber()); store.Add(new IfTable()); var users = new UserRegistry(); users.Add(new OctetString("neither"), DefaultPrivacyProvider.DefaultPair); users.Add(new OctetString("authen"), new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("authentication")))); if (DESPrivacyProvider.IsSupported) { users.Add(new OctetString("privacy"), new DESPrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")))); } if (AESPrivacyProviderBase.IsSupported) { users.Add(new OctetString("aes"), new AESPrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")))); users.Add(new OctetString("aes192"), new AES192PrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")))); users.Add(new OctetString("aes256"), new AES256PrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")))); } var getv1 = new GetV1MessageHandler(); var getv1Mapping = new HandlerMapping("v1", "GET", getv1); var getv23 = new GetMessageHandler(); var getv23Mapping = new HandlerMapping("v2,v3", "GET", getv23); var setv1 = new SetV1MessageHandler(); var setv1Mapping = new HandlerMapping("v1", "SET", setv1); var setv23 = new SetMessageHandler(); var setv23Mapping = new HandlerMapping("v2,v3", "SET", setv23); var getnextv1 = new GetNextV1MessageHandler(); var getnextv1Mapping = new HandlerMapping("v1", "GETNEXT", getnextv1); var getnextv23 = new GetNextMessageHandler(); var getnextv23Mapping = new HandlerMapping("v2,v3", "GETNEXT", getnextv23); var getbulk = new GetBulkMessageHandler(); var getbulkMapping = new HandlerMapping("v2,v3", "GETBULK", getbulk); var v1 = new Version1MembershipProvider(new OctetString("public"), new OctetString("public")); var v2 = new Version2MembershipProvider(new OctetString("public"), new OctetString("public")); var v3 = new Version3MembershipProvider(); var membership = new ComposedMembershipProvider(new IMembershipProvider[] { v1, v2, v3 }); var handlerFactory = new MessageHandlerFactory(new[] { getv1Mapping, getv23Mapping, setv1Mapping, setv23Mapping, getnextv1Mapping, getnextv23Mapping, getbulkMapping }); var pipelineFactory = new SnmpApplicationFactory(new RollingLogger(), store, membership, handlerFactory); _engine = new SnmpEngine(pipelineFactory, new Listener { Users = users }, new EngineGroup()); _engine.ExceptionRaised += (sender, e) => MessageBox.Show(e.Exception.ToString()); InitializeComponent(); if (PlatformSupport.Platform == PlatformType.Windows) { // FIXME: work around a Mono WinForms issue. Icon = Properties.Resources.network_server; } actEnabled.Image = Properties.Resources.media_playback_start; tstxtPort.Text = @"161"; tscbIP.Items.Add(StrAllUnassigned); foreach (IPAddress address in Dns.GetHostEntry(string.Empty).AddressList.Where(address => !address.IsIPv6LinkLocal)) { tscbIP.Items.Add(address); } tscbIP.SelectedIndex = 0; }
public static void Main(string[] args) { if (args.Length != 0) { return; } var store = new ObjectStore(); store.Add(new SysDescr()); store.Add(new SysObjectId()); store.Add(new SysUpTime()); store.Add(new SysContact()); store.Add(new SysName()); store.Add(new SysLocation()); store.Add(new SysServices()); store.Add(new SysORLastChange()); store.Add(new SysORTable()); store.Add(new IfNumber()); store.Add(new IfTable()); var users = new UserRegistry(); users.Add(new OctetString("neither"), DefaultPrivacyProvider.DefaultPair); users.Add(new OctetString("authen"), new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("authentication")))); if (DESPrivacyProvider.IsSupported) { users.Add(new OctetString("privacy"), new DESPrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")))); } if (AESPrivacyProviderBase.IsSupported) { users.Add(new OctetString("aes"), new AESPrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")))); users.Add(new OctetString("aes192"), new AES192PrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")))); users.Add(new OctetString("aes256"), new AES256PrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")))); } var getv1 = new GetV1MessageHandler(); var getv1Mapping = new HandlerMapping("v1", "GET", getv1); var getv23 = new GetMessageHandler(); var getv23Mapping = new HandlerMapping("v2,v3", "GET", getv23); var setv1 = new SetV1MessageHandler(); var setv1Mapping = new HandlerMapping("v1", "SET", setv1); var setv23 = new SetMessageHandler(); var setv23Mapping = new HandlerMapping("v2,v3", "SET", setv23); var getnextv1 = new GetNextV1MessageHandler(); var getnextv1Mapping = new HandlerMapping("v1", "GETNEXT", getnextv1); var getnextv23 = new GetNextMessageHandler(); var getnextv23Mapping = new HandlerMapping("v2,v3", "GETNEXT", getnextv23); var getbulk = new GetBulkMessageHandler(); var getbulkMapping = new HandlerMapping("v2,v3", "GETBULK", getbulk); var v1 = new Version1MembershipProvider(new OctetString("public"), new OctetString("public")); var v2 = new Version2MembershipProvider(new OctetString("public"), new OctetString("public")); var v3 = new Version3MembershipProvider(); var membership = new ComposedMembershipProvider(new IMembershipProvider[] { v1, v2, v3 }); var handlerFactory = new MessageHandlerFactory(new[] { getv1Mapping, getv23Mapping, setv1Mapping, setv23Mapping, getnextv1Mapping, getnextv23Mapping, getbulkMapping }); var pipelineFactory = new SnmpApplicationFactory(store, membership, handlerFactory); using (var engine = new SnmpEngine(pipelineFactory, new Listener { Users = users }, new EngineGroup())) { engine.Listener.AddBinding(new IPEndPoint(IPAddress.Any, 161)); engine.Listener.ExceptionRaised += Engine_ExceptionRaised; engine.Listener.MessageReceived += RequestReceived; engine.Start(); Console.WriteLine("#SNMP is available at https://sharpsnmp.com"); Console.WriteLine("Press any key to stop . . . "); Console.Read(); engine.Stop(); } }
private static ObjectStore CreateStore(RavenServer server) { var store = new ObjectStore(); store.Add(new ServerUrl(server.Configuration)); store.Add(new ServerPublicUrl(server.Configuration)); store.Add(new ServerTcpUrl(server.Configuration)); store.Add(new ServerPublicTcpUrl(server.Configuration)); store.Add(new ServerVersion()); store.Add(new ServerFullVersion()); store.Add(new ServerUpTime(server.Statistics)); store.Add(new ServerUpTimeGlobal(server.Statistics)); store.Add(new ServerPid()); store.Add(new ServerConcurrentRequests(server.Metrics)); store.Add(new ServerTotalRequests(server.Metrics)); store.Add(new ServerRequestsPerSecond(server.Metrics)); store.Add(new ProcessCpu(server.CpuUsageCalculator)); store.Add(new MachineCpu(server.CpuUsageCalculator)); store.Add(new ServerTotalMemory()); store.Add(new ServerLastRequestTime(server.Statistics)); store.Add(new DatabaseLoadedCount(server.ServerStore.DatabasesLandlord)); store.Add(new DatabaseTotalCount(server.ServerStore)); store.Add(new ClusterNodeState(server.ServerStore)); store.Add(new ClusterNodeTag(server.ServerStore)); store.Add(new ClusterId(server.ServerStore)); store.Add(new ClusterIndex(server.ServerStore)); store.Add(new ClusterTerm(server.ServerStore)); store.Add(new ServerLicenseType(server.ServerStore)); store.Add(new ServerLicenseExpiration(server.ServerStore)); store.Add(new ServerLicenseExpirationLeft(server.ServerStore)); return(store); }
private void Initialize() { _objectStore.Add(new DatabaseName(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseCountOfIndexes(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseCountOfStaleIndexes(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseCountOfDocuments(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseCountOfRevisionDocuments(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseCountOfAttachments(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseCountOfUniqueAttachments(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseAlerts(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseId(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseUpTime(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseLoaded(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseRehabs(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabasePerformanceHints(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseIndexingErrors(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseDocPutsPerSecond(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseMapIndexIndexedPerSecond(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseMapReduceIndexMappedPerSecond(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseMapReduceIndexReducedPerSecond(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseRequestsPerSecond(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseRequestsCount(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseNumberOfAutoIndexes(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseNumberOfDisabledIndexes(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseNumberOfErrorIndexes(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseNumberOfIdleIndexes(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseNumberOfIndexes(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseNumberOfStaticIndexes(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseDocumentsStorageAllocatedSize(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseDocumentsStorageUsedSize(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseIndexStorageAllocatedSize(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseIndexStorageUsedSize(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseTotalStorageSize(_databaseName, _databaseLandlord, _databaseIndex)); _objectStore.Add(new DatabaseStorageDiskRemainingSpace(_databaseName, _databaseLandlord, _databaseIndex)); //AddIndexesFromMappingDocument(); }
public void NoSuchObject() { var handler = new GetMessageHandler(); var mock = new Mock<ScalarObject>(new ObjectIdentifier("1.3.6.1.2.1.1.2.0")); mock.Setup(foo => foo.Data).Throws<AccessFailureException>(); mock.Setup(foo => foo.MatchGet(new ObjectIdentifier("1.3.6.1.2.1.1.2.0"))).Returns(mock.Object); var store = new ObjectStore(); store.Add(mock.Object); var context = SnmpContextFactory.Create( new GetRequestMessage( 300, VersionCode.V1, new OctetString("lextm"), new List<Variable> { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.2.0")) } ), new IPEndPoint(IPAddress.Loopback, 100), new UserRegistry(), null, null); handler.Handle(context, store); var noSuchObject = (ResponseMessage)context.Response; Assert.AreEqual(new NoSuchObject(), noSuchObject.Variables()[0].Data); }
public void UndoRedo() { UndoMgr undomgr = new UndoMgr(5); ObjectStore<TestObject> objstore = new ObjectStore<TestObject>(undomgr); undomgr.BeginCommand(57, "Command1"); objstore.Add(new TestObject(5, "hello", 5.4F)); objstore.Add(new TestObject(7, "hi", 3.4F)); objstore.Add(new TestObject(9, "bat", 9.9F)); undomgr.EndCommand(57); undomgr.BeginCommand(58, "Command2"); objstore.Add(new TestObject(11, "foo", 1.4F)); objstore.Replace(new Id<TestObject>(2), new TestObject(8, "goodbye", 9.4F)); objstore.Remove(new Id<TestObject>(1)); undomgr.EndCommand(58); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(9, "bat", 9.9F), new TestObject(11, "foo", 1.4F), new TestObject(8, "goodbye", 9.4F) }); undomgr.Undo(); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(5, "hello", 5.4F), new TestObject(7, "hi", 3.4F), new TestObject(9, "bat", 9.9F) }); undomgr.Undo(); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { }); undomgr.Redo(); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(5, "hello", 5.4F), new TestObject(7, "hi", 3.4F), new TestObject(9, "bat", 9.9F) }); undomgr.Redo(); TestUtil.TestEnumerableAnyOrder(objstore.All, new TestObject[] { new TestObject(9, "bat", 9.9F), new TestObject(11, "foo", 1.4F), new TestObject(8, "goodbye", 9.4F) }); }
private ObjectStore CreateStore(RavenDBOptions serverOptions) { var store = new ObjectStore(); store.Add(new ServerUpTime(serverOptions.RequestManager)); store.Add(new ServerUpTimeGlobal(serverOptions.RequestManager)); store.Add(new ServerName(serverOptions.SystemDatabase.Configuration)); store.Add(new ServerBuildVersion()); store.Add(new ServerProductVersion()); store.Add(new ServerPid()); store.Add(new ServerTotalRequests(serverOptions.RequestManager)); store.Add(new ServerConcurrentRequests(serverOptions.RequestManager)); store.Add(new ServerCpu()); store.Add(new ServerTotalMemory()); store.Add(new ServerUrl(serverOptions.SystemDatabase.Configuration)); store.Add(new ServerIndexingErrors(serverOptions.DatabaseLandlord)); store.Add(new ServerLastRequestTime(serverOptions.RequestManager)); store.Add(new DatabaseLoadedCount(serverOptions.DatabaseLandlord)); store.Add(new DatabaseTotalCount(serverOptions.SystemDatabase)); return(store); }
private SnmpEngine CreateEngine() { // TODO: this is a hack. review it later. var store = new ObjectStore(); store.Add(new SysDescr()); store.Add(new SysObjectId()); store.Add(new SysUpTime()); store.Add(new SysContact()); store.Add(new SysName()); store.Add(new SysLocation()); store.Add(new SysServices()); store.Add(new SysORLastChange()); store.Add(new SysORTable()); store.Add(new IfNumber()); store.Add(new IfTable()); store.Add(new TimeoutObject()); var users = new UserRegistry(); users.Add(new OctetString("neither"), DefaultPrivacyProvider.DefaultPair); users.Add(new OctetString("authen"), new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("authentication")))); #if !NETSTANDARD users.Add(new OctetString("privacy"), new DESPrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")))); #endif var getv1 = new GetV1MessageHandler(); var getv1Mapping = new HandlerMapping("v1", "GET", getv1); var getv23 = new GetMessageHandler(); var getv23Mapping = new HandlerMapping("v2,v3", "GET", getv23); var setv1 = new SetV1MessageHandler(); var setv1Mapping = new HandlerMapping("v1", "SET", setv1); var setv23 = new SetMessageHandler(); var setv23Mapping = new HandlerMapping("v2,v3", "SET", setv23); var getnextv1 = new GetNextV1MessageHandler(); var getnextv1Mapping = new HandlerMapping("v1", "GETNEXT", getnextv1); var getnextv23 = new GetNextMessageHandler(); var getnextv23Mapping = new HandlerMapping("v2,v3", "GETNEXT", getnextv23); var getbulk = new GetBulkMessageHandler(); var getbulkMapping = new HandlerMapping("v2,v3", "GETBULK", getbulk); var v1 = new Version1MembershipProvider(new OctetString("public"), new OctetString("public")); var v2 = new Version2MembershipProvider(new OctetString("public"), new OctetString("public")); var v3 = new Version3MembershipProvider(); var membership = new ComposedMembershipProvider(new IMembershipProvider[] { v1, v2, v3 }); var handlerFactory = new MessageHandlerFactory(new[] { getv1Mapping, getv23Mapping, setv1Mapping, setv23Mapping, getnextv1Mapping, getnextv23Mapping, getbulkMapping }); var pipelineFactory = new SnmpApplicationFactory(store, membership, handlerFactory); var listener = new Listener { Users = users }; listener.ExceptionRaised += (sender, e) => { Assert.True(false, "unexpected exception"); }; return(new SnmpEngine(pipelineFactory, listener, new EngineGroup())); }
public void IfObjectIsNotNeuralNet_Throw() { ObjectStore.Add("x", "y"); Assert.Throws <NNXException>(() => ExcelFunctions.GetWeights("x", 2)); }
private static ObjectStore CreateStore(RavenServer server) { var store = new ObjectStore(); store.Add(new ServerUrl(server.Configuration)); store.Add(new ServerPublicUrl(server.Configuration)); store.Add(new ServerTcpUrl(server.Configuration)); store.Add(new ServerPublicTcpUrl(server.Configuration)); store.Add(new ServerVersion()); store.Add(new ServerFullVersion()); store.Add(new ServerUpTime(server.Statistics)); store.Add(new ServerUpTimeGlobal(server.Statistics)); store.Add(new ServerPid()); store.Add(new ServerConcurrentRequests(server.Metrics)); store.Add(new ServerTotalRequests(server.Metrics)); store.Add(new ServerRequestsPerSecond(server.Metrics)); store.Add(new ProcessCpu(server.MetricCacher, server.CpuUsageCalculator)); store.Add(new MachineCpu(server.MetricCacher, server.CpuUsageCalculator)); store.Add(new CpuCreditsBase(server.CpuCreditsBalance)); store.Add(new CpuCreditsMax(server.CpuCreditsBalance)); store.Add(new CpuCreditsRemaining(server.CpuCreditsBalance)); store.Add(new CpuCreditsCurrentConsumption(server.CpuCreditsBalance)); store.Add(new CpuCreditsBackgroundTasksAlertRaised(server.CpuCreditsBalance)); store.Add(new CpuCreditsFailoverAlertRaised(server.CpuCreditsBalance)); store.Add(new CpuCreditsAlertRaised(server.CpuCreditsBalance)); store.Add(new ServerTotalMemory(server.MetricCacher)); store.Add(new ServerLowMemoryFlag()); store.Add(new ServerTotalSwapSize(server.MetricCacher)); store.Add(new ServerTotalSwapUsage(server.MetricCacher)); store.Add(new ServerWorkingSetSwapUsage(server.MetricCacher)); store.Add(new ServerDirtyMemory()); store.Add(new ServerLastRequestTime(server.Statistics)); store.Add(new ServerLastAuthorizedNonClusterAdminRequestTime(server.Statistics)); store.Add(new DatabaseLoadedCount(server.ServerStore.DatabasesLandlord)); store.Add(new DatabaseTotalCount(server.ServerStore)); store.Add(new DatabaseOldestBackup(server.ServerStore)); store.Add(new ClusterNodeState(server.ServerStore)); store.Add(new ClusterNodeTag(server.ServerStore)); store.Add(new ClusterId(server.ServerStore)); store.Add(new ClusterIndex(server.ServerStore)); store.Add(new ClusterTerm(server.ServerStore)); store.Add(new ServerLicenseType(server.ServerStore)); store.Add(new ServerLicenseExpiration(server.ServerStore)); store.Add(new ServerLicenseExpirationLeft(server.ServerStore)); store.Add(new ServerLicenseUtilizedCpuCores(server.ServerStore)); store.Add(new ServerLicenseMaxCpuCores(server.ServerStore)); store.Add(new ServerStorageUsedSize(server.ServerStore)); store.Add(new ServerStorageTotalSize(server.ServerStore)); store.Add(new ServerStorageDiskRemainingSpace(server.ServerStore)); store.Add(new ServerStorageDiskRemainingSpacePercentage(server.ServerStore)); store.Add(new ServerCertificateExpiration(server.ServerStore)); store.Add(new ServerCertificateExpirationLeft(server.ServerStore)); store.Add(new WellKnownAdminCertificates(server.ServerStore)); store.Add(new MachineProcessorCount()); store.Add(new MachineAssignedProcessorCount()); store.Add(new ServerBackupsCurrent(server.ServerStore)); store.Add(new ServerBackupsMax(server.ServerStore)); return(store); }
private static ObjectStore CreateStore(RavenServer server) { var store = new ObjectStore(); store.Add(new ServerUrl(server.Configuration)); store.Add(new ServerPublicUrl(server.Configuration)); store.Add(new ServerTcpUrl(server.Configuration)); store.Add(new ServerPublicTcpUrl(server.Configuration)); store.Add(new ServerVersion()); store.Add(new ServerFullVersion()); store.Add(new ServerUpTime(server.Statistics)); store.Add(new ServerUpTimeGlobal(server.Statistics)); store.Add(new ServerPid()); store.Add(new ServerConcurrentRequests(server.Metrics)); store.Add(new ServerTotalRequests(server.Metrics)); store.Add(new ServerRequestsPerSecond(server.Metrics)); store.Add(new ProcessCpu(server.CpuUsageCalculator)); store.Add(new MachineCpu(server.CpuUsageCalculator)); store.Add(new CpuCreditsBase(server.CpuCreditsBalance)); store.Add(new CpuCreditsMax(server.CpuCreditsBalance)); store.Add(new CpuCreditsRemaining(server.CpuCreditsBalance)); store.Add(new CpuCreditsCurrentConsumption(server.CpuCreditsBalance)); store.Add(new CpuCreditsBackgroundTasksAlertRaised(server.CpuCreditsBalance)); store.Add(new CpuCreditsFailoverAlertRaised(server.CpuCreditsBalance)); store.Add(new CpuCreditsAlertRaised(server.CpuCreditsBalance)); store.Add(new ServerTotalMemory()); store.Add(new ServerLowMemoryFlag()); store.Add(new ServerLastRequestTime(server.Statistics)); store.Add(new DatabaseLoadedCount(server.ServerStore.DatabasesLandlord)); store.Add(new DatabaseTotalCount(server.ServerStore)); store.Add(new ClusterNodeState(server.ServerStore)); store.Add(new ClusterNodeTag(server.ServerStore)); store.Add(new ClusterId(server.ServerStore)); store.Add(new ClusterIndex(server.ServerStore)); store.Add(new ClusterTerm(server.ServerStore)); store.Add(new ServerLicenseType(server.ServerStore)); store.Add(new ServerLicenseExpiration(server.ServerStore)); store.Add(new ServerLicenseExpirationLeft(server.ServerStore)); store.Add(new ServerStorageUsedSize(server.ServerStore)); store.Add(new ServerStorageTotalSize(server.ServerStore)); store.Add(new ServerStorageDiskRemainingSpace(server.ServerStore)); store.Add(new ServerStorageDiskRemainingSpacePercentage(server.ServerStore)); return(store); }