public void Handle(ISnmpContext context, ObjectStore store) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (store == null) { throw new ArgumentNullException(nameof(store)); } context.CopyRequest(ErrorCode.InconsistentName, int.MaxValue); if (context.TooBig) { context.GenerateTooBig(); return; } int index = 0; ErrorCode status = ErrorCode.NoError; IList <Variable> result = new List <Variable>(); foreach (Variable v in context.Request.Pdu().Variables) { index++; ScalarObject obj = store.GetObject(v.Id); if (obj != null) { try { obj.Data = v.Data; } catch (AccessFailureException) { status = ErrorCode.NoAccess; } catch (ArgumentException ex) { if (!Enum.TryParse <ErrorCode>(ex.Message, out status) || status == ErrorCode.NoError) { status = ErrorCode.WrongType; } } catch (Exception) { status = ErrorCode.GenError; } } else { status = ErrorCode.NotWritable; } if (status != ErrorCode.NoError) { context.CopyRequest(status, index); return; } result.Add(v); } context.GenerateResponse(result); }
/// <summary> /// Initializes a new instance of the <see cref="SnmpApplicationFactory"/> class. /// </summary> /// <param name="store">The store.</param> /// <param name="membershipProvider">The membership provider.</param> /// <param name="factory">The factory.</param> public SnmpApplicationFactory(ObjectStore store, IMembershipProvider membershipProvider, MessageHandlerFactory factory) : this(null, store, membershipProvider, factory) // TODO: handle the null case in the future. { }
public void Handle(ISnmpContext context, ObjectStore store) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (store == null) { throw new ArgumentNullException(nameof(store)); } ISnmpPdu pdu = context.Request.Pdu(); IList <Variable> result = new List <Variable>(); int index = 0; int nonrepeaters = pdu.ErrorStatus.ToInt32(); IList <Variable> variables = pdu.Variables; for (int i = 0; i < nonrepeaters; i++) { Variable v = variables[i]; index++; try { ScalarObject next = store.GetNextObject(v.Id); result.Add(next == null ? new Variable(v.Id, new EndOfMibView()) : next.Variable); } catch (Exception) { context.CopyRequest(ErrorCode.GenError, index); return; } } for (int j = nonrepeaters; j < variables.Count; j++) { Variable v = variables[j]; index++; Variable temp = v; int repetition = pdu.ErrorIndex.ToInt32(); while (repetition-- > 0) { try { ScalarObject next = store.GetNextObject(temp.Id); if (next == null) { temp = new Variable(temp.Id, new EndOfMibView()); result.Add(temp); break; } // TODO: how to handle write only object here? result.Add(next.Variable); temp = next.Variable; } catch (Exception) { context.CopyRequest(ErrorCode.GenError, index); return; } } } context.GenerateResponse(result); }